mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 19:27:56 +01:00
[Settings] Temporary string showing the latest available version (#6254)
This commit is contained in:
@@ -238,16 +238,17 @@ namespace updating
|
||||
}
|
||||
}
|
||||
|
||||
std::future<void> check_new_version_available()
|
||||
std::future<std::wstring> check_new_version_available()
|
||||
{
|
||||
const auto new_version = co_await get_new_github_version_info_async();
|
||||
if (!new_version)
|
||||
{
|
||||
updating::notifications::show_unavailable();
|
||||
co_return;
|
||||
co_return VersionHelper{ VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION }.toWstring();
|
||||
}
|
||||
|
||||
updating::notifications::show_available(new_version.value());
|
||||
co_return new_version->version_string;
|
||||
}
|
||||
|
||||
std::future<std::wstring> download_update()
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace updating
|
||||
std::future<void> try_autoupdate(const bool download_updates_automatically);
|
||||
std::filesystem::path get_pending_updates_path();
|
||||
|
||||
std::future<void> check_new_version_available();
|
||||
std::future<std::wstring> check_new_version_available();
|
||||
std::future<std::wstring> download_update();
|
||||
|
||||
// non-localized
|
||||
|
||||
@@ -106,6 +106,8 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
|
||||
private bool _isSystemThemeRadioButtonChecked = false;
|
||||
private bool _autoDownloadUpdates = false;
|
||||
|
||||
private string _latestAvailableVersion = string.Empty;
|
||||
|
||||
// Gets or sets a value indicating whether packaged.
|
||||
public bool Packaged
|
||||
{
|
||||
@@ -328,11 +330,28 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
// Temp string. Appears when a user clicks "Check for updates" button and shows latest version available on the Github.
|
||||
public string LatestAvailableVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
return _latestAvailableVersion;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_latestAvailableVersion != value)
|
||||
{
|
||||
_latestAvailableVersion = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
// Notify UI of property change
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfigs);
|
||||
|
||||
SendConfigMSG(outsettings.ToString());
|
||||
|
||||
@@ -8,7 +8,7 @@ using Microsoft.PowerLauncher.Telemetry;
|
||||
using Microsoft.PowerToys.Settings.UI.Views;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.Toolkit.Wpf.UI.XamlHost;
|
||||
using Windows.UI.Popups;
|
||||
using Windows.Data.Json;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Runner
|
||||
{
|
||||
@@ -56,6 +56,25 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
|
||||
Program.GetTwoWayIPCManager().Send(msg);
|
||||
});
|
||||
|
||||
// receive IPC Message
|
||||
Program.IPCMessageReceivedCallback = (string msg) =>
|
||||
{
|
||||
if (ShellPage.ShellHandler.IPCResponseHandleList != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
JsonObject json = JsonObject.Parse(msg);
|
||||
foreach (Action<JsonObject> handle in ShellPage.ShellHandler.IPCResponseHandleList)
|
||||
{
|
||||
handle(json);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
shellPage.SetElevationStatus(Program.IsElevated);
|
||||
shellPage.SetIsUserAnAdmin(Program.IsUserAnAdmin);
|
||||
shellPage.Refresh();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
|
||||
|
||||
public static int PowerToysPID { get; set; }
|
||||
|
||||
public static Action<string> IPCMessageReceivedCallback { get; set; }
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
@@ -63,7 +65,16 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
|
||||
Environment.Exit(0);
|
||||
});
|
||||
|
||||
ipcmanager = new TwoWayPipeMessageIPCManaged(args[1], args[0], null);
|
||||
ipcmanager = new TwoWayPipeMessageIPCManaged(args[1], args[0], (string message) =>
|
||||
{
|
||||
if (IPCMessageReceivedCallback != null && message.Length > 0)
|
||||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
|
||||
{
|
||||
IPCMessageReceivedCallback(message);
|
||||
}));
|
||||
}
|
||||
});
|
||||
ipcmanager.Start();
|
||||
app.Run();
|
||||
}
|
||||
|
||||
@@ -723,4 +723,10 @@
|
||||
<data name="FancyZones_MoveWindowsBasedOnPositionCheckBoxControl.Content" xml:space="preserve">
|
||||
<value>Move windows based on their position</value>
|
||||
</data>
|
||||
<data name="GeneralSettings_NewVersionIsAvailable" xml:space="preserve">
|
||||
<value>New update available</value>
|
||||
</data>
|
||||
<data name="GeneralSettings_VersionIsLatest" xml:space="preserve">
|
||||
<value>You have the latest available version.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -116,6 +116,9 @@
|
||||
<HyperlinkButton NavigateUri="https://github.com/microsoft/PowerToys/releases" Margin="4,-6,0,0">
|
||||
<TextBlock Text="{x:Bind ViewModel.PowerToysVersion }" />
|
||||
</HyperlinkButton>
|
||||
<TextBlock Text="{x:Bind ViewModel.LatestAvailableVersion, Mode=OneWay}"
|
||||
Foreground="{ThemeResource SystemControlErrorTextForegroundBrush}"
|
||||
Margin="16,0,0,0" />
|
||||
</StackPanel>
|
||||
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
|
||||
using Windows.ApplicationModel.Resources;
|
||||
using Windows.Data.Json;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
||||
@@ -40,6 +42,34 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
ShellPage.SendRestartAdminIPCMessage,
|
||||
ShellPage.SendCheckForUpdatesIPCMessage);
|
||||
|
||||
ShellPage.ShellHandler.IPCResponseHandleList.Add((JsonObject json) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
string version = json.GetNamedString("version");
|
||||
bool isLatest = json.GetNamedBoolean("isVersionLatest");
|
||||
|
||||
var str = string.Empty;
|
||||
if (isLatest)
|
||||
{
|
||||
str = ResourceLoader.GetForCurrentView().GetString("GeneralSettings_VersionIsLatest");
|
||||
}
|
||||
else if (version != string.Empty)
|
||||
{
|
||||
str = ResourceLoader.GetForCurrentView().GetString("GeneralSettings_NewVersionIsAvailable");
|
||||
if (str != string.Empty)
|
||||
{
|
||||
str += ": " + version;
|
||||
}
|
||||
}
|
||||
|
||||
ViewModel.LatestAvailableVersion = string.Format(str);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
});
|
||||
|
||||
DataContext = ViewModel;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||
using Windows.Data.Json;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
@@ -43,6 +45,11 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
/// </summary>
|
||||
public ShellViewModel ViewModel { get; } = new ShellViewModel();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of functions that handle IPC responses.
|
||||
/// </summary>
|
||||
public List<System.Action<JsonObject>> IPCResponseHandleList { get; } = new List<System.Action<JsonObject>>();
|
||||
|
||||
public static bool IsElevated { get; set; }
|
||||
|
||||
public static bool IsUserAnAdmin { get; set; }
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include <common/json.h>
|
||||
#include <common\settings_helpers.cpp>
|
||||
#include <common/os-detect.h>
|
||||
#include <common/version.h>
|
||||
#include <common/VersionHelper.h>
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
@@ -48,8 +50,9 @@ json::JsonObject get_all_settings()
|
||||
return result;
|
||||
}
|
||||
|
||||
void dispatch_json_action_to_module(const json::JsonObject& powertoys_configs)
|
||||
std::optional<std::wstring> dispatch_json_action_to_module(const json::JsonObject& powertoys_configs)
|
||||
{
|
||||
std::optional<std::wstring> result;
|
||||
for (const auto& powertoy_element : powertoys_configs)
|
||||
{
|
||||
const std::wstring name{ powertoy_element.Key().c_str() };
|
||||
@@ -76,9 +79,15 @@ void dispatch_json_action_to_module(const json::JsonObject& powertoys_configs)
|
||||
}
|
||||
else if (action == L"check_for_updates")
|
||||
{
|
||||
std::thread{ [] {
|
||||
check_for_updates();
|
||||
} }.detach();
|
||||
std::wstring latestVersion = check_for_updates();
|
||||
VersionHelper current_version(VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION);
|
||||
bool isRunningLatest = latestVersion.compare(current_version.toWstring()) == 0;
|
||||
|
||||
json::JsonObject json;
|
||||
json.SetNamedValue(L"version", json::JsonValue::CreateStringValue(latestVersion));
|
||||
json.SetNamedValue(L"isVersionLatest", json::JsonValue::CreateBooleanValue(isRunningLatest));
|
||||
|
||||
result.emplace(json.Stringify());
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
@@ -90,6 +99,8 @@ void dispatch_json_action_to_module(const json::JsonObject& powertoys_configs)
|
||||
const auto element = powertoy_element.Value().Stringify();
|
||||
modules().at(name)->call_custom_action(element.c_str());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +157,11 @@ void dispatch_received_json(const std::wstring& json_to_parse)
|
||||
}
|
||||
else if (name == L"action")
|
||||
{
|
||||
dispatch_json_action_to_module(value.GetObjectW());
|
||||
auto result = dispatch_json_action_to_module(value.GetObjectW());
|
||||
if (result.has_value())
|
||||
{
|
||||
current_settings_ipc->send(result.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -66,15 +66,16 @@ void github_update_worker()
|
||||
}
|
||||
}
|
||||
|
||||
void check_for_updates()
|
||||
std::wstring check_for_updates()
|
||||
{
|
||||
try
|
||||
{
|
||||
updating::check_new_version_available();
|
||||
return updating::check_new_version_available().get();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Couldn't autoupdate
|
||||
return std::wstring();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
bool start_msi_uninstallation_sequence();
|
||||
void github_update_worker();
|
||||
void check_for_updates();
|
||||
std::wstring check_for_updates();
|
||||
bool launch_pending_update();
|
||||
Reference in New Issue
Block a user