From da52d485a6d47506897cac4c56e14abcebfde091 Mon Sep 17 00:00:00 2001 From: gokcekantarci <115616017+gokcekantarci@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:10:18 +0300 Subject: [PATCH] [runner]Fix opening settings through the update notification (#35429) --- src/common/notifications/notifications.cpp | 16 ++++++++++++++-- src/common/notifications/notifications.h | 2 +- src/runner/UpdateUtils.cpp | 10 ++++++---- src/runner/main.cpp | 6 ++++++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/common/notifications/notifications.cpp b/src/common/notifications/notifications.cpp index c0bbd3ce80..8b245cfa79 100644 --- a/src/common/notifications/notifications.cpp +++ b/src/common/notifications/notifications.cpp @@ -178,7 +178,8 @@ void notifications::show_toast_with_activations(std::wstring message, std::wstring title, std::wstring_view background_handler_id, std::vector 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 // 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. // Windows instantiates the snoozed toast from scratch before showing it again, so all bindings that were set // using NotificationData would be empty. - toast_xml += LR"()"; + // Add the launch attribute if launch_uri is provided, otherwise omit it + toast_xml += LR"()"; + if (!launch_uri.empty()) + { + toast_xml += LR"()"; // Use the launch URI if provided + } + else + { + toast_xml += LR"()"; // No launch attribute if empty + } + + toast_xml += LR"()"; toast_xml += LR"()"; toast_xml += std::move(title); toast_xml += LR"()"; diff --git a/src/common/notifications/notifications.h b/src/common/notifications/notifications.h index e0048012a1..c9a57a2ba7 100644 --- a/src/common/notifications/notifications.h +++ b/src/common/notifications/notifications.h @@ -56,7 +56,7 @@ namespace notifications using action_t = std::variant; 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 actions, toast_params params = {}); + void show_toast_with_activations(std::wstring plaintext_message, std::wstring title, std::wstring_view background_handler_id, std::vector actions, toast_params params = {}, std::wstring launch_uri = L""); void update_toast_progress_bar(std::wstring_view tag, progress_bar_params params); void remove_toasts_by_tag(std::wstring_view tag); void remove_all_scheduled_toasts(); diff --git a/src/runner/UpdateUtils.cpp b/src/runner/UpdateUtils.cpp index 4558b37cb3..23743d2001 100644 --- a/src/runner/UpdateUtils.cpp +++ b/src/runner/UpdateUtils.cpp @@ -53,8 +53,9 @@ void ShowNewVersionAvailable(const new_version_download_info& info) { link_button{ GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_UPDATE_NOW), L"powertoys://update_now/" }, link_button{ GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_MORE_INFO), - L"powertoys://open_settings/" } }, - std::move(toast_params)); + L"powertoys://open_overview/" } }, + std::move(toast_params), + L"powertoys://open_overview/"); } void ShowOpenSettingsForUpdate() @@ -65,13 +66,14 @@ void ShowOpenSettingsForUpdate() std::vector actions = { 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), GET_RESOURCE_STRING(IDS_TOAST_TITLE), {}, std::move(actions), - std::move(toast_params)); + std::move(toast_params), + L"powertoys://open_overview/"); } SHELLEXECUTEINFOW LaunchPowerToysUpdate(const wchar_t* cmdline) diff --git a/src/runner/main.cpp b/src/runner/main.cpp index bd7cabdec7..c2f45868f6 100644 --- a/src/runner/main.cpp +++ b/src/runner/main.cpp @@ -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 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_overview = L"open_overview/"; const std::wstring_view update_now = L"update_now/"; 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); 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 { return toast_notification_handler_result::exit_error;