From c3fa300b5cf49c09d074343119f37cda1b19590a Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 30 Jun 2020 11:44:32 +0400 Subject: [PATCH] Create notifications manager after reading settings. --- Telegram/SourceFiles/core/application.cpp | 1 + Telegram/SourceFiles/main/main_domain.cpp | 2 + .../window/notifications_manager.cpp | 38 ++++++++++++++----- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 61e1504a01..cfeaf930f4 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -183,6 +183,7 @@ void Application::run() { refreshGlobalProxy(); // Depends on Global::start(). // Depends on OpenSSL on macOS, so on ThirdParty::start(). + // Depends on notifications settings. _notifications = std::make_unique(); startLocalStorage(); diff --git a/Telegram/SourceFiles/main/main_domain.cpp b/Telegram/SourceFiles/main/main_domain.cpp index 6b8fd61cc0..5f139504fd 100644 --- a/Telegram/SourceFiles/main/main_domain.cpp +++ b/Telegram/SourceFiles/main/main_domain.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_account.h" #include "storage/localstorage.h" #include "export/export_settings.h" +#include "window/notifications_manager.h" #include "facades.h" namespace Main { @@ -28,6 +29,7 @@ Domain::Domain(const QString &dataName) _active.changes( ) | rpl::take(1) | rpl::start_with_next([] { Local::rewriteSettingsIfNeeded(); + Core::App().notifications().createManager(); }, _lifetime); } diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index 73d428cb25..e542e5ee08 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -52,8 +52,6 @@ constexpr auto kSystemAlertDuration = crl::time(0); System::System() : _waitTimer([=] { showNext(); }) , _waitForAllGroupedTimer([=] { showGrouped(); }) { - createManager(); - subscribe(settingsChanged(), [=](ChangeType type) { if (type == ChangeType::DesktopEnabled) { App::wnd()->updateTrayMenu(); @@ -174,7 +172,9 @@ void System::schedule(not_null item) { } void System::clearAll() { - _manager->clearAll(); + if (_manager) { + _manager->clearAll(); + } for (auto i = _whenMaps.cbegin(), e = _whenMaps.cend(); i != e; ++i) { i->first->clearNotifications(); @@ -186,7 +186,9 @@ void System::clearAll() { } void System::clearFromHistory(not_null history) { - _manager->clearFromHistory(history); + if (_manager) { + _manager->clearFromHistory(history); + } history->clearNotifications(); _whenMaps.remove(history); @@ -199,7 +201,9 @@ void System::clearFromHistory(not_null history) { } void System::clearFromSession(not_null session) { - _manager->clearFromSession(session); + if (_manager) { + _manager->clearFromSession(session); + } for (auto i = _whenMaps.begin(); i != _whenMaps.end();) { const auto history = i->first; @@ -228,17 +232,23 @@ void System::clearFromSession(not_null session) { } void System::clearIncomingFromHistory(not_null history) { - _manager->clearFromHistory(history); + if (_manager) { + _manager->clearFromHistory(history); + } history->clearIncomingNotifications(); _whenAlerts.remove(history); } void System::clearFromItem(not_null item) { - _manager->clearFromItem(item); + if (_manager) { + _manager->clearFromItem(item); + } } void System::clearAllFast() { - _manager->clearAllFast(); + if (_manager) { + _manager->clearAllFast(); + } _whenMaps.clear(); _whenAlerts.clear(); @@ -293,6 +303,8 @@ void System::checkDelayed() { } void System::showGrouped() { + Expects(_manager != nullptr); + if (const auto session = findSession(_lastHistorySessionId)) { if (const auto lastItem = session->data().message(_lastHistoryItemId)) { _waitForAllGroupedTimer.cancel(); @@ -305,7 +317,11 @@ void System::showGrouped() { } void System::showNext() { - if (App::quitting()) return; + Expects(_manager != nullptr); + + if (App::quitting()) { + return; + } const auto isSameGroup = [=](HistoryItem *item) { if (!_lastHistorySessionId || !_lastHistoryItemId || !item) { @@ -536,7 +552,9 @@ void System::ensureSoundCreated() { } void System::updateAll() { - _manager->updateAll(); + if (_manager) { + _manager->updateAll(); + } } Manager::DisplayOptions Manager::GetNotificationOptions(HistoryItem *item) {