mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
updating: remove all scheduled toast notifications from previous versions (#8644)
This commit is contained in:
@@ -28,6 +28,9 @@
|
||||
|
||||
using namespace winrt::Windows::ApplicationModel::Background;
|
||||
using winrt::Windows::Data::Xml::Dom::XmlDocument;
|
||||
using winrt::Windows::UI::Notifications::NotificationData;
|
||||
using winrt::Windows::UI::Notifications::NotificationUpdateResult;
|
||||
using winrt::Windows::UI::Notifications::ScheduledToastNotification;
|
||||
using winrt::Windows::UI::Notifications::ToastNotification;
|
||||
using winrt::Windows::UI::Notifications::ToastNotificationManager;
|
||||
|
||||
@@ -396,7 +399,7 @@ void notifications::show_toast_with_activations(std::wstring message,
|
||||
map.Insert(L"progressValueString", std::to_wstring(static_cast<int>(progress * 100)) + std::wstring(L"%"));
|
||||
map.Insert(L"progressTitle", params.progress_bar->progress_title);
|
||||
}
|
||||
winrt::Windows::UI::Notifications::NotificationData data{ map };
|
||||
NotificationData data{ map };
|
||||
notification.Data(std::move(data));
|
||||
|
||||
const auto notifier = winstore::running_as_packaged() ? ToastNotificationManager::ToastNotificationManager::CreateToastNotifier() :
|
||||
@@ -438,14 +441,13 @@ void notifications::update_toast_progress_bar(std::wstring_view tag, progress_ba
|
||||
map.Insert(L"progressValueString", std::to_wstring(static_cast<int>(progress * 100)) + std::wstring(L"%"));
|
||||
map.Insert(L"progressTitle", params.progress_title);
|
||||
|
||||
winrt::Windows::UI::Notifications::NotificationData data(map);
|
||||
winrt::Windows::UI::Notifications::NotificationUpdateResult res = notifier.Update(data, tag, DEFAULT_TOAST_GROUP);
|
||||
NotificationData data(map);
|
||||
NotificationUpdateResult res = notifier.Update(data, tag, DEFAULT_TOAST_GROUP);
|
||||
}
|
||||
|
||||
void notifications::remove_toasts(std::wstring_view tag)
|
||||
void notifications::remove_toasts_by_tag(std::wstring_view tag)
|
||||
{
|
||||
using namespace winrt::Windows::System;
|
||||
|
||||
try
|
||||
{
|
||||
User currentUser{ *User::FindAllAsync(UserType::LocalUser, UserAuthenticationStatus::LocallyAuthenticated).get().First() };
|
||||
@@ -455,6 +457,7 @@ void notifications::remove_toasts(std::wstring_view tag)
|
||||
}
|
||||
currentUser.GetPropertyAsync(KnownUserProperties::AccountName());
|
||||
auto toastHistory = ToastNotificationManager::GetForUser(currentUser).History();
|
||||
|
||||
toastHistory.Remove(tag, DEFAULT_TOAST_GROUP, APPLICATION_ID);
|
||||
}
|
||||
catch (...)
|
||||
@@ -462,3 +465,20 @@ void notifications::remove_toasts(std::wstring_view tag)
|
||||
// Couldn't get the current user or problem removing the toast => nothing we can do
|
||||
}
|
||||
}
|
||||
|
||||
void notifications::remove_all_scheduled_toasts()
|
||||
{
|
||||
const auto notifier = winstore::running_as_packaged() ? ToastNotificationManager::ToastNotificationManager::CreateToastNotifier() :
|
||||
ToastNotificationManager::ToastNotificationManager::CreateToastNotifier(APPLICATION_ID);
|
||||
|
||||
try
|
||||
{
|
||||
for (const auto& scheduled_toast : notifier.GetScheduledToastNotifications())
|
||||
{
|
||||
notifier.RemoveFromSchedule(scheduled_toast);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,5 +62,6 @@ 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<action_t> actions, toast_params params = {});
|
||||
void update_toast_progress_bar(std::wstring_view tag, progress_bar_params params);
|
||||
void remove_toasts(std::wstring_view tag);
|
||||
void remove_toasts_by_tag(std::wstring_view tag);
|
||||
void remove_all_scheduled_toasts();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace updating
|
||||
|
||||
void show_unavailable(const notifications::strings& strings, std::wstring reason)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
remove_toasts_by_tag(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||
show_toast(std::move(reason), strings.TOAST_TITLE, std::move(toast_params));
|
||||
@@ -32,7 +32,7 @@ namespace updating
|
||||
|
||||
void show_available(const updating::new_version_download_info& info, const notifications::strings& strings)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
remove_toasts_by_tag(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||
std::wstring contents = strings.GITHUB_NEW_VERSION_AVAILABLE;
|
||||
@@ -51,7 +51,7 @@ namespace updating
|
||||
|
||||
void show_download_start(const updating::new_version_download_info& info, const notifications::strings& strings)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
remove_toasts_by_tag(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
progress_bar_params progress_bar_params;
|
||||
std::wstring progress_title{ info.version.toWstring() };
|
||||
@@ -70,7 +70,7 @@ namespace updating
|
||||
|
||||
void show_visit_github(const updating::new_version_download_info& info, const notifications::strings& strings)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
remove_toasts_by_tag(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||
std::wstring contents = strings.GITHUB_NEW_VERSION_AVAILABLE_OFFER_VISIT;
|
||||
@@ -86,7 +86,7 @@ namespace updating
|
||||
|
||||
void show_install_error(const updating::new_version_download_info& info, const notifications::strings& strings)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
remove_toasts_by_tag(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||
std::wstring contents = strings.GITHUB_NEW_VERSION_DOWNLOAD_INSTALL_ERROR;
|
||||
@@ -101,7 +101,7 @@ namespace updating
|
||||
|
||||
void show_version_ready(const updating::new_version_download_info& info, const notifications::strings& strings)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
remove_toasts_by_tag(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||
std::wstring new_version_ready{ strings.GITHUB_NEW_VERSION_READY_TO_INSTALL };
|
||||
@@ -125,7 +125,7 @@ namespace updating
|
||||
|
||||
void show_uninstallation_error(const notifications::strings& strings)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
remove_toasts_by_tag(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
show_toast(strings.UNINSTALLATION_UNKNOWN_ERROR, strings.TOAST_TITLE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user