mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-05 04:39:08 +08: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:
parent
293b06d083
commit
2f130bcc62
@ -12,7 +12,8 @@ struct UpdateState
|
||||
upToDate = 0,
|
||||
errorDownloading = 1,
|
||||
readyToDownload = 2,
|
||||
readyToInstall = 3
|
||||
readyToInstall = 3,
|
||||
networkError = 4
|
||||
} state = upToDate;
|
||||
std::wstring releasePageUrl;
|
||||
std::optional<std::time_t> githubUpdateLastCheckedDate;
|
||||
|
@ -262,20 +262,22 @@ void CheckForUpdatesCallback()
|
||||
auto new_version_info = get_github_version_info_async().get();
|
||||
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
|
||||
new_version_info = version_up_to_date{};
|
||||
// We couldn't get a new version from github for some reason, log error
|
||||
state.state = UpdateState::networkError;
|
||||
Logger::error(L"Couldn't obtain version info from github: {}", new_version_info.error());
|
||||
}
|
||||
|
||||
// Auto download setting
|
||||
bool download_update = !IsMeteredConnection() && get_general_settings().downloadUpdatesAutomatically;
|
||||
if (powertoys_gpo::getDisableAutomaticUpdateDownloadValue() == powertoys_gpo::gpo_rule_configured_enabled)
|
||||
else
|
||||
{
|
||||
Logger::info(L"Automatic download of updates is disabled by GPO.");
|
||||
download_update = false;
|
||||
// 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.");
|
||||
download_update = false;
|
||||
}
|
||||
|
||||
ProcessNewVersionInfo(*new_version_info, state, download_update, false);
|
||||
}
|
||||
|
||||
ProcessNewVersionInfo(*new_version_info, state, download_update, false);
|
||||
|
||||
UpdateState::store([&](UpdateState& v) {
|
||||
v = std::move(state);
|
||||
|
@ -19,6 +19,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
ErrorDownloading,
|
||||
ReadyToDownload,
|
||||
ReadyToInstall,
|
||||
NetworkError,
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
// 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.
|
||||
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";
|
||||
|
||||
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
@ -952,54 +933,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
PowerToysNewAvailableVersionLink = UpdatingSettingsConfig.ReleasePageLink;
|
||||
UpdateCheckedDate = UpdatingSettingsConfig.LastCheckedDateLocalized;
|
||||
|
||||
_isNoNetwork = PowerToysUpdatingState == UpdatingSettings.UpdatingState.NetworkError;
|
||||
NotifyPropertyChanged(nameof(IsNoNetwork));
|
||||
NotifyPropertyChanged(nameof(IsNewVersionDownloading));
|
||||
NotifyPropertyChanged(nameof(IsUpdatePanelVisible));
|
||||
_isNewVersionChecked = PowerToysUpdatingState == UpdatingSettings.UpdatingState.UpToDate && !IsNewVersionDownloading;
|
||||
NotifyPropertyChanged(nameof(IsNewVersionCheckedAndUpToDate));
|
||||
|
||||
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/" />
|
||||
</StackPanel>
|
||||
</labs:SettingsCard.Description>
|
||||
<Grid Visibility="{Binding PowerToysUpdatingState, Mode=OneWay, Converter={StaticResource UpdateStateToBoolConverter}, ConverterParameter=UpToDate}">
|
||||
<Grid Visibility="{Binding IsUpdatePanelVisible, Mode=OneWay}">
|
||||
<StackPanel
|
||||
VerticalAlignment="Center"
|
||||
Orientation="Horizontal"
|
||||
|
Loading…
Reference in New Issue
Block a user