Skip to content

Commit b252d60

Browse files
committed
Added functionality to synchronize zoom across all tabs and communities.
1 parent c45c953 commit b252d60

File tree

7 files changed

+50
-5
lines changed

7 files changed

+50
-5
lines changed

app/common/config-schemata.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const configSchemata = {
1212
autoHideMenubar: z.boolean(),
1313
autoUpdate: z.boolean(),
1414
badgeOption: z.boolean(),
15+
useOneZoom: z.boolean(),
1516
betaUpdate: z.boolean(),
1617
// eslint-disable-next-line @typescript-eslint/naming-convention
1718
customCSS: z.string().or(z.literal(false)).nullable(),

app/common/typed-ipc.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type MainMessage = {
55
"clear-app-settings": () => void;
66
"configure-spell-checker": () => void;
77
"fetch-user-agent": () => string;
8+
'zoom-other-tabs': (zoomLevel: number) => void;
89
"focus-app": () => void;
910
"focus-this-webview": () => void;
1011
"new-clipboard-key": () => {key: Uint8Array; sig: Uint8Array};
@@ -18,6 +19,7 @@ export type MainMessage = {
1819
"toggle-app": () => void;
1920
"toggle-badge-option": (newValue: boolean) => void;
2021
"toggle-menubar": (showMenubar: boolean) => void;
22+
"toggle-one-zoom": (newValue: boolean) => void;
2123
toggleAutoLauncher: (AutoLaunchValue: boolean) => void;
2224
"unread-count": (unreadCount: number) => void;
2325
"update-badge": (messageCount: number) => void;

app/main/index.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import {sentryInit} from "./sentry.js";
3131
import {setAutoLaunch} from "./startup.js";
3232
import {ipcMain, send} from "./typed-ipc-main.js";
3333

34+
35+
3436
import "gatemaker/electron-setup"; // eslint-disable-line import/no-unassigned-import
3537

3638
// eslint-disable-next-line @typescript-eslint/naming-convention
@@ -154,7 +156,6 @@ function createMainWindow(): BrowserWindow {
154156
app.quit();
155157
return;
156158
}
157-
158159
await app.whenReady();
159160

160161
if (process.env.GDK_BACKEND !== GDK_BACKEND) {
@@ -259,6 +260,7 @@ function createMainWindow(): BrowserWindow {
259260
AppMenu.setMenu({
260261
tabs: [],
261262
});
263+
262264
mainWindow = createMainWindow();
263265

264266
// Auto-hide menu bar on Windows + Linux
@@ -278,6 +280,13 @@ function createMainWindow(): BrowserWindow {
278280
}
279281
});
280282

283+
ipcMain.on('zoom-other-tabs', (event, zoomLevel) => {
284+
BrowserWindow.getAllWindows().forEach((window) => {
285+
window.webContents.setZoomLevel(zoomLevel);
286+
});
287+
});
288+
289+
281290
ipcMain.on("fetch-user-agent", (event) => {
282291
event.returnValue = session
283292
.fromPartition("persist:webviewsession")

app/renderer/js/components/webview.ts

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {WebContents} from "electron/main";
22
import fs from "node:fs";
33
import process from "node:process";
4+
//import { ipcRenderer } from 'electron';
45

56
import * as remote from "@electron/remote";
67
import {app, dialog} from "@electron/remote";
@@ -158,16 +159,28 @@ export default class WebView {
158159
this.show();
159160
}
160161

162+
private syncZooms(): void {
163+
// Sync zoom level with other tabs if useOneZoom is enabled
164+
const useOneZoom = ConfigUtil.getConfigItem("useOneZoom", true);
165+
if(useOneZoom) {
166+
const zoomLevel = this.getWebContents().zoomLevel;
167+
ipcRenderer.send('zoom-other-tabs', zoomLevel);
168+
}
169+
}
170+
161171
zoomIn(): void {
162172
this.getWebContents().zoomLevel += 0.5;
173+
this.syncZooms();
163174
}
164175

165176
zoomOut(): void {
166177
this.getWebContents().zoomLevel -= 0.5;
178+
this.syncZooms();
167179
}
168180

169181
zoomActualSize(): void {
170182
this.getWebContents().zoomLevel = 0;
183+
this.syncZooms();
171184
}
172185

173186
logOut(): void {

app/renderer/js/main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export class ServerManagerView {
176176
// Default settings which should be respected
177177
const settingOptions: Partial<Config> = {
178178
autoHideMenubar: false,
179+
useOneZoom: true,
179180
trayIcon: true,
180181
useManualProxy: false,
181182
useSystemProxy: false,

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

+19
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
132132
</div>
133133
<div class="setting-control"></div>
134134
</div>
135+
<div class="setting-row" id="one-zoom-option">
136+
<div class="setting-description">
137+
${t.__("Use one zoom for all server tabs")}</div>
138+
<div class="setting-control"></div>
139+
</div>
135140
<div
136141
class="setting-row"
137142
id="spellcheck-langs"
@@ -213,6 +218,7 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
213218
`.html;
214219

215220
updateTrayOption();
221+
useOneZoom();
216222
updateBadgeOption();
217223
updateSilentOption();
218224
autoUpdateOption();
@@ -263,6 +269,19 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
263269
});
264270
}
265271

272+
function useOneZoom(): void {
273+
generateSettingOption({
274+
$element: $root.querySelector("#one-zoom-option .setting-control")!,
275+
value: ConfigUtil.getConfigItem("useOneZoom", false),
276+
clickHandler() {
277+
const newValue = !ConfigUtil.getConfigItem("useOneZoom", false);
278+
ConfigUtil.setConfigItem("useOneZoom", newValue);
279+
useOneZoom();
280+
},
281+
})
282+
return;
283+
}
284+
266285
function updateMenubarOption(): void {
267286
generateSettingOption({
268287
$element: $root.querySelector("#menubar-option .setting-control")!,

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)