Skip to content

Commit

Permalink
Fire state-changed upon setState of window (#250)
Browse files Browse the repository at this point in the history
Fixes #248
  • Loading branch information
bingenito authored Jun 4, 2019
1 parent 755f131 commit b28ffa7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
13 changes: 8 additions & 5 deletions packages/desktopjs-electron/src/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,14 @@ export class ElectronContainerWindow extends ContainerWindow {
}

public setState(state: any): Promise<void> {
if (this.innerWindow && this.innerWindow.webContents) {
return this.innerWindow.webContents.executeJavaScript(`if (window.setState) { window.setState(JSON.parse(\`${JSON.stringify(state)}\`)); }`);
} else {
return Promise.resolve();
}
const promise = (this.innerWindow && this.innerWindow.webContents)
? this.innerWindow.webContents.executeJavaScript(`if (window.setState) { window.setState(JSON.parse(\`${JSON.stringify(state)}\`)); }`)
: Promise.resolve();

return promise.then(() => {
this.emit("state-changed", { name: "state-changed", sender: this });
ContainerWindow.emit("state-changed", { name: "state-changed", windowId: this.id } );
});
}

protected attachListener(eventName: string, listener: (...args: any[]) => void): void {
Expand Down
3 changes: 3 additions & 0 deletions packages/desktopjs-openfin/src/openfin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ export class OpenFinContainerWindow extends ContainerWindow {
}

resolve();
}).then(() => {
this.emit("state-changed", { name: "state-changed", sender: this });
ContainerWindow.emit("state-changed", { name: "state-changed", windowId: this.id } );
});
}

Expand Down
3 changes: 3 additions & 0 deletions packages/desktopjs/src/Default/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export namespace Default {
}

resolve();
}).then(() => {
this.emit("state-changed", { name: "state-changed", sender: this });
ContainerWindow.emit("state-changed", { name: "state-changed", windowId: this.id } );
});
}

Expand Down
3 changes: 2 additions & 1 deletion packages/desktopjs/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export type WindowEventType =
"maximize" |
"minimize" |
"restore" |
"beforeunload";
"beforeunload" |
"state-changed";

export class WindowEventArgs extends EventArgs {
public readonly window?: ContainerWindow;
Expand Down

0 comments on commit b28ffa7

Please sign in to comment.