Skip to content
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: 1 addition & 1 deletion packages/app/gmail/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
42 changes: 23 additions & 19 deletions packages/app/google-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function getGoogleAppFromUrl(url: string) {
type GoogleAppOptions = {
accountId: AccountConfig["id"];
url: string;
browserWindow?: BrowserWindowConstructorOptions;
window?: BrowserWindowConstructorOptions;
view?: WebContentsViewConstructorOptions;
};

Expand All @@ -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;

Expand All @@ -82,7 +86,7 @@ export class GoogleApp {
) {
instance.view.webContents.loadURL(url);

instance.browserWindow.focus();
instance.window.focus();

return true;
}
Expand Down Expand Up @@ -214,19 +218,19 @@ export class GoogleApp {

app: SupportedGoogleApp | undefined;

browserWindow: BrowserWindow;
window: BrowserWindow;

view: WebContentsView;

private powerSaveBlockerId: number | undefined;

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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -382,30 +386,30 @@ 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(),
});
};

broadcastPageTitle = () => {
ipc.renderer.send(
this.browserWindow.webContents,
this.window.webContents,
"googleApp.pageTitleChanged",
this.view.webContents.getTitle(),
);
};

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,
Expand Down
4 changes: 4 additions & 0 deletions packages/app/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading