From 3ad5d17612fe7df0ad3db230d03fee8a120bc8e8 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 14 Sep 2015 19:28:13 +0800 Subject: [PATCH 1/5] [OS X] Implement 'activate-with-open-windows' event for app. --- atom/browser/api/atom_api_app.cc | 4 ++++ atom/browser/api/atom_api_app.h | 1 + atom/browser/browser.cc | 4 ++++ atom/browser/browser.h | 3 +++ atom/browser/browser_observer.h | 4 ++++ atom/browser/mac/atom_application_delegate.mm | 1 + docs/api/app.md | 5 +++++ 7 files changed, 22 insertions(+) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index e2d265c5da39..f7c20483b490 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -171,6 +171,10 @@ void App::OnActivateWithNoOpenWindows() { Emit("activate-with-no-open-windows"); } +void App::OnActivateWithOpenWindows() { + Emit("activate-with-open-windows"); +} + void App::OnWillFinishLaunching() { Emit("will-finish-launching"); } diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 040f7e3363a9..5f29744e919b 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -42,6 +42,7 @@ class App : public mate::EventEmitter, void OnOpenFile(bool* prevent_default, const std::string& file_path) override; void OnOpenURL(const std::string& url) override; void OnActivateWithNoOpenWindows() override; + void OnActivateWithOpenWindows() override; void OnWillFinishLaunching() override; void OnFinishLaunching() override; void OnSelectCertificate( diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index 3419ecbe330d..11530375eff8 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -98,6 +98,10 @@ void Browser::ActivateWithNoOpenWindows() { FOR_EACH_OBSERVER(BrowserObserver, observers_, OnActivateWithNoOpenWindows()); } +void Browser::ActivateWithOpenWindows() { + FOR_EACH_OBSERVER(BrowserObserver, observers_, OnActivateWithOpenWindows()); +} + void Browser::WillFinishLaunching() { FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillFinishLaunching()); } diff --git a/atom/browser/browser.h b/atom/browser/browser.h index dc412cefb046..43b253c840a8 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -111,6 +111,9 @@ class Browser : public WindowListObserver { // Tell the application that application is activated with no open windows. void ActivateWithNoOpenWindows(); + // Tell the application that application is activated with open windows. + void ActivateWithOpenWindows(); + // Tell the application the loading has been done. void WillFinishLaunching(); void DidFinishLaunching(); diff --git a/atom/browser/browser_observer.h b/atom/browser/browser_observer.h index 20fd08a2e911..815d21bb843f 100644 --- a/atom/browser/browser_observer.h +++ b/atom/browser/browser_observer.h @@ -47,6 +47,10 @@ class BrowserObserver { // dock icon). virtual void OnActivateWithNoOpenWindows() {} + // The browser is activated with open windows (usually by clicking on the dock + // icon). + virtual void OnActivateWithOpenWindows() {} + // The browser has finished loading. virtual void OnWillFinishLaunching() {} virtual void OnFinishLaunching() {} diff --git a/atom/browser/mac/atom_application_delegate.mm b/atom/browser/mac/atom_application_delegate.mm index 16dcf6fd9523..0ee46e59e6ec 100644 --- a/atom/browser/mac/atom_application_delegate.mm +++ b/atom/browser/mac/atom_application_delegate.mm @@ -53,6 +53,7 @@ hasVisibleWindows:(BOOL)flag { atom::Browser* browser = atom::Browser::Get(); if (flag) { + browser->ActivateWithOpenWindows(); return YES; } else { browser->ActivateWithNoOpenWindows(); diff --git a/docs/api/app.md b/docs/api/app.md index 799db98882fe..bb77a32913fc 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -100,6 +100,11 @@ 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. +### Event: activated-with-open-windows _OS X_ + +Emitted when the application is activated while there are open windows, which +usually happens when clicks on the applications's dock icon. + ### Event: 'browser-window-blur' Returns: From c006c4efa422032e05b06f469f269ce8e4aa4ec2 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 14 Sep 2015 20:34:45 +0800 Subject: [PATCH 2/5] Mention 'activate-with-no-open-windows' on OS X only. --- docs/api/app.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/app.md b/docs/api/app.md index bb77a32913fc..12be27ce75fc 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -94,7 +94,7 @@ 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-with-no-open-windows' _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 From 377e7ee3a728b5b8fe67605025fefc98cfd4f9f4 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 14 Sep 2015 18:34:27 -0700 Subject: [PATCH 3/5] Implement 'activiate' event instead of 'activate-with-open-windows'. --- atom/browser/api/atom_api_app.cc | 4 ++-- atom/browser/api/atom_api_app.h | 2 +- atom/browser/browser.cc | 4 ++-- atom/browser/browser.h | 5 +++-- atom/browser/browser_observer.h | 6 +++--- atom/browser/mac/atom_application_delegate.mm | 2 +- docs/api/app.md | 11 ++++++++--- 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index f7c20483b490..cf187c451c83 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -171,8 +171,8 @@ void App::OnActivateWithNoOpenWindows() { Emit("activate-with-no-open-windows"); } -void App::OnActivateWithOpenWindows() { - Emit("activate-with-open-windows"); +void App::OnActivate(bool hasVisibleWindows) { + Emit("activate", hasVisibleWindows); } void App::OnWillFinishLaunching() { diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 5f29744e919b..7e16a8df4e6c 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -42,7 +42,7 @@ class App : public mate::EventEmitter, void OnOpenFile(bool* prevent_default, const std::string& file_path) override; void OnOpenURL(const std::string& url) override; void OnActivateWithNoOpenWindows() override; - void OnActivateWithOpenWindows() override; + void OnActivate(bool hasVisibleWindows) override; void OnWillFinishLaunching() override; void OnFinishLaunching() override; void OnSelectCertificate( diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index 11530375eff8..186b6c6e37af 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -98,8 +98,8 @@ void Browser::ActivateWithNoOpenWindows() { FOR_EACH_OBSERVER(BrowserObserver, observers_, OnActivateWithNoOpenWindows()); } -void Browser::ActivateWithOpenWindows() { - FOR_EACH_OBSERVER(BrowserObserver, observers_, OnActivateWithOpenWindows()); +void Browser::Activate(bool hasVisibleWindows) { + FOR_EACH_OBSERVER(BrowserObserver, observers_, OnActivate(hasVisibleWindows)); } void Browser::WillFinishLaunching() { diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 43b253c840a8..3afa1b5a688c 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -111,8 +111,9 @@ class Browser : public WindowListObserver { // Tell the application that application is activated with no open windows. void ActivateWithNoOpenWindows(); - // Tell the application that application is activated with open windows. - void ActivateWithOpenWindows(); + // Tell the application that application is activated with visible/invisible + // windows. + void Activate(bool hasVisibleWindows); // 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 815d21bb843f..37be4922ddfa 100644 --- a/atom/browser/browser_observer.h +++ b/atom/browser/browser_observer.h @@ -47,9 +47,9 @@ class BrowserObserver { // dock icon). virtual void OnActivateWithNoOpenWindows() {} - // The browser is activated with open windows (usually by clicking on the dock - // icon). - virtual void OnActivateWithOpenWindows() {} + // The browser is activated with visible/invisible windows (usually by + // clicking on the dock icon). + virtual void OnActivate(bool hasVisibleWindows) {} // 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 0ee46e59e6ec..525e700e2b4e 100644 --- a/atom/browser/mac/atom_application_delegate.mm +++ b/atom/browser/mac/atom_application_delegate.mm @@ -52,8 +52,8 @@ - (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication hasVisibleWindows:(BOOL)flag { atom::Browser* browser = atom::Browser::Get(); + browser->Activate(static_cast(flag)); if (flag) { - browser->ActivateWithOpenWindows(); return YES; } else { browser->ActivateWithNoOpenWindows(); diff --git a/docs/api/app.md b/docs/api/app.md index 12be27ce75fc..ba61e1a0e0d8 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -100,10 +100,15 @@ 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. -### Event: activated-with-open-windows _OS X_ +### Event: 'activate' _OS X_ -Emitted when the application is activated while there are open windows, which -usually happens when clicks on the applications'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' From 40d93ce55aa0e478b639b0b07e42de1328930ae4 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 14 Sep 2015 18:36:05 -0700 Subject: [PATCH 4/5] Deprecate 'activate-with-no-open-windows' event. --- atom/browser/mac/atom_application_delegate.mm | 1 + docs/api/app.md | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/atom/browser/mac/atom_application_delegate.mm b/atom/browser/mac/atom_application_delegate.mm index 525e700e2b4e..7bdab03e0dc8 100644 --- a/atom/browser/mac/atom_application_delegate.mm +++ b/atom/browser/mac/atom_application_delegate.mm @@ -56,6 +56,7 @@ if (flag) { return YES; } else { + // Deprecated API, for compatibility. browser->ActivateWithNoOpenWindows(); return NO; } diff --git a/docs/api/app.md b/docs/api/app.md index ba61e1a0e0d8..85ad873de30d 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -94,12 +94,6 @@ 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' _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. - ### Event: 'activate' _OS X_ Returns: From 9652ed6508fa2cb048783f75e1c997461f9aa59b Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 14 Sep 2015 19:05:53 -0700 Subject: [PATCH 5/5] More fixes after code review. --- atom/browser/api/atom_api_app.cc | 8 ++------ atom/browser/api/atom_api_app.h | 3 +-- atom/browser/api/lib/app.coffee | 1 + atom/browser/browser.cc | 10 ++++------ atom/browser/browser.h | 5 +---- atom/browser/browser_observer.h | 6 +----- atom/browser/mac/atom_application_delegate.mm | 8 +------- 7 files changed, 11 insertions(+), 30 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index cf187c451c83..43b3d82df109 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -167,12 +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 hasVisibleWindows) { - Emit("activate", hasVisibleWindows); +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 7e16a8df4e6c..255f780e578d 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -41,8 +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 hasVisibleWindows) 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 186b6c6e37af..9d2a9fc1effb 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -94,12 +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 hasVisibleWindows) { - FOR_EACH_OBSERVER(BrowserObserver, observers_, OnActivate(hasVisibleWindows)); +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 3afa1b5a688c..d135556b8760 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -108,12 +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 hasVisibleWindows); + 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 37be4922ddfa..45e86e620f84 100644 --- a/atom/browser/browser_observer.h +++ b/atom/browser/browser_observer.h @@ -43,13 +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 hasVisibleWindows) {} + 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 7bdab03e0dc8..a18d2fe40fcd 100644 --- a/atom/browser/mac/atom_application_delegate.mm +++ b/atom/browser/mac/atom_application_delegate.mm @@ -53,13 +53,7 @@ hasVisibleWindows:(BOOL)flag { atom::Browser* browser = atom::Browser::Get(); browser->Activate(static_cast(flag)); - if (flag) { - return YES; - } else { - // Deprecated API, for compatibility. - browser->ActivateWithNoOpenWindows(); - return NO; - } + return flag; } @end