mirror of
https://github.com/microsoft/PowerToys
synced 2025-08-31 06:25:20 +00:00
[Runner]Fix network errors when checking for updates (#26742)
* General: re-implementing network error handling * Remove unreferenced dead code * Minor modification in the update procedure. Removing the code part which updates the UI before the real check on new version. UI will be updated after the real check is done.
This commit is contained in:
@@ -12,7 +12,8 @@ struct UpdateState
|
|||||||
upToDate = 0,
|
upToDate = 0,
|
||||||
errorDownloading = 1,
|
errorDownloading = 1,
|
||||||
readyToDownload = 2,
|
readyToDownload = 2,
|
||||||
readyToInstall = 3
|
readyToInstall = 3,
|
||||||
|
networkError = 4
|
||||||
} state = upToDate;
|
} state = upToDate;
|
||||||
std::wstring releasePageUrl;
|
std::wstring releasePageUrl;
|
||||||
std::optional<std::time_t> githubUpdateLastCheckedDate;
|
std::optional<std::time_t> githubUpdateLastCheckedDate;
|
||||||
|
@@ -262,20 +262,22 @@ void CheckForUpdatesCallback()
|
|||||||
auto new_version_info = get_github_version_info_async().get();
|
auto new_version_info = get_github_version_info_async().get();
|
||||||
if (!new_version_info)
|
if (!new_version_info)
|
||||||
{
|
{
|
||||||
// If we couldn't get a new version from github for some reason, assume we're up to date, but also log error
|
// We couldn't get a new version from github for some reason, log error
|
||||||
new_version_info = version_up_to_date{};
|
state.state = UpdateState::networkError;
|
||||||
Logger::error(L"Couldn't obtain version info from github: {}", new_version_info.error());
|
Logger::error(L"Couldn't obtain version info from github: {}", new_version_info.error());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// Auto download setting
|
|
||||||
bool download_update = !IsMeteredConnection() && get_general_settings().downloadUpdatesAutomatically;
|
|
||||||
if (powertoys_gpo::getDisableAutomaticUpdateDownloadValue() == powertoys_gpo::gpo_rule_configured_enabled)
|
|
||||||
{
|
{
|
||||||
Logger::info(L"Automatic download of updates is disabled by GPO.");
|
// Auto download setting
|
||||||
download_update = false;
|
bool download_update = !IsMeteredConnection() && get_general_settings().downloadUpdatesAutomatically;
|
||||||
|
if (powertoys_gpo::getDisableAutomaticUpdateDownloadValue() == powertoys_gpo::gpo_rule_configured_enabled)
|
||||||
|
{
|
||||||
|
Logger::info(L"Automatic download of updates is disabled by GPO.");
|
||||||
|
download_update = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProcessNewVersionInfo(*new_version_info, state, download_update, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessNewVersionInfo(*new_version_info, state, download_update, false);
|
|
||||||
|
|
||||||
UpdateState::store([&](UpdateState& v) {
|
UpdateState::store([&](UpdateState& v) {
|
||||||
v = std::move(state);
|
v = std::move(state);
|
||||||
|
@@ -19,6 +19,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
|||||||
ErrorDownloading,
|
ErrorDownloading,
|
||||||
ReadyToDownload,
|
ReadyToDownload,
|
||||||
ReadyToInstall,
|
ReadyToInstall,
|
||||||
|
NetworkError,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets or sets a value of the updating state
|
// Gets or sets a value of the updating state
|
||||||
|
@@ -679,6 +679,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsUpdatePanelVisible
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return PowerToysUpdatingState == UpdatingSettings.UpdatingState.UpToDate || PowerToysUpdatingState == UpdatingSettings.UpdatingState.NetworkError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null, bool reDoBackupDryRun = true)
|
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null, bool reDoBackupDryRun = true)
|
||||||
{
|
{
|
||||||
// Notify UI of property change
|
// Notify UI of property change
|
||||||
@@ -792,33 +800,6 @@ 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();
|
|
||||||
IsNewVersionDownloading = string.IsNullOrEmpty(UpdatingSettingsConfig.DownloadedInstallerFilename);
|
|
||||||
NotifyPropertyChanged(nameof(IsDownloadAllowed));
|
|
||||||
|
|
||||||
if (_isNewVersionChecked)
|
|
||||||
{
|
|
||||||
_isNewVersionChecked = !IsNewVersionDownloading;
|
|
||||||
NotifyPropertyChanged(nameof(IsNewVersionCheckedAndUpToDate));
|
|
||||||
}
|
|
||||||
|
|
||||||
GeneralSettingsConfig.CustomActionName = "check_for_updates";
|
GeneralSettingsConfig.CustomActionName = "check_for_updates";
|
||||||
|
|
||||||
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||||
@@ -952,54 +933,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
PowerToysNewAvailableVersionLink = UpdatingSettingsConfig.ReleasePageLink;
|
PowerToysNewAvailableVersionLink = UpdatingSettingsConfig.ReleasePageLink;
|
||||||
UpdateCheckedDate = UpdatingSettingsConfig.LastCheckedDateLocalized;
|
UpdateCheckedDate = UpdatingSettingsConfig.LastCheckedDateLocalized;
|
||||||
|
|
||||||
|
_isNoNetwork = PowerToysUpdatingState == UpdatingSettings.UpdatingState.NetworkError;
|
||||||
|
NotifyPropertyChanged(nameof(IsNoNetwork));
|
||||||
|
NotifyPropertyChanged(nameof(IsNewVersionDownloading));
|
||||||
|
NotifyPropertyChanged(nameof(IsUpdatePanelVisible));
|
||||||
_isNewVersionChecked = PowerToysUpdatingState == UpdatingSettings.UpdatingState.UpToDate && !IsNewVersionDownloading;
|
_isNewVersionChecked = PowerToysUpdatingState == UpdatingSettings.UpdatingState.UpToDate && !IsNewVersionDownloading;
|
||||||
NotifyPropertyChanged(nameof(IsNewVersionCheckedAndUpToDate));
|
NotifyPropertyChanged(nameof(IsNewVersionCheckedAndUpToDate));
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,7 +34,7 @@
|
|||||||
NavigateUri="https://github.com/microsoft/PowerToys/releases/" />
|
NavigateUri="https://github.com/microsoft/PowerToys/releases/" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</labs:SettingsCard.Description>
|
</labs:SettingsCard.Description>
|
||||||
<Grid Visibility="{Binding PowerToysUpdatingState, Mode=OneWay, Converter={StaticResource UpdateStateToBoolConverter}, ConverterParameter=UpToDate}">
|
<Grid Visibility="{Binding IsUpdatePanelVisible, Mode=OneWay}">
|
||||||
<StackPanel
|
<StackPanel
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Orientation="Horizontal"
|
Orientation="Horizontal"
|
||||||
|
Reference in New Issue
Block a user