[runner]Fix opening settings through the update notification (#35429)

This commit is contained in:
gokcekantarci 2024-10-28 15:10:18 +03:00 committed by GitHub
parent 515f2386d9
commit da52d485a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 7 deletions

View File

@ -178,7 +178,8 @@ void notifications::show_toast_with_activations(std::wstring message,
std::wstring title, std::wstring title,
std::wstring_view background_handler_id, std::wstring_view background_handler_id,
std::vector<action_t> actions, std::vector<action_t> actions,
toast_params params) toast_params params,
std::wstring launch_uri)
{ {
// DO NOT LOCALIZE any string in this function, because they're XML tags and a subject to // DO NOT LOCALIZE any string in this function, because they're XML tags and a subject to
// https://learn.microsoft.com/windows/uwp/design/shell/tiles-and-notifications/toast-xml-schema // https://learn.microsoft.com/windows/uwp/design/shell/tiles-and-notifications/toast-xml-schema
@ -189,7 +190,18 @@ void notifications::show_toast_with_activations(std::wstring message,
// We must set toast's title and contents immediately, because some of the toasts we send could be snoozed. // We must set toast's title and contents immediately, because some of the toasts we send could be snoozed.
// Windows instantiates the snoozed toast from scratch before showing it again, so all bindings that were set // Windows instantiates the snoozed toast from scratch before showing it again, so all bindings that were set
// using NotificationData would be empty. // using NotificationData would be empty.
toast_xml += LR"(<?xml version="1.0"?><toast><visual><binding template="ToastGeneric">)"; // Add the launch attribute if launch_uri is provided, otherwise omit it
toast_xml += LR"(<?xml version="1.0"?>)";
if (!launch_uri.empty())
{
toast_xml += LR"(<toast launch=")" + launch_uri + LR"(" activationType="protocol">)"; // Use the launch URI if provided
}
else
{
toast_xml += LR"(<toast>)"; // No launch attribute if empty
}
toast_xml += LR"(<visual><binding template="ToastGeneric">)";
toast_xml += LR"(<text id="1">)"; toast_xml += LR"(<text id="1">)";
toast_xml += std::move(title); toast_xml += std::move(title);
toast_xml += LR"(</text>)"; toast_xml += LR"(</text>)";

View File

@ -56,7 +56,7 @@ namespace notifications
using action_t = std::variant<link_button, background_activated_button, snooze_button>; using action_t = std::variant<link_button, background_activated_button, snooze_button>;
void show_toast(std::wstring plaintext_message, std::wstring title, toast_params params = {}); void show_toast(std::wstring plaintext_message, std::wstring title, toast_params params = {});
void show_toast_with_activations(std::wstring plaintext_message, std::wstring title, std::wstring_view background_handler_id, std::vector<action_t> actions, toast_params params = {}); void show_toast_with_activations(std::wstring plaintext_message, std::wstring title, std::wstring_view background_handler_id, std::vector<action_t> actions, toast_params params = {}, std::wstring launch_uri = L"");
void update_toast_progress_bar(std::wstring_view tag, progress_bar_params params); void update_toast_progress_bar(std::wstring_view tag, progress_bar_params params);
void remove_toasts_by_tag(std::wstring_view tag); void remove_toasts_by_tag(std::wstring_view tag);
void remove_all_scheduled_toasts(); void remove_all_scheduled_toasts();

View File

@ -53,8 +53,9 @@ void ShowNewVersionAvailable(const new_version_download_info& info)
{ link_button{ GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_UPDATE_NOW), { link_button{ GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_UPDATE_NOW),
L"powertoys://update_now/" }, L"powertoys://update_now/" },
link_button{ GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_MORE_INFO), link_button{ GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_MORE_INFO),
L"powertoys://open_settings/" } }, L"powertoys://open_overview/" } },
std::move(toast_params)); std::move(toast_params),
L"powertoys://open_overview/");
} }
void ShowOpenSettingsForUpdate() void ShowOpenSettingsForUpdate()
@ -65,13 +66,14 @@ void ShowOpenSettingsForUpdate()
std::vector<action_t> actions = { std::vector<action_t> actions = {
link_button{ GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_MORE_INFO), link_button{ GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_MORE_INFO),
L"powertoys://open_settings/" }, L"powertoys://open_overview/" },
}; };
show_toast_with_activations(GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_AVAILABLE), show_toast_with_activations(GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_AVAILABLE),
GET_RESOURCE_STRING(IDS_TOAST_TITLE), GET_RESOURCE_STRING(IDS_TOAST_TITLE),
{}, {},
std::move(actions), std::move(actions),
std::move(toast_params)); std::move(toast_params),
L"powertoys://open_overview/");
} }
SHELLEXECUTEINFOW LaunchPowerToysUpdate(const wchar_t* cmdline) SHELLEXECUTEINFOW LaunchPowerToysUpdate(const wchar_t* cmdline)

View File

@ -275,6 +275,7 @@ toast_notification_handler_result toast_notification_handler(const std::wstring_
const std::wstring_view cant_drag_elevated_disable = L"cant_drag_elevated_disable/"; const std::wstring_view cant_drag_elevated_disable = L"cant_drag_elevated_disable/";
const std::wstring_view couldnt_toggle_powerpreview_modules_disable = L"couldnt_toggle_powerpreview_modules_disable/"; const std::wstring_view couldnt_toggle_powerpreview_modules_disable = L"couldnt_toggle_powerpreview_modules_disable/";
const std::wstring_view open_settings = L"open_settings/"; const std::wstring_view open_settings = L"open_settings/";
const std::wstring_view open_overview = L"open_overview/";
const std::wstring_view update_now = L"update_now/"; const std::wstring_view update_now = L"update_now/";
if (param == cant_drag_elevated_disable) if (param == cant_drag_elevated_disable)
@ -296,6 +297,11 @@ toast_notification_handler_result toast_notification_handler(const std::wstring_
open_menu_from_another_instance(std::nullopt); open_menu_from_another_instance(std::nullopt);
return toast_notification_handler_result::exit_success; return toast_notification_handler_result::exit_success;
} }
else if (param == open_overview)
{
open_menu_from_another_instance("Overview");
return toast_notification_handler_result::exit_success;
}
else else
{ {
return toast_notification_handler_result::exit_error; return toast_notification_handler_result::exit_error;