8000 feat: promisify app.dock.show() by codebytere · Pull Request #16904 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: promisify app.dock.show() #16904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion atom/browser/browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class Browser : public WindowListObserver {

// Hide/Show dock.
void DockHide();
void DockShow();
v8::Local<v8::Promise> DockShow(v8::Isolate* isolate);
bool DockIsVisible();

// Set docks' menu.
Expand Down
7 changes: 6 additions & 1 deletion atom/browser/browser_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "atom/browser/window_list.h"
#include "atom/common/application_info.h"
#include "atom/common/platform_util.h"
#include "atom/common/promise_util.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/foundation_util.h"
#include "base/mac/mac_util.h"
Expand Down Expand Up @@ -338,7 +339,8 @@ void RemoveFromLoginItems() {
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];
ProcessSerialNumber psn = {0, kCurrentProcess};
if (active) {
Expand All @@ -357,11 +359,14 @@ void RemoveFromLoginItems() {
dispatch_after(one_ms, dispatch_get_main_queue(), ^{
[[NSRunningApplication currentApplication]
activateWithOptions:NSApplicationActivateIgnoringOtherApps];
promise->Resolve();
});
});
} else {
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
promise->Resolve();
}
return promise->GetHandle();
}

void Browser::DockSetMenu(AtomMenuModel* model) {
Expand Down
4 changes: 1 addition & 3 deletions docs/api/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -1295,13 +1295,11 @@ Hides the dock icon.

### `app.dock.show()` _macOS_

Shows the dock icon.
Returns `Promise<void>` - Resolves when the dock icon is shown.

### `app.dock.isVisible()` _macOS_

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_

Expand Down
32 changes: 22 additions & 10 deletions spec/api-app-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1110,17 +1110,29 @@ describe('app module', () => {
})
})

describe('dock.setMenu', () => {
before(function () {
if (process.platform !== 'darwin') {
this.skip()
}
describe('dock APIs', () => {
describe('dock.setMenu()', () => {
it('keeps references to the menu', function () {
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', () => {
app.dock.setMenu(new Menu())
const v8Util = process.atomBinding('v8_util')
v8Util.requestGarbageCollectionForTesting()
describe('dock.show()', () => {
before(function () {
if (process.platform !== 'darwin') this.skip()
})

it('returns a Promise', () => {
expect(app.dock.show()).to.be.a('promise')
})

it('eventually fulfills', () => {
expect(app.dock.show()).to.be.eventually.fulfilled()
})
})
})

Expand All @@ -1131,7 +1143,7 @@ describe('app module', () => {

it('becomes fulfilled if the app is already ready', () => {
expect(app.isReady()).to.be.true()
return expect(app.whenReady()).to.be.eventually.fulfilled
expect(app.whenReady()).to.be.eventually.fulfilled()
})
})

Expand Down
0