diff --git a/src/Default/default.ts b/src/Default/default.ts index ae0d4e32..60db4c00 100644 --- a/src/Default/default.ts +++ b/src/Default/default.ts @@ -264,6 +264,7 @@ export class DefaultContainer extends WebContainerBase { } const window = this.globalWindow.open(url, target, features); + window[Container.windowOptionsPropertyKey] = options; // Store the original options // Set name as a unique desktopJS name property instead of overloading window.name window[DefaultContainer.windowNamePropertyKey] = newOptions.name; @@ -342,7 +343,7 @@ export class DefaultContainer extends WebContainerBase { for (const key in windows) { const win = windows[key]; if (this.globalWindow !== win) { - layout.windows.push({ name: win.name, url: win.location.toString(), bounds: { x: win.screenX, y: win.screenY, width: win.outerWidth, height: win.outerHeight } }); + layout.windows.push({ name: win.name, url: win.location.toString(), bounds: { x: win.screenX, y: win.screenY, width: win.outerWidth, height: win.outerHeight }, options: win[Container.windowOptionsPropertyKey] }); } } diff --git a/src/Electron/electron.ts b/src/Electron/electron.ts index ca3449d4..f855583d 100644 --- a/src/Electron/electron.ts +++ b/src/Electron/electron.ts @@ -320,7 +320,7 @@ export class ElectronContainer extends WebContainerBase { public getMainWindow(): ContainerWindow { for (const window of this.browserWindow.getAllWindows()) { - if (window.options && window.options.main) { + if (window[Container.windowOptionsPropertyKey] && window[Container.windowOptionsPropertyKey].main) { return this.wrapWindow(window); } } @@ -359,6 +359,7 @@ export class ElectronContainer extends WebContainerBase { */ if (this.isRemote) { electronWindow["name"] = (this.internalIpc).sendSync(InternalMessageType.initialize, { id: electronWindow.id, name: windowName, options: newOptions }); + electronWindow[Container.windowOptionsPropertyKey] = options; } else { this.windowManager.initializeWindow(electronWindow, windowName, newOptions); } @@ -444,6 +445,7 @@ export class ElectronContainer extends WebContainerBase { name: window.name, url: window.innerWindow.webContents.getURL(), main: (mainWindow === window.innerWindow), + options: window.innerWindow[Container.windowOptionsPropertyKey], bounds: window.innerWindow.getBounds(), group: group.map(win => win.id) }); @@ -502,7 +504,7 @@ export class ElectronWindowManager { public initializeWindow(win: any, name: string, options: any) { win.name = name; - win.options = options; + win[Container.windowOptionsPropertyKey] = options; if (options && options.main && (!("quitOnClose" in options) || options.quitOnClose)) { win.on("closed", () => { diff --git a/src/OpenFin/openfin.ts b/src/OpenFin/openfin.ts index 97e429bf..64f49c77 100644 --- a/src/OpenFin/openfin.ts +++ b/src/OpenFin/openfin.ts @@ -592,6 +592,7 @@ export class OpenFinContainer extends WebContainerBase { promises.push(new Promise((innerResolve, innerReject) => { window.getBounds(bounds => { window.getOptions(options => { + delete (options).show; // show is an undocumented option that interferes with the createWindow mapping of show -> autoShow window.getGroup(group => { layout.windows.push( { @@ -599,6 +600,7 @@ export class OpenFinContainer extends WebContainerBase { id: window.name, url: window.getNativeWindow() ? window.getNativeWindow().location.toString() : options.url, main: (mainWindow.name === window.name), + options: options, bounds: { x: bounds.left, y: bounds.top, width: bounds.width, height: bounds.height }, group: group.map(win => win.name) }); diff --git a/src/container.ts b/src/container.ts index 5ad54db9..a75dbce1 100644 --- a/src/container.ts +++ b/src/container.ts @@ -29,6 +29,8 @@ export abstract class Container extends EventEmitter implements ContainerWindowM private static _ipc: MessageBus; // tslint:disable-line + public static readonly windowOptionsPropertyKey: string = "desktopJS-options"; + /** * Display type of current Container. * @type {string} @@ -176,7 +178,7 @@ export abstract class ContainerBase extends Container { if (layout && layout.windows) { const promises: Promise[] = []; for (const window of layout.windows) { - const options: any = Object.assign({}, window.bounds); + const options: any = Object.assign(window.options || {}, window.bounds); options.name = window.name; if (window.main) { this.getMainWindow().setBounds(window.bounds); diff --git a/src/window.ts b/src/window.ts index b6973f8a..d5511189 100644 --- a/src/window.ts +++ b/src/window.ts @@ -251,6 +251,7 @@ export class PersistedWindow { public name: string; public id: string; public bounds: any; + public options?: any; public url?: string; public main?: boolean; public group?: string[]; diff --git a/tests/unit/Electron/electron.spec.ts b/tests/unit/Electron/electron.spec.ts index a65ec3e8..d7ba4fd8 100644 --- a/tests/unit/Electron/electron.spec.ts +++ b/tests/unit/Electron/electron.spec.ts @@ -1,6 +1,7 @@ import { ElectronContainer, ElectronContainerWindow, ElectronMessageBus, ElectronWindowManager } from "../../../src/Electron/electron"; import { MessageBusSubscription } from "../../../src/ipc"; import { ContainerWindow } from "../../../src/window"; +import { Container } from "../../../src/container"; class MockEventEmitter { private eventListeners: Map = new Map(); @@ -377,7 +378,7 @@ describe("ElectronContainer", () => { fromId(): any { }; }; - windows[1]["options"] = { main: true }; + windows[1][Container.windowOptionsPropertyKey] = { main: true }; spyOn(container.browserWindow, "fromId").and.returnValue(innerWin);