mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
[Settings]Show No network error when trying to update (#21500)
This commit is contained in:
@@ -1744,6 +1744,9 @@ From there, simply click on one of the supported files in the File Explorer and
|
|||||||
<data name="General_UpToDate.Title" xml:space="preserve">
|
<data name="General_UpToDate.Title" xml:space="preserve">
|
||||||
<value>PowerToys is up to date</value>
|
<value>PowerToys is up to date</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="General_CantCheck.Title" xml:space="preserve">
|
||||||
|
<value>Network error. Please try again later</value>
|
||||||
|
</data>
|
||||||
<data name="General_DownloadAndInstall.Content" xml:space="preserve">
|
<data name="General_DownloadAndInstall.Content" xml:space="preserve">
|
||||||
<value>Download & install</value>
|
<value>Download & install</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using System.Diagnostics;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Abstractions;
|
using System.IO.Abstractions;
|
||||||
|
using System.Net.NetworkInformation;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
@@ -159,6 +160,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
|
|
||||||
private bool _isNewVersionDownloading;
|
private bool _isNewVersionDownloading;
|
||||||
private bool _isNewVersionChecked;
|
private bool _isNewVersionChecked;
|
||||||
|
private bool _isNoNetwork;
|
||||||
|
|
||||||
private bool _settingsBackupRestoreMessageVisible;
|
private bool _settingsBackupRestoreMessageVisible;
|
||||||
private string _settingsBackupMessage;
|
private string _settingsBackupMessage;
|
||||||
@@ -592,6 +594,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsNoNetwork
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _isNoNetwork;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool SettingsBackupRestoreMessageVisible
|
public bool SettingsBackupRestoreMessageVisible
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -737,6 +747,23 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
// callback function to launch the URL to check for updates.
|
// callback function to launch the URL to check for updates.
|
||||||
private void CheckForUpdatesClick()
|
private void CheckForUpdatesClick()
|
||||||
{
|
{
|
||||||
|
// check if network is available
|
||||||
|
bool isNetAvailable = IsNetworkAvailable();
|
||||||
|
|
||||||
|
// check if the state changed
|
||||||
|
bool prevState = _isNoNetwork;
|
||||||
|
_isNoNetwork = !isNetAvailable;
|
||||||
|
if (prevState != _isNoNetwork)
|
||||||
|
{
|
||||||
|
NotifyPropertyChanged(nameof(IsNoNetwork));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isNetAvailable)
|
||||||
|
{
|
||||||
|
_isNewVersionDownloading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
RefreshUpdatingState();
|
RefreshUpdatingState();
|
||||||
IsNewVersionDownloading = string.IsNullOrEmpty(UpdatingSettingsConfig.DownloadedInstallerFilename);
|
IsNewVersionDownloading = string.IsNullOrEmpty(UpdatingSettingsConfig.DownloadedInstallerFilename);
|
||||||
NotifyPropertyChanged(nameof(IsDownloadAllowed));
|
NotifyPropertyChanged(nameof(IsDownloadAllowed));
|
||||||
@@ -886,5 +913,48 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
NotifyPropertyChanged(nameof(IsDownloadAllowed));
|
NotifyPropertyChanged(nameof(IsDownloadAllowed));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether any network connection is available
|
||||||
|
/// Filter virtual network cards.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// <c>true</c> if a network connection is available; otherwise, <c>false</c>.
|
||||||
|
/// </returns>
|
||||||
|
public static bool IsNetworkAvailable()
|
||||||
|
{
|
||||||
|
if (!NetworkInterface.GetIsNetworkAvailable())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
|
||||||
|
{
|
||||||
|
// discard because of standard reasons
|
||||||
|
if ((ni.OperationalStatus != OperationalStatus.Up) ||
|
||||||
|
(ni.NetworkInterfaceType == NetworkInterfaceType.Loopback) ||
|
||||||
|
(ni.NetworkInterfaceType == NetworkInterfaceType.Tunnel))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// discard virtual cards (virtual box, virtual pc, etc.)
|
||||||
|
if (ni.Description.Contains("virtual", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
ni.Name.Contains("virtual", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// discard "Microsoft Loopback Adapter", it will not show as NetworkInterfaceType.Loopback but as Ethernet Card.
|
||||||
|
if (ni.Description.Equals("Microsoft Loopback Adapter", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,13 @@
|
|||||||
IsTabStop="{Binding IsNewVersionCheckedAndUpToDate, Mode=OneWay}"
|
IsTabStop="{Binding IsNewVersionCheckedAndUpToDate, Mode=OneWay}"
|
||||||
IsOpen="{Binding IsNewVersionCheckedAndUpToDate, Mode=OneWay}"/>
|
IsOpen="{Binding IsNewVersionCheckedAndUpToDate, Mode=OneWay}"/>
|
||||||
|
|
||||||
|
<!-- Network error while checking for new version -->
|
||||||
|
<InfoBar x:Uid="General_CantCheck"
|
||||||
|
IsClosable="False"
|
||||||
|
Severity="Error"
|
||||||
|
IsTabStop="{Binding IsNoNetwork, Mode=OneWay}"
|
||||||
|
IsOpen="{Binding IsNoNetwork, Mode=OneWay}"/>
|
||||||
|
|
||||||
<!-- New version available -->
|
<!-- New version available -->
|
||||||
<InfoBar x:Uid="General_NewVersionAvailable"
|
<InfoBar x:Uid="General_NewVersionAvailable"
|
||||||
IsClosable="False"
|
IsClosable="False"
|
||||||
|
|||||||
Reference in New Issue
Block a user