mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 12:46:47 +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 namespace winrt::Windows::ApplicationModel::Background;
|
||||||
using winrt::Windows::Data::Xml::Dom::XmlDocument;
|
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::ToastNotification;
|
||||||
using winrt::Windows::UI::Notifications::ToastNotificationManager;
|
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"progressValueString", std::to_wstring(static_cast<int>(progress * 100)) + std::wstring(L"%"));
|
||||||
map.Insert(L"progressTitle", params.progress_bar->progress_title);
|
map.Insert(L"progressTitle", params.progress_bar->progress_title);
|
||||||
}
|
}
|
||||||
winrt::Windows::UI::Notifications::NotificationData data{ map };
|
NotificationData data{ map };
|
||||||
notification.Data(std::move(data));
|
notification.Data(std::move(data));
|
||||||
|
|
||||||
const auto notifier = winstore::running_as_packaged() ? ToastNotificationManager::ToastNotificationManager::CreateToastNotifier() :
|
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"progressValueString", std::to_wstring(static_cast<int>(progress * 100)) + std::wstring(L"%"));
|
||||||
map.Insert(L"progressTitle", params.progress_title);
|
map.Insert(L"progressTitle", params.progress_title);
|
||||||
|
|
||||||
winrt::Windows::UI::Notifications::NotificationData data(map);
|
NotificationData data(map);
|
||||||
winrt::Windows::UI::Notifications::NotificationUpdateResult res = notifier.Update(data, tag, DEFAULT_TOAST_GROUP);
|
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;
|
using namespace winrt::Windows::System;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
User currentUser{ *User::FindAllAsync(UserType::LocalUser, UserAuthenticationStatus::LocallyAuthenticated).get().First() };
|
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());
|
currentUser.GetPropertyAsync(KnownUserProperties::AccountName());
|
||||||
auto toastHistory = ToastNotificationManager::GetForUser(currentUser).History();
|
auto toastHistory = ToastNotificationManager::GetForUser(currentUser).History();
|
||||||
|
|
||||||
toastHistory.Remove(tag, DEFAULT_TOAST_GROUP, APPLICATION_ID);
|
toastHistory.Remove(tag, DEFAULT_TOAST_GROUP, APPLICATION_ID);
|
||||||
}
|
}
|
||||||
catch (...)
|
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
|
// 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(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 = {});
|
||||||
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(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)
|
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 };
|
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||||
show_toast(std::move(reason), strings.TOAST_TITLE, std::move(toast_params));
|
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)
|
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 };
|
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||||
std::wstring contents = strings.GITHUB_NEW_VERSION_AVAILABLE;
|
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)
|
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;
|
progress_bar_params progress_bar_params;
|
||||||
std::wstring progress_title{ info.version.toWstring() };
|
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)
|
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 };
|
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||||
std::wstring contents = strings.GITHUB_NEW_VERSION_AVAILABLE_OFFER_VISIT;
|
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)
|
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 };
|
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||||
std::wstring contents = strings.GITHUB_NEW_VERSION_DOWNLOAD_INSTALL_ERROR;
|
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)
|
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 };
|
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||||
std::wstring new_version_ready{ strings.GITHUB_NEW_VERSION_READY_TO_INSTALL };
|
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)
|
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);
|
show_toast(strings.UNINSTALLATION_UNKNOWN_ERROR, strings.TOAST_TITLE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -318,7 +318,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
}
|
}
|
||||||
case SpecialMode::ReportSuccessfulUpdate:
|
case SpecialMode::ReportSuccessfulUpdate:
|
||||||
{
|
{
|
||||||
notifications::remove_toasts(notifications::UPDATING_PROCESS_TOAST_TAG);
|
notifications::remove_toasts_by_tag(notifications::UPDATING_PROCESS_TOAST_TAG);
|
||||||
|
notifications::remove_all_scheduled_toasts();
|
||||||
notifications::show_toast(GET_RESOURCE_STRING(IDS_PT_UPDATE_MESSAGE_BOX_TEXT),
|
notifications::show_toast(GET_RESOURCE_STRING(IDS_PT_UPDATE_MESSAGE_BOX_TEXT),
|
||||||
L"PowerToys",
|
L"PowerToys",
|
||||||
notifications::toast_params{ notifications::UPDATING_PROCESS_TOAST_TAG });
|
notifications::toast_params{ notifications::UPDATING_PROCESS_TOAST_TAG });
|
||||||
|
|||||||
Reference in New Issue
Block a user