From: Daniel Pham Date: Tue, 1 Mar 2016 20:05:44 +0000 (-0500) Subject: :apple: Add 'dark-mode-changed' event to app api X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c4049cb393cc6266e5d1cc34780621b8dad2ad26;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git :apple: Add 'dark-mode-changed' event to app api --- diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 53415c4..76a5f32 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -282,6 +282,12 @@ void App::OnGpuProcessCrashed(base::TerminationStatus exit_code) { Emit("gpu-process-crashed"); } +#if defined(OS_MACOSX) +void App::OnDarkModeChanged() { + Emit("dark-mode-changed"); +} +#endif + base::FilePath App::GetPath(mate::Arguments* args, const std::string& name) { bool succeed = false; base::FilePath path; @@ -370,7 +376,8 @@ 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)) + .SetMethod("isDarkModeEnabled", + base::Bind(&Browser::IsDarkModeEnabled, browser)) #endif #if defined(OS_WIN) .SetMethod("setUserTasks", diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index c59b915..54d3f9d 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -71,6 +71,10 @@ class App : public AtomBrowserClient::Delegate, // content::GpuDataManagerObserver: void OnGpuProcessCrashed(base::TerminationStatus exit_code) override; +#if defined(OS_MACOSX) + void OnDarkModeChanged() override; +#endif + // mate::Wrappable: mate::ObjectTemplateBuilder GetObjectTemplateBuilder( v8::Isolate* isolate) override; diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index 7a2c22e..7fbe016 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -181,4 +181,8 @@ void Browser::OnWindowAllClosed() { FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWindowAllClosed()); } +void Browser::DarkModeChanged() { + FOR_EACH_OBSERVER(BrowserObserver, observers_, OnDarkModeChanged()); +} + } // namespace atom diff --git a/atom/browser/browser.h b/atom/browser/browser.h index b2e1679..04b7a72 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -145,6 +145,8 @@ class Browser : public WindowListObserver { // Request basic auth login. void RequestLogin(LoginHandler* login_handler); + void DarkModeChanged(); + void AddObserver(BrowserObserver* obs) { observers_.AddObserver(obs); } diff --git a/atom/browser/browser_observer.h b/atom/browser/browser_observer.h index f6d76bc..0577712 100644 --- a/atom/browser/browser_observer.h +++ b/atom/browser/browser_observer.h @@ -45,6 +45,8 @@ class BrowserObserver { // The browser requests HTTP login. virtual void OnLogin(LoginHandler* login_handler) {} + virtual void OnDarkModeChanged() {} + protected: virtual ~BrowserObserver() {} }; diff --git a/atom/browser/mac/atom_application_delegate.mm b/atom/browser/mac/atom_application_delegate.mm index 7662162..0b9c60e 100644 --- a/atom/browser/mac/atom_application_delegate.mm +++ b/atom/browser/mac/atom_application_delegate.mm @@ -24,6 +24,9 @@ // Don't add the "Enter Full Screen" menu item automatically. [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"NSFullScreenMenuItemEverywhere"]; + // Add observer to monitor the system's Dark Mode theme. + [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(darkModeChanged:) name:@"AppleInterfaceThemeChangedNotification" object:nil]; + atom::Browser::Get()->WillFinishLaunching(); } @@ -59,4 +62,8 @@ return flag; } +- (void)darkModeChanged:(NSNotification *)notify { + atom::Browser::Get()->DarkModeChanged(); +} + @end diff --git a/docs/api/app.md b/docs/api/app.md index 3d0790a..3469c6b 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -228,6 +228,10 @@ app.on('login', function(event, webContents, request, authInfo, callback) { Emitted when the gpu process crashes. +### Event: 'dark-mode-changed' _OS X_ + +Emitted when the system's Dark Mode theme is toggled. + ## Methods The `app` object has the following methods: