diff --git a/examples/electron/electron.js b/examples/electron/electron.js index a14f4145..124a4fbc 100644 --- a/examples/electron/electron.js +++ b/examples/electron/electron.js @@ -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, { diff --git a/examples/web/assets/js/app.js b/examples/web/assets/js/app.js index d596b503..5118f5e4 100644 --- a/examples/web/assets/js/app.js +++ b/examples/web/assets/js/app.js @@ -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 diff --git a/packages/desktopjs-electron/src/electron.ts b/packages/desktopjs-electron/src/electron.ts index 820a8a70..e979f8e1 100644 --- a/packages/desktopjs-electron/src/electron.ts +++ b/packages/desktopjs-electron/src/electron.ts @@ -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); @@ -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 diff --git a/packages/desktopjs-openfin/src/openfin.ts b/packages/desktopjs-openfin/src/openfin.ts index 425bd239..bec937dd 100644 --- a/packages/desktopjs-openfin/src/openfin.ts +++ b/packages/desktopjs-openfin/src/openfin.ts @@ -145,13 +145,19 @@ export class OpenFinContainerWindow extends ContainerWindow { } return new Promise((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 { return new Promise((resolve, reject) => { - this.innerWindow.leaveGroup(resolve, reject); + this.innerWindow.leaveGroup(() => { + ContainerWindow.emit("window-leaveGroup", { name: "window-leaveGroup", windowId: this.id } ); + resolve(); + }, reject); }); } diff --git a/packages/desktopjs/src/window.ts b/packages/desktopjs/src/window.ts index 40ef5842..2b0b2059 100644 --- a/packages/desktopjs/src/window.ts +++ b/packages/desktopjs/src/window.ts @@ -55,6 +55,8 @@ export class Rectangle { // tslint:disable-line export type WindowEventType = "window-created" | + "window-joinGroup" | + "window-leaveGroup" | "move" | "resize" | "close" | @@ -64,8 +66,7 @@ export type WindowEventType = "maximize" | "minimize" | "restore" | - "beforeunload" - ; + "beforeunload"; export class WindowEventArgs extends EventArgs { public readonly window?: ContainerWindow; @@ -73,6 +74,10 @@ export class WindowEventArgs extends EventArgs { 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-"; @@ -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); }