diff --git a/packages/desktopjs-electron/src/electron.ts b/packages/desktopjs-electron/src/electron.ts index 129036bf..8590a4c4 100644 --- a/packages/desktopjs-electron/src/electron.ts +++ b/packages/desktopjs-electron/src/electron.ts @@ -7,7 +7,7 @@ import { registerContainer, ContainerWindow, PersistedWindowLayout, Rectangle, Container, WebContainerBase, ScreenManager, Display, Point, ObjectTransform, PropertyMap, NotificationOptions, ContainerNotification, TrayIconDetails, MenuItem, Guid, MessageBus, MessageBusSubscription, MessageBusOptions, GlobalShortcutManager, - EventArgs, WindowEventArgs, IContainerOptions + EventArgs, WindowEventArgs } from "@morgan-stanley/desktopjs"; registerContainer("Electron", { @@ -386,7 +386,7 @@ export class ElectronContainer extends WebContainerBase { } if (options && options.autoStartOnLogin) { - this.electron.setLoginItemSettings({ + this.app.setLoginItemSettings({ openAtLogin: options.autoStartOnLogin }); } @@ -409,10 +409,9 @@ export class ElectronContainer extends WebContainerBase { } } - public async getOptions(): Promise { + public async getOptions(): Promise { try { - const autoStartOnLogin = await this.isAutoStartEnabledAtLogin(); - return { autoStartOnLogin }; + return { autoStartOnLogin: await this.isAutoStartEnabledAtLogin() }; } catch(error) { throw new Error("Error getting Container options. " + error); } @@ -421,7 +420,7 @@ export class ElectronContainer extends WebContainerBase { private isAutoStartEnabledAtLogin(): Promise { return new Promise((resolve, reject) => { try { - const config = this.electron.getLoginItemSettings(); + const config = this.app.getLoginItemSettings(); resolve(config.openAtLogin); } catch (err) { reject(err); diff --git a/packages/desktopjs-electron/tests/electron.spec.ts b/packages/desktopjs-electron/tests/electron.spec.ts index e2dab002..24bdeacd 100644 --- a/packages/desktopjs-electron/tests/electron.spec.ts +++ b/packages/desktopjs-electron/tests/electron.spec.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-empty-function */ import { ElectronContainer, ElectronContainerWindow, ElectronMessageBus, ElectronWindowManager } from "../src/electron"; -import { ContainerWindow, Container, IContainerOptions } from "@morgan-stanley/desktopjs"; +import { ContainerWindow, Container } from "@morgan-stanley/desktopjs"; class MockEventEmitter { private eventListeners: Map = new Map(); @@ -474,9 +474,8 @@ describe("ElectronContainer", () => { require: (type: string) => { return {} }, getCurrentWindow: () => { return windows[0]; }, process: { versions: { electron: "1", chrome: "2" } }, - setLoginItemSettings: (config) => { }, - getLoginItemSettings: () => { return {}; } }; + container = new ElectronContainer(electron, new MockIpc(), globalWindow); }); @@ -497,18 +496,6 @@ describe("ElectronContainer", () => { expect(console.error).toHaveBeenCalledTimes(1); }); - it("options autoStartOnLogin to setLoginItemSettings", () => { - spyOn(electron, "setLoginItemSettings").and.callThrough(); - const container = new ElectronContainer(electron, new MockMainIpc(), globalWindow, { autoStartOnLogin: true }); - expect(electron.setLoginItemSettings).toHaveBeenCalledWith({ openAtLogin: true }); - }); - - it("options missing autoStartOnLogin does not invoke setLoginItemSettings", () => { - spyOn(electron, "setLoginItemSettings").and.callThrough(); - const container = new ElectronContainer(electron, new MockMainIpc(), globalWindow, { }); - expect(electron.setLoginItemSettings).toHaveBeenCalledTimes(0); - }); - it("electron members are copied", () => { expect((container).app).toEqual(electron.app); expect((container).browserWindow).toEqual(electron.BrowserWindow); @@ -630,6 +617,54 @@ describe("ElectronContainer", () => { }); }); + describe("LoginItemSettings", () => { + it("options autoStartOnLogin to setLoginItemSettings", () => { + electron.app.setLoginItemSettings = jasmine.createSpy().and.stub(); + const container = new ElectronContainer(electron, new MockMainIpc(), globalWindow, { autoStartOnLogin: true }); + expect(electron.app.setLoginItemSettings).toHaveBeenCalledWith({ openAtLogin: true }); + }); + + it("options missing autoStartOnLogin does not invoke setLoginItemSettings", () => { + electron.app.setLoginItemSettings = jasmine.createSpy().and.stub(); + const container = new ElectronContainer(electron, new MockMainIpc(), globalWindow, { }); + expect(electron.app.setLoginItemSettings).toHaveBeenCalledTimes(0); + }); + + it("setOptions allows the auto startup settings to be turned on", () => { + electron.app.setLoginItemSettings = jasmine.createSpy().and.stub(); + container.setOptions({ autoStartOnLogin: true }); + expect(electron.app.setLoginItemSettings).toHaveBeenCalledWith({ openAtLogin: true }); + }); + + it("setOptions errors out on setLoginItemSettings", () => { + electron.app.setLoginItemSettings = jasmine.createSpy().and.callFake(() => { + throw new Error("something went wrong"); + }); + spyOn(console, "error"); + container.setOptions({ autoStartOnLogin: true }); + expect(electron.app.setLoginItemSettings).toHaveBeenCalledWith({ openAtLogin: true }); + expect(console.error).toHaveBeenCalledTimes(1); + }); + + it("getOptions returns autoStartOnLogin status", (done) => { + electron.app.getLoginItemSettings = jasmine.createSpy().and.returnValue({ openAtLogin: true }); + container.getOptions().then((result: any) => { + expect(electron.app.getLoginItemSettings).toHaveBeenCalled(); + expect(result.autoStartOnLogin).toEqual(true); + }).then(done); + }); + + it("getOptions error out while fetching auto start info", (done) => { + electron.app.getLoginItemSettings = jasmine.createSpy().and.callFake(() => { + throw new Error("something went wrong"); + }); + container.getOptions().then(() => { }, (err) => { + expect(electron.app.getLoginItemSettings).toHaveBeenCalled(); + expect(err).toEqual(new Error("Error getting Container options. Error: something went wrong")); + }).then(done); + }); + }); + describe("window management", () => { beforeEach(() => { electron.BrowserWindow = { @@ -744,40 +779,6 @@ describe("ElectronContainer", () => { expect(layout.windows[0].name === "win1") }).then(done); }); - - it("setOptions allows the auto startup settings to be turned on", () => { - spyOn(electron, "setLoginItemSettings").and.callThrough(); - container.setOptions({ autoStartOnLogin: true }); - expect(electron.setLoginItemSettings).toHaveBeenCalledWith({ openAtLogin: true }); - }); - - it("setOptions errors out on setLoginItemSettings", () => { - spyOn(electron, "setLoginItemSettings").and.callFake(() => { - throw new Error("something went wrong"); - }); - spyOn(console, "error"); - container.setOptions({ autoStartOnLogin: true }); - expect(electron.setLoginItemSettings).toHaveBeenCalledWith({ openAtLogin: true }); - expect(console.error).toHaveBeenCalledTimes(1); - }); - - it("getOptions returns autoStartOnLogin status", (done) => { - spyOn(electron, "getLoginItemSettings").and.returnValue({ openAtLogin: true }); - container.getOptions().then((result: IContainerOptions) => { - expect(electron.getLoginItemSettings).toHaveBeenCalled(); - expect(result.autoStartOnLogin).toEqual(true); - }).then(done); - }); - - it("getOptions error out while fetching auto start info", (done) => { - spyOn(electron, "getLoginItemSettings").and.callFake(() => { - throw new Error("something went wrong"); - }); - container.getOptions().then(() => { }, (err) => { - expect(electron.getLoginItemSettings).toHaveBeenCalled(); - expect(err).toEqual(new Error("Error getting Container options. Error: something went wrong")); - }).then(done); - }); }); }); diff --git a/packages/desktopjs-openfin/src/openfin.ts b/packages/desktopjs-openfin/src/openfin.ts index 8cf7b727..57dc48cc 100644 --- a/packages/desktopjs-openfin/src/openfin.ts +++ b/packages/desktopjs-openfin/src/openfin.ts @@ -6,7 +6,7 @@ import { registerContainer, ContainerWindow, PersistedWindowLayout, Rectangle, Container, WebContainerBase, ScreenManager, Display, Point, ObjectTransform, PropertyMap, NotificationOptions, ContainerNotification, TrayIconDetails, MenuItem, Guid, MessageBus, MessageBusSubscription, MessageBusOptions, EventArgs, - GlobalShortcutManager, WindowEventArgs, IContainerOptions + GlobalShortcutManager, WindowEventArgs } from "@morgan-stanley/desktopjs"; registerContainer("OpenFin", { @@ -444,10 +444,9 @@ export class OpenFinContainer extends WebContainerBase { } } - public async getOptions(): Promise { + public async getOptions(): Promise { try { - const autoStartOnLogin = await this.isAutoStartEnabledAtLogin(); - return { autoStartOnLogin }; + return { autoStartOnLogin: await this.isAutoStartEnabledAtLogin() }; } catch(error) { throw new Error("Error getting Container options. " + error); } diff --git a/packages/desktopjs-openfin/tests/openfin.spec.ts b/packages/desktopjs-openfin/tests/openfin.spec.ts index d5d23dd5..af078604 100644 --- a/packages/desktopjs-openfin/tests/openfin.spec.ts +++ b/packages/desktopjs-openfin/tests/openfin.spec.ts @@ -1,6 +1,6 @@ import {} from "jasmine"; import { OpenFinContainer, OpenFinContainerWindow, OpenFinMessageBus } from "../src/openfin"; -import { ContainerWindow, MessageBusSubscription, MenuItem, IContainerOptions } from "@morgan-stanley/desktopjs"; +import { ContainerWindow, MessageBusSubscription, MenuItem } from "@morgan-stanley/desktopjs"; class MockDesktop { public static application: any = { @@ -770,7 +770,7 @@ describe("OpenFinContainer", () => { const current = app.getCurrent(); spyOn(app, "getCurrent").and.callThrough(); spyOn(current, "getShortcuts").and.callFake((callback) => callback({ systemStartup: true })); - container.getOptions().then((result: IContainerOptions) => { + container.getOptions().then((result: any) => { expect(app.getCurrent).toHaveBeenCalled(); expect(current.getShortcuts).toHaveBeenCalled(); expect(result.autoStartOnLogin).toEqual(true); diff --git a/packages/desktopjs/src/desktop.ts b/packages/desktopjs/src/desktop.ts index 03a49fd6..193be3b0 100644 --- a/packages/desktopjs/src/desktop.ts +++ b/packages/desktopjs/src/desktop.ts @@ -15,6 +15,5 @@ export * from "./tray"; export * from "./window"; export * from "./shortcut"; export * from "./Default/default"; -export * from "./i-container-options"; export const version = "PACKAGE_VERSION"; diff --git a/packages/desktopjs/src/i-container-options.ts b/packages/desktopjs/src/i-container-options.ts deleted file mode 100644 index ae253f01..00000000 --- a/packages/desktopjs/src/i-container-options.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface IContainerOptions { - autoStartOnLogin?: boolean; -} \ No newline at end of file diff --git a/packages/desktopjs/tests/unit/container.spec.ts b/packages/desktopjs/tests/unit/container.spec.ts index 38d58032..ac6678c1 100644 --- a/packages/desktopjs/tests/unit/container.spec.ts +++ b/packages/desktopjs/tests/unit/container.spec.ts @@ -4,7 +4,6 @@ import { ContainerWindow, PersistedWindowLayout } from "../../src/window"; import { NotificationOptions } from "../../src/notification"; import { MessageBus, MessageBusSubscription, MessageBusOptions } from "../../src/ipc"; import { EventArgs, EventEmitter } from "../../src/events"; -import { IContainerOptions } from "../../src/i-container-options"; class MockContainer extends ContainerBase { protected closeAllWindows(excludeSelf?: boolean): Promise { @@ -32,7 +31,7 @@ class MockContainer extends ContainerBase { throw new Error("Method not implemented."); } - public getOptions(): Promise { + public getOptions(): Promise { throw new Error("Method not implemented."); }