From 7bde92deb9afbe20b3c979c56b3d4025e1c6a507 Mon Sep 17 00:00:00 2001 From: Gabriel Handford Date: Mon, 1 Aug 2016 15:22:37 -0700 Subject: [PATCH] Add isVisible() to app.dock --- atom/browser/api/atom_api_app.cc | 1 + atom/browser/browser.h | 1 + atom/browser/browser_mac.mm | 6 ++++++ docs/api/app.md | 6 ++++++ lib/browser/api/app.js | 1 + 5 files changed, 15 insertions(+) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 8a66c04..534e5c4 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 771a29a..96fad18 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 d4b615e..2cfb4ca 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 1220f36..ca1a36c 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 0ea788b..a63ef24 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 } -- 2.7.4