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 "general_settings.h"
|
||||||
#include <common/themes/windows_colors.h>
|
#include <common/themes/windows_colors.h>
|
||||||
#include "restart_elevated.h"
|
#include "restart_elevated.h"
|
||||||
|
#include "update_state.h"
|
||||||
#include "update_utils.h"
|
#include "update_utils.h"
|
||||||
#include "centralized_kb_hook.h"
|
#include "centralized_kb_hook.h"
|
||||||
|
|
||||||
@ -19,9 +20,10 @@
|
|||||||
#include <common/version/helper.h>
|
#include <common/version/helper.h>
|
||||||
#include <common/logger/logger.h>
|
#include <common/logger/logger.h>
|
||||||
#include <common/utils/elevation.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/os-detect.h>
|
||||||
|
#include <common/utils/process_path.h>
|
||||||
|
#include <common/utils/timeutil.h>
|
||||||
|
#include <common/utils/winapi_error.h>
|
||||||
|
|
||||||
#define BUFSIZE 1024
|
#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"version", json::JsonValue::CreateStringValue(latestVersion.toWstring()));
|
||||||
json.SetNamedValue(L"isVersionLatest", json::JsonValue::CreateBooleanValue(!new_version_info));
|
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());
|
result.emplace(json.Stringify());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,6 +99,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
|||||||
private bool _autoDownloadUpdates;
|
private bool _autoDownloadUpdates;
|
||||||
|
|
||||||
private string _latestAvailableVersion = string.Empty;
|
private string _latestAvailableVersion = string.Empty;
|
||||||
|
private string _updateCheckedDate = string.Empty;
|
||||||
|
|
||||||
// Gets or sets a value indicating whether packaged.
|
// Gets or sets a value indicating whether packaged.
|
||||||
public bool 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.
|
// Temp string. Appears when a user clicks "Check for updates" button and shows latest version available on the Github.
|
||||||
public string LatestAvailableVersion
|
public string LatestAvailableVersion
|
||||||
{
|
{
|
||||||
@ -368,6 +387,17 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
|||||||
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||||
GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings);
|
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());
|
SendCheckForUpdatesConfigMSG(customaction.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -704,6 +704,9 @@
|
|||||||
<data name="General_Version.Text" xml:space="preserve">
|
<data name="General_Version.Text" xml:space="preserve">
|
||||||
<value>Version:</value>
|
<value>Version:</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="General_VersionLastChecked.Text" xml:space="preserve">
|
||||||
|
<value>Last checked: </value>
|
||||||
|
</data>
|
||||||
<data name="General_Version.AutomationProperties.Name" xml:space="preserve">
|
<data name="General_Version.AutomationProperties.Name" xml:space="preserve">
|
||||||
<value>Version</value>
|
<value>Version</value>
|
||||||
</data>
|
</data>
|
||||||
@ -873,4 +876,4 @@
|
|||||||
<data name="ColorPicker_ShowColorName.Content" xml:space="preserve">
|
<data name="ColorPicker_ShowColorName.Content" xml:space="preserve">
|
||||||
<value>Show color name</value>
|
<value>Show color name</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
@ -127,6 +127,14 @@
|
|||||||
Margin="16,0,0,0" />
|
Margin="16,0,0,0" />
|
||||||
</StackPanel>
|
</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"
|
<Button x:Uid="GeneralPage_CheckForUpdates"
|
||||||
Style="{StaticResource AccentButtonStyle}"
|
Style="{StaticResource AccentButtonStyle}"
|
||||||
|
@ -53,8 +53,8 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string version = json.GetNamedString("version");
|
string version = json.GetNamedString("version", string.Empty);
|
||||||
bool isLatest = json.GetNamedBoolean("isVersionLatest");
|
bool isLatest = json.GetNamedBoolean("isVersionLatest", false);
|
||||||
|
|
||||||
var str = string.Empty;
|
var str = string.Empty;
|
||||||
if (isLatest)
|
if (isLatest)
|
||||||
@ -71,7 +71,17 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Using CurrentCulture since this is user-facing
|
// Using CurrentCulture since this is user-facing
|
||||||
ViewModel.LatestAvailableVersion = string.Format(CultureInfo.CurrentCulture, str);
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user