Add isVisible() to app.dock

This commit is contained in:
Gabriel Handford 2016-08-01 15:22:37 -07:00
parent eb73303f28
commit 7bde92deb9
5 changed files with 15 additions and 0 deletions

View file

@ -656,6 +656,7 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
base::Bind(&Browser::DockGetBadgeText, browser)); base::Bind(&Browser::DockGetBadgeText, browser));
dict.SetMethod("dockHide", base::Bind(&Browser::DockHide, browser)); dict.SetMethod("dockHide", base::Bind(&Browser::DockHide, browser));
dict.SetMethod("dockShow", base::Bind(&Browser::DockShow, browser)); dict.SetMethod("dockShow", base::Bind(&Browser::DockShow, browser));
dict.SetMethod("dockIsVisible", base::Bind(&Browser::DockIsVisible, browser));
dict.SetMethod("dockSetMenu", &DockSetMenu); dict.SetMethod("dockSetMenu", &DockSetMenu);
dict.SetMethod("dockSetIcon", base::Bind(&Browser::DockSetIcon, browser)); dict.SetMethod("dockSetIcon", base::Bind(&Browser::DockSetIcon, browser));
#endif #endif

View file

@ -136,6 +136,7 @@ class Browser : public WindowListObserver {
// Hide/Show dock. // Hide/Show dock.
void DockHide(); void DockHide();
void DockShow(); void DockShow();
bool DockIsVisible();
// Set docks' menu. // Set docks' menu.
void DockSetMenu(AtomMenuModel* model); void DockSetMenu(AtomMenuModel* model);

View file

@ -208,6 +208,12 @@ void Browser::DockHide() {
TransformProcessType(&psn, kProcessTransformToUIElementApplication); 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() { void Browser::DockShow() {
BOOL active = [[NSRunningApplication currentApplication] isActive]; BOOL active = [[NSRunningApplication currentApplication] isActive];
ProcessSerialNumber psn = { 0, kCurrentProcess }; ProcessSerialNumber psn = { 0, kCurrentProcess };

View file

@ -725,6 +725,12 @@ Hides the dock icon.
Shows 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_ ### `app.dock.setMenu(menu)` _macOS_
* `menu` [Menu](menu.md) * `menu` [Menu](menu.md)

View file

@ -40,6 +40,7 @@ if (process.platform === 'darwin') {
getBadge: bindings.dockGetBadgeText, getBadge: bindings.dockGetBadgeText,
hide: bindings.dockHide, hide: bindings.dockHide,
show: bindings.dockShow, show: bindings.dockShow,
isVisible: bindings.dockIsVisible,
setMenu: bindings.dockSetMenu, setMenu: bindings.dockSetMenu,
setIcon: bindings.dockSetIcon setIcon: bindings.dockSetIcon
} }