diff --git a/packages/app/gmail/index.ts b/packages/app/gmail/index.ts index 5076fea2..2f347391 100644 --- a/packages/app/gmail/index.ts +++ b/packages/app/gmail/index.ts @@ -521,7 +521,7 @@ export class Gmail { const googleApp = new GoogleApp({ accountId: this.accountId, url, - browserWindow: { width: 800, height: 600 }, + window: { width: 800, height: 600 }, view: options, }); diff --git a/packages/app/google-app.ts b/packages/app/google-app.ts index 4a74bb25..98901fe9 100644 --- a/packages/app/google-app.ts +++ b/packages/app/google-app.ts @@ -51,7 +51,7 @@ function getGoogleAppFromUrl(url: string) { type GoogleAppOptions = { accountId: AccountConfig["id"]; url: string; - browserWindow?: BrowserWindowConstructorOptions; + window?: BrowserWindowConstructorOptions; view?: WebContentsViewConstructorOptions; }; @@ -72,6 +72,10 @@ export class GoogleApp { return GoogleApp.instances.get(webContents.id); } + static getAllWindows() { + return Array.from(GoogleApp.instances.values(), (instance) => instance.window); + } + static reuseWindowByHostname(accountId: AccountConfig["id"], url: string) { const urlHostname = new URL(url).hostname; @@ -82,7 +86,7 @@ export class GoogleApp { ) { instance.view.webContents.loadURL(url); - instance.browserWindow.focus(); + instance.window.focus(); return true; } @@ -214,7 +218,7 @@ export class GoogleApp { app: SupportedGoogleApp | undefined; - browserWindow: BrowserWindow; + window: BrowserWindow; view: WebContentsView; @@ -222,11 +226,11 @@ export class GoogleApp { private viewDestroyed = false; - constructor({ accountId, url, browserWindow, view }: GoogleAppOptions) { + constructor({ accountId, url, window, view }: GoogleAppOptions) { this.accountId = accountId; this.app = getGoogleAppFromUrl(url); - this.browserWindow = this.createBrowserWindow(browserWindow); + this.window = this.createBrowserWindow(window); this.view = this.createView({ url, options: view }); this.updateViewBounds(); @@ -235,19 +239,19 @@ export class GoogleApp { this.view.webContents.once("destroyed", () => { this.viewDestroyed = true; - if (!this.browserWindow.isDestroyed()) { - this.browserWindow.close(); + if (!this.window.isDestroyed()) { + this.window.close(); } }); - this.browserWindow.on("resize", this.updateViewBounds); - this.browserWindow.on("close", this.handleClose); + this.window.on("resize", this.updateViewBounds); + this.window.on("close", this.handleClose); - this.account.instance.windows.add(this.browserWindow); + this.account.instance.windows.add(this.window); this.setupApp(); - GoogleApp.instances.set(this.browserWindow.webContents.id, this); + GoogleApp.instances.set(this.window.webContents.id, this); } private createBrowserWindow(options?: BrowserWindowConstructorOptions) { @@ -289,13 +293,13 @@ export class GoogleApp { }, }); - this.browserWindow.contentView.addChildView(view); + this.window.contentView.addChildView(view); setupWindowContextMenu(view); applyViewZoomLimits(view); - broadcastFoundInPageResults(view, this.browserWindow.webContents); + broadcastFoundInPageResults(view, this.window.webContents); this.setWindowOpenHandler(view); @@ -323,9 +327,9 @@ export class GoogleApp { this.teardownApp(); - this.account.instance.windows.delete(this.browserWindow); + this.account.instance.windows.delete(this.window); - GoogleApp.instances.delete(this.browserWindow.webContents.id); + GoogleApp.instances.delete(this.window.webContents.id); }; private setupApp() { @@ -382,7 +386,7 @@ export class GoogleApp { }; broadcastNavigationState = () => { - ipc.renderer.send(this.browserWindow.webContents, "googleApp.navigationStateChanged", { + ipc.renderer.send(this.window.webContents, "googleApp.navigationStateChanged", { canGoBack: this.view.webContents.navigationHistory.canGoBack(), canGoForward: this.view.webContents.navigationHistory.canGoForward(), }); @@ -390,7 +394,7 @@ export class GoogleApp { broadcastPageTitle = () => { ipc.renderer.send( - this.browserWindow.webContents, + this.window.webContents, "googleApp.pageTitleChanged", this.view.webContents.getTitle(), ); @@ -398,14 +402,14 @@ export class GoogleApp { broadcastLoadingState = () => { ipc.renderer.send( - this.browserWindow.webContents, + this.window.webContents, "googleApp.loadingStateChanged", this.view.webContents.isLoading(), ); }; updateViewBounds = () => { - const { width, height } = this.browserWindow.getContentBounds(); + const { width, height } = this.window.getContentBounds(); this.view.setBounds({ x: 0, diff --git a/packages/app/ipc.ts b/packages/app/ipc.ts index 69b7bcb6..9430b5ae 100644 --- a/packages/app/ipc.ts +++ b/packages/app/ipc.ts @@ -54,6 +54,10 @@ class Ipc { config.store, ); } + + for (const googleAppWindow of GoogleApp.getAllWindows()) { + ipc.renderer.send(googleAppWindow.webContents, "config.configChanged", config.store); + } }); config.onDidChange("accounts", () => { diff --git a/packages/app/menu.ts b/packages/app/menu.ts index ab49d99d..331eb893 100644 --- a/packages/app/menu.ts +++ b/packages/app/menu.ts @@ -431,7 +431,7 @@ export class AppMenu { const googleApp = GoogleApp.tryFromWebContents(focusedWindow.webContents); if (googleApp) { - googleApp.browserWindow.webContents.openDevTools({ mode: "detach" }); + googleApp.window.webContents.openDevTools({ mode: "detach" }); googleApp.view.webContents.openDevTools(); }