diff --git a/src/common/updating/updateState.h b/src/common/updating/updateState.h index 35ca699a47..6aba8d969b 100644 --- a/src/common/updating/updateState.h +++ b/src/common/updating/updateState.h @@ -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 githubUpdateLastCheckedDate; diff --git a/src/runner/UpdateUtils.cpp b/src/runner/UpdateUtils.cpp index 0b182e4a3d..8445fdcc6b 100644 --- a/src/runner/UpdateUtils.cpp +++ b/src/runner/UpdateUtils.cpp @@ -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); diff --git a/src/settings-ui/Settings.UI.Library/UpdatingSettings.cs b/src/settings-ui/Settings.UI.Library/UpdatingSettings.cs index e3ae5706ff..16e9e50ab7 100644 --- a/src/settings-ui/Settings.UI.Library/UpdatingSettings.cs +++ b/src/settings-ui/Settings.UI.Library/UpdatingSettings.cs @@ -19,6 +19,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library ErrorDownloading, ReadyToDownload, ReadyToInstall, + NetworkError, } // Gets or sets a value of the updating state diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index 874c20722a..827eac8a64 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -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)); } } - - /// - /// Indicates whether any network connection is available - /// Filter virtual network cards. - /// - /// - /// true if a network connection is available; otherwise, false. - /// - 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; - } } } diff --git a/src/settings-ui/Settings.UI/Views/GeneralPage.xaml b/src/settings-ui/Settings.UI/Views/GeneralPage.xaml index c116088bd3..de3561ed0b 100644 --- a/src/settings-ui/Settings.UI/Views/GeneralPage.xaml +++ b/src/settings-ui/Settings.UI/Views/GeneralPage.xaml @@ -34,7 +34,7 @@ NavigateUri="https://github.com/microsoft/PowerToys/releases/" /> - +