From b29877554c865aeeceeff20c608f331a95269833 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Tue, 30 Sep 2025 08:55:26 +0000 Subject: [PATCH] Make experimental option for non-native notifications cross-platform --- .../linux/notifications_manager_linux.cpp | 3 --- .../platform/mac/notifications_manager_mac.mm | 17 +-------------- .../platform/platform_notifications_manager.h | 2 -- .../win/notifications_manager_win.cpp | 3 --- .../settings/settings_experimental.cpp | 3 +-- .../settings/settings_notifications.cpp | 4 ++-- .../window/notifications_manager.cpp | 21 +++++++++++++++++-- .../window/notifications_manager.h | 2 ++ 8 files changed, 25 insertions(+), 30 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index 0cbf79dad9..f2f9b02cac 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -37,9 +37,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Platform { namespace Notifications { - -const char kOptionMacCustomNotification[] = ""; - namespace { using namespace gi::repository; diff --git a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm index 9e845179e6..3747d9b715 100644 --- a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm +++ b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm @@ -198,21 +198,6 @@ using Manager = Platform::Notifications::Manager; namespace Platform { namespace Notifications { -const char kOptionMacCustomNotification[] = "mac-custom-notification"; - -base::options::toggle OptionMacCustomNotification({ - .id = kOptionMacCustomNotification, - .name = "Non-native notifications on macOS", - .scope = [] { -#ifdef Q_OS_MAC - return true; -#else // !Q_OS_MAC - return false; -#endif // !Q_OS_MAC - }, - .restartRequired = true, -}); - bool SkipToastForCustom() { return false; } @@ -234,7 +219,7 @@ bool Supported() { } bool Enforced() { - return !OptionMacCustomNotification.value() && Supported(); + return Supported(); } bool ByDefault() { diff --git a/Telegram/SourceFiles/platform/platform_notifications_manager.h b/Telegram/SourceFiles/platform/platform_notifications_manager.h index 1e4cbb0e6f..da41f6010e 100644 --- a/Telegram/SourceFiles/platform/platform_notifications_manager.h +++ b/Telegram/SourceFiles/platform/platform_notifications_manager.h @@ -12,8 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Platform { namespace Notifications { -extern const char kOptionMacCustomNotification[]; - [[nodiscard]] bool SkipToastForCustom(); void MaybePlaySoundForCustom(Fn playSound); void MaybeFlashBounceForCustom(Fn flashBounce); diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp index bb91c83848..2692923efd 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp @@ -52,9 +52,6 @@ using winrt::com_ptr; namespace Platform { namespace Notifications { - -const char kOptionMacCustomNotification[] = ""; - namespace { constexpr auto kQuerySettingsEachMs = 1000; diff --git a/Telegram/SourceFiles/settings/settings_experimental.cpp b/Telegram/SourceFiles/settings/settings_experimental.cpp index 04938b5189..61aebda936 100644 --- a/Telegram/SourceFiles/settings/settings_experimental.cpp +++ b/Telegram/SourceFiles/settings/settings_experimental.cpp @@ -36,7 +36,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_document_resolver.h" #include "styles/style_settings.h" #include "styles/style_layers.h" -#include "platform/platform_notifications_manager.h" namespace Settings { namespace { @@ -156,6 +155,7 @@ void SetupExperimental( addToggle(Webview::kOptionWebviewLegacyEdge); addToggle(kOptionAutoScrollInactiveChat); addToggle(Window::Notifications::kOptionHideReplyButton); + addToggle(Window::Notifications::kOptionCustomNotification); addToggle(Window::Notifications::kOptionGNotification); addToggle(Core::kOptionFreeType); addToggle(Core::kOptionSkipUrlSchemeRegister); @@ -166,7 +166,6 @@ void SetupExperimental( addToggle(kOptionFastButtonsMode); } addToggle(Window::kOptionDisableTouchbar); - addToggle(Platform::Notifications::kOptionMacCustomNotification); } } // namespace diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index b42ae02ec0..5b5b6f758d 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -1225,7 +1225,7 @@ void SetupNotificationsContent( auto nativeText = [&] { if (!Platform::Notifications::Supported() - || Platform::Notifications::Enforced()) { + || Core::App().notifications().nativeEnforced()) { return rpl::producer(); } else if (Platform::IsWindows()) { return tr::lng_settings_use_windows(); @@ -1248,7 +1248,7 @@ void SetupNotificationsContent( ))->toggleOn(rpl::single(settings.nativeNotifications())); }(); - const auto advancedSlide = !Platform::Notifications::Enforced() + const auto advancedSlide = !Core::App().notifications().nativeEnforced() ? container->add( object_ptr>( container, diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index affd4badc9..7147d8317d 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -132,6 +132,19 @@ constexpr auto kSystemAlertDuration = crl::time(0); } // namespace +const char kOptionCustomNotification[] = "custom-notification"; + +base::options::toggle OptionCustomNotification({ + .id = kOptionCustomNotification, + .name = "Force non-native notifications availability", + .description = "Allow to disable native notifications" + " even if custom notifications are broken on this platform", + .scope = [] { + return Platform::Notifications::Enforced(); + }, + .restartRequired = true, +}); + const char kOptionGNotification[] = "gnotification"; const char kOptionHideReplyButton[] = "hide-reply-button"; @@ -208,7 +221,7 @@ void System::setManager(Fn()> create) { }); if ((Core::App().settings().nativeNotifications() - || Platform::Notifications::Enforced()) + || nativeEnforced()) && Platform::Notifications::Supported()) { if (_manager->type() == ManagerType::Native) { return; @@ -220,7 +233,7 @@ void System::setManager(Fn()> create) { } } - if (Platform::Notifications::Enforced()) { + if (nativeEnforced()) { if (_manager->type() != ManagerType::Dummy) { _manager = std::make_unique(this); } @@ -238,6 +251,10 @@ rpl::producer<> System::managerChanged() const { return _managerChanged.events(); } +bool System::nativeEnforced() const { + return !OptionCustomNotification.value() && Platform::Notifications::Enforced(); +} + Main::Session *System::findSession(uint64 sessionId) const { for (const auto &[index, account] : Core::App().domain().accounts()) { if (const auto session = account->maybeSession()) { diff --git a/Telegram/SourceFiles/window/notifications_manager.h b/Telegram/SourceFiles/window/notifications_manager.h index 1e84c3a63a..190f4b2a46 100644 --- a/Telegram/SourceFiles/window/notifications_manager.h +++ b/Telegram/SourceFiles/window/notifications_manager.h @@ -88,6 +88,7 @@ using toggle = option; namespace Window::Notifications { +extern const char kOptionCustomNotification[]; extern const char kOptionGNotification[]; extern base::options::toggle OptionGNotification; @@ -111,6 +112,7 @@ public: void setManager(Fn()> create); [[nodiscard]] Manager &manager() const; [[nodiscard]] rpl::producer<> managerChanged() const; + [[nodiscard]] bool nativeEnforced() const; void checkDelayed(); void schedule(Data::ItemNotification notification);