]> khamidou — GitHub mirrors - electron.git/commitdiff
Add 'activate-with-no-open-windows' event for app.
authorCheng Zhao <zcbenz@gmail.com>
Wed, 5 Mar 2014 10:09:44 +0000 (18:09 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 5 Mar 2014 10:09:44 +0000 (18:09 +0800)
Fixes #194.

browser/api/atom_api_app.cc
browser/api/atom_api_app.h
browser/atom_application_delegate_mac.mm
browser/browser.cc
browser/browser.h
browser/browser_observer.h
docs/api/browser/app.md

index f2b021c0d68532f235667d78bf38e5e795231da6..d07c387ba178b4b927cf786a35e7dfd5448ea16f 100644 (file)
@@ -44,6 +44,10 @@ void App::OnOpenURL(const std::string& url) {
   Emit("open-url", &args);
 }
 
+void App::OnActivateWithNoOpenWindows() {
+  Emit("activate-with-no-open-windows");
+}
+
 void App::OnWillFinishLaunching() {
   Emit("will-finish-launching");
 }
index 7ca6d0817af233d6523e5df90b395afb7abc05d8..9d3eccff187befe649eda7e995138b796c58236b 100644 (file)
@@ -29,6 +29,7 @@ class App : public EventEmitter,
   virtual void OnOpenFile(bool* prevent_default,
                           const std::string& file_path) OVERRIDE;
   virtual void OnOpenURL(const std::string& url) OVERRIDE;
+  virtual void OnActivateWithNoOpenWindows() OVERRIDE;
   virtual void OnWillFinishLaunching() OVERRIDE;
   virtual void OnFinishLaunching() OVERRIDE;
 
index 76dc16fff165e0cff458b0305aef23bfbc4d68ea..1843298bd5ac3b5ac43630d65428cdb48fc2b0c6 100644 (file)
   }
 }
 
+- (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication
+                    hasVisibleWindows:(BOOL)flag {
+  atom::Browser* browser = atom::Browser::Get();
+  if (flag) {
+    return YES;
+  } else {
+    browser->ActivateWithNoOpenWindows();
+    return NO;
+  }
+}
+
 @end
index 49f2cef4ef6de54b02273b45c2060e4191d890bc..6567aea1546e4a7b225d460d9abeee4dc52e29e0 100644 (file)
@@ -74,6 +74,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::WillFinishLaunching() {
   FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillFinishLaunching());
 }
index d20fc973ff26722af97d4de3b11cd067ca6254ca..759e9680f205045e454868d638b477a273675e55 100644 (file)
@@ -62,6 +62,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 the loading has been done.
   void WillFinishLaunching();
   void DidFinishLaunching();
index 20b13ad47646bf1dc8420ec1bf627366e53b23b0..e7f1cd92216565e6d4c9a3283747077da52912d6 100644 (file)
@@ -26,6 +26,10 @@ 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 has finished loading.
   virtual void OnWillFinishLaunching() {}
   virtual void OnFinishLaunching() {}
index ae2ec9da61523bc13da8ec1f3708e8949673a012..4c34f883598458f3ef72700df78b036031bd1ffe 100644 (file)
@@ -66,6 +66,12 @@ 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
+
+Emitted when the application is activated while there is no opened windows. It
+usually happens when user has closed all of application's windows and then
+click on the application's dock icon.
+
 ## app.quit()
 
 Try to close all windows. If all windows are successfully closed, the