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): confirm missing registry keys before silent install
EtienneLescot7df47ab591b4
diff --git a/electron/auto-updater.test.ts b/electron/auto-updater.test.tsindex 50dcbd7af..36c9168df 100644--- a/electron/auto-updater.test.ts+++ b/electron/auto-updater.test.ts@@ -34,8 +34,19 @@ vi.mock("./windows-update", () => ({installWindowsUpdate: mocks.installWindowsUpdate,assertWindowsUpdateIdle: mocks.assertWindowsUpdateIdle,}));-// `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 })) }));+vi.mock("node:child_process", () => ({ spawnSync: vi.fn() }));++function missingInstallQuery(_command: string, args?: readonly string[]) {+ const root = args?.[1]?.startsWith("HKLM") ? "HKEY_LOCAL_MACHINE" : "HKEY_CURRENT_USER";+ return {+ status: args?.includes("/v") ? 1 : 0,+ stdout: `\r\n${root}\\Software\\OtherApp\r\n`,+ } as ReturnType<typeof spawnSync>;+}++beforeEach(() => {+ vi.mocked(spawnSync).mockReset().mockImplementation(missingInstallQuery);+});function state(overrides: Partial<InstallReadiness> = {}): InstallReadiness {return { recording: false, inApplicationsFolder: true, platform: "linux", ...overrides };@@ -192,7 +203,7 @@ describe("self-update flow", () => {await installSelfUpdate();} finally {if (platform) Object.defineProperty(process, "platform", platform);- vi.mocked(spawnSync).mockReturnValue({ status: 1 } as ReturnType<typeof spawnSync>);+ vi.mocked(spawnSync).mockImplementation(missingInstallQuery);}expect(mocks.autoUpdater.quitAndInstall).toHaveBeenCalledWith(false, true);expect(mocks.installWindowsUpdate).not.toHaveBeenCalled();@@ -209,10 +220,11 @@ describe("self-update flow", () => {});});mocks.autoUpdater.downloadUpdate.mockResolvedValue(["verified-installer.exe"]);- vi.mocked(spawnSync)- .mockReturnValueOnce({ status: 0 } as ReturnType<typeof spawnSync>)- .mockReturnValueOnce({ status: 1 } as ReturnType<typeof spawnSync>)- .mockReturnValue({ status: 0 } as ReturnType<typeof spawnSync>);+ vi.mocked(spawnSync).mockImplementation((command, args) =>+ args?.[1]?.startsWith("HKLM")+ ? ({ status: 0 } as ReturnType<typeof spawnSync>)+ : missingInstallQuery(command, args),+ );Object.defineProperty(process, "platform", { value: "win32" });try {let settled = false;@@ -228,7 +240,7 @@ describe("self-update flow", () => {} finally {finish?.();if (platform) Object.defineProperty(process, "platform", platform);- vi.mocked(spawnSync).mockReturnValue({ status: 1 } as ReturnType<typeof spawnSync>);+ vi.mocked(spawnSync).mockImplementation(missingInstallQuery);}});@@ -262,17 +274,55 @@ describe("self-update flow", () => {it.each(["HKLM", "HKCU"])("keeps the app open when the %s query fails", async (hive) => {const platform = Object.getOwnPropertyDescriptor(process, "platform");Object.defineProperty(process, "platform", { value: "win32" });- vi.mocked(spawnSync)- .mockReturnValueOnce({ status: hive === "HKLM" ? null : 0 } as ReturnType<typeof spawnSync>)- .mockReturnValueOnce({ status: hive === "HKCU" ? null : 1 } as ReturnType<typeof spawnSync>)- .mockReturnValue({ status: null } as ReturnType<typeof spawnSync>);+ vi.mocked(spawnSync).mockImplementation((command, args) =>+ args?.[1]?.startsWith(hive)+ ? ({ status: null } as ReturnType<typeof spawnSync>)+ : missingInstallQuery(command, args),+ );try {await expect(installSelfUpdate()).rejects.toThrow("Could not confirm the Windows installation type",);} finally {if (platform) Object.defineProperty(process, "platform", platform);- vi.mocked(spawnSync).mockReturnValue({ status: 1 } as ReturnType<typeof spawnSync>);+ vi.mocked(spawnSync).mockImplementation(missingInstallQuery);+ }+ expect(mocks.autoUpdater.quitAndInstall).not.toHaveBeenCalled();+ expect(mocks.installWindowsUpdate).not.toHaveBeenCalled();+ });++ it.each([+ "HKLM",+ "HKCU",+ ])("does not mistake a failed %s value query for absence", async (hive) => {+ const platform = Object.getOwnPropertyDescriptor(process, "platform");+ Object.defineProperty(process, "platform", { value: "win32" });+ vi.mocked(spawnSync).mockImplementation((command, args) => {+ if (!args?.[1]?.startsWith(hive)) return missingInstallQuery(command, args);+ if (args.includes("/v")) return { status: 1 } as ReturnType<typeof spawnSync>;+ const root = hive === "HKLM" ? "HKEY_LOCAL_MACHINE" : "HKEY_CURRENT_USER";+ return {+ status: 0,+ stdout: `${root}\\${NSIS_INSTALL_KEY}\r\n`,+ } as ReturnType<typeof spawnSync>;+ });+ try {+ await expect(installSelfUpdate()).rejects.toThrow("Could not confirm");+ } finally {+ if (platform) Object.defineProperty(process, "platform", platform);+ }+ expect(mocks.autoUpdater.quitAndInstall).not.toHaveBeenCalled();+ expect(mocks.installWindowsUpdate).not.toHaveBeenCalled();+ });++ it("keeps the app open when parent enumeration also fails", async () => {+ const platform = Object.getOwnPropertyDescriptor(process, "platform");+ Object.defineProperty(process, "platform", { value: "win32" });+ vi.mocked(spawnSync).mockReturnValue({ status: 1 } as ReturnType<typeof spawnSync>);+ try {+ await expect(installSelfUpdate()).rejects.toThrow("Could not confirm");+ } finally {+ if (platform) Object.defineProperty(process, "platform", platform);}expect(mocks.autoUpdater.quitAndInstall).not.toHaveBeenCalled();expect(mocks.installWindowsUpdate).not.toHaveBeenCalled();diff --git a/electron/auto-updater.ts b/electron/auto-updater.tsindex 8b69b4f71..684c5398d 100644--- a/electron/auto-updater.ts+++ b/electron/auto-updater.ts@@ -93,11 +93,22 @@ export const NSIS_INSTALL_KEY = "Software\\5b412b41-8d8b-5faf-b557-de4fe681e5fc"function nsisInstallStatus(hive: "HKLM" | "HKCU"): number | null {const key = `${hive}\\${NSIS_INSTALL_KEY}`;const args = ["query", key, "/v", "InstallLocation", "/reg:64"];- return spawnSync("reg", args, { windowsHide: true }).status;+ const { status } = spawnSync("reg", args, { windowsHide: true });+ if (status !== 1) return status;+ // reg's exit 1 means any failure, including access denied. Confirm absence by+ // successfully enumerating the parent, without parsing localized error text.+ const parent = spawnSync("reg", ["query", `${hive}\\Software`, "/reg:64"], {+ windowsHide: true,+ encoding: "utf8",+ });+ if (parent.status !== 0) return null;+ const root = hive === "HKLM" ? "HKEY_LOCAL_MACHINE" : "HKEY_CURRENT_USER";+ const keys = parent.stdout.split(/\r?\n/).map((line) => line.trim().toLowerCase());+ return keys.includes(`${root}\\${NSIS_INSTALL_KEY}`.toLowerCase()) ? null : 1;}function hasNsisInstall(hive: "HKLM" | "HKCU"): boolean {- // Exit 1 is reg's "key not found". Anything else, reg itself failing to run included, counts+ // Status 1 is returned only after confirming absence. Any uncertain result counts// as present, so this selector never treats an uncertain copy as absent. The installer// coordinator below refuses failed queries rather than quitting with an unknown target.return nsisInstallStatus(hive) !== 1;diff --git a/src/hooks/recorderHandle.test.ts b/src/hooks/recorderHandle.test.tsindex 59f731785..c3bf1a33a 100644--- a/src/hooks/recorderHandle.test.ts+++ b/src/hooks/recorderHandle.test.ts@@ -245,22 +245,33 @@ describe("createRecorderHandle", () => {expect(closeRecordingStream).toHaveBeenCalledWith("rec.webm");});- it("discard waits for a pending open before closing its stream", async () => {+ it("discard drains a write queued during a pending open before closing its stream", async () => {let finishOpen: ((result: { success: boolean }) => void) | undefined;const open = new Promise<{ success: boolean }>((resolve) => {finishOpen = resolve;});+ let finishAppend: (() => void) | undefined;+ const append = new Promise<void>((resolve) => {+ finishAppend = resolve;+ });const closeRecordingStream = vi.fn(async () => ({ success: true }));stubElectronAPI({openRecordingStream: vi.fn(() => open),- appendRecordingChunk: vi.fn(async () => ({ success: true })),+ appendRecordingChunk: vi.fn(async () => {+ await append;+ return { success: true };+ }),closeRecordingStream,});const handle = createRecorderHandle({} as MediaStream, { mimeType: "video/webm" }, "rec.webm");+ driver(handle).emit(new Blob(["pending chunk"]));const discarded = handle.discard();await tick();expect(closeRecordingStream).not.toHaveBeenCalled();finishOpen?.({ success: true });+ await tick();+ expect(closeRecordingStream).not.toHaveBeenCalled();+ finishAppend?.();await discarded;expect(closeRecordingStream).toHaveBeenCalledWith("rec.webm");driver(handle).stop();diff --git a/src/hooks/useScreenRecorder.restartFailure.test.tsx b/src/hooks/useScreenRecorder.restartFailure.test.tsxindex 00293717c..564936f41 100644--- a/src/hooks/useScreenRecorder.restartFailure.test.tsx+++ b/src/hooks/useScreenRecorder.restartFailure.test.tsx@@ -193,7 +193,7 @@ describe("browser take start reservation", () => {);});- it("stops and discards a handle retained when later recorder setup fails", async () => {+ it("stops a retained handle and waits for its blob before discarding failed startup", async () => {stubBrowserCapture();const recorder = Object.assign(new EventTarget(), {state: "recording" as RecordingState,@@ -204,9 +204,12 @@ describe("browser take start reservation", () => {vi.spyOn(recorder, "addEventListener").mockImplementationOnce(() => {throw new Error("later setup failed");});+ let finishBlob: ((blob: Blob) => void) | undefined;const failed = {recorder: recorder as unknown as MediaRecorder,- recordedBlobPromise: Promise.resolve(new Blob()),+ recordedBlobPromise: new Promise<Blob>((resolve) => {+ finishBlob = resolve;+ }),isStreaming: () => true,discard: vi.fn(async () => undefined),};@@ -217,6 +220,9 @@ describe("browser take start reservation", () => {await view.result.current.startRecordingImmediately();});expect(recorder.stop).toHaveBeenCalledOnce();+ expect(failed.discard).not.toHaveBeenCalled();+ finishBlob?.(new Blob());+ await settle();expect(failed.discard).toHaveBeenCalledOnce();expect(api.setRecordingState).toHaveBeenCalledWith(false);expect(view.result.current.recording).toBe(false);