From e58ff6c71c09ebcfb9a9636becc2a14d917162d5 Mon Sep 17 00:00:00 2001 From: Andrey Nekrasov Date: Thu, 17 Dec 2020 19:38:23 +0300 Subject: [PATCH] Auto-updating: add text for "Last checked" (#8645) --- src/runner/settings_window.cpp | 22 ++++++++++++-- .../ViewModels/GeneralViewModel.cs | 30 +++++++++++++++++++ .../Strings/en-us/Resources.resw | 5 +++- .../Views/GeneralPage.xaml | 8 +++++ .../Views/GeneralPage.xaml.cs | 16 ++++++++-- 5 files changed, 75 insertions(+), 6 deletions(-) diff --git a/src/runner/settings_window.cpp b/src/runner/settings_window.cpp index 9eaacf356a..bd8da48d5c 100644 --- a/src/runner/settings_window.cpp +++ b/src/runner/settings_window.cpp @@ -10,6 +10,7 @@ #include "general_settings.h" #include #include "restart_elevated.h" +#include "update_state.h" #include "update_utils.h" #include "centralized_kb_hook.h" @@ -19,9 +20,10 @@ #include #include #include -#include -#include #include +#include +#include +#include #define BUFSIZE 1024 @@ -92,6 +94,22 @@ std::optional dispatch_json_action_to_module(const json::JsonObjec json.SetNamedValue(L"version", json::JsonValue::CreateStringValue(latestVersion.toWstring())); json.SetNamedValue(L"isVersionLatest", json::JsonValue::CreateBooleanValue(!new_version_info)); + result.emplace(json.Stringify()); + UpdateState::store([](UpdateState& state) { + state.github_update_last_checked_date.emplace(timeutil::now()); + }); + } + else if (action == L"request_update_state_date") + { + json::JsonObject json; + + auto update_state = UpdateState::read(); + if (update_state.github_update_last_checked_date) + { + const time_t date = *update_state.github_update_last_checked_date; + json.SetNamedValue(L"updateStateDate", json::JsonValue::CreateStringValue(std::to_wstring(date))); + } + result.emplace(json.Stringify()); } } diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/GeneralViewModel.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/GeneralViewModel.cs index b2e94bfce4..a7bf581ee1 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/GeneralViewModel.cs @@ -99,6 +99,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels private bool _autoDownloadUpdates; private string _latestAvailableVersion = string.Empty; + private string _updateCheckedDate = string.Empty; // Gets or sets a value indicating whether packaged. public bool Packaged @@ -333,6 +334,24 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels } } + public string UpdateCheckedDate + { + get + { + RequestUpdateCheckedDate(); + return _updateCheckedDate; + } + + set + { + if (_updateCheckedDate != value) + { + _updateCheckedDate = value; + NotifyPropertyChanged(); + } + } + } + // Temp string. Appears when a user clicks "Check for updates" button and shows latest version available on the Github. public string LatestAvailableVersion { @@ -368,6 +387,17 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig); GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings); + SendCheckForUpdatesConfigMSG(customaction.ToString()); + RequestUpdateCheckedDate(); + } + + private void RequestUpdateCheckedDate() + { + GeneralSettingsConfig.CustomActionName = "request_update_state_date"; + + OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig); + GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings); + SendCheckForUpdatesConfigMSG(customaction.ToString()); } diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw index 9d1dd3650e..9ea9377bbe 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw @@ -704,6 +704,9 @@ Version: + + Last checked: + Version @@ -873,4 +876,4 @@ Show color name - + diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml index 86161eb44e..c1e6412e9f 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml @@ -127,6 +127,14 @@ Margin="16,0,0,0" /> + + + +