diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index e2d265c5da39..43b3d82df109 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -167,8 +167,8 @@ void App::OnOpenURL(const std::string& url) { Emit("open-url", url); } -void App::OnActivateWithNoOpenWindows() { - Emit("activate-with-no-open-windows"); +void App::OnActivate(bool has_visible_windows) { + Emit("activate", has_visible_windows); } void App::OnWillFinishLaunching() { diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 040f7e3363a9..255f780e578d 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -41,7 +41,7 @@ class App : public mate::EventEmitter, void OnQuit() override; void OnOpenFile(bool* prevent_default, const std::string& file_path) override; void OnOpenURL(const std::string& url) override; - void OnActivateWithNoOpenWindows() override; + void OnActivate(bool has_visible_windows) override; void OnWillFinishLaunching() override; void OnFinishLaunching() override; void OnSelectCertificate( diff --git a/atom/browser/api/lib/app.coffee b/atom/browser/api/lib/app.coffee index b3446e86e23a..d1dc3fc68962 100644 --- a/atom/browser/api/lib/app.coffee +++ b/atom/browser/api/lib/app.coffee @@ -45,6 +45,7 @@ app.getHomeDir = -> @getPath 'home' app.getDataPath = -> @getPath 'userData' app.setDataPath = (path) -> @setPath 'userData', path app.resolveProxy = -> @defaultSession.resolveProxy.apply @defaultSession, arguments +app.on 'activate', (event, hasVisibleWindows) -> @emit 'activate-with-no-open-windows' if hasVisibleWindows # Session wrapper. sessionBindings._setWrapSession wrapSession diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index 3419ecbe330d..9d2a9fc1effb 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -94,8 +94,10 @@ void Browser::OpenURL(const std::string& url) { FOR_EACH_OBSERVER(BrowserObserver, observers_, OnOpenURL(url)); } -void Browser::ActivateWithNoOpenWindows() { - FOR_EACH_OBSERVER(BrowserObserver, observers_, OnActivateWithNoOpenWindows()); +void Browser::Activate(bool has_visible_windows) { + FOR_EACH_OBSERVER(BrowserObserver, + observers_, + OnActivate(has_visible_windows)); } void Browser::WillFinishLaunching() { diff --git a/atom/browser/browser.h b/atom/browser/browser.h index dc412cefb046..d135556b8760 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -108,8 +108,9 @@ class Browser : public WindowListObserver { // Tell the application to open a url. void OpenURL(const std::string& url); - // Tell the application that application is activated with no open windows. - void ActivateWithNoOpenWindows(); + // Tell the application that application is activated with visible/invisible + // windows. + void Activate(bool has_visible_windows); // Tell the application the loading has been done. void WillFinishLaunching(); diff --git a/atom/browser/browser_observer.h b/atom/browser/browser_observer.h index 20fd08a2e911..45e86e620f84 100644 --- a/atom/browser/browser_observer.h +++ b/atom/browser/browser_observer.h @@ -43,9 +43,9 @@ class BrowserObserver { // Browser is used to open a url. virtual void OnOpenURL(const std::string& url) {} - // The browser is activated with no open windows (usually by clicking on the - // dock icon). - virtual void OnActivateWithNoOpenWindows() {} + // The browser is activated with visible/invisible windows (usually by + // clicking on the dock icon). + virtual void OnActivate(bool has_visible_windows) {} // The browser has finished loading. virtual void OnWillFinishLaunching() {} diff --git a/atom/browser/mac/atom_application_delegate.mm b/atom/browser/mac/atom_application_delegate.mm index 16dcf6fd9523..a18d2fe40fcd 100644 --- a/atom/browser/mac/atom_application_delegate.mm +++ b/atom/browser/mac/atom_application_delegate.mm @@ -52,12 +52,8 @@ - (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication hasVisibleWindows:(BOOL)flag { atom::Browser* browser = atom::Browser::Get(); - if (flag) { - return YES; - } else { - browser->ActivateWithNoOpenWindows(); - return NO; - } + browser->Activate(static_cast(flag)); + return flag; } @end diff --git a/docs/api/app.md b/docs/api/app.md index 799db98882fe..85ad873de30d 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -94,11 +94,15 @@ must be registered to be opened by your application. You should call `event.preventDefault()` if you want to handle this event. -### Event: 'activate-with-no-open-windows' +### Event: 'activate' _OS X_ -Emitted when the application is activated while there are no open windows, which -usually happens when the user has closed all of the application's windows and -then clicks on the application's dock icon. +Returns: + +* `event` Event +* `hasVisibleWindows` Bool + +Emitted when the application is activated, which usually happens when clicks on +the applications's dock icon. ### Event: 'browser-window-blur'