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 static grouping events to ContainerWindow #213

Merged
merged 2 commits into from
Feb 1, 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
2 changes: 2 additions & 0 deletions examples/electron/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function createWindow() {
let container = desktopJS.resolveContainer();

desktopJS.ContainerWindow.addListener("window-created", (e) => container.log("info", "Window created - static (ContainerWindow): " + e.windowId + ", " + e.windowName));
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)));

snapAssist = new desktopJS.SnapAssistWindowManager(container,
{
Expand Down
3 changes: 3 additions & 0 deletions examples/web/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ document.addEventListener("DOMContentLoaded", function (event) {
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));

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)));

subscribe();

// If url is provided a hash, try to navigate to bootstrap tab if exists
Expand Down
3 changes: 3 additions & 0 deletions packages/desktopjs-electron/src/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ export class ElectronWindowManager {
for (const win of windows) {
win.group = target.group || (target.group = Guid.newGuid());
this.registerWindowEvents(win);

ContainerWindow.emit("window-joinGroup", { name: "window-joinGroup", windowId: win.id, targetWindowId: target.id });
}

this.registerWindowEvents(target);
Expand All @@ -621,6 +623,7 @@ export class ElectronWindowManager {
for (const win of windows) {
this.unregisterWindowEvents(win);
win.group = null;
ContainerWindow.emit("window-leaveGroup", { name: "window-leaveGroup", windowId: win.id });
}

// Group all windows by group and for any group consisting of one window unhook and clear the group
Expand Down
10 changes: 8 additions & 2 deletions packages/desktopjs-openfin/src/openfin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,19 @@ export class OpenFinContainerWindow extends ContainerWindow {
}

return new Promise<void>((resolve, reject) => {
this.innerWindow.joinGroup(target.innerWindow, resolve, reject);
this.innerWindow.joinGroup(target.innerWindow, () => {
ContainerWindow.emit("window-joinGroup", { name: "window-joinGroup", windowId: this.id, targetWindowId: target.id } );
resolve();
}, reject);
});
}

public leaveGroup(): Promise<void> {
return new Promise<void>((resolve, reject) => {
this.innerWindow.leaveGroup(resolve, reject);
this.innerWindow.leaveGroup(() => {
ContainerWindow.emit("window-leaveGroup", { name: "window-leaveGroup", windowId: this.id } );
resolve();
}, reject);
});
}

Expand Down
15 changes: 10 additions & 5 deletions packages/desktopjs/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export class Rectangle { // tslint:disable-line

export type WindowEventType =
"window-created" |
"window-joinGroup" |
"window-leaveGroup" |
"move" |
"resize" |
"close" |
Expand All @@ -64,15 +66,18 @@ export type WindowEventType =
"maximize" |
"minimize" |
"restore" |
"beforeunload"
;
"beforeunload";

export class WindowEventArgs extends EventArgs {
public readonly window?: ContainerWindow;
public readonly windowId: string;
public readonly windowName?: string;
}

export class WindowGroupEventArgs extends WindowEventArgs {
public readonly targetWindowId?: string;
}

/** Represents a container window. */
export abstract class ContainerWindow extends EventEmitter {
private static readonly staticEventScopePrefix: string = "containerwindow-";
Expand Down Expand Up @@ -201,15 +206,15 @@ export abstract class ContainerWindow extends EventEmitter {
return super.removeListener(eventName, callback);
}

public static addListener(eventName: WindowEventType, listener: (event: WindowEventArgs) => void): void { // tslint:disable-line
public static addListener(eventName: WindowEventType, listener: (event: WindowEventArgs | WindowGroupEventArgs) => void): void { // tslint:disable-line
EventEmitter.addListener(ContainerWindow.staticEventScopePrefix + eventName, listener);
}

public static removeListener(eventName: WindowEventType, listener: (event: WindowEventArgs) => void): void { // tslint:disable-line
public static removeListener(eventName: WindowEventType, listener: (event: WindowEventArgs | WindowGroupEventArgs) => void): void { // tslint:disable-line
EventEmitter.removeListener(ContainerWindow.staticEventScopePrefix + eventName, listener);
}

public static emit(eventName: WindowEventType, eventArgs: WindowEventArgs): void { // tslint:disable-line
public static emit(eventName: WindowEventType, eventArgs: WindowEventArgs | WindowGroupEventArgs): void { // tslint:disable-line
EventEmitter.emit(ContainerWindow.staticEventScopePrefix + eventName, eventArgs, Container.ipc);
}

Expand Down