mirror of https://github.com/procxx/kepka.git
Respect macOS do not disturb settings. Fix #3095.
This commit is contained in:
parent
b5d9eee489
commit
a5c83467d6
|
@ -25,13 +25,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace Notifications {
|
namespace Notifications {
|
||||||
|
|
||||||
inline bool SkipAudio() {
|
bool SkipAudio();
|
||||||
return false;
|
bool SkipToast();
|
||||||
}
|
|
||||||
|
|
||||||
inline bool SkipToast() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Manager : public Window::Notifications::NativeManager {
|
class Manager : public Window::Notifications::NativeManager {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -30,7 +30,22 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
NeverFreedPointer<Platform::Notifications::Manager> 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
|
} // namespace
|
||||||
|
|
||||||
|
@ -98,6 +113,21 @@ std::weak_ptr<Manager*> _manager;
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace Notifications {
|
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() {
|
bool Supported() {
|
||||||
return (cPlatform() != dbipMacOld);
|
return (cPlatform() != dbipMacOld);
|
||||||
}
|
}
|
||||||
|
|
|
@ -637,12 +637,12 @@ void queryUserNotificationState() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr int QuerySettingsEachMs = 1000;
|
static constexpr auto kQuerySettingsEachMs = 1000;
|
||||||
TimeMs LastSettingsQueryMs = 0;
|
TimeMs LastSettingsQueryMs = 0;
|
||||||
|
|
||||||
void querySystemNotificationSettings() {
|
void querySystemNotificationSettings() {
|
||||||
auto ms = getms(true);
|
auto ms = getms(true);
|
||||||
if (LastSettingsQueryMs > 0 && ms <= LastSettingsQueryMs + QuerySettingsEachMs) {
|
if (LastSettingsQueryMs > 0 && ms <= LastSettingsQueryMs + kQuerySettingsEachMs) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LastSettingsQueryMs = ms;
|
LastSettingsQueryMs = ms;
|
||||||
|
|
Loading…
Reference in New Issue