From b252d60fb30d3cc1e79243b3fc3a2b6d5accfd6f Mon Sep 17 00:00:00 2001 From: coxtrent Date: Wed, 17 Apr 2024 03:36:19 -0400 Subject: [PATCH 1/3] Added functionality to synchronize zoom across all tabs and communities. --- app/common/config-schemata.ts | 1 + app/common/typed-ipc.ts | 2 ++ app/main/index.ts | 11 ++++++++++- app/renderer/js/components/webview.ts | 13 +++++++++++++ app/renderer/js/main.ts | 1 + .../js/pages/preference/general-section.ts | 19 +++++++++++++++++++ package-lock.json | 8 ++++---- 7 files changed, 50 insertions(+), 5 deletions(-) diff --git a/app/common/config-schemata.ts b/app/common/config-schemata.ts index e2db7b80f..c61a63d7c 100644 --- a/app/common/config-schemata.ts +++ b/app/common/config-schemata.ts @@ -12,6 +12,7 @@ export const configSchemata = { autoHideMenubar: z.boolean(), autoUpdate: z.boolean(), badgeOption: z.boolean(), + useOneZoom: z.boolean(), betaUpdate: z.boolean(), // eslint-disable-next-line @typescript-eslint/naming-convention customCSS: z.string().or(z.literal(false)).nullable(), diff --git a/app/common/typed-ipc.ts b/app/common/typed-ipc.ts index 269f42984..25c43b8b8 100644 --- a/app/common/typed-ipc.ts +++ b/app/common/typed-ipc.ts @@ -5,6 +5,7 @@ export type MainMessage = { "clear-app-settings": () => void; "configure-spell-checker": () => void; "fetch-user-agent": () => string; + 'zoom-other-tabs': (zoomLevel: number) => void; "focus-app": () => void; "focus-this-webview": () => void; "new-clipboard-key": () => {key: Uint8Array; sig: Uint8Array}; @@ -18,6 +19,7 @@ export type MainMessage = { "toggle-app": () => void; "toggle-badge-option": (newValue: boolean) => void; "toggle-menubar": (showMenubar: boolean) => void; + "toggle-one-zoom": (newValue: boolean) => void; toggleAutoLauncher: (AutoLaunchValue: boolean) => void; "unread-count": (unreadCount: number) => void; "update-badge": (messageCount: number) => void; diff --git a/app/main/index.ts b/app/main/index.ts index 5edc3ae79..81191be37 100644 --- a/app/main/index.ts +++ b/app/main/index.ts @@ -31,6 +31,8 @@ import {sentryInit} from "./sentry.js"; import {setAutoLaunch} from "./startup.js"; import {ipcMain, send} from "./typed-ipc-main.js"; + + import "gatemaker/electron-setup"; // eslint-disable-line import/no-unassigned-import // eslint-disable-next-line @typescript-eslint/naming-convention @@ -154,7 +156,6 @@ function createMainWindow(): BrowserWindow { app.quit(); return; } - await app.whenReady(); if (process.env.GDK_BACKEND !== GDK_BACKEND) { @@ -259,6 +260,7 @@ function createMainWindow(): BrowserWindow { AppMenu.setMenu({ tabs: [], }); + mainWindow = createMainWindow(); // Auto-hide menu bar on Windows + Linux @@ -278,6 +280,13 @@ function createMainWindow(): BrowserWindow { } }); + ipcMain.on('zoom-other-tabs', (event, zoomLevel) => { + BrowserWindow.getAllWindows().forEach((window) => { + window.webContents.setZoomLevel(zoomLevel); + }); + }); + + ipcMain.on("fetch-user-agent", (event) => { event.returnValue = session .fromPartition("persist:webviewsession") diff --git a/app/renderer/js/components/webview.ts b/app/renderer/js/components/webview.ts index e51e0af95..d246e5704 100644 --- a/app/renderer/js/components/webview.ts +++ b/app/renderer/js/components/webview.ts @@ -1,6 +1,7 @@ import type {WebContents} from "electron/main"; import fs from "node:fs"; import process from "node:process"; +//import { ipcRenderer } from 'electron'; import * as remote from "@electron/remote"; import {app, dialog} from "@electron/remote"; @@ -158,16 +159,28 @@ export default class WebView { this.show(); } + private syncZooms(): void { + // Sync zoom level with other tabs if useOneZoom is enabled + const useOneZoom = ConfigUtil.getConfigItem("useOneZoom", true); + if(useOneZoom) { + const zoomLevel = this.getWebContents().zoomLevel; + ipcRenderer.send('zoom-other-tabs', zoomLevel); + } + } + zoomIn(): void { this.getWebContents().zoomLevel += 0.5; + this.syncZooms(); } zoomOut(): void { this.getWebContents().zoomLevel -= 0.5; + this.syncZooms(); } zoomActualSize(): void { this.getWebContents().zoomLevel = 0; + this.syncZooms(); } logOut(): void { diff --git a/app/renderer/js/main.ts b/app/renderer/js/main.ts index 7c693ee58..1a8c11ab8 100644 --- a/app/renderer/js/main.ts +++ b/app/renderer/js/main.ts @@ -176,6 +176,7 @@ export class ServerManagerView { // Default settings which should be respected const settingOptions: Partial = { autoHideMenubar: false, + useOneZoom: true, trayIcon: true, useManualProxy: false, useSystemProxy: false, diff --git a/app/renderer/js/pages/preference/general-section.ts b/app/renderer/js/pages/preference/general-section.ts index 782dde253..d6e4fb8b9 100644 --- a/app/renderer/js/pages/preference/general-section.ts +++ b/app/renderer/js/pages/preference/general-section.ts @@ -132,6 +132,11 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
+
+
+ ${t.__("Use one zoom for all server tabs")}
+
+
Date: Wed, 17 Apr 2024 20:22:17 -0400 Subject: [PATCH 2/3] Moved the button above the spellchecker switch b ecause the spellchecker switch has a subtitle associated with it that I don'tk now how to move so this makes more sense. --- app/common/typed-ipc.ts | 3 +-- app/main/index.ts | 13 ++++++------- app/renderer/js/components/webview.ts | 19 +++++++++---------- .../js/pages/preference/general-section.ts | 15 +++++++++------ 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/common/typed-ipc.ts b/app/common/typed-ipc.ts index 25c43b8b8..a88f3328a 100644 --- a/app/common/typed-ipc.ts +++ b/app/common/typed-ipc.ts @@ -5,7 +5,6 @@ export type MainMessage = { "clear-app-settings": () => void; "configure-spell-checker": () => void; "fetch-user-agent": () => string; - 'zoom-other-tabs': (zoomLevel: number) => void; "focus-app": () => void; "focus-this-webview": () => void; "new-clipboard-key": () => {key: Uint8Array; sig: Uint8Array}; @@ -19,12 +18,12 @@ export type MainMessage = { "toggle-app": () => void; "toggle-badge-option": (newValue: boolean) => void; "toggle-menubar": (showMenubar: boolean) => void; - "toggle-one-zoom": (newValue: boolean) => void; toggleAutoLauncher: (AutoLaunchValue: boolean) => void; "unread-count": (unreadCount: number) => void; "update-badge": (messageCount: number) => void; "update-menu": (properties: MenuProperties) => void; "update-taskbar-icon": (data: string, text: string) => void; + "zoom-other-tabs": (zoomLevel: number) => void; }; export type MainCall = { diff --git a/app/main/index.ts b/app/main/index.ts index 81191be37..64182e85f 100644 --- a/app/main/index.ts +++ b/app/main/index.ts @@ -31,8 +31,6 @@ import {sentryInit} from "./sentry.js"; import {setAutoLaunch} from "./startup.js"; import {ipcMain, send} from "./typed-ipc-main.js"; - - import "gatemaker/electron-setup"; // eslint-disable-line import/no-unassigned-import // eslint-disable-next-line @typescript-eslint/naming-convention @@ -156,6 +154,7 @@ function createMainWindow(): BrowserWindow { app.quit(); return; } + await app.whenReady(); if (process.env.GDK_BACKEND !== GDK_BACKEND) { @@ -280,13 +279,13 @@ function createMainWindow(): BrowserWindow { } }); - ipcMain.on('zoom-other-tabs', (event, zoomLevel) => { - BrowserWindow.getAllWindows().forEach((window) => { - window.webContents.setZoomLevel(zoomLevel); - }); + ipcMain.on("zoom-other-tabs", (event, zoomLevel) => { + const windows = BrowserWindow.getAllWindows(); + for (const window of windows) { + window.webContents.setZoomLevel(zoomLevel); + } }); - ipcMain.on("fetch-user-agent", (event) => { event.returnValue = session .fromPartition("persist:webviewsession") diff --git a/app/renderer/js/components/webview.ts b/app/renderer/js/components/webview.ts index d246e5704..89582f895 100644 --- a/app/renderer/js/components/webview.ts +++ b/app/renderer/js/components/webview.ts @@ -1,7 +1,6 @@ import type {WebContents} from "electron/main"; import fs from "node:fs"; import process from "node:process"; -//import { ipcRenderer } from 'electron'; import * as remote from "@electron/remote"; import {app, dialog} from "@electron/remote"; @@ -159,15 +158,6 @@ export default class WebView { this.show(); } - private syncZooms(): void { - // Sync zoom level with other tabs if useOneZoom is enabled - const useOneZoom = ConfigUtil.getConfigItem("useOneZoom", true); - if(useOneZoom) { - const zoomLevel = this.getWebContents().zoomLevel; - ipcRenderer.send('zoom-other-tabs', zoomLevel); - } - } - zoomIn(): void { this.getWebContents().zoomLevel += 0.5; this.syncZooms(); @@ -237,6 +227,15 @@ export default class WebView { ipcRenderer.send("forward-to", this.webContentsId, channel, ...arguments_); } + private syncZooms(): void { + // Sync zoom level with other tabs if useOneZoom is enabled + const useOneZoom = ConfigUtil.getConfigItem("useOneZoom", true); + if (useOneZoom) { + const zoomLevel = this.getWebContents().getZoomLevel(); + ipcRenderer.send("zoom-other-tabs", zoomLevel); + } + } + private registerListeners(): void { const webContents = this.getWebContents(); diff --git a/app/renderer/js/pages/preference/general-section.ts b/app/renderer/js/pages/preference/general-section.ts index d6e4fb8b9..ee165336a 100644 --- a/app/renderer/js/pages/preference/general-section.ts +++ b/app/renderer/js/pages/preference/general-section.ts @@ -126,15 +126,16 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
-
+
- ${t.__("Enable spellchecker (requires restart)")} + ${t.__("Use one zoom for all server tabs")}
-
+
- ${t.__("Use one zoom for all server tabs")}
+ ${t.__("Enable spellchecker (requires restart)")} +
Date: Fri, 26 Apr 2024 20:09:32 -0400 Subject: [PATCH 3/3] Set zoom to work across all tabs and not to affect sidebar. --- app/common/typed-ipc.ts | 3 ++- app/main/index.ts | 9 +------ app/renderer/js/components/webview.ts | 20 +++++++--------- app/renderer/js/main.ts | 24 +++++++++++++++++++ .../js/pages/preference/general-section.ts | 4 ++-- 5 files changed, 37 insertions(+), 23 deletions(-) diff --git a/app/common/typed-ipc.ts b/app/common/typed-ipc.ts index a88f3328a..7ca7ca776 100644 --- a/app/common/typed-ipc.ts +++ b/app/common/typed-ipc.ts @@ -15,6 +15,7 @@ export type MainMessage = { "reload-full-app": () => void; "save-last-tab": (index: number) => void; "switch-server-tab": (index: number) => void; + "sync-zooms": () => void; "toggle-app": () => void; "toggle-badge-option": (newValue: boolean) => void; "toggle-menubar": (showMenubar: boolean) => void; @@ -23,7 +24,6 @@ export type MainMessage = { "update-badge": (messageCount: number) => void; "update-menu": (properties: MenuProperties) => void; "update-taskbar-icon": (data: string, text: string) => void; - "zoom-other-tabs": (zoomLevel: number) => void; }; export type MainCall = { @@ -65,6 +65,7 @@ export type RendererMessage = { "show-keyboard-shortcuts": () => void; "show-notification-settings": () => void; "switch-server-tab": (index: number) => void; + "sync-zooms": () => void; "tab-devtools": () => void; "toggle-autohide-menubar": ( autoHideMenubar: boolean, diff --git a/app/main/index.ts b/app/main/index.ts index 64182e85f..682d6eb2c 100644 --- a/app/main/index.ts +++ b/app/main/index.ts @@ -154,7 +154,7 @@ function createMainWindow(): BrowserWindow { app.quit(); return; } - + await app.whenReady(); if (process.env.GDK_BACKEND !== GDK_BACKEND) { @@ -279,13 +279,6 @@ function createMainWindow(): BrowserWindow { } }); - ipcMain.on("zoom-other-tabs", (event, zoomLevel) => { - const windows = BrowserWindow.getAllWindows(); - for (const window of windows) { - window.webContents.setZoomLevel(zoomLevel); - } - }); - ipcMain.on("fetch-user-agent", (event) => { event.returnValue = session .fromPartition("persist:webviewsession") diff --git a/app/renderer/js/components/webview.ts b/app/renderer/js/components/webview.ts index 89582f895..115f8e6bc 100644 --- a/app/renderer/js/components/webview.ts +++ b/app/renderer/js/components/webview.ts @@ -158,19 +158,24 @@ export default class WebView { this.show(); } + getZoomFactor(): number { + return this.getWebContents().getZoomFactor(); + } + + setZoomFactor(value: number): void { + this.getWebContents().setZoomFactor(value); + } + zoomIn(): void { this.getWebContents().zoomLevel += 0.5; - this.syncZooms(); } zoomOut(): void { this.getWebContents().zoomLevel -= 0.5; - this.syncZooms(); } zoomActualSize(): void { this.getWebContents().zoomLevel = 0; - this.syncZooms(); } logOut(): void { @@ -227,15 +232,6 @@ export default class WebView { ipcRenderer.send("forward-to", this.webContentsId, channel, ...arguments_); } - private syncZooms(): void { - // Sync zoom level with other tabs if useOneZoom is enabled - const useOneZoom = ConfigUtil.getConfigItem("useOneZoom", true); - if (useOneZoom) { - const zoomLevel = this.getWebContents().getZoomLevel(); - ipcRenderer.send("zoom-other-tabs", zoomLevel); - } - } - private registerListeners(): void { const webContents = this.getWebContents(); diff --git a/app/renderer/js/main.ts b/app/renderer/js/main.ts index 1a8c11ab8..c4b8254b2 100644 --- a/app/renderer/js/main.ts +++ b/app/renderer/js/main.ts @@ -887,18 +887,21 @@ export class ServerManagerView { "zoomIn", (webview) => { webview.zoomIn(); + this.syncZooms(webview.getZoomFactor()); }, ], [ "zoomOut", (webview) => { webview.zoomOut(); + this.syncZooms(webview.getZoomFactor()); }, ], [ "zoomActualSize", (webview) => { webview.zoomActualSize(); + this.syncZooms(webview.getZoomFactor()); }, ], [ @@ -1085,6 +1088,10 @@ export class ServerManagerView { }, ); + ipcRenderer.on("sync-zooms", () => { + this.syncZooms(); + }); + ipcRenderer.on("enter-fullscreen", () => { this.$fullscreenPopup.classList.add("show"); this.$fullscreenPopup.classList.remove("hidden"); @@ -1177,6 +1184,23 @@ export class ServerManagerView { await dingSound.play(); }); } + + private syncZooms(value = 1): void { + const shouldUseOneZoom = ConfigUtil.getConfigItem("useOneZoom", true); + if (shouldUseOneZoom) { + for (const tab of this.tabs) { + if (tab instanceof ServerTab) { + tab.webview + .then((webv) => { + webv.setZoomFactor(value); + }) + .catch((error) => { + console.error("Error syncing zoom factors:", error); + }); + } + } + } + } } window.addEventListener("load", async () => { diff --git a/app/renderer/js/pages/preference/general-section.ts b/app/renderer/js/pages/preference/general-section.ts index ee165336a..6fdaf80a8 100644 --- a/app/renderer/js/pages/preference/general-section.ts +++ b/app/renderer/js/pages/preference/general-section.ts @@ -128,7 +128,7 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
- ${t.__("Use one zoom for all server tabs")} + ${t.__("Use one zoom for all organization tabs")}
@@ -279,7 +279,7 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void { ConfigUtil.setConfigItem("useOneZoom", newValue); useOneZoom(); if (newValue) { - ipcRenderer.send("zoom-other-tabs", 1); + ipcRenderer.send("sync-zooms"); } }, });