diff --git a/CHANGELOG.md b/CHANGELOG.md index 34a7760..e20b594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,26 @@ Releases before 0.1.9 predate this file — see the ## [Unreleased] ### Added +- **UI scale and zoom shortcuts.** Ctrl or Cmd with `=` (or `+`), `-` and `0` zoom the + window in, out and back to 100%, from 75% up to 300%, and Settings > General > UI scale + picks a size too. It is remembered, and the orb stays at its own size. (#60) - **Russian speech recognition and voice replies.** Pick Russian in Settings > Voice and OpenLive hears you with Parakeet v3, Whisper or Nemotron 3.5 and answers with Supertonic or Piper (Denis or Dmitri). Numbers, dates, times, percentages, "№" and rubles (₽) are read aloud in Russian too, and the interface font now covers Cyrillic. The interface stays in English. (#61) +### Fixed +- **Ctrl+= now zooms in.** Only Ctrl+- worked before, because the menu's zoom in needed Shift. +- **An older Ctrl+- zoom carries over.** A zoom level set before UI scale existed becomes the nearest step on first launch. +- **The window fits small and scaled screens.** A first launch opens at most as large as the + screen's usable area, centered, and the window can always be resized down to fit the screen + it is on, such as a 1080p laptop at 150% scaling. +- **Layouts hold up at large zoom.** The call's orb shrinks to the room it has instead of + overlapping the hints and controls, the top bar folds its chips to icons in a narrow window, + the home page's version no longer sits over the buttons, and text sizes follow the root + size. (#60) + ## [0.4.1] - 2026-11-11 ### Changed diff --git a/apps/desktop/README.md b/apps/desktop/README.md index 8fc3618..2c946b6 100644 --- a/apps/desktop/README.md +++ b/apps/desktop/README.md @@ -76,6 +76,15 @@ NSIS installers run unsigned (users see a SmartScreen warning). To sign, provide code-signing cert via electron-builder's `win.certificateFile` + `CSC_KEY_PASSWORD`, or an Azure Trusted Signing / EV cert. Not required to ship. +## Zoom + +`Ctrl`/`Cmd` + `=` (or `+`) zooms in, `-` zooms out, `0` resets, on the main window +only (also the numpad keys, and View in the menu). It moves through 75, 90, 100, +110, 125, 150, 175, 200, 250 and 300 percent, and Settings > General > UI scale +picks one too. The scale is kept in `/state/appearance.json`. The orb stays +at 100 percent. On a first launch the window opens at most as large as the work +area of the screen it is on, and its minimum size follows the screen it moves to. + ## What's in the package ``` diff --git a/apps/desktop/electron-builder.yml b/apps/desktop/electron-builder.yml index ec6ac48..65bb3ea 100644 --- a/apps/desktop/electron-builder.yml +++ b/apps/desktop/electron-builder.yml @@ -40,6 +40,7 @@ files: - splash.html - telemetry-map.cjs - window-state.cjs + - zoom.cjs - login-item.cjs - update-gate.cjs - prev-exit.cjs diff --git a/apps/desktop/main.cjs b/apps/desktop/main.cjs index 4d47d3d..73fb1ba 100644 --- a/apps/desktop/main.cjs +++ b/apps/desktop/main.cjs @@ -17,7 +17,8 @@ const flowRuntime = require("./flow-runtime.cjs"); const { osHasGlass, glassSupport, effectiveLook } = require("./look.cjs"); const orbPointer = require("./orb-pointer.cjs"); const { isExternalUrl } = require("./external-url.cjs"); -const { restoreWindow, windowSnapshot } = require("./window-state.cjs"); +const { restoreWindow, minFor, fitRect, firstRunWindow, windowSnapshot } = require("./window-state.cjs"); +const { sameZoom, sanitizeZoom, nextZoom, zoomKeyAction, legacyHostZoom, ZOOM_STEPS } = require("./zoom.cjs"); const { trayTemplate, orbOwner } = require("./tray-menu.cjs"); const { talkBindings, pttRouter } = require("./talk.cjs"); const { loginDefaultReady } = require("./login-item.cjs"); @@ -435,6 +436,7 @@ function agentArgs() { // ── window bounds: remember size, position, maximized and fullscreen ───────── const windowStateFile = () => stateFile("window-state.json"); const MAIN_MIN = { width: 940, height: 640 }; +const MAIN_PREFERRED = { width: 1180, height: 800 }; function loadWindowState() { let saved = null; try { saved = JSON.parse(fs.readFileSync(windowStateFile(), "utf8")); } catch { /* no saved state */ } @@ -444,6 +446,24 @@ function saveWindowState() { if (!mainWin || mainWin.isDestroyed()) return; try { writeAtomic(fs, windowStateFile(), JSON.stringify(windowSnapshot(mainWin))); } catch { /* best-effort */ } } +/** The work area of the display `bounds` sits on, or the primary's for a window with no place yet. */ +const workAreaOf = (bounds) => (bounds?.x != null ? screen.getDisplayMatching(bounds) : screen.getPrimaryDisplay()).workArea; +const mainDisplayId = () => screen.getDisplayMatching(mainWin.getBounds()).id; +/** Keeps the window usable on the display it is on: its minimum never exceeds that + * work area and, when `reclamp`, a window that no longer fits is brought back inside it. + * Never on a move (it would fight the person dragging), and only where the window's + * own screen lost room: a resize that follows is saved, so a passing change (a remote + * session, a projector, a taskbar that hides) must not shrink it for good. */ +function fitMainWindow(reclamp = false) { + if (!mainWin || mainWin.isDestroyed()) return; + const bounds = mainWin.getBounds(); + const work = workAreaOf(bounds); + const min = minFor(MAIN_MIN, work); + mainWin.setMinimumSize(min.width, min.height); + if (!reclamp || mainWin.isMaximized() || mainWin.isFullScreen() || mainWin.isMinimized()) return; + const fit = fitRect(bounds, work, MAIN_MIN); + if (["x", "y", "width", "height"].some((k) => fit[k] !== bounds[k])) mainWin.setBounds(fit); +} // ── one-time things (first ⌘Q notice, the login-item default) ──────────────── const onceFile = () => stateFile("once.json"); @@ -475,13 +495,28 @@ const CLEAR = "#00000000"; const PAGE_BG = { dark: "#0b0b0c", light: "#efede8" }; // --background in .dark / :root const THEMES = new Set(["system", "light", "dark"]); const appearanceFile = () => stateFile("appearance.json"); -let appearance = {}; // { theme, look, probe: { version, slow } } +let appearance = {}; // { theme, look, zoom, probe: { version, slow } } let look = "flat"; // what the main window wears right now let lookTimer = null; let winTransparencyOff = false; +let zoom = 1; // the main window's UI scale, one of ZOOM_STEPS +function legacyZoom() { + try { return legacyHostZoom(JSON.parse(fs.readFileSync(path.join(app.getPath("userData"), "Preferences"), "utf8")), WEB_HOST); } catch { return null; } +} function loadAppearance() { - try { appearance = JSON.parse(fs.readFileSync(appearanceFile(), "utf8")) || {}; } catch { appearance = {}; } + let writable = false; // only a missing file or a valid object may be written back; anything else might be recoverable + appearance = {}; + try { + const parsed = JSON.parse(fs.readFileSync(appearanceFile(), "utf8")); + if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) { appearance = parsed; writable = true; } + } catch (e) { writable = e.code === "ENOENT"; } + if (appearance.zoom === undefined) { + // Before the scale was kept here, Chromium kept the main window's as a per-host zoom level. + appearance.zoom = legacyZoom() ?? 1; // kept even when none, so Preferences is read once + if (writable) saveAppearance(); + } + zoom = sanitizeZoom(appearance.zoom); // Native surfaces (the material's tint, the title bar) follow the app's theme, not the OS's. nativeTheme.themeSource = THEMES.has(appearance.theme) ? appearance.theme : "system"; readWinTransparency(); @@ -602,6 +637,39 @@ function wireAppearance() { app.on("gpu-info-update", refreshLook); } +// ── zoom: the main window's UI scale, kept in appearance.json beside the theme ─ +// Chromium zooms per origin and every window here is on the same one, so a level +// set on the main window would scale the orb and the hidden owner with it. Every +// window therefore opens `zoomMode: "isolated"` (its own level), and the orb and +// the owner are held at 100% (holdZoom). +const zoomState = () => ({ factor: zoom, steps: ZOOM_STEPS }); + +/** Holds `wc` at `factor()` now and after every load, so a reload never leaves it at the origin's level. */ +function holdZoom(wc, factor) { + const apply = () => { if (!wc.isDestroyed() && !sameZoom(wc.getZoomFactor(), factor())) wc.setZoomFactor(factor()); }; + apply(); + wc.on("dom-ready", apply); +} + +function setZoom(v) { + const next = sanitizeZoom(v); + if (next !== zoom) { + zoom = next; + appearance.zoom = next; + saveAppearance(); + if (mainWin && !mainWin.isDestroyed()) { + mainWin.webContents.setZoomFactor(zoom); + mainWin.webContents.send("openlive:zoom-changed", zoomState()); + } + } + return zoomState(); +} + +function wireZoom() { + ipcMain.on("openlive:zoom", (e) => { e.returnValue = zoomState(); }); + ipcMain.handle("openlive:zoom-set", (e, v) => (isMainWc(e.sender) && Number.isFinite(v) ? setZoom(v) : zoomState())); +} + // ── windows ────────────────────────────────────────────────────────────────── function createSplash() { splashWin = new BrowserWindow({ @@ -617,9 +685,11 @@ function createSplash() { function createMainWindow() { const saved = loadWindowState(); + const start = saved ?? firstRunWindow(MAIN_PREFERRED, screen.getDisplayNearestPoint(screen.getCursorScreenPoint()).workArea, MAIN_MIN); + const min = minFor(MAIN_MIN, workAreaOf(start)); mainWin = new BrowserWindow({ - width: saved?.width || 1180, height: saved?.height || 800, minWidth: MAIN_MIN.width, minHeight: MAIN_MIN.height, - ...(saved && saved.x != null ? { x: saved.x, y: saved.y } : {}), + width: start.width, height: start.height, minWidth: min.width, minHeight: min.height, + ...(start.x != null ? { x: start.x, y: start.y } : {}), show: false, // Never `transparent: true`: transparent windows take a slower macOS compositing // path that competes with the on-device WebGPU voice models (adds turn latency), @@ -641,6 +711,8 @@ function createMainWindow() { // in-origin) — keep it in the Chromium sandbox. The preload only uses // contextBridge/ipcRenderer, which are available in sandboxed preloads. sandbox: true, + // The UI scale is this window's own (see the zoom section), set before its first frame. + zoomMode: "isolated", zoomFactor: zoom, // A call keeps running while this window is minimised or hidden, and its // renderer runs the whole voice pipeline: throttled timers would wreck // turn-taking (hold timers, TTS drain). @@ -657,6 +729,25 @@ function createMainWindow() { }, }); for (const ev of ["resize", "move", "close", "maximize", "unmaximize", "enter-full-screen", "leave-full-screen"]) mainWin.on(ev, saveWindowState); + // A new display brings its own work area, so its minimum size has to follow. `moved` + // is macOS and Windows only, so this listens to `move` and acts when the display changes. + let onDisplay = null; + mainWin.on("move", () => { + const id = mainDisplayId(); + if (id === onDisplay) return; + onDisplay = id; + fitMainWindow(); + }); + holdZoom(mainWin.webContents, () => zoom); + // The menu's zoom accelerators are display only (menu click below). A key + // handled here is claimed, which stops the menu's own accelerator for it, so + // one press steps once, and it works on layouts where the menu's does not. + mainWin.webContents.on("before-input-event", (e, input) => { + const action = zoomKeyAction(input, process.platform); + if (!action) return; + e.preventDefault(); + setZoom(nextZoom(zoom, action)); + }); // A backstop for OS settings that change without telling nativeTheme. mainWin.on("focus", refreshLook); mainWin.on("focus", () => telemetry.markActiveDay("main_window")); @@ -727,8 +818,9 @@ function makePanelWindow(route, bounds) { // on Windows, and one the window manager never focuses on Linux. focusable: false, ...(process.platform === "darwin" ? { type: "panel" } : {}), - webPreferences: { preload: path.join(__dirname, "preload.cjs"), contextIsolation: true, nodeIntegration: false, sandbox: true, backgroundThrottling: false }, + webPreferences: { preload: path.join(__dirname, "preload.cjs"), contextIsolation: true, nodeIntegration: false, sandbox: true, backgroundThrottling: false, zoomMode: "isolated", zoomFactor: 1 }, }); + holdZoom(win.webContents, () => 1); win.setAlwaysOnTop(true, "floating", 1); win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true, skipTransformProcessType: true }); // Electron's panel still activates OpenLive on a click, bringing the main @@ -805,8 +897,9 @@ function createOwnerWindow() { if (ownerWin && !ownerWin.isDestroyed()) return ownerWin; ownerWin = new BrowserWindow({ width: 480, height: 320, show: false, skipTaskbar: true, - webPreferences: { preload: path.join(__dirname, "preload.cjs"), contextIsolation: true, nodeIntegration: false, sandbox: true, backgroundThrottling: false, additionalArguments: agentArgs() }, + webPreferences: { preload: path.join(__dirname, "preload.cjs"), contextIsolation: true, nodeIntegration: false, sandbox: true, backgroundThrottling: false, zoomMode: "isolated", zoomFactor: 1, additionalArguments: agentArgs() }, }); + holdZoom(ownerWin.webContents, () => 1); ownerWin.loadURL(`${WEB_URL}/flow-owner`); ownerWin.webContents.on("did-start-loading", () => { ownerReady = false; }); // Loaded means the web server answers, so Dictate's state can be read for the tray. @@ -1373,6 +1466,12 @@ function wireWindowIpc() { telemetry.track("remote_ollama_prompt", { outcome, scheme: u.protocol === "https:" ? "https" : "http" }); } }); + screen.on("display-added", () => fitMainWindow()); + screen.on("display-removed", () => fitMainWindow(true)); + screen.on("display-metrics-changed", (_e, display, changed) => { + const room = changed.some((m) => m === "workArea" || m === "bounds" || m === "scaleFactor"); + fitMainWindow(room && !!mainWin && !mainWin.isDestroyed() && mainDisplayId() === display.id); + }); ipcMain.on("openlive:win-close", () => { if (mainWin) mainWin.close(); }); ipcMain.on("openlive:win-min", () => { if (mainWin) mainWin.minimize(); }); ipcMain.on("openlive:win-zoom", () => { @@ -1564,6 +1663,14 @@ function buildMenu() { { label: `Close to ${isMac ? "Menu Bar" : "Tray"}`, accelerator: "CmdOrCtrl+Q", click: closeToMenuBar }, { label: "Quit OpenLive", click: () => quitApp("app_menu") }, ]; + // The role's Zoom In wants Shift (its accelerator is Ctrl+Plus), which left Ctrl+= dead. + // The key itself is handled in createMainWindow, so a click is all this item answers. + const zoomItem = (label, accelerator, action) => ({ + label, accelerator, + // Electron flags every click with no mouse button as an accelerator (VoiceOver and + // menu-key activations included), so only one with Ctrl or Cmd down is the shortcut itself. + click: (_item, _win, e) => { if (!(e.triggeredByAccelerator && (e.ctrlKey || e.metaKey))) setZoom(nextZoom(zoom, action)); }, + }); const template = [ ...(isMac ? [{ role: "appMenu", submenu: [ { role: "about", label: "About OpenLive" }, @@ -1577,7 +1684,15 @@ function buildMenu() { { type: "separator" }, ...closeItems, ] }] : [{ label: "File", submenu: closeItems }]), { role: "editMenu" }, - { role: "viewMenu" }, + { label: "View", submenu: [ + { role: "reload" }, { role: "forceReload" }, { role: "toggleDevTools" }, + { type: "separator" }, + zoomItem("Actual Size", "CommandOrControl+0", "reset"), + zoomItem("Zoom In", "CommandOrControl+=", "in"), + zoomItem("Zoom Out", "CommandOrControl+-", "out"), + { type: "separator" }, + { role: "togglefullscreen" }, + ] }, { role: "windowMenu" }, { role: "help", submenu: [ { label: "OpenLive on GitHub", click: () => shell.openExternal("https://github.com/katipally/openlive") }, @@ -1693,6 +1808,7 @@ async function boot() { loadAppearance(); loadPreferences(); wireAppearance(); + wireZoom(); wirePermissions(); wirePanelIpc(); wireNotifyIpc(); diff --git a/apps/desktop/preload.cjs b/apps/desktop/preload.cjs index 40d328c..35e889b 100644 --- a/apps/desktop/preload.cjs +++ b/apps/desktop/preload.cjs @@ -54,6 +54,14 @@ contextBridge.exposeInMainWorld("openlive", { set: (patch) => ipcRenderer.invoke("openlive:appearance-set", patch), onChange: (cb) => listen("openlive:appearance-changed", cb), }, + // The main window's UI scale, the same way: `get` is synchronous. Resolves / + // delivers { factor, steps }, `factor` being one of `steps` (1 is 100%). `set` + // takes a factor and snaps it to the nearest step; the shortcuts move it too. + zoom: { + get: () => ipcRenderer.sendSync("openlive:zoom"), + set: (factor) => ipcRenderer.invoke("openlive:zoom-set", factor), + onChange: (cb) => listen("openlive:zoom-changed", cb), + }, // Product-usage telemetry. Main checks every message against its schema and keeps // nothing else; only the main window and Flow's owner are heard. get() resolves to // { active, enabled, noticeSeen, installIdTail, username, feedback, appVersion, osName, osMajor }, and diff --git a/apps/desktop/window-state.cjs b/apps/desktop/window-state.cjs index 7877f8f..120cf88 100644 --- a/apps/desktop/window-state.cjs +++ b/apps/desktop/window-state.cjs @@ -35,9 +35,35 @@ function restoreWindow(saved, { displays, primary, min }) { }; } +/** The smallest the window may be on `work`: its minimum, or the whole work + * area where that is smaller, so a small or heavily scaled screen never has a + * window it cannot fit. */ +const minFor = (min, work) => ({ width: Math.min(min.width, work.width), height: Math.min(min.height, work.height) }); + +/** `rect` shrunk to fit `work` (not under `minFor`) and pulled inside it. */ +function fitRect(rect, work, min) { + const m = minFor(min, work); + const width = Math.round(clamp(rect.width, m.width, work.width)); + const height = Math.round(clamp(rect.height, m.height, work.height)); + return { + x: Math.round(clamp(rect.x, work.x, work.x + work.width - width)), + y: Math.round(clamp(rect.y, work.y, work.y + work.height - height)), + width, height, + }; +} + +/** The first launch's window: `preferred` size, shrunk to the work area of the + * display it opens on and centered in it. */ +function firstRunWindow(preferred, work, min) { + const m = minFor(min, work); + const width = Math.round(clamp(preferred.width, m.width, work.width)); + const height = Math.round(clamp(preferred.height, m.height, work.height)); + return { x: work.x + Math.round((work.width - width) / 2), y: work.y + Math.round((work.height - height) / 2), width, height }; +} + /** What to save: the bounds it returns to, whatever state it is in now. */ function windowSnapshot(win) { return { ...win.getNormalBounds(), maximized: win.isMaximized(), fullscreen: win.isFullScreen() }; } -module.exports = { restoreWindow, windowSnapshot }; +module.exports = { restoreWindow, minFor, fitRect, firstRunWindow, windowSnapshot }; diff --git a/apps/desktop/window-state.test.ts b/apps/desktop/window-state.test.ts index 606d559..5edf9b7 100644 --- a/apps/desktop/window-state.test.ts +++ b/apps/desktop/window-state.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from "vitest"; import { createRequire } from "node:module"; -const { restoreWindow, windowSnapshot } = createRequire(import.meta.url)("./window-state.cjs"); +const { restoreWindow, minFor, fitRect, firstRunWindow, windowSnapshot } = createRequire(import.meta.url)("./window-state.cjs"); const display = (x: number, y: number, width: number, height: number) => ({ workArea: { x, y, width, height } }); const laptop = display(0, 25, 1440, 875); // macOS: under the menu bar @@ -45,6 +45,43 @@ describe("restoreWindow", () => { }); }); +describe("minFor", () => { + it("is the minimum where the work area holds it, and the work area where it does not", () => { + expect(minFor(min, laptop.workArea)).toEqual(min); + expect(minFor(min, { x: 0, y: 0, width: 640, height: 480 })).toEqual({ width: 640, height: 480 }); + expect(minFor(min, { x: 0, y: 0, width: 1920, height: 400 })).toEqual({ width: 940, height: 400 }); + }); +}); + +describe("fitRect", () => { + it("leaves a window that fits where it is", () => { + expect(fitRect({ x: 100, y: 100, width: 1000, height: 700 }, laptop.workArea, min)).toEqual({ x: 100, y: 100, width: 1000, height: 700 }); + }); + it("shrinks a window the work area cannot hold and pulls it inside", () => { + expect(fitRect({ x: 300, y: 300, width: 1180, height: 800 }, { x: 0, y: 0, width: 1024, height: 576 }, min)) + .toEqual({ x: 0, y: 0, width: 1024, height: 576 }); + expect(fitRect({ x: -200, y: 900, width: 1000, height: 700 }, laptop.workArea, min)).toEqual({ x: 0, y: 200, width: 1000, height: 700 }); + }); + it("never goes under the minimum the work area allows", () => { + expect(fitRect({ x: 0, y: 0, width: 100, height: 100 }, laptop.workArea, min)).toMatchObject({ width: 940, height: 640 }); + }); +}); + +describe("firstRunWindow", () => { + const preferred = { width: 1180, height: 800 }; + it("opens the preferred size centered in a work area that holds it", () => { + expect(firstRunWindow(preferred, laptop.workArea, min)).toEqual({ x: 130, y: 63, width: 1180, height: 800 }); + expect(firstRunWindow(preferred, external.workArea, min)).toEqual({ x: 2130, y: 300, width: 1180, height: 800 }); + }); + it("shrinks to a work area that cannot hold it, such as 1080p at 150 percent", () => { + expect(firstRunWindow(preferred, { x: 0, y: 0, width: 1280, height: 672 }, min)).toEqual({ x: 50, y: 0, width: 1180, height: 672 }); + expect(firstRunWindow(preferred, { x: 0, y: 0, width: 1000, height: 600 }, min)).toEqual({ x: 0, y: 0, width: 1000, height: 600 }); + }); + it("fills a work area smaller than the minimum, never spilling off it", () => { + expect(firstRunWindow(preferred, { x: 10, y: 20, width: 800, height: 500 }, min)).toEqual({ x: 10, y: 20, width: 800, height: 500 }); + }); +}); + describe("windowSnapshot", () => { it("keeps the normal bounds under a maximized or fullscreen window", () => { const win = { getNormalBounds: () => ({ x: 10, y: 20, width: 1000, height: 700 }), isMaximized: () => false, isFullScreen: () => true }; diff --git a/apps/desktop/zoom.cjs b/apps/desktop/zoom.cjs new file mode 100644 index 0000000..44221b6 --- /dev/null +++ b/apps/desktop/zoom.cjs @@ -0,0 +1,59 @@ +"use strict"; +// The main window's UI scale: the steps it moves in, and the keys that move it. +// Pure, so the main process and its tests share one answer. + +/** Zoom factors as Chromium takes them (1.25 is 125 percent), 75 to 300 percent. */ +const ZOOM_STEPS = [0.75, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3]; + +/** A zoom level round-trips through a logarithm, so a factor read back is only + * this close to the one set. The steps are much further apart. */ +const sameZoom = (a, b) => Math.abs(a - b) < 1e-3; + +const num = (v) => typeof v === "number" && Number.isFinite(v); + +/** The step nearest `v`, or 100 percent for anything that is not a number. Ties go to the smaller. */ +function sanitizeZoom(v) { + if (!num(v)) return 1; + return ZOOM_STEPS.reduce((best, s) => (Math.abs(s - v) < Math.abs(best - v) ? s : best)); +} + +/** Where "in", "out" or "reset" takes `current`, which may sit between steps or + * outside the range: the next step in that direction, held at the ends. */ +function nextZoom(current, action) { + if (action === "reset") return 1; + const from = num(current) ? current : 1; + if (action === "in") return ZOOM_STEPS.find((s) => s > from && !sameZoom(s, from)) ?? ZOOM_STEPS.at(-1); + if (action === "out") return ZOOM_STEPS.findLast((s) => s < from && !sameZoom(s, from)) ?? ZOOM_STEPS[0]; + return sanitizeZoom(from); +} + +const BY_KEY = { "=": "in", "+": "in", "-": "out", _: "out", 0: "reset" }; +// The numpad reports its own code whatever NumLock does to its key. Digit0 is +// for layouts whose 0 key types something else (AZERTY's "à"). Equal and Minus +// are not here on purpose: on other layouts those keys type ´ ß ) and the like. +const BY_CODE = { NumpadAdd: "in", NumpadSubtract: "out", Numpad0: "reset", Digit0: "reset" }; + +/** What a `before-input-event` key press asks of the zoom: "in", "out", "reset" + * or null. Ctrl on Windows and Linux, Cmd on a Mac; Shift is allowed, since + * "+" is Shift and "=" on most keyboards. By `key`, not `code`, so a layout + * with "+" or "-" elsewhere still works. */ +function zoomKeyAction(input, platform) { + if (input.type !== "keyDown" || input.alt) return null; + const mod = platform === "darwin" ? input.meta && !input.control : input.control && !input.meta; + return mod ? BY_CODE[input.code] ?? BY_KEY[input.key] ?? null : null; +} + +/** The scale a person left on `host` before it was kept in appearance.json: Chromium's + * saved per-host zoom level (`prefs` is its parsed Preferences file) as a step, or null + * when there is none. A level L is a factor of 1.2 ** L. */ +function legacyHostZoom(prefs, host) { + const byPartition = prefs?.partition?.per_host_zoom_levels; + if (!byPartition || typeof byPartition !== "object") return null; + for (const hosts of Object.values(byPartition)) { + const level = hosts?.[host]; + if (num(level)) return sanitizeZoom(1.2 ** level); + } + return null; +} + +module.exports = { ZOOM_STEPS, sameZoom, sanitizeZoom, nextZoom, zoomKeyAction, legacyHostZoom }; diff --git a/apps/desktop/zoom.test.ts b/apps/desktop/zoom.test.ts new file mode 100644 index 0000000..0649cb1 --- /dev/null +++ b/apps/desktop/zoom.test.ts @@ -0,0 +1,147 @@ +import { describe, expect, it } from "vitest"; +import { createRequire } from "node:module"; + +const { ZOOM_STEPS, sameZoom, sanitizeZoom, nextZoom, zoomKeyAction, legacyHostZoom } = createRequire(import.meta.url)("./zoom.cjs"); + +describe("ZOOM_STEPS", () => { + it("run from 75 to 300 percent, ascending, with 100 among them", () => { + expect(ZOOM_STEPS[0]).toBe(0.75); + expect(ZOOM_STEPS.at(-1)).toBe(3); + expect(ZOOM_STEPS).toContain(1); + expect([...ZOOM_STEPS].sort((a: number, b: number) => a - b)).toEqual(ZOOM_STEPS); + }); +}); + +describe("sanitizeZoom", () => { + it("keeps a step as it is", () => { + for (const s of ZOOM_STEPS) expect(sanitizeZoom(s)).toBe(s); + }); + it("snaps anything else to the nearest step, held inside the range", () => { + expect(sanitizeZoom(1.12)).toBe(1.1); + expect(sanitizeZoom(1.4)).toBe(1.5); + expect(sanitizeZoom(0.1)).toBe(0.75); + expect(sanitizeZoom(-4)).toBe(0.75); + expect(sanitizeZoom(50)).toBe(3); + expect(sanitizeZoom(Infinity)).toBe(1); + }); + it("answers 100 percent for what is not a number", () => { + for (const v of [NaN, undefined, null, "1.5", {}, [], true]) expect(sanitizeZoom(v)).toBe(1); + }); +}); + +describe("sameZoom", () => { + it("forgives the logarithm's rounding and nothing near a step", () => { + expect(sameZoom(1.1, 1.1000000000000003)).toBe(true); + expect(sameZoom(1, 1.1)).toBe(false); + }); +}); + +describe("nextZoom", () => { + it("moves one step at a time", () => { + expect(nextZoom(1, "in")).toBe(1.1); + expect(nextZoom(1, "out")).toBe(0.9); + expect(nextZoom(0.9, "out")).toBe(0.75); + expect(nextZoom(2, "in")).toBe(2.5); + }); + it("holds at the ends", () => { + expect(nextZoom(3, "in")).toBe(3); + expect(nextZoom(0.75, "out")).toBe(0.75); + }); + it("goes to the next step from between two, and from outside the range", () => { + expect(nextZoom(1.05, "in")).toBe(1.1); + expect(nextZoom(1.05, "out")).toBe(1); + expect(nextZoom(5, "in")).toBe(3); + expect(nextZoom(5, "out")).toBe(3); + expect(nextZoom(0.5, "in")).toBe(0.75); + expect(nextZoom(0.5, "out")).toBe(0.75); + }); + it("is not thrown by a factor read back a hair off its step", () => { + expect(nextZoom(1.1000000000000003, "in")).toBe(1.25); + expect(nextZoom(1.0999999999999999, "out")).toBe(1); + }); + it("resets to 100 percent from anywhere, and treats a broken current as 100", () => { + for (const c of [0.75, 1, 1.37, 3, NaN, undefined]) expect(nextZoom(c, "reset")).toBe(1); + expect(nextZoom(NaN, "in")).toBe(1.1); + expect(nextZoom(undefined, "out")).toBe(0.9); + }); + it("snaps for an action it does not know", () => { + expect(nextZoom(1.4, "sideways")).toBe(1.5); + }); +}); + +describe("zoomKeyAction", () => { + const key = (o: object) => ({ type: "keyDown", key: "", code: "", control: false, meta: false, shift: false, alt: false, ...o }); + const ctrl = (o: object) => key({ control: true, ...o }); + const cmd = (o: object) => key({ meta: true, ...o }); + + it("reads Ctrl on Windows and Linux", () => { + for (const p of ["win32", "linux"]) { + expect(zoomKeyAction(ctrl({ key: "=", code: "Equal" }), p)).toBe("in"); + expect(zoomKeyAction(ctrl({ key: "+", code: "Equal", shift: true }), p)).toBe("in"); + expect(zoomKeyAction(ctrl({ key: "-", code: "Minus" }), p)).toBe("out"); + expect(zoomKeyAction(ctrl({ key: "_", code: "Minus", shift: true }), p)).toBe("out"); + expect(zoomKeyAction(ctrl({ key: "0", code: "Digit0" }), p)).toBe("reset"); + } + }); + it("reads Cmd on a Mac", () => { + expect(zoomKeyAction(cmd({ key: "=", code: "Equal" }), "darwin")).toBe("in"); + expect(zoomKeyAction(cmd({ key: "-", code: "Minus" }), "darwin")).toBe("out"); + expect(zoomKeyAction(cmd({ key: "0", code: "Digit0" }), "darwin")).toBe("reset"); + }); + it("reads the numpad by its code, with NumLock on or off", () => { + expect(zoomKeyAction(ctrl({ key: "+", code: "NumpadAdd" }), "win32")).toBe("in"); + expect(zoomKeyAction(ctrl({ key: "-", code: "NumpadSubtract" }), "win32")).toBe("out"); + expect(zoomKeyAction(ctrl({ key: "0", code: "Numpad0" }), "win32")).toBe("reset"); + expect(zoomKeyAction(ctrl({ key: "Insert", code: "Numpad0" }), "win32")).toBe("reset"); + expect(zoomKeyAction(cmd({ key: "+", code: "NumpadAdd" }), "darwin")).toBe("in"); + }); + it("finds a layout's own plus and minus by what they type", () => { + expect(zoomKeyAction(ctrl({ key: "+", code: "BracketRight" }), "linux")).toBe("in"); + expect(zoomKeyAction(ctrl({ key: "-", code: "Slash" }), "linux")).toBe("out"); + }); + it("finds reset on the 0 key of a layout that types something else there", () => { + expect(zoomKeyAction(ctrl({ key: "à", code: "Digit0" }), "win32")).toBe("reset"); + expect(zoomKeyAction(ctrl({ key: "0", code: "Digit0", shift: true }), "linux")).toBe("reset"); + }); + it("does not read the Equal and Minus keys by position", () => { + expect(zoomKeyAction(ctrl({ key: "´", code: "Equal" }), "linux")).toBeNull(); + expect(zoomKeyAction(ctrl({ key: "ß", code: "Minus" }), "linux")).toBeNull(); + }); + it("needs the platform's modifier and no other", () => { + expect(zoomKeyAction(key({ key: "=" }), "win32")).toBeNull(); + expect(zoomKeyAction(cmd({ key: "=" }), "win32")).toBeNull(); + expect(zoomKeyAction(ctrl({ key: "=" }), "darwin")).toBeNull(); + expect(zoomKeyAction(key({ key: "=", control: true, meta: true }), "darwin")).toBeNull(); + // AltGr arrives as Ctrl+Alt on Windows and types characters. + expect(zoomKeyAction(ctrl({ key: "-", alt: true }), "win32")).toBeNull(); + }); + it("answers a press, not its release, and no other key", () => { + expect(zoomKeyAction(ctrl({ type: "keyUp", key: "=" }), "win32")).toBeNull(); + expect(zoomKeyAction(ctrl({ key: "r", code: "KeyR" }), "win32")).toBeNull(); + expect(zoomKeyAction(ctrl({ key: "1", code: "Digit1" }), "win32")).toBeNull(); + }); +}); + +describe("legacyHostZoom", () => { + const prefs = (hosts: object, part = "1234567") => ({ partition: { per_host_zoom_levels: { [part]: hosts } } }); + + it("turns Chromium's saved level into the nearest step", () => { + expect(legacyHostZoom(prefs({ localhost: 1 }), "localhost")).toBe(1.25); + expect(legacyHostZoom(prefs({ localhost: 3 }), "localhost")).toBe(1.75); + expect(legacyHostZoom(prefs({ localhost: -1 }), "localhost")).toBe(0.9); + expect(legacyHostZoom(prefs({ localhost: -9 }), "localhost")).toBe(0.75); + expect(legacyHostZoom(prefs({ localhost: 5 }), "localhost")).toBe(2.5); + expect(legacyHostZoom(prefs({ localhost: 99 }), "localhost")).toBe(3); + }); + it("reads the host from whichever partition holds it", () => { + const p = { partition: { per_host_zoom_levels: { a: { "example.com": 2 }, b: { localhost: 2 } } } }; + expect(legacyHostZoom(p, "localhost")).toBe(1.5); + }); + it("answers null when there is nothing usable to carry over", () => { + for (const p of [undefined, null, "x", 3, [], {}, { partition: null }, { partition: {} }, { partition: { per_host_zoom_levels: "x" } }, + { partition: { per_host_zoom_levels: { a: null } } }, prefs({}), prefs({ "example.com": 2 }), + prefs({ localhost: "2" }), prefs({ localhost: NaN }), prefs({ localhost: null })]) { + expect(legacyHostZoom(p, "localhost")).toBeNull(); + } + }); +}); diff --git a/apps/web/src/app/globals.css b/apps/web/src/app/globals.css index cfb0300..aaea136 100644 --- a/apps/web/src/app/globals.css +++ b/apps/web/src/app/globals.css @@ -98,27 +98,27 @@ /* ── Type scale — the ONLY font sizes in the app. Each token is a Tailwind text-* utility (text-micro, text-caption, …). Desktop-app scale: denser than web defaults, aligned to the SF/Segoe optical sizes. ────────────── */ - --text-micro: 10px; /* smallest legal size: keycaps, badges */ - --text-micro--line-height: 14px; - --text-caption: 11px; /* secondary metadata, eyebrows, timestamps */ - --text-caption--line-height: 15px; - --text-label: 12px; /* control labels, list secondary text */ - --text-label--line-height: 16px; - --text-body: 13px; /* default UI + chat text */ - --text-body--line-height: 20px; - --text-callout: 14px; /* emphasized body, primary buttons */ - --text-callout--line-height: 20px; - --text-title-sm: 15px; /* card titles, section headers */ - --text-title-sm--line-height: 21px; - --text-title: 17px; /* page/panel titles */ - --text-title--line-height: 23px; - --text-title-lg: 22px; /* screen headlines */ - --text-title-lg--line-height: 27px; - --text-display: 32px; /* the hero wordmark only */ - --text-display--line-height: 38px; + --text-micro: 0.625rem; /* smallest legal size: keycaps, badges */ + --text-micro--line-height: 0.875rem; + --text-caption: 0.6875rem; /* secondary metadata, eyebrows, timestamps */ + --text-caption--line-height: 0.9375rem; + --text-label: 0.75rem; /* control labels, list secondary text */ + --text-label--line-height: 1rem; + --text-body: 0.8125rem; /* default UI + chat text */ + --text-body--line-height: 1.25rem; + --text-callout: 0.875rem; /* emphasized body, primary buttons */ + --text-callout--line-height: 1.25rem; + --text-title-sm: 0.9375rem; /* card titles, section headers */ + --text-title-sm--line-height: 1.3125rem; + --text-title: 1.0625rem; /* page/panel titles */ + --text-title--line-height: 1.4375rem; + --text-title-lg: 1.375rem; /* screen headlines */ + --text-title-lg--line-height: 1.6875rem; + --text-display: 2rem; /* the hero wordmark only */ + --text-display--line-height: 2.375rem; /* legacy alias — same metrics as body */ - --text-chat: 13px; - --text-chat--line-height: 21px; + --text-chat: 0.8125rem; + --text-chat--line-height: 1.3125rem; /* One radius system. sm: chips' inner marks, badges, checkboxes, tooltips, menu items. md: fields, selects, segmented tracks, list rows. lg: cards and diff --git a/apps/web/src/app/page.tsx b/apps/web/src/app/page.tsx index 6babdbc..6f29481 100644 --- a/apps/web/src/app/page.tsx +++ b/apps/web/src/app/page.tsx @@ -168,7 +168,7 @@ export default function Home() { ) : ( -
+
{/* Frameless-window drag handle: a title-bar-high strip clear of the macOS traffic lights and the Windows/Linux caption buttons, both (the server cannot tell which this window has). Desktop only (.desktop). Settings lives in the hero CTA row @@ -177,7 +177,7 @@ export default function Home() {
-
+

OpenLive

@@ -207,7 +207,7 @@ export default function Home() {
-