mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-11 20:23:07 +08:00
Auto-updating: add text for "Last checked" (#8645)
This commit is contained in:
parent
24141abde2
commit
e58ff6c71c
@ -10,6 +10,7 @@
|
||||
#include "general_settings.h"
|
||||
#include <common/themes/windows_colors.h>
|
||||
#include "restart_elevated.h"
|
||||
#include "update_state.h"
|
||||
#include "update_utils.h"
|
||||
#include "centralized_kb_hook.h"
|
||||
|
||||
@ -19,9 +20,10 @@
|
||||
#include <common/version/helper.h>
|
||||
#include <common/logger/logger.h>
|
||||
#include <common/utils/elevation.h>
|
||||
#include <common/utils/winapi_error.h>
|
||||
#include <common/utils/process_path.h>
|
||||
#include <common/utils/os-detect.h>
|
||||
#include <common/utils/process_path.h>
|
||||
#include <common/utils/timeutil.h>
|
||||
#include <common/utils/winapi_error.h>
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
@ -92,6 +94,22 @@ std::optional<std::wstring> 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());
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -704,6 +704,9 @@
|
||||
<data name="General_Version.Text" xml:space="preserve">
|
||||
<value>Version:</value>
|
||||
</data>
|
||||
<data name="General_VersionLastChecked.Text" xml:space="preserve">
|
||||
<value>Last checked: </value>
|
||||
</data>
|
||||
<data name="General_Version.AutomationProperties.Name" xml:space="preserve">
|
||||
<value>Version</value>
|
||||
</data>
|
||||
|
@ -127,6 +127,14 @@
|
||||
Margin="16,0,0,0" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="{StaticResource SmallBottomMargin}"
|
||||
AutomationProperties.LabeledBy="{Binding ElementName=General_VersionLastChecked}">
|
||||
<TextBlock x:Name="General_VersionLastChecked" x:Uid="General_VersionLastChecked" />
|
||||
<TextBlock Text="{x:Bind ViewModel.UpdateCheckedDate, Mode=OneWay}"
|
||||
Foreground="{ThemeResource ListViewItemForegroundPointerOver}"
|
||||
Margin="6,0" />
|
||||
</StackPanel>
|
||||
|
||||
<Button x:Uid="GeneralPage_CheckForUpdates"
|
||||
Style="{StaticResource AccentButtonStyle}"
|
||||
|
@ -53,8 +53,8 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
{
|
||||
try
|
||||
{
|
||||
string version = json.GetNamedString("version");
|
||||
bool isLatest = json.GetNamedBoolean("isVersionLatest");
|
||||
string version = json.GetNamedString("version", string.Empty);
|
||||
bool isLatest = json.GetNamedBoolean("isVersionLatest", false);
|
||||
|
||||
var str = string.Empty;
|
||||
if (isLatest)
|
||||
@ -71,8 +71,18 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
}
|
||||
|
||||
// Using CurrentCulture since this is user-facing
|
||||
if (!string.IsNullOrEmpty(str))
|
||||
{
|
||||
ViewModel.LatestAvailableVersion = string.Format(CultureInfo.CurrentCulture, str);
|
||||
}
|
||||
|
||||
string updateStateDate = json.GetNamedString("updateStateDate", string.Empty);
|
||||
if (!string.IsNullOrEmpty(updateStateDate) && long.TryParse(updateStateDate, out var uTCTime))
|
||||
{
|
||||
var localTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(uTCTime).ToLocalTime();
|
||||
ViewModel.UpdateCheckedDate = localTime.ToString(CultureInfo.CurrentCulture);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("Exception encountered when reading the version.", e);
|
||||
|
Loading…
Reference in New Issue
Block a user