Skip to content

Commit 0f60c70

Browse files
authored
broadcast zoom changed notifications (#2989)
1 parent 1b3c7c7 commit 0f60c70

3 files changed

Lines changed: 26 additions & 13 deletions

File tree

emain/emain-menu.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { focusedBuilderWindow, getBuilderWindowById } from "./emain-builder";
99
import { openBuilderWindow } from "./emain-ipc";
1010
import { isDev, unamePlatform } from "./emain-platform";
1111
import { clearTabCache } from "./emain-tabview";
12-
import { decreaseZoomLevel, increaseZoomLevel } from "./emain-util";
12+
import { decreaseZoomLevel, increaseZoomLevel, resetZoomLevel } from "./emain-util";
1313
import {
1414
createNewWaveWindow,
1515
createWorkspace,
@@ -238,8 +238,7 @@ function makeViewMenu(
238238
click: (_, window) => {
239239
const wc = getWindowWebContents(window) ?? webContents;
240240
if (wc) {
241-
wc.setZoomFactor(1);
242-
wc.send("zoom-factor-change", 1);
241+
resetZoomLevel(wc);
243242
}
244243
},
245244
},

emain/emain-tabview.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
handleCtrlShiftFocus,
1616
handleCtrlShiftState,
1717
increaseZoomLevel,
18+
resetZoomLevel,
1819
shFrameNavHandler,
1920
shNavHandler,
2021
} from "./emain-util";
@@ -48,8 +49,7 @@ function handleWindowsMenuAccelerators(
4849
}
4950

5051
if (checkKeyPressed(waveEvent, "Ctrl:0")) {
51-
tabView.webContents.setZoomFactor(1);
52-
tabView.webContents.send("zoom-factor-change", 1);
52+
resetZoomLevel(tabView.webContents);
5353
return true;
5454
}
5555

@@ -165,9 +165,6 @@ export class WaveTabView extends WebContentsView {
165165
removeWaveTabView(this.waveTabId);
166166
this.isDestroyed = true;
167167
});
168-
this.webContents.on("zoom-changed", (_event, zoomDirection) => {
169-
this.webContents.send("zoom-factor-change", this.webContents.getZoomFactor());
170-
});
171168
this.setBackgroundColor(computeBgColor(fullConfig));
172169
}
173170

@@ -339,9 +336,6 @@ export async function getOrCreateWebViewForTab(waveWindowId: string, tabId: stri
339336
}
340337
}
341338
});
342-
tabView.webContents.on("zoom-changed", (e) => {
343-
tabView.webContents.send("zoom-changed");
344-
});
345339
tabView.webContents.setWindowOpenHandler(({ url, frameName }) => {
346340
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("file://")) {
347341
console.log("openExternal fallback", url);

emain/emain-util.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,36 @@ const MinZoomLevel = 0.4;
1212
const MaxZoomLevel = 2.6;
1313
const ZoomDelta = 0.2;
1414

15+
// Note: Chromium automatically syncs zoom factor across all WebContents
16+
// sharing the same origin/session, so we only need to notify renderers
17+
// to update their CSS/state — not call setZoomFactor on each one.
18+
// We broadcast to all WebContents (including devtools, webviews, etc.) but
19+
// that is safe because "zoom-factor-change" is a custom app-defined event
20+
// that only our renderers listen to; unrecognized IPC messages are ignored.
21+
function broadcastZoomFactorChanged(newZoomFactor: number): void {
22+
for (const wc of electron.webContents.getAllWebContents()) {
23+
if (wc.isDestroyed()) {
24+
continue;
25+
}
26+
wc.send("zoom-factor-change", newZoomFactor);
27+
}
28+
}
29+
1530
export function increaseZoomLevel(webContents: electron.WebContents): void {
1631
const newZoom = Math.min(MaxZoomLevel, webContents.getZoomFactor() + ZoomDelta);
1732
webContents.setZoomFactor(newZoom);
18-
webContents.send("zoom-factor-change", newZoom);
33+
broadcastZoomFactorChanged(newZoom);
1934
}
2035

2136
export function decreaseZoomLevel(webContents: electron.WebContents): void {
2237
const newZoom = Math.max(MinZoomLevel, webContents.getZoomFactor() - ZoomDelta);
2338
webContents.setZoomFactor(newZoom);
24-
webContents.send("zoom-factor-change", newZoom);
39+
broadcastZoomFactorChanged(newZoom);
40+
}
41+
42+
export function resetZoomLevel(webContents: electron.WebContents): void {
43+
webContents.setZoomFactor(1);
44+
broadcastZoomFactorChanged(1);
2545
}
2646

2747
export function getElectronExecPath(): string {

0 commit comments

Comments
 (0)