From b57e623c119c020506805302e3b8269c7d5a736d Mon Sep 17 00:00:00 2001 From: Micha Hanselmann Date: Tue, 16 Jul 2019 17:06:32 -0700 Subject: [PATCH] refactor: use NativeTheme dark mode detection on macOS 10.14+ --- shell/browser/api/atom_api_system_preferences_mac.mm | 4 ++-- shell/browser/ui/tray_icon_cocoa.mm | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/shell/browser/api/atom_api_system_preferences_mac.mm b/shell/browser/api/atom_api_system_preferences_mac.mm index 66118c03606a..5bc68289b46d 100644 --- a/shell/browser/api/atom_api_system_preferences_mac.mm +++ b/shell/browser/api/atom_api_system_preferences_mac.mm @@ -28,6 +28,7 @@ #include "shell/browser/ui/cocoa/NSColor+Hex.h" #include "shell/common/native_mate_converters/gurl_converter.h" #include "shell/common/native_mate_converters/value_converter.h" +#include "ui/native_theme/native_theme.h" namespace mate { template <> @@ -636,8 +637,7 @@ void SystemPreferences::RemoveUserDefault(const std::string& name) { bool SystemPreferences::IsDarkMode() { if (@available(macOS 10.14, *)) { - return [[NSApplication sharedApplication].effectiveAppearance.name - isEqualToString:NSAppearanceNameDarkAqua]; + return ui::NativeTheme::GetInstanceForNativeUi()->SystemDarkModeEnabled(); } NSString* mode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"]; diff --git a/shell/browser/ui/tray_icon_cocoa.mm b/shell/browser/ui/tray_icon_cocoa.mm index 8a83a8feb3b2..12303bf35e7c 100644 --- a/shell/browser/ui/tray_icon_cocoa.mm +++ b/shell/browser/ui/tray_icon_cocoa.mm @@ -20,6 +20,7 @@ #include "ui/events/cocoa/cocoa_event_utils.h" #include "ui/gfx/image/image.h" #include "ui/gfx/mac/coordinate_conversion.h" +#include "ui/native_theme/native_theme.h" namespace { @@ -153,8 +154,7 @@ const CGFloat kVerticalTitleMargin = 2; - (BOOL)isDarkMode { if (@available(macOS 10.14, *)) { - return [[NSApplication sharedApplication].effectiveAppearance.name - isEqualToString:NSAppearanceNameDarkAqua]; + return ui::NativeTheme::GetInstanceForNativeUi()->SystemDarkModeEnabled(); } NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; NSString* mode = [defaults stringForKey:@"AppleInterfaceStyle"];