From fb56345e6cb1df744bc8816622c33547b5ac9508 Mon Sep 17 00:00:00 2001 From: Neil Enns Date: Wed, 1 May 2024 13:37:10 -0700 Subject: [PATCH] Initial implementation --- package-lock.json | 2 +- src/app/components/mini.tsx | 4 +++- src/index.ts | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index e6ffdcd..d2e8a10 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15685,7 +15685,7 @@ "node_modules/trackaudio-afv": { "version": "1.0.0", "resolved": "file:backend/trackaudio-afv-1.0.0.tgz", - "integrity": "sha512-wCfWsUYAz7aWluWGz7nZnyW3TgOyhAAkI7hCpjNqWqW0ryyWcBQNc+VrjQB/upP1Ro60wHITkXNzkB8DiZ0VOg==", + "integrity": "sha512-qRv29lJSktzmkBH2BTcP2gy7L1KHrpJixvcDDySiAXOGBMnwNL8+8lmEkOYaaBPSQ3E8OxPGi4pg1U1jH/tBtA==", "dependencies": { "bindings": "^1.5.0", "node-addon-api": "^1.1.0" diff --git a/src/app/components/mini.tsx b/src/app/components/mini.tsx index 64adb61..79849fe 100644 --- a/src/app/components/mini.tsx +++ b/src/app/components/mini.tsx @@ -19,7 +19,9 @@ const Mini: React.FC = () => { :{" "} {radio.lastReceivedCallsign ? radio.lastReceivedCallsign : ""} diff --git a/src/index.ts b/src/index.ts index ba284ad..1a988ac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,9 @@ import { getKeyFromNumber } from "./helper"; declare const MAIN_WINDOW_WEBPACK_ENTRY: string; declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string; +// The increment for window zoom with each mouse wheel movement +const ZOOM_DELTA = 0.2; + // Handle creating/removing shortcuts on Windows when installing/uninstalling. if (require("electron-squirrel-startup")) app.quit(); @@ -100,10 +103,19 @@ const createWindow = (): void => { webPreferences: { preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY, }, + // Required to handle resetting the zoom level to 1.0 on app launch + show: false, }); mainWindow.setAlwaysOnTop(currentConfiguration.alwaysOnTop || false); + // Reset the zoom level to 1.0 on app launch. This is to work around a long-standing + // bug in Electron that was opened in 2017 and closed without fixing. See + // https://github.com/electron/electron/issues/10572 for more details. + mainWindow.once("ready-to-show", () => { + mainWindow.webContents.zoomFactor = 1.0; + }); + if (process.platform !== "darwin") { mainWindow.setMenu(null); } @@ -130,6 +142,24 @@ const createWindow = (): void => { } } }); + + // Support setting window zoom via ctrl + mouse wheel + mainWindow.webContents.on("zoom-changed", (_, zoomDirection) => { + const currentZoom = mainWindow.webContents.getZoomFactor(); + const newZoom = + zoomDirection === "in" + ? currentZoom + ZOOM_DELTA + : currentZoom - ZOOM_DELTA; + + // Cap the zoom level between 100% and 300%. There's a setVisualZoomLevelLimits() in electron + // but it's async, and also appears to only limit the pinch-to-zoom level, not the zoom level + // set via setZoomFactor(). + if (newZoom > 1 && newZoom < 3) { + mainWindow.webContents.setZoomFactor(newZoom); + } + }); + + mainWindow.show(); }; // This method will be called when Electron has finished