mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 03:07:56 +01:00
updating: remove previous progress toasts
toast notifications: - add method for removing existing toasts - add method for updating existing toast contents/title - refactoring
This commit is contained in:
committed by
Andrey Nekrasov
parent
5593f81242
commit
5e772340bc
@@ -300,7 +300,7 @@ int bootstrapper()
|
||||
break;
|
||||
}
|
||||
progressParams.progress = std::min(0.99f, progressParams.progress + 0.001f);
|
||||
notifications::update_progress_bar_toast(TOAST_TAG, progressParams);
|
||||
notifications::update_toast_progress_bar(TOAST_TAG, progressParams);
|
||||
}
|
||||
} }.detach();
|
||||
}
|
||||
@@ -313,7 +313,7 @@ int bootstrapper()
|
||||
std::scoped_lock lock{ progressLock };
|
||||
progressParams.progress = value;
|
||||
progressParams.progress_title = title;
|
||||
notifications::update_progress_bar_toast(TOAST_TAG, progressParams);
|
||||
notifications::update_toast_progress_bar(TOAST_TAG, progressParams);
|
||||
};
|
||||
|
||||
spdlog::debug("Extracting embedded MSI installer");
|
||||
|
||||
@@ -11,7 +11,10 @@
|
||||
#include <winrt/Windows.Data.Xml.Dom.h>
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include <winrt/Windows.UI.Notifications.h>
|
||||
#include <winrt/Windows.UI.Notifications.Management.h>
|
||||
#include <winrt/Windows.ApplicationModel.Background.h>
|
||||
#include <winrt/Windows.System.h>
|
||||
#include <winrt/Windows.System.UserProfile.h>
|
||||
#include <wil/com.h>
|
||||
#include <propvarutil.h>
|
||||
#include <propkey.h>
|
||||
@@ -39,6 +42,7 @@ namespace
|
||||
constexpr std::wstring_view APPIDS_REGISTRY = LR"(Software\Classes\AppUserModelId\)";
|
||||
|
||||
std::wstring APPLICATION_ID = L"Microsoft.PowerToysWin32";
|
||||
constexpr std::wstring_view DEFAULT_TOAST_GROUP = L"PowerToysToastTag";
|
||||
}
|
||||
|
||||
namespace localized_strings
|
||||
@@ -275,11 +279,10 @@ void notifications::show_toast_with_activations(std::wstring message,
|
||||
std::wstring toast_xml;
|
||||
toast_xml.reserve(2048);
|
||||
|
||||
toast_xml += LR"(<?xml version="1.0"?><toast><visual><binding template="ToastGeneric"><text id="1">)";
|
||||
toast_xml += title;
|
||||
toast_xml += LR"(</text><text id="2">)";
|
||||
toast_xml += message;
|
||||
toast_xml += L"</text>";
|
||||
toast_xml += LR"(<?xml version="1.0"?><toast><visual><binding template="ToastGeneric">)";
|
||||
toast_xml += LR"(<text id="1">{title}</text>)";
|
||||
toast_xml += LR"(<text id="2">{message}</text>)";
|
||||
|
||||
if (params.progress_bar.has_value())
|
||||
{
|
||||
toast_xml += LR"(<progress title="{progressTitle}" value="{progressValue}" valueStringOverride="{progressValueString}" status="" />)";
|
||||
@@ -373,17 +376,20 @@ void notifications::show_toast_with_activations(std::wstring message,
|
||||
xml_escape(toast_xml);
|
||||
toast_xml_doc.LoadXml(toast_xml);
|
||||
ToastNotification notification{ toast_xml_doc };
|
||||
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);
|
||||
winrt::Windows::Foundation::Collections::StringMap map;
|
||||
map.Insert(L"progressValue", std::to_wstring(progress));
|
||||
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);
|
||||
notification.Data(data);
|
||||
}
|
||||
winrt::Windows::UI::Notifications::NotificationData data{ map };
|
||||
notification.Data(std::move(data));
|
||||
|
||||
const auto notifier = winstore::running_as_packaged() ? ToastNotificationManager::ToastNotificationManager::CreateToastNotifier() :
|
||||
ToastNotificationManager::ToastNotificationManager::CreateToastNotifier(APPLICATION_ID);
|
||||
@@ -412,7 +418,7 @@ void notifications::show_toast_with_activations(std::wstring message,
|
||||
}
|
||||
}
|
||||
|
||||
void notifications::update_progress_bar_toast(std::wstring_view tag, progress_bar_params params)
|
||||
void notifications::update_toast_progress_bar(std::wstring_view tag, progress_bar_params params)
|
||||
{
|
||||
const auto notifier = winstore::running_as_packaged() ?
|
||||
ToastNotificationManager::ToastNotificationManager::CreateToastNotifier() :
|
||||
@@ -425,5 +431,41 @@ void notifications::update_progress_bar_toast(std::wstring_view tag, progress_ba
|
||||
map.Insert(L"progressTitle", params.progress_title);
|
||||
|
||||
winrt::Windows::UI::Notifications::NotificationData data(map);
|
||||
winrt::Windows::UI::Notifications::NotificationUpdateResult res = notifier.Update(data, tag);
|
||||
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;
|
||||
|
||||
try
|
||||
{
|
||||
User currentUser{ *User::FindAllAsync(UserType::LocalUser, UserAuthenticationStatus::LocallyAuthenticated).get().First() };
|
||||
if (!currentUser)
|
||||
{
|
||||
return;
|
||||
}
|
||||
currentUser.GetPropertyAsync(KnownUserProperties::AccountName());
|
||||
auto toastHistory = ToastNotificationManager::GetForUser(currentUser).History();
|
||||
toastHistory.Remove(tag, DEFAULT_TOAST_GROUP, APPLICATION_ID);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Couldn't get the current user or problem removing the toast => nothing we can do
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
namespace notifications
|
||||
{
|
||||
constexpr inline const wchar_t TOAST_ACTIVATED_LAUNCH_ARG[] = L"-ToastActivated";
|
||||
constexpr inline const wchar_t UPDATING_PROCESS_TOAST_TAG[] = L"PTUpdateNotifyTag";
|
||||
|
||||
void override_application_id(const std::wstring_view appID);
|
||||
void register_background_toast_handler();
|
||||
@@ -59,5 +60,7 @@ 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_progress_bar_toast(std::wstring_view tag, progress_bar_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);
|
||||
}
|
||||
|
||||
@@ -1,150 +1,161 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "toast_notifications_helper.h"
|
||||
|
||||
#include <common/notifications.h>
|
||||
|
||||
#include "updating.h"
|
||||
|
||||
#include "VersionHelper.h"
|
||||
#include "version.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
const wchar_t UPDATE_NOTIFY_TOAST_TAG[] = L"PTUpdateNotifyTag";
|
||||
const wchar_t UPDATE_READY_TOAST_TAG[] = L"PTUpdateReadyTag";
|
||||
const wchar_t TOAST_TITLE[] = L"PowerToys Update";
|
||||
}
|
||||
|
||||
namespace localized_strings
|
||||
{
|
||||
const wchar_t GITHUB_NEW_VERSION_AVAILABLE[] = L"An update to PowerToys is available.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_DOWNLOAD_STARTED[] = L"PowerToys download started.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_READY_TO_INSTALL[] = L"An update to PowerToys is ready to install.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_DOWNLOAD_INSTALL_ERROR[] = L"Error: couldn't download PowerToys installer. Visit our GitHub page to update.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_UPDATE_NOW[] = L"Update now";
|
||||
const wchar_t GITHUB_NEW_VERSION_UPDATE_AFTER_RESTART[] = L"At next launch";
|
||||
|
||||
const wchar_t UNINSTALLATION_UNKNOWN_ERROR[] = L"Error: please uninstall the previous version of PowerToys manually.";
|
||||
|
||||
const wchar_t GITHUB_NEW_VERSION_AVAILABLE_OFFER_VISIT[] = L"An update to PowerToys is available. Visit our GitHub page to update.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_UNAVAILABLE[] = L"PowerToys is up to date.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_VISIT[] = L"Visit";
|
||||
const wchar_t GITHUB_NEW_VERSION_MORE_INFO[] = L"More info...";
|
||||
const wchar_t GITHUB_NEW_VERSION_ABORT[] = L"Abort";
|
||||
const wchar_t GITHUB_NEW_VERSION_SNOOZE_TITLE[] = L"Click Snooze to be reminded in:";
|
||||
const wchar_t GITHUB_NEW_VERSION_UPDATE_SNOOZE_1D[] = L"1 day";
|
||||
const wchar_t GITHUB_NEW_VERSION_UPDATE_SNOOZE_5D[] = L"5 days";
|
||||
const wchar_t DOWNLOAD_IN_PROGRESS[] = L"Downloading...";
|
||||
const wchar_t DOWNLOAD_COMPLETE[] = L"Download complete";
|
||||
|
||||
}
|
||||
|
||||
namespace updating
|
||||
{
|
||||
namespace notifications
|
||||
{
|
||||
using namespace localized_strings;
|
||||
|
||||
std::wstring current_version_to_next_version(const updating::new_version_download_info& info)
|
||||
{
|
||||
auto current_version_to_next_version = VersionHelper{ VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION }.toWstring();
|
||||
current_version_to_next_version += L" -> ";
|
||||
current_version_to_next_version += info.version_string;
|
||||
return current_version_to_next_version;
|
||||
}
|
||||
|
||||
void show_unavailable()
|
||||
{
|
||||
::notifications::toast_params toast_params{ UPDATE_NOTIFY_TOAST_TAG, false };
|
||||
std::wstring contents = GITHUB_NEW_VERSION_UNAVAILABLE;
|
||||
::notifications::show_toast(std::move(contents), TOAST_TITLE, std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_available(const updating::new_version_download_info& info)
|
||||
{
|
||||
::notifications::toast_params toast_params{ UPDATE_NOTIFY_TOAST_TAG, false };
|
||||
std::wstring contents = GITHUB_NEW_VERSION_AVAILABLE;
|
||||
contents += current_version_to_next_version(info);
|
||||
|
||||
::notifications::show_toast_with_activations(std::move(contents),
|
||||
TOAST_TITLE,
|
||||
{},
|
||||
{ ::notifications::link_button{ GITHUB_NEW_VERSION_UPDATE_NOW, L"powertoys://download_and_install_update/" }, ::notifications::link_button{ GITHUB_NEW_VERSION_MORE_INFO, info.release_page_uri.ToString().c_str() } },
|
||||
std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_download_start(const updating::new_version_download_info& info)
|
||||
{
|
||||
::notifications::progress_bar_params progress_bar_params;
|
||||
std::wstring progress_title{ info.version_string };
|
||||
progress_title += L' ';
|
||||
progress_title += localized_strings::DOWNLOAD_IN_PROGRESS;
|
||||
|
||||
progress_bar_params.progress_title = progress_title;
|
||||
progress_bar_params.progress = .0f;
|
||||
::notifications::toast_params toast_params{ UPDATE_NOTIFY_TOAST_TAG, false, std::move(progress_bar_params) };
|
||||
::notifications::show_toast_with_activations(localized_strings::GITHUB_NEW_VERSION_DOWNLOAD_STARTED,
|
||||
TOAST_TITLE,
|
||||
{},
|
||||
{},
|
||||
std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_visit_github(const updating::new_version_download_info& info)
|
||||
{
|
||||
::notifications::toast_params toast_params{ UPDATE_NOTIFY_TOAST_TAG, false };
|
||||
std::wstring contents = GITHUB_NEW_VERSION_AVAILABLE_OFFER_VISIT;
|
||||
contents += current_version_to_next_version(info);
|
||||
::notifications::show_toast_with_activations(std::move(contents),
|
||||
TOAST_TITLE,
|
||||
{},
|
||||
{ ::notifications::link_button{ GITHUB_NEW_VERSION_VISIT, info.release_page_uri.ToString().c_str() } },
|
||||
std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_install_error(const updating::new_version_download_info& info)
|
||||
{
|
||||
::notifications::toast_params toast_params{ UPDATE_NOTIFY_TOAST_TAG, false };
|
||||
std::wstring contents = GITHUB_NEW_VERSION_DOWNLOAD_INSTALL_ERROR;
|
||||
contents += current_version_to_next_version(info);
|
||||
::notifications::show_toast_with_activations(std::move(contents),
|
||||
TOAST_TITLE,
|
||||
{},
|
||||
{ ::notifications::link_button{ GITHUB_NEW_VERSION_VISIT, info.release_page_uri.ToString().c_str() } },
|
||||
std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_version_ready(const updating::new_version_download_info& info)
|
||||
{
|
||||
::notifications::toast_params toast_params{ UPDATE_READY_TOAST_TAG, false };
|
||||
std::wstring new_version_ready{ GITHUB_NEW_VERSION_READY_TO_INSTALL };
|
||||
new_version_ready += current_version_to_next_version(info);
|
||||
|
||||
::notifications::show_toast_with_activations(std::move(new_version_ready),
|
||||
TOAST_TITLE,
|
||||
{},
|
||||
{ ::notifications::link_button{ GITHUB_NEW_VERSION_UPDATE_NOW, L"powertoys://update_now/" + info.installer_filename },
|
||||
::notifications::link_button{ GITHUB_NEW_VERSION_UPDATE_AFTER_RESTART, L"powertoys://schedule_update/" + info.installer_filename },
|
||||
::notifications::snooze_button{ GITHUB_NEW_VERSION_SNOOZE_TITLE, { { GITHUB_NEW_VERSION_UPDATE_SNOOZE_1D, 24 * 60 }, { GITHUB_NEW_VERSION_UPDATE_SNOOZE_5D, 120 * 60 } } } },
|
||||
std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_uninstallation_error()
|
||||
{
|
||||
::notifications::show_toast(localized_strings::UNINSTALLATION_UNKNOWN_ERROR, TOAST_TITLE);
|
||||
}
|
||||
|
||||
void update_download_progress(const updating::new_version_download_info& info, float progress)
|
||||
{
|
||||
::notifications::progress_bar_params progress_bar_params;
|
||||
|
||||
std::wstring progress_title{ info.version_string };
|
||||
progress_title += L' ';
|
||||
progress_title += progress < 1 ? localized_strings::DOWNLOAD_IN_PROGRESS : localized_strings::DOWNLOAD_COMPLETE;
|
||||
progress_bar_params.progress_title = progress_title;
|
||||
progress_bar_params.progress = progress;
|
||||
::notifications::update_progress_bar_toast(UPDATE_NOTIFY_TOAST_TAG, progress_bar_params);
|
||||
}
|
||||
}
|
||||
#include "pch.h"
|
||||
|
||||
#include "notifications.h"
|
||||
|
||||
#include <common/notifications.h>
|
||||
|
||||
#include "updating.h"
|
||||
|
||||
#include "VersionHelper.h"
|
||||
#include "version.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
const wchar_t TOAST_TITLE[] = L"PowerToys Update";
|
||||
}
|
||||
|
||||
namespace localized_strings
|
||||
{
|
||||
const wchar_t GITHUB_NEW_VERSION_AVAILABLE[] = L"An update to PowerToys is available.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_DOWNLOAD_STARTED[] = L"PowerToys download started.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_READY_TO_INSTALL[] = L"An update to PowerToys is ready to install.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_DOWNLOAD_INSTALL_ERROR[] = L"Error: couldn't download PowerToys installer. Visit our GitHub page to update.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_UPDATE_NOW[] = L"Update now";
|
||||
const wchar_t GITHUB_NEW_VERSION_UPDATE_AFTER_RESTART[] = L"At next launch";
|
||||
|
||||
const wchar_t UNINSTALLATION_UNKNOWN_ERROR[] = L"Error: please uninstall the previous version of PowerToys manually.";
|
||||
|
||||
const wchar_t GITHUB_NEW_VERSION_AVAILABLE_OFFER_VISIT[] = L"An update to PowerToys is available. Visit our GitHub page to update.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_UNAVAILABLE[] = L"PowerToys is up to date.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_VISIT[] = L"Visit";
|
||||
const wchar_t GITHUB_NEW_VERSION_MORE_INFO[] = L"More info...";
|
||||
const wchar_t GITHUB_NEW_VERSION_ABORT[] = L"Abort";
|
||||
const wchar_t GITHUB_NEW_VERSION_SNOOZE_TITLE[] = L"Click Snooze to be reminded in:";
|
||||
const wchar_t GITHUB_NEW_VERSION_UPDATE_SNOOZE_1D[] = L"1 day";
|
||||
const wchar_t GITHUB_NEW_VERSION_UPDATE_SNOOZE_5D[] = L"5 days";
|
||||
const wchar_t DOWNLOAD_IN_PROGRESS[] = L"Downloading...";
|
||||
const wchar_t DOWNLOAD_COMPLETE[] = L"Download complete";
|
||||
}
|
||||
|
||||
namespace updating
|
||||
{
|
||||
namespace notifications
|
||||
{
|
||||
using namespace localized_strings;
|
||||
using namespace ::notifications;
|
||||
std::wstring current_version_to_next_version(const updating::new_version_download_info& info)
|
||||
{
|
||||
auto current_version_to_next_version = VersionHelper{ VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION }.toWstring();
|
||||
current_version_to_next_version += L" -> ";
|
||||
current_version_to_next_version += info.version_string;
|
||||
return current_version_to_next_version;
|
||||
}
|
||||
|
||||
void show_unavailable()
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||
std::wstring contents = GITHUB_NEW_VERSION_UNAVAILABLE;
|
||||
show_toast(std::move(contents), TOAST_TITLE, std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_available(const updating::new_version_download_info& info)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||
std::wstring contents = GITHUB_NEW_VERSION_AVAILABLE;
|
||||
contents += current_version_to_next_version(info);
|
||||
|
||||
show_toast_with_activations(std::move(contents),
|
||||
TOAST_TITLE,
|
||||
{},
|
||||
{ link_button{ GITHUB_NEW_VERSION_UPDATE_NOW, L"powertoys://download_and_install_update/" }, link_button{ GITHUB_NEW_VERSION_MORE_INFO, info.release_page_uri.ToString().c_str() } },
|
||||
std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_download_start(const updating::new_version_download_info& info)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
progress_bar_params progress_bar_params;
|
||||
std::wstring progress_title{ info.version_string };
|
||||
progress_title += L' ';
|
||||
progress_title += localized_strings::DOWNLOAD_IN_PROGRESS;
|
||||
|
||||
progress_bar_params.progress_title = progress_title;
|
||||
progress_bar_params.progress = .0f;
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false, std::move(progress_bar_params) };
|
||||
show_toast_with_activations(localized_strings::GITHUB_NEW_VERSION_DOWNLOAD_STARTED,
|
||||
TOAST_TITLE,
|
||||
{},
|
||||
{},
|
||||
std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_visit_github(const updating::new_version_download_info& info)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||
std::wstring contents = GITHUB_NEW_VERSION_AVAILABLE_OFFER_VISIT;
|
||||
contents += current_version_to_next_version(info);
|
||||
show_toast_with_activations(std::move(contents),
|
||||
TOAST_TITLE,
|
||||
{},
|
||||
{ link_button{ GITHUB_NEW_VERSION_VISIT, info.release_page_uri.ToString().c_str() } },
|
||||
std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_install_error(const updating::new_version_download_info& info)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||
std::wstring contents = GITHUB_NEW_VERSION_DOWNLOAD_INSTALL_ERROR;
|
||||
contents += current_version_to_next_version(info);
|
||||
show_toast_with_activations(std::move(contents),
|
||||
TOAST_TITLE,
|
||||
{},
|
||||
{ link_button{ GITHUB_NEW_VERSION_VISIT, info.release_page_uri.ToString().c_str() } },
|
||||
std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_version_ready(const updating::new_version_download_info& info)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||
std::wstring new_version_ready{ GITHUB_NEW_VERSION_READY_TO_INSTALL };
|
||||
new_version_ready += current_version_to_next_version(info);
|
||||
|
||||
show_toast_with_activations(std::move(new_version_ready),
|
||||
TOAST_TITLE,
|
||||
{},
|
||||
{ link_button{ GITHUB_NEW_VERSION_UPDATE_NOW, L"powertoys://update_now/" + info.installer_filename },
|
||||
link_button{ GITHUB_NEW_VERSION_UPDATE_AFTER_RESTART, L"powertoys://schedule_update/" + info.installer_filename },
|
||||
snooze_button{ GITHUB_NEW_VERSION_SNOOZE_TITLE, { { GITHUB_NEW_VERSION_UPDATE_SNOOZE_1D, 24 * 60 }, { GITHUB_NEW_VERSION_UPDATE_SNOOZE_5D, 120 * 60 } } } },
|
||||
std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_uninstallation_error()
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
show_toast(localized_strings::UNINSTALLATION_UNKNOWN_ERROR, TOAST_TITLE);
|
||||
}
|
||||
|
||||
void update_download_progress(const updating::new_version_download_info& info, float progress)
|
||||
{
|
||||
progress_bar_params progress_bar_params;
|
||||
|
||||
std::wstring progress_title{ info.version_string };
|
||||
progress_title += L' ';
|
||||
progress_title += progress < 1 ? localized_strings::DOWNLOAD_IN_PROGRESS : localized_strings::DOWNLOAD_COMPLETE;
|
||||
progress_bar_params.progress_title = progress_title;
|
||||
progress_bar_params.progress = progress;
|
||||
update_toast_progress_bar(UPDATING_PROCESS_TOAST_TAG, progress_bar_params);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
namespace updating
|
||||
{
|
||||
struct new_version_download_info;
|
||||
|
||||
namespace notifications
|
||||
{
|
||||
void show_unavailable();
|
||||
void show_available(const updating::new_version_download_info& info);
|
||||
void show_download_start(const updating::new_version_download_info& info);
|
||||
void show_visit_github(const updating::new_version_download_info& info);
|
||||
void show_install_error(const updating::new_version_download_info& info);
|
||||
void show_version_ready(const updating::new_version_download_info& info);
|
||||
void show_uninstallation_error();
|
||||
|
||||
void update_download_progress(const updating::new_version_download_info& info, float progress);
|
||||
}
|
||||
#pragma once
|
||||
|
||||
namespace updating
|
||||
{
|
||||
struct new_version_download_info;
|
||||
|
||||
namespace notifications
|
||||
{
|
||||
void show_unavailable();
|
||||
void show_available(const updating::new_version_download_info& info);
|
||||
void show_download_start(const updating::new_version_download_info& info);
|
||||
void show_visit_github(const updating::new_version_download_info& info);
|
||||
void show_install_error(const updating::new_version_download_info& info);
|
||||
void show_version_ready(const updating::new_version_download_info& info);
|
||||
void show_uninstallation_error();
|
||||
|
||||
void update_download_progress(const updating::new_version_download_info& info, float progress);
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,8 @@
|
||||
#include "version.h"
|
||||
|
||||
#include "http_client.h"
|
||||
#include "notifications.h"
|
||||
#include "updating.h"
|
||||
#include "toast_notifications_helper.h"
|
||||
|
||||
#include <msi.h>
|
||||
#include <common/common.h>
|
||||
|
||||
@@ -175,14 +175,14 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="dotnet_installation.h" />
|
||||
<ClInclude Include="http_client.h" />
|
||||
<ClInclude Include="toast_notifications_helper.h" />
|
||||
<ClInclude Include="notifications.h" />
|
||||
<ClInclude Include="updating.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dotnet_installation.cpp" />
|
||||
<ClCompile Include="http_client.cpp" />
|
||||
<ClCompile Include="toast_notifications_helper.cpp" />
|
||||
<ClCompile Include="notifications.cpp" />
|
||||
<ClCompile Include="updating.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(CIBuild)'!='true'">Create</PrecompiledHeader>
|
||||
|
||||
@@ -21,15 +21,15 @@
|
||||
<ClInclude Include="updating.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="toast_notifications_helper.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="http_client.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="dotnet_installation.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="notifications.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp">
|
||||
@@ -38,15 +38,15 @@
|
||||
<ClCompile Include="updating.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="toast_notifications_helper.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="http_client.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="dotnet_installation.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="notifications.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
@@ -301,8 +301,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
return 0;
|
||||
}
|
||||
case SpecialMode::ReportSuccessfulUpdate:
|
||||
notifications::show_toast(localized_strings::PT_UPDATE_MESSAGE_BOX_TEXT, L"PowerToys");
|
||||
{
|
||||
notifications::remove_toasts(notifications::UPDATING_PROCESS_TOAST_TAG);
|
||||
notifications::show_toast(localized_strings::PT_UPDATE_MESSAGE_BOX_TEXT,
|
||||
L"PowerToys",
|
||||
notifications::toast_params{ notifications::UPDATING_PROCESS_TOAST_TAG });
|
||||
break;
|
||||
}
|
||||
|
||||
case SpecialMode::None:
|
||||
// continue as usual
|
||||
|
||||
Reference in New Issue
Block a user