From 9b59e74d66e949454c9333c74b6a0441de97ed00 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 25 Jan 2021 03:16:32 +0400 Subject: [PATCH] Make native notifications setting tri-state --- Telegram/SourceFiles/core/core_settings.cpp | 13 +++++++++---- Telegram/SourceFiles/core/core_settings.h | 9 ++++++--- .../platform/linux/notifications_manager_linux.cpp | 6 +++++- .../linux/notifications_manager_linux_dummy.cpp | 4 ++++ .../platform/mac/notifications_manager_mac.mm | 4 ++++ .../platform/platform_notifications_manager.h | 1 + .../platform/win/notifications_manager_win.cpp | 4 ++++ 7 files changed, 33 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index aa6bded0d..ace2fcd29 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -60,7 +60,7 @@ QByteArray Settings::serialize() const { << qint32(_desktopNotify ? 1 : 0) << qint32(_flashBounceNotify ? 1 : 0) << static_cast(_notifyView) - << qint32(_nativeNotifications ? 1 : 0) + << qint32(_nativeNotifications ? (*_nativeNotifications ? 1 : 2) : 0) << qint32(_notificationsCount) << static_cast(_notificationsCorner) << qint32(_autoLock) @@ -141,7 +141,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { qint32 desktopNotify = _desktopNotify ? 1 : 0; qint32 flashBounceNotify = _flashBounceNotify ? 1 : 0; qint32 notifyView = static_cast(_notifyView); - qint32 nativeNotifications = _nativeNotifications ? 1 : 0; + qint32 nativeNotifications = _nativeNotifications ? (*_nativeNotifications ? 1 : 2) : 0; qint32 notificationsCount = _notificationsCount; qint32 notificationsCorner = static_cast(_notificationsCorner); qint32 autoLock = _autoLock; @@ -313,7 +313,12 @@ void Settings::addFromSerialized(const QByteArray &serialized) { case dbinvShowName: case dbinvShowPreview: _notifyView = uncheckedNotifyView; break; } - _nativeNotifications = (nativeNotifications == 1); + switch (nativeNotifications) { + case 0: _nativeNotifications = std::nullopt; break; + case 1: _nativeNotifications = true; break; + case 2: _nativeNotifications = false; break; + default: break; + } _notificationsCount = (notificationsCount > 0) ? notificationsCount : 3; const auto uncheckedNotificationsCorner = static_cast(notificationsCorner); switch (uncheckedNotificationsCorner) { @@ -479,7 +484,7 @@ void Settings::resetOnLastLogout() { _desktopNotify = true; _flashBounceNotify = true; _notifyView = dbinvShowPreview; - //_nativeNotifications = false; + //_nativeNotifications = std::nullopt; //_notificationsCount = 3; //_notificationsCorner = ScreenCorner::BottomRight; _includeMutedCounter = true; diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index 64b201ee8..67ffc1f25 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/themes/window_themes_embedded.h" #include "window/window_controls_layout.h" #include "ui/chat/attach/attach_send_files_way.h" +#include "platform/platform_notifications_manager.h" enum class RectPart; @@ -135,10 +136,12 @@ public: _notifyView = value; } [[nodiscard]] bool nativeNotifications() const { - return _nativeNotifications; + return _nativeNotifications.value_or(Platform::Notifications::ByDefault()); } void setNativeNotifications(bool value) { - _nativeNotifications = value; + _nativeNotifications = (value == Platform::Notifications::ByDefault()) + ? std::nullopt + : std::make_optional(value); } [[nodiscard]] int notificationsCount() const { return _notificationsCount; @@ -529,7 +532,7 @@ private: bool _desktopNotify = true; bool _flashBounceNotify = true; DBINotifyView _notifyView = dbinvShowPreview; - bool _nativeNotifications = false; + std::optional _nativeNotifications; int _notificationsCount = 3; ScreenCorner _notificationsCorner = ScreenCorner::BottomRight; bool _includeMutedCounter = true; diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index 9effa1964..7df885b33 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -698,7 +698,11 @@ bool Supported() { bool Enforced() { // Wayland doesn't support positioning // and custom notifications don't work here - return IsQualifiedDaemon() || IsWayland(); + return IsWayland(); +} + +bool ByDefault() { + return IsQualifiedDaemon(); } void Create(Window::Notifications::System *system) { diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux_dummy.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux_dummy.cpp index 3e11353d9..c51b92fed 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux_dummy.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux_dummy.cpp @@ -35,6 +35,10 @@ bool Enforced() { return IsWayland(); } +bool ByDefault() { + return false; +} + void Create(Window::Notifications::System *system) { if (Enforced()) { using DummyManager = Window::Notifications::DummyManager; diff --git a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm index 522f585bb..310b2829b 100644 --- a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm +++ b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm @@ -167,6 +167,10 @@ bool Enforced() { return Supported(); } +bool ByDefault() { + return Supported(); +} + void Create(Window::Notifications::System *system) { if (Supported()) { system->setManager(std::make_unique(system)); diff --git a/Telegram/SourceFiles/platform/platform_notifications_manager.h b/Telegram/SourceFiles/platform/platform_notifications_manager.h index 2a4a7849f..eb3efbddb 100644 --- a/Telegram/SourceFiles/platform/platform_notifications_manager.h +++ b/Telegram/SourceFiles/platform/platform_notifications_manager.h @@ -18,6 +18,7 @@ namespace Notifications { [[nodiscard]] bool Supported(); [[nodiscard]] bool Enforced(); +[[nodiscard]] bool ByDefault(); void Create(Window::Notifications::System *system); } // namespace Notifications diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp index c4ac40370..0fbdb331d 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp @@ -273,6 +273,10 @@ bool Enforced() { return false; } +bool ByDefault() { + return false; +} + void Create(Window::Notifications::System *system) { #ifndef __MINGW32__ if (Core::App().settings().nativeNotifications() && Supported()) {