diff --git a/src/common/notifications/notifications.cpp b/src/common/notifications/notifications.cpp index c3a389187e..90195b4e5f 100644 --- a/src/common/notifications/notifications.cpp +++ b/src/common/notifications/notifications.cpp @@ -282,9 +282,16 @@ void notifications::show_toast_with_activations(std::wstring message, std::wstring toast_xml; toast_xml.reserve(2048); + // 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"()"; - toast_xml += LR"({title})"; - toast_xml += LR"({message})"; + toast_xml += LR"()"; + toast_xml += std::move(title); + toast_xml += LR"()"; + toast_xml += LR"()"; + toast_xml += std::move(message); + toast_xml += LR"()"; if (params.progress_bar.has_value()) { @@ -382,8 +389,6 @@ void notifications::show_toast_with_activations(std::wstring message, notification.Group(DEFAULT_TOAST_GROUP); winrt::Windows::Foundation::Collections::StringMap map; - map.Insert(L"message", std::move(message)); - map.Insert(L"title", std::move(title)); if (params.progress_bar.has_value()) { float progress = std::clamp(params.progress_bar->progress, 0.0f, 1.0f); @@ -437,21 +442,6 @@ void notifications::update_toast_progress_bar(std::wstring_view tag, progress_ba winrt::Windows::UI::Notifications::NotificationUpdateResult res = notifier.Update(data, tag, DEFAULT_TOAST_GROUP); } -void notifications::update_toast_contents(std::wstring_view tag, std::wstring plaintext_message, std::wstring title) -{ - const auto notifier = winstore::running_as_packaged() ? - ToastNotificationManager::ToastNotificationManager::CreateToastNotifier() : - ToastNotificationManager::ToastNotificationManager::CreateToastNotifier(APPLICATION_ID); - - winrt::Windows::Foundation::Collections::StringMap map; - - map.Insert(L"title", std::move(title)); - map.Insert(L"message", std::move(plaintext_message)); - - winrt::Windows::UI::Notifications::NotificationData data(map); - winrt::Windows::UI::Notifications::NotificationUpdateResult res = notifier.Update(data, tag, DEFAULT_TOAST_GROUP); -} - void notifications::remove_toasts(std::wstring_view tag) { using namespace winrt::Windows::System; diff --git a/src/common/notifications/notifications.h b/src/common/notifications/notifications.h index 01a0a986e0..d5cee41bc4 100644 --- a/src/common/notifications/notifications.h +++ b/src/common/notifications/notifications.h @@ -62,6 +62,5 @@ namespace notifications 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 update_toast_progress_bar(std::wstring_view tag, progress_bar_params params); - void update_toast_contents(std::wstring_view tag, std::wstring plaintext_message, std::wstring title); void remove_toasts(std::wstring_view tag); }