Skip to content

Commit 498b581

Browse files
committed
Set zoom to work across all tabs and not to affect sidebar.
1 parent c374dea commit 498b581

File tree

5 files changed

+37
-23
lines changed

5 files changed

+37
-23
lines changed

app/common/typed-ipc.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type MainMessage = {
1515
"reload-full-app": () => void;
1616
"save-last-tab": (index: number) => void;
1717
"switch-server-tab": (index: number) => void;
18+
"sync-zooms": () => void;
1819
"toggle-app": () => void;
1920
"toggle-badge-option": (newValue: boolean) => void;
2021
"toggle-menubar": (showMenubar: boolean) => void;
@@ -23,7 +24,6 @@ export type MainMessage = {
2324
"update-badge": (messageCount: number) => void;
2425
"update-menu": (properties: MenuProperties) => void;
2526
"update-taskbar-icon": (data: string, text: string) => void;
26-
"zoom-other-tabs": (zoomLevel: number) => void;
2727
};
2828

2929
export type MainCall = {
@@ -65,6 +65,7 @@ export type RendererMessage = {
6565
"show-keyboard-shortcuts": () => void;
6666
"show-notification-settings": () => void;
6767
"switch-server-tab": (index: number) => void;
68+
"sync-zooms": () => void;
6869
"tab-devtools": () => void;
6970
"toggle-autohide-menubar": (
7071
autoHideMenubar: boolean,

app/main/index.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function createMainWindow(): BrowserWindow {
154154
app.quit();
155155
return;
156156
}
157-
157+
158158
await app.whenReady();
159159

160160
if (process.env.GDK_BACKEND !== GDK_BACKEND) {
@@ -279,13 +279,6 @@ function createMainWindow(): BrowserWindow {
279279
}
280280
});
281281

282-
ipcMain.on("zoom-other-tabs", (event, zoomLevel) => {
283-
const windows = BrowserWindow.getAllWindows();
284-
for (const window of windows) {
285-
window.webContents.setZoomLevel(zoomLevel);
286-
}
287-
});
288-
289282
ipcMain.on("fetch-user-agent", (event) => {
290283
event.returnValue = session
291284
.fromPartition("persist:webviewsession")

app/renderer/js/components/webview.ts

+8-12
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,24 @@ export default class WebView {
158158
this.show();
159159
}
160160

161+
getZoomFactor(): number {
162+
return this.getWebContents().getZoomFactor();
163+
}
164+
165+
setZoomFactor(value: number): void {
166+
this.getWebContents().setZoomFactor(value);
167+
}
168+
161169
zoomIn(): void {
162170
this.getWebContents().zoomLevel += 0.5;
163-
this.syncZooms();
164171
}
165172

166173
zoomOut(): void {
167174
this.getWebContents().zoomLevel -= 0.5;
168-
this.syncZooms();
169175
}
170176

171177
zoomActualSize(): void {
172178
this.getWebContents().zoomLevel = 0;
173-
this.syncZooms();
174179
}
175180

176181
logOut(): void {
@@ -227,15 +232,6 @@ export default class WebView {
227232
ipcRenderer.send("forward-to", this.webContentsId, channel, ...arguments_);
228233
}
229234

230-
private syncZooms(): void {
231-
// Sync zoom level with other tabs if useOneZoom is enabled
232-
const useOneZoom = ConfigUtil.getConfigItem("useOneZoom", true);
233-
if (useOneZoom) {
234-
const zoomLevel = this.getWebContents().getZoomLevel();
235-
ipcRenderer.send("zoom-other-tabs", zoomLevel);
236-
}
237-
}
238-
239235
private registerListeners(): void {
240236
const webContents = this.getWebContents();
241237

app/renderer/js/main.ts

+24
Original file line numberDiff line numberDiff line change
@@ -887,18 +887,21 @@ export class ServerManagerView {
887887
"zoomIn",
888888
(webview) => {
889889
webview.zoomIn();
890+
this.syncZooms(webview.getZoomFactor());
890891
},
891892
],
892893
[
893894
"zoomOut",
894895
(webview) => {
895896
webview.zoomOut();
897+
this.syncZooms(webview.getZoomFactor());
896898
},
897899
],
898900
[
899901
"zoomActualSize",
900902
(webview) => {
901903
webview.zoomActualSize();
904+
this.syncZooms(webview.getZoomFactor());
902905
},
903906
],
904907
[
@@ -1085,6 +1088,10 @@ export class ServerManagerView {
10851088
},
10861089
);
10871090

1091+
ipcRenderer.on("sync-zooms", () => {
1092+
this.syncZooms();
1093+
});
1094+
10881095
ipcRenderer.on("enter-fullscreen", () => {
10891096
this.$fullscreenPopup.classList.add("show");
10901097
this.$fullscreenPopup.classList.remove("hidden");
@@ -1177,6 +1184,23 @@ export class ServerManagerView {
11771184
await dingSound.play();
11781185
});
11791186
}
1187+
1188+
private syncZooms(value = 1): void {
1189+
const shouldUseOneZoom = ConfigUtil.getConfigItem("useOneZoom", true);
1190+
if (shouldUseOneZoom) {
1191+
for (const tab of this.tabs) {
1192+
if (tab instanceof ServerTab) {
1193+
tab.webview
1194+
.then((webv) => {
1195+
webv.setZoomFactor(value);
1196+
})
1197+
.catch((error) => {
1198+
console.error("Error syncing zoom factors:", error);
1199+
});
1200+
}
1201+
}
1202+
}
1203+
}
11801204
}
11811205

11821206
window.addEventListener("load", async () => {

app/renderer/js/pages/preference/general-section.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
128128
</div>
129129
<div class="setting-row" id="one-zoom-option">
130130
<div class="setting-description">
131-
${t.__("Use one zoom for all server tabs")}
131+
${t.__("Use one zoom for all organization tabs")}
132132
</div>
133133
<div class="setting-control"></div>
134134
</div>
@@ -279,7 +279,7 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
279279
ConfigUtil.setConfigItem("useOneZoom", newValue);
280280
useOneZoom();
281281
if (newValue) {
282-
ipcRenderer.send("zoom-other-tabs", 1);
282+
ipcRenderer.send("sync-zooms");
283283
}
284284
},
285285
});

0 commit comments

Comments
 (0)