diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index e54d7fee17..53415c4d9c 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -370,6 +370,7 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder( #if defined(OS_MACOSX) .SetMethod("hide", base::Bind(&Browser::Hide, browser)) .SetMethod("show", base::Bind(&Browser::Show, browser)) + .SetMethod("isDarkModeEnabled", base::Bind(&Browser::IsDarkModeEnabled, browser)) #endif #if defined(OS_WIN) .SetMethod("setUserTasks", diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 2c44eaa107..b2e1679b7f 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -83,6 +83,9 @@ class Browser : public WindowListObserver { // Show the application. void Show(); + // Check if Dark Mode enabled. + bool IsDarkModeEnabled(); + // Bounce the dock icon. enum BounceType { BOUNCE_CRITICAL = 0, diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index bc0be22dca..affeead255 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -26,6 +26,11 @@ void Browser::Show() { [[AtomApplication sharedApplication] unhide:nil]; } +bool Browser::IsDarkModeEnabled() { + NSString *mode = CFBridgingRelease(CFPreferencesCopyValue((CFStringRef)@"AppleInterfaceStyle", kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost)); + return [mode isEqualToString: @"Dark"]; +} + void Browser::AddRecentDocument(const base::FilePath& path) { NSString* path_string = base::mac::FilePathToNSString(path); if (!path_string) diff --git a/docs/api/app.md b/docs/api/app.md index bdf0a8a558..3d0790a929 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -461,6 +461,10 @@ if (browserOptions.transparent) { } ``` +### `app.isDarkModeEnabled()` _OS X_ + +This method returns `true` if Dark Mode is enabled, and `false` otherwise. + ### `app.commandLine.appendSwitch(switch[, value])` Append a switch (with optional `value`) to Chromium's command line.