Merge pull request #2777 from atom/dock-clicked
Implement 'activate' event for app.
This commit is contained in:
commit
fe2219a635
8 changed files with 24 additions and 20 deletions
|
@ -167,8 +167,8 @@ void App::OnOpenURL(const std::string& url) {
|
||||||
Emit("open-url", url);
|
Emit("open-url", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::OnActivateWithNoOpenWindows() {
|
void App::OnActivate(bool has_visible_windows) {
|
||||||
Emit("activate-with-no-open-windows");
|
Emit("activate", has_visible_windows);
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::OnWillFinishLaunching() {
|
void App::OnWillFinishLaunching() {
|
||||||
|
|
|
@ -41,7 +41,7 @@ class App : public mate::EventEmitter,
|
||||||
void OnQuit() override;
|
void OnQuit() override;
|
||||||
void OnOpenFile(bool* prevent_default, const std::string& file_path) override;
|
void OnOpenFile(bool* prevent_default, const std::string& file_path) override;
|
||||||
void OnOpenURL(const std::string& url) override;
|
void OnOpenURL(const std::string& url) override;
|
||||||
void OnActivateWithNoOpenWindows() override;
|
void OnActivate(bool has_visible_windows) override;
|
||||||
void OnWillFinishLaunching() override;
|
void OnWillFinishLaunching() override;
|
||||||
void OnFinishLaunching() override;
|
void OnFinishLaunching() override;
|
||||||
void OnSelectCertificate(
|
void OnSelectCertificate(
|
||||||
|
|
|
@ -45,6 +45,7 @@ app.getHomeDir = -> @getPath 'home'
|
||||||
app.getDataPath = -> @getPath 'userData'
|
app.getDataPath = -> @getPath 'userData'
|
||||||
app.setDataPath = (path) -> @setPath 'userData', path
|
app.setDataPath = (path) -> @setPath 'userData', path
|
||||||
app.resolveProxy = -> @defaultSession.resolveProxy.apply @defaultSession, arguments
|
app.resolveProxy = -> @defaultSession.resolveProxy.apply @defaultSession, arguments
|
||||||
|
app.on 'activate', (event, hasVisibleWindows) -> @emit 'activate-with-no-open-windows' if hasVisibleWindows
|
||||||
|
|
||||||
# Session wrapper.
|
# Session wrapper.
|
||||||
sessionBindings._setWrapSession wrapSession
|
sessionBindings._setWrapSession wrapSession
|
||||||
|
|
|
@ -94,8 +94,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() {
|
void Browser::Activate(bool has_visible_windows) {
|
||||||
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnActivateWithNoOpenWindows());
|
FOR_EACH_OBSERVER(BrowserObserver,
|
||||||
|
observers_,
|
||||||
|
OnActivate(has_visible_windows));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::WillFinishLaunching() {
|
void Browser::WillFinishLaunching() {
|
||||||
|
|
|
@ -108,8 +108,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.
|
// Tell the application that application is activated with visible/invisible
|
||||||
void ActivateWithNoOpenWindows();
|
// windows.
|
||||||
|
void Activate(bool has_visible_windows);
|
||||||
|
|
||||||
// Tell the application the loading has been done.
|
// Tell the application the loading has been done.
|
||||||
void WillFinishLaunching();
|
void WillFinishLaunching();
|
||||||
|
|
|
@ -43,9 +43,9 @@ 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
|
// The browser is activated with visible/invisible windows (usually by
|
||||||
// dock icon).
|
// clicking on the dock icon).
|
||||||
virtual void OnActivateWithNoOpenWindows() {}
|
virtual void OnActivate(bool has_visible_windows) {}
|
||||||
|
|
||||||
// The browser has finished loading.
|
// The browser has finished loading.
|
||||||
virtual void OnWillFinishLaunching() {}
|
virtual void OnWillFinishLaunching() {}
|
||||||
|
|
|
@ -52,12 +52,8 @@
|
||||||
- (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication
|
- (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication
|
||||||
hasVisibleWindows:(BOOL)flag {
|
hasVisibleWindows:(BOOL)flag {
|
||||||
atom::Browser* browser = atom::Browser::Get();
|
atom::Browser* browser = atom::Browser::Get();
|
||||||
if (flag) {
|
browser->Activate(static_cast<bool>(flag));
|
||||||
return YES;
|
return flag;
|
||||||
} else {
|
|
||||||
browser->ActivateWithNoOpenWindows();
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -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.
|
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
|
Returns:
|
||||||
usually happens when the user has closed all of the application's windows and
|
|
||||||
then clicks on the application's dock icon.
|
* `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'
|
### Event: 'browser-window-blur'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue