Skip to content

Commit

Permalink
refactor: use NativeTheme dark mode detection on macOS 10.14+ (#19310)
Browse files Browse the repository at this point in the history
  • Loading branch information
Micha Hanselmann authored and codebytere committed Jul 17, 2019
1 parent 46c0859 commit 04c7453
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions atom/browser/api/atom_api_system_preferences_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "base/values.h"
#include "native_mate/object_template_builder.h"
#include "net/base/mac/url_conversions.h"
#include "ui/native_theme/native_theme.h"

namespace mate {
template <>
Expand Down Expand Up @@ -558,8 +559,7 @@ AVMediaType ParseMediaType(const std::string& media_type) {

bool SystemPreferences::IsDarkMode() {
if (@available(macOS 10.15, *)) {
return [[NSApplication sharedApplication].effectiveAppearance.name
isEqualToString:NSAppearanceNameDarkAqua];
return ui::NativeTheme::GetInstanceForNativeUi()->SystemDarkModeEnabled();
}
NSString* mode = [[NSUserDefaults standardUserDefaults]
stringForKey:@"AppleInterfaceStyle"];
Expand Down
10 changes: 5 additions & 5 deletions atom/browser/ui/tray_icon_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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 {

Expand Down Expand Up @@ -150,8 +151,7 @@ - (void)drawRect:(NSRect)dirtyRect {

- (BOOL)isDarkMode {
if (@available(macOS 10.15, *)) {
return [[NSApplication sharedApplication].effectiveAppearance.name
isEqualToString:NSAppearanceNameDarkAqua];
return ui::NativeTheme::GetInstanceForNativeUi()->SystemDarkModeEnabled();
}
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSString* mode = [defaults stringForKey:@"AppleInterfaceStyle"];
Expand Down Expand Up @@ -335,9 +335,9 @@ - (void)popUpContextMenu:(atom::AtomMenuModel*)menu_model {

// Show a custom menu.
if (menu_model) {
base::scoped_nsobject<AtomMenuController> menuController(
[[AtomMenuController alloc] initWithModel:menu_model
useDefaultAccelerator:NO]);
base::scoped_nsobject<AtomMenuController> menuController([
[AtomMenuController alloc] initWithModel:menu_model
useDefaultAccelerator:NO]);
forceHighlight_ = YES; // Should highlight when showing menu.
[self setNeedsDisplay:YES];

Expand Down

0 comments on commit 04c7453

Please sign in to comment.