Support auto-night mode on macOS.

This commit is contained in:
John Preston 2020-07-23 12:30:20 +04:00
parent 8c4e8212cd
commit 25d69434ec
5 changed files with 23 additions and 19 deletions

View file

@ -199,6 +199,7 @@ private:
- (void) darkModeChanged:(NSNotification *)aNotification {
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
Core::App().settings().setSystemDarkMode(Platform::IsDarkMode());
Core::App().domain().notifyUnreadBadgeChanged();
});
}
@ -650,7 +651,7 @@ void MainWindow::updateIconCounters() {
_private->setWindowBadge(string);
if (trayIcon) {
bool dm = objc_darkMode();
bool dm = Platform::IsDarkMenuBar();
auto &bg = (muted ? st::trayCounterBgMute : st::trayCounterBg);
QIcon icon;
QImage img(psTrayIcon(dm)), imgsel(psTrayIcon(true));

View file

@ -18,9 +18,7 @@ namespace Platform {
void RemoveQuarantine(const QString &path);
inline std::optional<bool> IsDarkMode() {
return std::nullopt;
}
[[nodiscard]] bool IsDarkMenuBar();
inline void FallbackFontConfigCheckBegin() {
}

View file

@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwindow.h"
#include "history/history_location_manager.h"
#include "base/platform/mac/base_utilities_mac.h"
#include "base/platform/base_platform_info.h"
#include <QtGui/QDesktopServices>
#include <QtWidgets/QApplication>
@ -137,6 +138,25 @@ void RemoveQuarantine(const QString &path) {
removexattr(local.data(), kQuarantineAttribute, 0);
}
bool IsDarkMenuBar() {
bool result = false;
@autoreleasepool {
NSDictionary *dict = [[NSUserDefaults standardUserDefaults] persistentDomainForName:NSGlobalDomain];
id style = [dict objectForKey:Q2NSString(strStyleOfInterface())];
BOOL darkModeOn = (style && [style isKindOfClass:[NSString class]] && NSOrderedSame == [style caseInsensitiveCompare:@"dark"]);
result = darkModeOn ? true : false;
}
return result;
}
std::optional<bool> IsDarkMode() {
return IsMac10_14OrGreater()
? std::make_optional(IsDarkMenuBar())
: std::nullopt;
}
void RegisterCustomScheme(bool force) {
#ifndef TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
OSStatus result = LSSetDefaultHandlerForURLScheme(CFSTR("tg"), (CFStringRef)[[NSBundle mainBundle] bundleIdentifier]);

View file

@ -10,8 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
// e is NSEvent*
bool objc_handleMediaKeyEvent(void *e);
bool objc_darkMode();
void objc_debugShowAlert(const QString &str);
void objc_outputDebugString(const QString &str);

View file

@ -218,19 +218,6 @@ void SetApplicationIcon(const QIcon &icon) {
} // namespace Platform
bool objc_darkMode() {
bool result = false;
@autoreleasepool {
NSDictionary *dict = [[NSUserDefaults standardUserDefaults] persistentDomainForName:NSGlobalDomain];
id style = [dict objectForKey:Q2NSString(strStyleOfInterface())];
BOOL darkModeOn = (style && [style isKindOfClass:[NSString class]] && NSOrderedSame == [style caseInsensitiveCompare:@"dark"]);
result = darkModeOn ? true : false;
}
return result;
}
bool objc_handleMediaKeyEvent(void *ev) {
auto e = reinterpret_cast<NSEvent*>(ev);