diff --git a/packages/desktopjs-electron/src/electron.ts b/packages/desktopjs-electron/src/electron.ts index 2c7bb247..820a8a70 100644 --- a/packages/desktopjs-electron/src/electron.ts +++ b/packages/desktopjs-electron/src/electron.ts @@ -177,6 +177,13 @@ export class ElectronContainerWindow extends ContainerWindow { return Promise.resolve(); } + public bringToFront(): Promise { + return new Promise(resolve => { + this.innerWindow.moveTop(); + resolve(); + }); + } + public getOptions(): Promise { return new Promise((resolve, reject) => { const options = (this.isRemote) diff --git a/packages/desktopjs-electron/tests/electron.spec.ts b/packages/desktopjs-electron/tests/electron.spec.ts index 00b3e4c0..065f2eed 100644 --- a/packages/desktopjs-electron/tests/electron.spec.ts +++ b/packages/desktopjs-electron/tests/electron.spec.ts @@ -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 { @@ -408,6 +410,13 @@ describe("ElectronContainerWindow", () => { expect((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", () => { diff --git a/packages/desktopjs-openfin/src/openfin.ts b/packages/desktopjs-openfin/src/openfin.ts index e5fbe21e..425bd239 100644 --- a/packages/desktopjs-openfin/src/openfin.ts +++ b/packages/desktopjs-openfin/src/openfin.ts @@ -155,6 +155,12 @@ export class OpenFinContainerWindow extends ContainerWindow { }); } + public bringToFront(): Promise { + return new Promise((resolve, reject) => { + this.innerWindow.bringToFront(resolve, reject); + }); + } + public getOptions(): Promise { return new Promise((resolve, reject) => { this.innerWindow.getOptions(options => resolve(options.customData ? JSON.parse(options.customData) : undefined), reject); diff --git a/packages/desktopjs-openfin/tests/openfin.spec.ts b/packages/desktopjs-openfin/tests/openfin.spec.ts index 5cecc9a1..fac1c512 100644 --- a/packages/desktopjs-openfin/tests/openfin.spec.ts +++ b/packages/desktopjs-openfin/tests/openfin.spec.ts @@ -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 { } @@ -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", () => { diff --git a/packages/desktopjs/src/window.ts b/packages/desktopjs/src/window.ts index 4213565e..40ef5842 100644 --- a/packages/desktopjs/src/window.ts +++ b/packages/desktopjs/src/window.ts @@ -145,6 +145,11 @@ export abstract class ContainerWindow extends EventEmitter { return Promise.resolve(); } + public bringToFront(): Promise { + // Provide simple delegation to focus/activate by default + return this.focus(); + } + public abstract getOptions(): Promise; /** Retrieves custom window state from underlying native window by invoking 'window.getState()' if defined. */ diff --git a/packages/desktopjs/tests/unit/window.spec.ts b/packages/desktopjs/tests/unit/window.spec.ts index 2ed6662b..ba9cd0c2 100644 --- a/packages/desktopjs/tests/unit/window.spec.ts +++ b/packages/desktopjs/tests/unit/window.spec.ts @@ -9,6 +9,7 @@ class MockWindow extends ContainerWindow { return; } + public focus(): Promise { return Promise.resolve(); } public minimize(): Promise { return Promise.resolve(); } public restore(): Promise { return Promise.resolve(); } } @@ -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", () => {