Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add container.ready event #239

Merged
merged 2 commits into from
May 9, 2019
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
54 changes: 29 additions & 25 deletions examples/web/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var container = desktopJS.resolveContainer();
var container;
var snapAssist;

var hostName = document.getElementById('hostName');
Expand Down Expand Up @@ -59,38 +59,42 @@ desktopJS.Electron.ElectronContainer.prototype.showNotification = function (titl
document.addEventListener("DOMContentLoaded", function (event) {
updatefps();

hostName.innerHTML = container.hostType + " • " + container.uuid + " • "+ desktopJS.version;
container = desktopJS.resolveContainer();

$("#button-joingroup").prop("disabled", !container.getCurrentWindow().allowGrouping);
$("#button-leavegroup").prop("disabled", !container.getCurrentWindow().allowGrouping);
container.ready().then(() => {
hostName.innerHTML = container.hostType + " • " + container.uuid + " • " + desktopJS.version;

container.addListener("window-created", (e) => container.log("info", "Window created: " + e.window + ", " + e.windowId + ", " + e.windowName));
container.addListener("layout-loaded", (e) => container.log("info", "Layout loaded"));
container.addListener("layout-saved", (e) => container.log("info", "Layout saved"));
$("#button-joingroup").prop("disabled", !container.getCurrentWindow().allowGrouping);
$("#button-leavegroup").prop("disabled", !container.getCurrentWindow().allowGrouping);

desktopJS.Container.addListener("window-created", (e) => container.log("info", "Window created - static (Container): " + e.windowId + ", " + e.windowName));
desktopJS.ContainerWindow.addListener("window-created", (e) => container.log("info", "Window created - static (ContainerWindow): " + e.windowId + ", " + e.windowName));
desktopJS.Container.addListener("layout-saved", (e) => container.log("info", "Layout saved - static: " + e.layoutName));
desktopJS.Container.addListener("layout-loaded", (e) => container.log("info", "Layout loaded - static: " + e.layoutName));
container.addListener("window-created", (e) => container.log("info", "Window created: " + e.window + ", " + e.windowId + ", " + e.windowName));
container.addListener("layout-loaded", (e) => container.log("info", "Layout loaded"));
container.addListener("layout-saved", (e) => container.log("info", "Layout saved"));

desktopJS.ContainerWindow.addListener("window-joinGroup", (e) => container.log("info", "grouped " + JSON.stringify(e)));
desktopJS.ContainerWindow.addListener("window-leaveGroup", (e) => container.log("info", "ungrouped" + JSON.stringify(e)));
desktopJS.Container.addListener("window-created", (e) => container.log("info", "Window created - static (Container): " + e.windowId + ", " + e.windowName));
desktopJS.ContainerWindow.addListener("window-created", (e) => container.log("info", "Window created - static (ContainerWindow): " + e.windowId + ", " + e.windowName));
desktopJS.Container.addListener("layout-saved", (e) => container.log("info", "Layout saved - static: " + e.layoutName));
desktopJS.Container.addListener("layout-loaded", (e) => container.log("info", "Layout loaded - static: " + e.layoutName));

subscribe();
desktopJS.ContainerWindow.addListener("window-joinGroup", (e) => container.log("info", "grouped " + JSON.stringify(e)));
desktopJS.ContainerWindow.addListener("window-leaveGroup", (e) => container.log("info", "ungrouped" + JSON.stringify(e)));

// If url is provided a hash, try to navigate to bootstrap tab if exists
var activeTab = $('[href="' + location.hash + '"]');
activeTab && activeTab.tab('show');
subscribe();

// Enable popovers
$('[data-toggle="popover"]').popover();
// If url is provided a hash, try to navigate to bootstrap tab if exists
var activeTab = $('[href="' + location.hash + '"]');
activeTab && activeTab.tab('show');

if (container.getCurrentWindow().id === "desktopJS") {
snapAssist = new desktopJS.SnapAssistWindowManager(container,
{
windowStateTracking: desktopJS.WindowStateTracking.Main | desktopJS.WindowStateTracking.Group
});
}
// Enable popovers
$('[data-toggle="popover"]').popover();

if (container.getCurrentWindow().id === "desktopJS") {
snapAssist = new desktopJS.SnapAssistWindowManager(container,
{
windowStateTracking: desktopJS.WindowStateTracking.Main | desktopJS.WindowStateTracking.Group
});
}
});
});

openWindowButton.onclick = function () {
Expand Down
4 changes: 4 additions & 0 deletions packages/desktopjs-openfin/src/openfin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ export class OpenFinContainer extends WebContainerBase {
});
}

public ready(): Promise<void> {
return new Promise(resolve => this.desktop.main(resolve));
}

public getMainWindow(): ContainerWindow {
if (!this.mainWindow) {
this.mainWindow = this.wrapWindow(this.desktop.Application.getCurrent().getWindow());
Expand Down
8 changes: 8 additions & 0 deletions packages/desktopjs-openfin/tests/openfin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MockDesktop {
}
}
}
main(callback): any { callback() };
GlobalHotkey: any = { };
Window: any = MockWindow;
Notification(): any { return {}; }
Expand Down Expand Up @@ -502,6 +503,13 @@ describe("OpenFinContainer", () => {
expect(container.hostType).toEqual("OpenFin");
});

it("ready invokes underlying main", (done) => {
spyOn(desktop, "main").and.callThrough();
container.ready().then(() => {
expect(desktop.main).toHaveBeenCalled();
}).then(done);
});

describe("ctor options", () => {
describe("registerUser", () => {
let desktop;
Expand Down
4 changes: 4 additions & 0 deletions packages/desktopjs/src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export abstract class Container extends EventEmitter implements ContainerWindowM
*/
public abstract uuid: string;

public ready(): Promise<void> {
return Promise.resolve();
}

public abstract getMainWindow(): ContainerWindow;

public abstract getCurrentWindow(): ContainerWindow;
Expand Down
4 changes: 4 additions & 0 deletions packages/desktopjs/tests/unit/container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ describe("container", () => {
expect(container.ipc).toBeDefined();
});

it("ready resolves", (done) => {
container.ready().then(done);
});

describe("Static events", () => {
it("addListener adds callback to listeners", () => {
expect(Container.listeners("TestEvent").length).toEqual(0);
Expand Down