Skip to content
This repository was archived by the owner on Sep 7, 2018. It is now read-only.
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
Empty file removed git
Empty file.
13 changes: 9 additions & 4 deletions packages/api-browser/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Window implements ssf.WindowCore {
eventListeners: Map<string, ((...args: any[]) => void)[]> = new Map();
id: string;

constructor(options, callback?, errorCallback?) {
constructor(options?, callback?, errorCallback?) {
this.children = [];

this.eventListeners = new Map();
Expand Down Expand Up @@ -83,9 +83,7 @@ class Window implements ssf.WindowCore {
return new Promise<Window>(resolve => {
let newWin = null;
if (window.opener) {
newWin = new Window(null);
newWin.innerWindow = window.opener;
newWin.id = window.opener.name;
newWin = Window.wrap(window.opener);
}

resolve(newWin);
Expand Down Expand Up @@ -242,6 +240,13 @@ class Window implements ssf.WindowCore {
currentWindow = new Window(null, callback, errorCallback);
return currentWindow;
}

static wrap(win: BrowserWindow) {
const wrappedWindow = new Window();
wrappedWindow.innerWindow = win;
wrappedWindow.id = String(win.name);
return wrappedWindow;
}
}

const objectToFeaturesString = (features) => {
Expand Down
7 changes: 7 additions & 0 deletions packages/api-electron/src/preload/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,13 @@ class Window implements ssf.Window {
currentWindow = new Window(null, callback, errorCallback);
return currentWindow;
}

static wrap(win: Electron.BrowserWindow) {
const wrappedWindow = new Window();
wrappedWindow.innerWindow = win;
wrappedWindow.id = String(win.id);
return wrappedWindow;
}
}

export default Window;
18 changes: 10 additions & 8 deletions packages/api-openfin/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Window implements ssf.Window {
innerWindow: fin.OpenFinWindow;
id: string;

constructor(options: ssf.WindowOptions, callback?: any, errorCallback?: any) {
constructor(options?: ssf.WindowOptions, callback?: any, errorCallback?: any) {
MessageService.subscribe('*', 'ssf-window-message', (...args) => {
const event = 'message';
if (this.eventListeners.has(event)) {
Expand Down Expand Up @@ -244,9 +244,7 @@ class Window implements ssf.Window {
names.forEach((name) => {
const app = fin.desktop.Application.wrap(name);
const win = app.getWindow();
const childWin = new Window(undefined);
childWin.innerWindow = win;
childWin.id = win.uuid + ':' + win.name;
const childWin = Window.wrap(win);
children.push(childWin);
});
resolve(children);
Expand Down Expand Up @@ -284,12 +282,9 @@ class Window implements ssf.Window {
resolve(null);
return;
}

const app = fin.desktop.Application.wrap(name);
const win = app.getWindow();
const parentWin = new Window(undefined);
parentWin.innerWindow = win;
parentWin.id = win.uuid + ':' + win.name;
const parentWin = Window.wrap(win);
resolve(parentWin);
};

Expand Down Expand Up @@ -522,6 +517,13 @@ class Window implements ssf.Window {
currentWindow = new Window(null, callback, errorCallback);
return currentWindow;
}

static wrap(win: fin.OpenFinWindow) {
const wrappedWin = new Window();
wrappedWin.innerWindow = win;
wrappedWin.id = win.uuid + ':' + win.name;
return wrappedWin;
}
}

export default Window;
6 changes: 6 additions & 0 deletions packages/api-specification/interface/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ declare namespace ssf {
* @returns The window.
*/
static getCurrentWindow(callback?: () => void, errorCallback?: () => void): Window;

/**
* Wraps a native container window with a ContainerJS window.
* @param window The native window to wrap.
*/
static wrap(window: Electron.BrowserWindow | fin.OpenFinWindow | BrowserWindow): Window;
}

/**
Expand Down
25 changes: 25 additions & 0 deletions packages/api-tests/test/window.core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,31 @@ describe('WindowCore API', function(done) {
return chainPromises(steps);
});

it.only('Should wrap a native window in a containerjs window object #ssf.Window.wrap', function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BenLambertNcl Just noticed this it.only was left in, preventing other tests from running.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, ill remove it from #243.

const windowTitle = 'windownamewrap';
const windowOptions = getWindowOptions({
name: windowTitle
});

/* eslint-disable no-undef */
const wrapScript = (callback) => {
ssf.app.ready().then(() => {
const inner = ssf.Window.getCurrentWindow().innerWindow;
const win = ssf.Window.wrap(inner);
callback(win.innerWindow != null);
});
};
/* eslint-enable no-undef */

const steps = [
...setupWindowSteps(windowOptions),
() => executeAsyncJavascript(app.client, wrapScript),
(result) => assert.equal(result.value, true)
];

return chainPromises(steps);
});

if (process.env.MOCHA_CONTAINER === 'electron') {
it('Should return the id of the window #ssf.Window.getId #ssf.WindowCore.getId', function() {
const windowTitle = 'windownameid';
Expand Down