diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 8a66c041f4a2..534e5c4e4a86 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -656,6 +656,7 @@ void Initialize(v8::Local exports, v8::Local unused, base::Bind(&Browser::DockGetBadgeText, browser)); dict.SetMethod("dockHide", base::Bind(&Browser::DockHide, browser)); dict.SetMethod("dockShow", base::Bind(&Browser::DockShow, browser)); + dict.SetMethod("dockIsVisible", base::Bind(&Browser::DockIsVisible, browser)); dict.SetMethod("dockSetMenu", &DockSetMenu); dict.SetMethod("dockSetIcon", base::Bind(&Browser::DockSetIcon, browser)); #endif diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 771a29a87a42..96fad18fc7f0 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -136,6 +136,7 @@ class Browser : public WindowListObserver { // Hide/Show dock. void DockHide(); void DockShow(); + bool DockIsVisible(); // Set docks' menu. void DockSetMenu(AtomMenuModel* model); diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index d4b615e73efb..2cfb4ca2cdf6 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -208,6 +208,12 @@ void Browser::DockHide() { TransformProcessType(&psn, kProcessTransformToUIElementApplication); } +bool Browser::DockIsVisible() { + // Because DockShow has a slight delay this may not be true immediately + // after that call. + return ([[NSRunningApplication currentApplication] activationPolicy] == NSApplicationActivationPolicyRegular); +} + void Browser::DockShow() { BOOL active = [[NSRunningApplication currentApplication] isActive]; ProcessSerialNumber psn = { 0, kCurrentProcess }; diff --git a/docs/api/app.md b/docs/api/app.md index 1220f36c9f8c..ca1a36c9f984 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -725,6 +725,12 @@ Hides the dock icon. Shows the dock icon. +### `app.dock.isVisible()` _macOS_ + +Returns whether the dock icon is visible. +The `app.dock.show()` call is asynchronous so this method might not +return true immediately after that call. + ### `app.dock.setMenu(menu)` _macOS_ * `menu` [Menu](menu.md) diff --git a/lib/browser/api/app.js b/lib/browser/api/app.js index 0ea788b94a71..a63ef241bb6d 100644 --- a/lib/browser/api/app.js +++ b/lib/browser/api/app.js @@ -40,6 +40,7 @@ if (process.platform === 'darwin') { getBadge: bindings.dockGetBadgeText, hide: bindings.dockHide, show: bindings.dockShow, + isVisible: bindings.dockIsVisible, setMenu: bindings.dockSetMenu, setIcon: bindings.dockSetIcon }