Skip to content
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

Add window.bringToFront() #210

Merged
merged 2 commits into from
Jan 3, 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
7 changes: 7 additions & 0 deletions packages/desktopjs-electron/src/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ export class ElectronContainerWindow extends ContainerWindow {
return Promise.resolve();
}

public bringToFront(): Promise<void> {
return new Promise<void>(resolve => {
this.innerWindow.moveTop();
resolve();
});
}

public getOptions(): Promise<any> {
return new Promise<any>((resolve, reject) => {
const options = (this.isRemote)
Expand Down
11 changes: 10 additions & 1 deletion packages/desktopjs-electron/tests/electron.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class MockWindow extends MockEventEmitter {
this.emit("move", null);
}

public flashFrame(enable: boolean): void { }
public flashFrame(enable: boolean): void { }

public moveTop(): void { }
}

class MockCapture {
Expand Down Expand Up @@ -408,6 +410,13 @@ describe("ElectronContainerWindow", () => {
expect((<any>container).windowManager.ungroupWindows).toHaveBeenCalled();
});
});

it ("bringToFront invokes underlying moveTop", (done) => {
spyOn(win.innerWindow, "moveTop").and.callThrough()
win.bringToFront().then(() => {
expect(innerWin.moveTop).toHaveBeenCalled();
}).then(done);
});
});

describe("ElectronContainer", () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/desktopjs-openfin/src/openfin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ export class OpenFinContainerWindow extends ContainerWindow {
});
}

public bringToFront(): Promise<void> {
return new Promise<void>((resolve, reject) => {
this.innerWindow.bringToFront(resolve, reject);
});
}

public getOptions(): Promise<any> {
return new Promise<any>((resolve, reject) => {
this.innerWindow.getOptions(options => resolve(options.customData ? JSON.parse(options.customData) : undefined), reject);
Expand Down
11 changes: 11 additions & 0 deletions packages/desktopjs-openfin/tests/openfin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ class MockWindow {
joinGroup(target: any, callback: any, errorCallback: any) { }
leaveGroup(callback: any, errorCallback: any) { }

bringToFront(callback:any, errorCallback: any) {
callback();
}

addEventListener(eventName: string, listener: any): void { }

removeEventListener(eventName: string, listener: any): void { }
Expand Down Expand Up @@ -474,6 +478,13 @@ describe("OpenFinContainerWindow", () => {
}).then(done);
});
});

it("bringToFront invokes underlying bringToFront", (done) => {
spyOn(innerWin, "bringToFront").and.callThrough();
win.bringToFront().then(() => {
expect(innerWin.bringToFront).toHaveBeenCalled();
}).then(done);
});
});

describe("OpenFinContainer", () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/desktopjs/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ export abstract class ContainerWindow extends EventEmitter {
return Promise.resolve();
}

public bringToFront(): Promise<void> {
// Provide simple delegation to focus/activate by default
return this.focus();
}

public abstract getOptions(): Promise<any>;

/** Retrieves custom window state from underlying native window by invoking 'window.getState()' if defined. */
Expand Down
9 changes: 9 additions & 0 deletions packages/desktopjs/tests/unit/window.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class MockWindow extends ContainerWindow {
return;
}

public focus(): Promise<void> { return Promise.resolve(); }
public minimize(): Promise<void> { return Promise.resolve(); }
public restore(): Promise<void> { return Promise.resolve(); }
}
Expand All @@ -29,6 +30,14 @@ describe ("ContainerWindow", () => {
expect(true);
}).then(done);
});

it("bringToFront invokes focus by default", (done) => {
const win = new MockWindow(undefined)
spyOn(win, "focus").and.callThrough();
win.bringToFront().then(() => {
expect(win.focus).toHaveBeenCalled();
}).then(done);
});
});

describe ("static events", () => {
Expand Down