diff --git a/doc/devdocs/common.md b/doc/devdocs/common.md index b8c4a254d2b4..8b4cdf84ad78 100644 --- a/doc/devdocs/common.md +++ b/doc/devdocs/common.md @@ -53,8 +53,8 @@ To use UWP-style toast notifications, simply include the header and call one of void show_toast(std::wstring_view message); // #1 void show_toast_background_activated( // #2 - std::wstring_view background_handler_id, std::wstring_view message, + std::wstring_view background_handler_id, std::vector button_labels); ``` We might add more functions in the future if the need arises, e.g. `show_toast_xml` which will accept raw XML for rich customization. @@ -74,8 +74,8 @@ Implement a toast activation handler/callback as a function in [handler_function void some_func() { // ... notifications::show_toast_background_activated( - L"awesome_toast", // activation handler id L"Toast message!", // text displayed in a toast + L"awesome_toast", // activation handler id {L"Press me!", L"Also could press me!", L"I'm here to be pressed!"} // buttons in a toast ); ``` diff --git a/src/common/notifications.cpp b/src/common/notifications.cpp index 681ed15553b8..96c64df79ca0 100644 --- a/src/common/notifications.cpp +++ b/src/common/notifications.cpp @@ -25,7 +25,7 @@ void notifications::register_background_toast_handler() { try { - // Re-request access to clean up from our previous versions + // Re-request access to clean up from previous PowerToys installations BackgroundExecutionManager::RemoveAccess(); BackgroundExecutionManager::RequestAccessAsync().get(); @@ -54,10 +54,10 @@ void notifications::register_background_toast_handler() void notifications::show_toast(std::wstring_view message) { // The toast won't be actually activated in the background, since it doesn't have any buttons - show_toast_background_activated({}, message, {}); + show_toast_background_activated(message, {}, {}); } -void notifications::show_toast_background_activated(std::wstring_view background_handler_id, std::wstring_view message, std::vector button_labels) +void notifications::show_toast_background_activated(std::wstring_view message, std::wstring_view background_handler_id, std::vector button_labels) { // DO NOT LOCALIZE any string in this function, because they're XML tags and a subject to // https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/toast-xml-schema @@ -71,8 +71,8 @@ void notifications::show_toast_background_activated(std::wstring_view background for (size_t i = 0; i < size(button_labels); ++i) { toast_xml += LR"( plaintext_button_labels); + void show_toast_background_activated(std::wstring_view plaintext_message, std::wstring_view background_handler_id, std::vector plaintext_button_labels); } diff --git a/src/common/notifications_winrt/BackgroundHandler.cpp b/src/common/notifications_winrt/BackgroundHandler.cpp index cbba3b1c9de5..6a73ff6c727f 100644 --- a/src/common/notifications_winrt/BackgroundHandler.cpp +++ b/src/common/notifications_winrt/BackgroundHandler.cpp @@ -8,6 +8,7 @@ namespace winrt::PowerToysNotifications::implementation { using Windows::ApplicationModel::Background::IBackgroundTaskInstance; using Windows::UI::Notifications::ToastNotificationActionTriggerDetail; + using Windows::Foundation::WwwFormUrlDecoder; void BackgroundHandler::Run(IBackgroundTaskInstance bti) { @@ -16,11 +17,11 @@ namespace winrt::PowerToysNotifications::implementation { return; } - std::wstring button_id_and_handler_data{ details.Argument() }; - std::wstring_view button_id_and_handler{ button_id_and_handler_data }; - const auto first_semicolon_pos = button_id_and_handler.find(';'); - const size_t button_id = std::stoi(button_id_and_handler_data.substr(0, first_semicolon_pos)); - const auto handler = button_id_and_handler.substr(first_semicolon_pos + 1); - dispatch_to_backround_handler(handler, std::move(bti), button_id); + + WwwFormUrlDecoder decoder{details.Argument()}; + + const size_t button_id = std::stoi(decoder.GetFirstValueByName(L"button_id").c_str()); + auto handler = decoder.GetFirstValueByName(L"handler"); + dispatch_to_backround_handler(std::move(handler), std::move(bti), button_id); } }