feat: promisify app.dock.show() (#16904)
* feat: promisify app.dock.show * add a spec
This commit is contained in:
parent
cd9bf72ee8
commit
ca83d36426
4 changed files with 30 additions and 15 deletions
|
@ -171,7 +171,7 @@ class Browser : public WindowListObserver {
|
||||||
|
|
||||||
// Hide/Show dock.
|
// Hide/Show dock.
|
||||||
void DockHide();
|
void DockHide();
|
||||||
void DockShow();
|
v8::Local<v8::Promise> DockShow(v8::Isolate* isolate);
|
||||||
bool DockIsVisible();
|
bool DockIsVisible();
|
||||||
|
|
||||||
// Set docks' menu.
|
// Set docks' menu.
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "atom/browser/window_list.h"
|
#include "atom/browser/window_list.h"
|
||||||
#include "atom/common/application_info.h"
|
#include "atom/common/application_info.h"
|
||||||
#include "atom/common/platform_util.h"
|
#include "atom/common/platform_util.h"
|
||||||
|
#include "atom/common/promise_util.h"
|
||||||
#include "base/mac/bundle_locations.h"
|
#include "base/mac/bundle_locations.h"
|
||||||
#include "base/mac/foundation_util.h"
|
#include "base/mac/foundation_util.h"
|
||||||
#include "base/mac/mac_util.h"
|
#include "base/mac/mac_util.h"
|
||||||
|
@ -338,7 +339,8 @@ bool Browser::DockIsVisible() {
|
||||||
NSApplicationActivationPolicyRegular);
|
NSApplicationActivationPolicyRegular);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::DockShow() {
|
v8::Local<v8::Promise> Browser::DockShow(v8::Isolate* isolate) {
|
||||||
|
scoped_refptr<util::Promise> promise = new util::Promise(isolate);
|
||||||
BOOL active = [[NSRunningApplication currentApplication] isActive];
|
BOOL active = [[NSRunningApplication currentApplication] isActive];
|
||||||
ProcessSerialNumber psn = {0, kCurrentProcess};
|
ProcessSerialNumber psn = {0, kCurrentProcess};
|
||||||
if (active) {
|
if (active) {
|
||||||
|
@ -357,11 +359,14 @@ void Browser::DockShow() {
|
||||||
dispatch_after(one_ms, dispatch_get_main_queue(), ^{
|
dispatch_after(one_ms, dispatch_get_main_queue(), ^{
|
||||||
[[NSRunningApplication currentApplication]
|
[[NSRunningApplication currentApplication]
|
||||||
activateWithOptions:NSApplicationActivateIgnoringOtherApps];
|
activateWithOptions:NSApplicationActivateIgnoringOtherApps];
|
||||||
|
promise->Resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||||
|
promise->Resolve();
|
||||||
}
|
}
|
||||||
|
return promise->GetHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::DockSetMenu(AtomMenuModel* model) {
|
void Browser::DockSetMenu(AtomMenuModel* model) {
|
||||||
|
|
|
@ -1295,13 +1295,11 @@ Hides the dock icon.
|
||||||
|
|
||||||
### `app.dock.show()` _macOS_
|
### `app.dock.show()` _macOS_
|
||||||
|
|
||||||
Shows the dock icon.
|
Returns `Promise<void>` - Resolves when the dock icon is shown.
|
||||||
|
|
||||||
### `app.dock.isVisible()` _macOS_
|
### `app.dock.isVisible()` _macOS_
|
||||||
|
|
||||||
Returns `Boolean` - Whether the dock icon is visible.
|
Returns `Boolean` - 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_
|
||||||
|
|
||||||
|
|
|
@ -1110,17 +1110,29 @@ describe('app module', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('dock.setMenu', () => {
|
describe('dock APIs', () => {
|
||||||
before(function () {
|
describe('dock.setMenu()', () => {
|
||||||
if (process.platform !== 'darwin') {
|
it('keeps references to the menu', function () {
|
||||||
this.skip()
|
if (process.platform !== 'darwin') this.skip()
|
||||||
}
|
|
||||||
|
app.dock.setMenu(new Menu())
|
||||||
|
const v8Util = process.atomBinding('v8_util')
|
||||||
|
v8Util.requestGarbageCollectionForTesting()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('keeps references to the menu', () => {
|
describe('dock.show()', () => {
|
||||||
app.dock.setMenu(new Menu())
|
before(function () {
|
||||||
const v8Util = process.atomBinding('v8_util')
|
if (process.platform !== 'darwin') this.skip()
|
||||||
v8Util.requestGarbageCollectionForTesting()
|
})
|
||||||
|
|
||||||
|
it('returns a Promise', () => {
|
||||||
|
expect(app.dock.show()).to.be.a('promise')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('eventually fulfills', () => {
|
||||||
|
expect(app.dock.show()).to.be.eventually.fulfilled()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1131,7 +1143,7 @@ describe('app module', () => {
|
||||||
|
|
||||||
it('becomes fulfilled if the app is already ready', () => {
|
it('becomes fulfilled if the app is already ready', () => {
|
||||||
expect(app.isReady()).to.be.true()
|
expect(app.isReady()).to.be.true()
|
||||||
return expect(app.whenReady()).to.be.eventually.fulfilled
|
expect(app.whenReady()).to.be.eventually.fulfilled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue