From 1e63a6a1a729551a7f355a393826fd6ca6cc66cf Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 22 Jun 2022 20:07:17 +0400 Subject: [PATCH] Fix possible crash in Windows Toast Notifications. --- .../win/notifications_manager_win.cpp | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp index eebe67cdf..97a7d2437 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp @@ -440,6 +440,7 @@ private: const QString &subtitle, const QString &msg, DisplayOptions options); + void tryHide(const ToastNotification ¬ification); [[nodiscard]] std::wstring ensureSendButtonIcon(); Window::Notifications::CachedUserpics _cachedUserpics; @@ -485,7 +486,7 @@ void Manager::Private::clearAll() { for (const auto &[key, notifications] : base::take(_notifications)) { for (const auto &[msgId, notification] : notifications) { - _notifier.Hide(notification); + tryHide(notification); } } } @@ -511,7 +512,7 @@ void Manager::Private::clearFromItem(not_null item) { if (i->second.empty()) { _notifications.erase(i); } - _notifier.Hide(taken); + tryHide(taken); } void Manager::Private::clearFromHistory(not_null history) { @@ -528,7 +529,7 @@ void Manager::Private::clearFromHistory(not_null history) { _notifications.erase(i); for (const auto &[msgId, notification] : temp) { - _notifier.Hide(notification); + tryHide(notification); } } } @@ -548,7 +549,7 @@ void Manager::Private::clearFromSession(not_null session) { _notifications.erase(i); for (const auto &[msgId, notification] : temp) { - _notifier.Hide(notification); + tryHide(notification); } } } @@ -807,7 +808,7 @@ bool Manager::Private::showNotificationInTryCatch( if (j != i->second.end()) { const auto existing = j->second; i->second.erase(j); - _notifier.Hide(existing); + tryHide(existing); i = _notifications.find(key); } } @@ -827,7 +828,14 @@ bool Manager::Private::showNotificationInTryCatch( return true; } -Manager::Manager(Window::Notifications::System *system) : NativeManager(system) +void Manager::Private::tryHide(const ToastNotification ¬ification) { + base::WinRT::Try([&] { + _notifier.Hide(notification); + }); +} + +Manager::Manager(Window::Notifications::System *system) +: NativeManager(system) , _private(std::make_unique(this, Private::Type::Rounded)) { }