|
|
@@ -3,7 +3,9 @@ import { app, BrowserWindow, dialog, net, nativeImage, nativeTheme, protocol } f
|
|
|
import { dirname, isAbsolute, join, relative, resolve } from "node:path"
|
|
|
import { fileURLToPath, pathToFileURL } from "node:url"
|
|
|
import type { TitlebarTheme } from "../preload/types"
|
|
|
+import { PINCH_ZOOM_ENABLED_KEY } from "./constants"
|
|
|
import { exportDebugLogs, write as writeLog } from "./logging"
|
|
|
+import { getStore } from "./store"
|
|
|
import { createUnresponsiveSampler } from "./unresponsive"
|
|
|
|
|
|
const root = dirname(fileURLToPath(import.meta.url))
|
|
|
@@ -33,7 +35,10 @@ let relaunchHandler = () => {
|
|
|
app.exit(0)
|
|
|
}
|
|
|
const titlebarThemes = new WeakMap<BrowserWindow, Partial<TitlebarTheme>>()
|
|
|
+const pinchZoomEnabled = new WeakMap<BrowserWindow, boolean>()
|
|
|
const titlebarHeight = 40
|
|
|
+const maxZoomLevel = 10
|
|
|
+const minZoomLevel = 0.2
|
|
|
|
|
|
export function setRelaunchHandler(handler: () => void) {
|
|
|
relaunchHandler = handler
|
|
|
@@ -79,6 +84,20 @@ export function updateTitlebar(win: BrowserWindow) {
|
|
|
win.setTitleBarOverlay(overlay(titlebarThemes.get(win), win.webContents.getZoomFactor()))
|
|
|
}
|
|
|
|
|
|
+export function setPinchZoomEnabled(enabled: boolean) {
|
|
|
+ getStore().set(PINCH_ZOOM_ENABLED_KEY, enabled)
|
|
|
+ for (const win of BrowserWindow.getAllWindows()) {
|
|
|
+ pinchZoomEnabled.set(win, enabled)
|
|
|
+ win.webContents.send("pinch-zoom-enabled-changed", enabled)
|
|
|
+ if (!enabled && win.webContents.getZoomFactor() !== 1) win.webContents.setZoomFactor(1)
|
|
|
+ updateZoom(win)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export function getPinchZoomEnabled() {
|
|
|
+ return getStore().get(PINCH_ZOOM_ENABLED_KEY) === true
|
|
|
+}
|
|
|
+
|
|
|
export function setDockIcon() {
|
|
|
if (process.platform !== "darwin") return
|
|
|
const icon = nativeImage.createFromPath(join(iconsDir(), "dock.png"))
|
|
|
@@ -392,13 +411,31 @@ function isRendererUrl(value?: string, html = false) {
|
|
|
}
|
|
|
|
|
|
function wireZoom(win: BrowserWindow) {
|
|
|
+ pinchZoomEnabled.set(win, getPinchZoomEnabled())
|
|
|
win.webContents.setZoomFactor(1)
|
|
|
- win.webContents.on("zoom-changed", () => {
|
|
|
- win.webContents.setZoomFactor(1)
|
|
|
- updateTitlebar(win)
|
|
|
+ win.webContents.on("zoom-changed", (event, zoomDirection) => {
|
|
|
+ event.preventDefault()
|
|
|
+ if (pinchZoomEnabled.get(win)) {
|
|
|
+ win.webContents.setZoomFactor(
|
|
|
+ clampZoom(win.webContents.getZoomFactor() + (zoomDirection === "in" ? 0.2 : -0.2)),
|
|
|
+ )
|
|
|
+ updateZoom(win)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (win.webContents.getZoomFactor() !== 1) win.webContents.setZoomFactor(1)
|
|
|
+ updateZoom(win)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+function clampZoom(value: number) {
|
|
|
+ return Math.min(Math.max(value, minZoomLevel), maxZoomLevel)
|
|
|
+}
|
|
|
+
|
|
|
+function updateZoom(win: BrowserWindow) {
|
|
|
+ updateTitlebar(win)
|
|
|
+ win.webContents.send("zoom-factor-changed", win.webContents.getZoomFactor())
|
|
|
+}
|
|
|
+
|
|
|
function upsertKeyValue(obj: Record<string, any>, keyToChange: string, value: any) {
|
|
|
const keyToChangeLower = keyToChange.toLowerCase()
|
|
|
for (const key of Object.keys(obj)) {
|