diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 394014e8b27e..e54d7fee1769 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -367,6 +367,10 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder( base::Bind(&Browser::ClearRecentDocuments, browser)) .SetMethod("setAppUserModelId", base::Bind(&Browser::SetAppUserModelID, browser)) +#if defined(OS_MACOSX) + .SetMethod("hide", base::Bind(&Browser::Hide, browser)) + .SetMethod("show", base::Bind(&Browser::Show, browser)) +#endif #if defined(OS_WIN) .SetMethod("setUserTasks", base::Bind(&Browser::SetUserTasks, browser)) diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 0b55fb600cff..2c44eaa107bc 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -77,6 +77,12 @@ class Browser : public WindowListObserver { void SetAppUserModelID(const base::string16& name); #if defined(OS_MACOSX) + // Hide the application. + void Hide(); + + // Show the application. + void Show(); + // Bounce the dock icon. enum BounceType { BOUNCE_CRITICAL = 0, diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index 1eb7fabdab06..bf9c9ef69e8e 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -18,6 +18,14 @@ void Browser::Focus() { [[AtomApplication sharedApplication] activateIgnoringOtherApps:YES]; } +void Browser::Hide() { + [[AtomApplication sharedApplication] hide:nil]; +} + +void Browser::Show() { + [[AtomApplication sharedApplication] unhide:nil]; +} + void Browser::AddRecentDocument(const base::FilePath& path) { NSString* path_string = base::mac::FilePathToNSString(path); if (!path_string) diff --git a/docs/api/app.md b/docs/api/app.md index a26defb447a6..4b5c6ee2a6a9 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -244,6 +244,14 @@ This method guarantees that all `beforeunload` and `unload` event handlers are correctly executed. It is possible that a window cancels the quitting by returning `false` in the `beforeunload` event handler. +### `app.hide()` _OS X_ + +Hides all application windows without minimising them. + +### `app.show()` _OS X_ + +Shows application windows after they were hidden. Does not automatically focus them. + ### `app.exit(exitCode)` * `exitCode` Integer