From 6718d238af15f25f945a2ca0d44621368720f198 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Tue, 26 Jul 2022 05:55:18 +0400 Subject: [PATCH] Switch to the dummy notification manager when notification daemon is not running on Linux --- .../linux/notifications_manager_linux.cpp | 40 +++++-------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index 9ae2bffff..7228a00dd 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -259,8 +259,7 @@ void GetCapabilities(Fn callback) { } void GetInhibited(Fn callback) { - if (!Supported() - || !CurrentCapabilities.contains(qsl("inhibitions"))) { + if (!CurrentCapabilities.contains(qsl("inhibitions"))) { crl::on_main([=] { callback(false); }); return; } @@ -744,12 +743,18 @@ void Create(Window::Notifications::System *system) { const auto managerSetter = [=] { using ManagerType = Window::Notifications::ManagerType; - if ((Core::App().settings().nativeNotifications() && Supported()) - || Enforced()) { + if ((Core::App().settings().nativeNotifications() || Enforced()) + && Supported()) { if (!system->managerType().has_value() || *system->managerType() != ManagerType::Native) { system->setManager(std::make_unique(system)); } + } else if (Enforced()) { + if (!system->managerType().has_value() + || *system->managerType() != ManagerType::Dummy) { + using DummyManager = Window::Notifications::DummyManager; + system->setManager(std::make_unique(system)); + } } else if (!system->managerType().has_value() || *system->managerType() != ManagerType::Default) { system->setManager(nullptr); @@ -838,10 +843,6 @@ private: Manager::Private::Private(not_null manager, Type type) : _manager(manager) , _cachedUserpics(type) { - if (!Supported()) { - return; - } - const auto serverInformation = CurrentServerInformation; const auto capabilities = CurrentCapabilities; @@ -913,10 +914,6 @@ void Manager::Private::showNotification( const QString &subtitle, const QString &msg, DisplayOptions options) { - if (!Supported()) { - return; - } - const auto key = FullPeer{ .sessionId = peer->session().uniqueId(), .peerId = peer->id @@ -962,10 +959,6 @@ void Manager::Private::showNotification( } void Manager::Private::clearAll() { - if (!Supported()) { - return; - } - for (const auto &[key, notifications] : base::take(_notifications)) { for (const auto &[msgId, notification] : notifications) { notification->close(); @@ -974,9 +967,6 @@ void Manager::Private::clearAll() { } void Manager::Private::clearFromItem(not_null item) { - if (!Supported()) { - return; - } const auto key = FullPeer{ .sessionId = item->history()->session().uniqueId(), .peerId = item->history()->peer->id @@ -998,10 +988,6 @@ void Manager::Private::clearFromItem(not_null item) { } void Manager::Private::clearFromHistory(not_null history) { - if (!Supported()) { - return; - } - const auto key = FullPeer{ .sessionId = history->session().uniqueId(), .peerId = history->peer->id @@ -1018,10 +1004,6 @@ void Manager::Private::clearFromHistory(not_null history) { } void Manager::Private::clearFromSession(not_null session) { - if (!Supported()) { - return; - } - const auto sessionId = session->uniqueId(); for (auto i = _notifications.begin(); i != _notifications.end();) { if (i->first.sessionId != sessionId) { @@ -1038,10 +1020,6 @@ void Manager::Private::clearFromSession(not_null session) { } void Manager::Private::clearNotification(NotificationId id) { - if (!Supported()) { - return; - } - auto i = _notifications.find(id.full); if (i != _notifications.cend()) { if (i->second.remove(id.msgId) && i->second.empty()) {