diff --git a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h index 9c6883689..a9c6bbbaa 100644 --- a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h +++ b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h @@ -25,13 +25,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace Platform { namespace Notifications { -inline bool SkipAudio() { - return false; -} - -inline bool SkipToast() { - return false; -} +bool SkipAudio(); +bool SkipToast(); class Manager : public Window::Notifications::NativeManager { public: diff --git a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm index 59c8aa689..c6a61cbac 100644 --- a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm +++ b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm @@ -30,7 +30,22 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace { -NeverFreedPointer ManagerInstance; +static constexpr auto kQuerySettingsEachMs = 1000; +auto DoNotDisturbEnabled = false; +auto LastSettingsQueryMs = 0; + +void queryDoNotDisturbState() { + auto ms = getms(true); + if (LastSettingsQueryMs > 0 && ms <= LastSettingsQueryMs + kQuerySettingsEachMs) { + return; + } + LastSettingsQueryMs = ms; + + id userDefaultsValue = [[[NSUserDefaults alloc] initWithSuiteName:@"com.apple.notificationcenterui"] objectForKey:@"doNotDisturb"]; + DoNotDisturbEnabled = [userDefaultsValue boolValue]; +} + +using Manager = Platform::Notifications::Manager; } // namespace @@ -98,6 +113,21 @@ std::weak_ptr _manager; namespace Platform { namespace Notifications { +bool SkipAudio() { + queryDoNotDisturbState(); + return DoNotDisturbEnabled; +} + +bool SkipToast() { + if (Supported()) { + // Do not skip native notifications because of Do not disturb. + // They respect this setting anyway. + return false; + } + queryDoNotDisturbState(); + return DoNotDisturbEnabled; +} + bool Supported() { return (cPlatform() != dbipMacOld); } diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp index 1e4dca9e3..cc916f736 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp @@ -637,12 +637,12 @@ void queryUserNotificationState() { } } -static constexpr int QuerySettingsEachMs = 1000; +static constexpr auto kQuerySettingsEachMs = 1000; TimeMs LastSettingsQueryMs = 0; void querySystemNotificationSettings() { auto ms = getms(true); - if (LastSettingsQueryMs > 0 && ms <= LastSettingsQueryMs + QuerySettingsEachMs) { + if (LastSettingsQueryMs > 0 && ms <= LastSettingsQueryMs + kQuerySettingsEachMs) { return; } LastSettingsQueryMs = ms;