Add 'activate-with-no-open-windows' event for app.

Fixes #194.
This commit is contained in:
Cheng Zhao 2014-03-05 18:09:44 +08:00
parent a74d3d210d
commit 839a751de5
7 changed files with 33 additions and 0 deletions

View file

@ -44,6 +44,10 @@ void App::OnOpenURL(const std::string& url) {
Emit("open-url", &args); Emit("open-url", &args);
} }
void App::OnActivateWithNoOpenWindows() {
Emit("activate-with-no-open-windows");
}
void App::OnWillFinishLaunching() { void App::OnWillFinishLaunching() {
Emit("will-finish-launching"); Emit("will-finish-launching");
} }

View file

@ -29,6 +29,7 @@ class App : public EventEmitter,
virtual void OnOpenFile(bool* prevent_default, virtual void OnOpenFile(bool* prevent_default,
const std::string& file_path) OVERRIDE; const std::string& file_path) OVERRIDE;
virtual void OnOpenURL(const std::string& url) OVERRIDE; virtual void OnOpenURL(const std::string& url) OVERRIDE;
virtual void OnActivateWithNoOpenWindows() OVERRIDE;
virtual void OnWillFinishLaunching() OVERRIDE; virtual void OnWillFinishLaunching() OVERRIDE;
virtual void OnFinishLaunching() OVERRIDE; virtual void OnFinishLaunching() OVERRIDE;

View file

@ -35,4 +35,15 @@
} }
} }
- (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication
hasVisibleWindows:(BOOL)flag {
atom::Browser* browser = atom::Browser::Get();
if (flag) {
return YES;
} else {
browser->ActivateWithNoOpenWindows();
return NO;
}
}
@end @end

View file

@ -74,6 +74,10 @@ void Browser::OpenURL(const std::string& url) {
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnOpenURL(url)); FOR_EACH_OBSERVER(BrowserObserver, observers_, OnOpenURL(url));
} }
void Browser::ActivateWithNoOpenWindows() {
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnActivateWithNoOpenWindows());
}
void Browser::WillFinishLaunching() { void Browser::WillFinishLaunching() {
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillFinishLaunching()); FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillFinishLaunching());
} }

View file

@ -62,6 +62,9 @@ class Browser : public WindowListObserver {
// Tell the application to open a url. // Tell the application to open a url.
void OpenURL(const std::string& 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. // Tell the application the loading has been done.
void WillFinishLaunching(); void WillFinishLaunching();
void DidFinishLaunching(); void DidFinishLaunching();

View file

@ -26,6 +26,10 @@ class BrowserObserver {
// Browser is used to open a url. // Browser is used to open a url.
virtual void OnOpenURL(const std::string& 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. // The browser has finished loading.
virtual void OnWillFinishLaunching() {} virtual void OnWillFinishLaunching() {}
virtual void OnFinishLaunching() {} virtual void OnFinishLaunching() {}

View 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. 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() ## app.quit()
Try to close all windows. If all windows are successfully closed, the Try to close all windows. If all windows are successfully closed, the