Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(updater): wait for the PowerShell elevation result

EtienneLescot6dd5c7a12d5f
diff --git a/electron/windows-update.test.ts b/electron/windows-update.test.ts
index 465a7c07d..3863ff183 100644
--- a/electron/windows-update.test.ts
+++ b/electron/windows-update.test.ts
@@ -34,7 +34,7 @@ describe("installWindowsUpdate", () => {
await vi.waitFor(() => expect(spawn).toHaveBeenCalledOnce());
expect(mocks.quit).not.toHaveBeenCalled();
expect(mocks.window.setEnabled.mock.calls).toEqual([[false]]);
- expect(child.unref).toHaveBeenCalledOnce();
+ expect(child.unref).not.toHaveBeenCalled();
child.emit("exit", 1223);
await install;
expect(mocks.quit).not.toHaveBeenCalled();
@@ -72,7 +72,7 @@ describe("installWindowsUpdate", () => {
expect(script).toContain("-FilePath 'C:\\update\\it''s $a`b.exe'");
expect(script).toContain("@('--updated', '/S', '--force-run') -Verb RunAs");
expect(script).toContain("NativeErrorCode -eq 1223");
- expect(options).toEqual({ detached: true, stdio: "ignore", windowsHide: true });
+ expect(options).toEqual({ detached: false, stdio: "ignore", windowsHide: true });
child.emit("exit", 1223);
await install;
});
diff --git a/electron/windows-update.ts b/electron/windows-update.ts
index 6f6603561..8445e7a05 100644
--- a/electron/windows-update.ts
+++ b/electron/windows-update.ts
@@ -50,11 +50,12 @@ try {
"-EncodedCommand",
Buffer.from(script, "utf16le").toString("base64"),
],
- { detached: true, stdio: "ignore", windowsHide: true },
+ // Windows PowerShell 5.1 can exit 0 without running the command when detached.
+ // The bridge must return its actual result; ShellExecute starts NSIS independently.
+ { detached: false, stdio: "ignore", windowsHide: true },
);
child.once("error", reject);
child.once("exit", resolve);
- child.unref();
});
if (exitCode === 1223) return; // User declined: retain the app and ready update badge.
if (exitCode !== 0) throw new Error(`Windows update elevation failed (${exitCode})`);