Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(updater): keep the wizard when a per-user and a per-machine install coexist
EtienneLescot4c5ffc99a77c
diff --git a/electron/auto-updater.test.ts b/electron/auto-updater.test.tsindex 5346668c5..460699f4e 100644--- a/electron/auto-updater.test.ts+++ b/electron/auto-updater.test.ts@@ -1,3 +1,5 @@+import fs from "node:fs";+import { UUID } from "builder-util-runtime";import { beforeEach, describe, expect, it, vi } from "vitest";import {blockedFromInstalling,@@ -5,6 +7,8 @@ import {downloadSelfUpdate,type InstallReadiness,installSelfUpdate,+ installsSilently,+ NSIS_INSTALL_KEY,} from "./auto-updater";const mocks = vi.hoisted(() => ({@@ -23,6 +27,8 @@ const mocks = vi.hoisted(() => ({vi.mock("electron", () => ({ app: mocks.app }));vi.mock("electron-updater", () => ({ autoUpdater: mocks.autoUpdater }));+// `reg query` finds no install, so the handover below is the same on every platform.+vi.mock("node:child_process", () => ({ spawnSync: vi.fn(() => ({ status: 1 })) }));function state(overrides: Partial<InstallReadiness> = {}): InstallReadiness {return { recording: false, inApplicationsFolder: true, platform: "linux", ...overrides };@@ -155,3 +161,32 @@ describe("self-update flow", () => {expect(mocks.autoUpdater.quitAndInstall).toHaveBeenCalledWith(true, true);});});++describe("installsSilently", () => {+ const installs =+ (...hives: string[]) =>+ (hive: string) =>+ hives.includes(hive);++ it("is silent with a single Windows install, per user or per machine", () => {+ expect(installsSilently("win32", installs("HKCU"))).toBe(true);+ expect(installsSilently("win32", installs("HKLM"))).toBe(true);+ });++ // /S would update the per-machine copy even when the per-user one is running.+ it("lets the wizard ask when a per-user and a per-machine install coexist", () => {+ expect(installsSilently("win32", installs("HKLM", "HKCU"))).toBe(false);+ });++ it("never asks off Windows", () => {+ expect(installsSilently("darwin", installs("HKLM", "HKCU"))).toBe(true);+ });++ it("reads the key electron-builder derives from the appId", () => {+ const appId = fs+ .readFileSync("electron-builder.json5", "utf8")+ .match(/"appId": "([^"]+)"/)?.[1];+ const ns = UUID.parse("50e065bc-3134-11e6-9bab-38c9862bdaf3"); // electron-builder's NsisTarget+ expect(NSIS_INSTALL_KEY).toBe(`Software\\${UUID.v5(appId ?? "", ns)}`);+ });+});diff --git a/electron/auto-updater.ts b/electron/auto-updater.tsindex 8153026af..14508063c 100644--- a/electron/auto-updater.ts+++ b/electron/auto-updater.ts@@ -8,6 +8,7 @@// bundle and come along. What does NOT come along is anything under userData — recordings,// projects, and the ~500 MB STT model — which is exactly what we want.+import { spawnSync } from "node:child_process";import { app } from "electron";import type { InstallChannel } from "./install-channel";import { ownsItsUpdates } from "./install-channel";@@ -82,13 +83,31 @@ export async function downloadSelfUpdate(): Promise<UpdateOutcome> {}}+/** Where electron-builder's NSIS installer records an install: `Software\<UUID v5 of appId>`,+ * under HKLM per machine and HKCU per user. auto-updater.test.ts pins it to the appId. */+export const NSIS_INSTALL_KEY = "Software\\5b412b41-8d8b-5faf-b557-de4fe681e5fc";++function hasNsisInstall(hive: "HKLM" | "HKCU"): boolean {+ const key = `${hive}\\${NSIS_INSTALL_KEY}`;+ const args = ["query", key, "/v", "InstallLocation", "/reg:64"];+ return spawnSync("reg", args, { windowsHide: true }).status === 0;+}++/** Whether the installer can run with /S. Without it the assisted NSIS installer shows its whole+ * wizard (#1437). A silent upgrade of a per-machine install still elevates itself+ * (UAC_RunElevated in electron-builder's installer.nsi), so the user sees only UAC. But /S+ * always picks the per-machine copy when one exists, so with both a per-user and a per-machine+ * install it could update the copy that is not running: there, let the wizard ask. */+export function installsSilently(+ platform: NodeJS.Platform = process.platform,+ hasInstall: (hive: "HKLM" | "HKCU") => boolean = hasNsisInstall,+): boolean {+ return platform !== "win32" || !(hasInstall("HKLM") && hasInstall("HKCU"));+}+/** Quit and hand over to the installer. Callers MUST have checked `blockedFromInstalling`. */export async function installSelfUpdate(): Promise<void> {const autoUpdater = await getUpdater();- // isSilent=true: without /S the assisted NSIS installer shows its whole wizard, starting on- // the install-mode page, which can pick the wrong copy when two installs coexist (#1437).- // A silent upgrade of a per-machine install still elevates itself (UAC_RunElevated in- // electron-builder's installer.nsi), so the user sees only the UAC prompt; dismissing it- // quits having installed nothing. isForceRunAfter=true so the app comes back up.- autoUpdater.quitAndInstall(true, true);+ // isForceRunAfter=true so the app comes back up.+ autoUpdater.quitAndInstall(installsSilently(), true);}