Skip to content
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
11 changes: 5 additions & 6 deletions packages/desktopjs-electron/src/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down Expand Up @@ -386,7 +386,7 @@ export class ElectronContainer extends WebContainerBase {
}

if (options && options.autoStartOnLogin) {
this.electron.setLoginItemSettings({
this.app.setLoginItemSettings({
openAtLogin: options.autoStartOnLogin
});
}
Expand All @@ -409,10 +409,9 @@ export class ElectronContainer extends WebContainerBase {
}
}

public async getOptions(): Promise<IContainerOptions> {
public async getOptions(): Promise<any> {
try {
const autoStartOnLogin = await this.isAutoStartEnabledAtLogin();
return { autoStartOnLogin };
return { autoStartOnLogin: await this.isAutoStartEnabledAtLogin() };
} catch(error) {
throw new Error("Error getting Container options. " + error);
}
Expand All @@ -421,7 +420,7 @@ export class ElectronContainer extends WebContainerBase {
private isAutoStartEnabledAtLogin(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
try {
const config = this.electron.getLoginItemSettings();
const config = this.app.getLoginItemSettings();
resolve(config.openAtLogin);
} catch (err) {
reject(err);
Expand Down
99 changes: 50 additions & 49 deletions packages/desktopjs-electron/tests/electron.spec.ts
Original file line number Diff line number Diff line change
@@ -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<string, any> = new Map();
Expand Down Expand Up @@ -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);
});

Expand All @@ -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((<any>container).app).toEqual(electron.app);
expect((<any>container).browserWindow).toEqual(electron.BrowserWindow);
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
});
});
});

Expand Down
7 changes: 3 additions & 4 deletions packages/desktopjs-openfin/src/openfin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down Expand Up @@ -444,10 +444,9 @@ export class OpenFinContainer extends WebContainerBase {
}
}

public async getOptions(): Promise<IContainerOptions> {
public async getOptions(): Promise<any> {
try {
const autoStartOnLogin = await this.isAutoStartEnabledAtLogin();
return { autoStartOnLogin };
return { autoStartOnLogin: await this.isAutoStartEnabledAtLogin() };
} catch(error) {
throw new Error("Error getting Container options. " + error);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/desktopjs-openfin/tests/openfin.spec.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion packages/desktopjs/src/desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
3 changes: 0 additions & 3 deletions packages/desktopjs/src/i-container-options.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/desktopjs/tests/unit/container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down Expand Up @@ -32,7 +31,7 @@ class MockContainer extends ContainerBase {
throw new Error("Method not implemented.");
}

public getOptions(): Promise<IContainerOptions> {
public getOptions(): Promise<any> {
throw new Error("Method not implemented.");
}

Expand Down