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(update): apply the updater settings on every call

Etienne Lescotc2163cfe2e2d
diff --git a/electron/auto-updater.test.ts b/electron/auto-updater.test.ts
index 17958b54a..3f60a2ec2 100644
--- a/electron/auto-updater.test.ts
+++ b/electron/auto-updater.test.ts
@@ -70,6 +70,10 @@ describe("blockedFromInstalling", () => {
describe("self-update flow", () => {
beforeEach(() => {
mocks.app.isPackaged = true;
+ // Back to electron-updater's DEFAULTS before every test, so "these are false" can only
+ // pass because this test's call configured them — not because an earlier test did.
+ mocks.autoUpdater.autoDownload = true;
+ mocks.autoUpdater.autoInstallOnAppQuit = true;
mocks.autoUpdater.checkForUpdates.mockReset();
mocks.autoUpdater.downloadUpdate.mockReset();
mocks.autoUpdater.quitAndInstall.mockReset();
@@ -93,10 +97,21 @@ describe("self-update flow", () => {
// is a window, so the stock autoInstallOnAppQuit would fire a ~243 MB installer when the
// user merely closed the HUD.
it("disables auto-download and install-on-quit before doing anything", async () => {
- mocks.autoUpdater.checkForUpdates.mockResolvedValue({ updateInfo: { version: "1.9.2" } });
+ // Asserted INSIDE the mock: checking after the call would still pass if the settings
+ // were applied late, and "late" is the whole failure — a check that starts downloading
+ // before autoDownload is turned off has already pulled ~243 MB the user never asked for.
+ const settingsWhenChecked: Array<boolean> = [];
+ mocks.autoUpdater.checkForUpdates.mockImplementation(() => {
+ settingsWhenChecked.push(
+ mocks.autoUpdater.autoDownload,
+ mocks.autoUpdater.autoInstallOnAppQuit,
+ );
+ return Promise.resolve({ updateInfo: { version: "1.9.2" } });
+ });
+
await checkForSelfUpdate("nsis");
- expect(mocks.autoUpdater.autoDownload).toBe(false);
- expect(mocks.autoUpdater.autoInstallOnAppQuit).toBe(false);
+
+ expect(settingsWhenChecked).toEqual([false, false]);
});
it("reports current when the feed offers the running version", async () => {
diff --git a/electron/auto-updater.ts b/electron/auto-updater.ts
index 9dbe17c89..fdee80d2b 100644
--- a/electron/auto-updater.ts
+++ b/electron/auto-updater.ts
@@ -36,21 +36,21 @@ export function blockedFromInstalling(state: InstallReadiness): string | null {
return null;
}
-let configured = false;
-
/** Loaded lazily: importing electron-updater costs startup time on every launch, and the
* channels that cannot use it must not pay for it at all. */
async function getUpdater() {
const { autoUpdater } = await import("electron-updater");
- if (!configured) {
- // Never surprise the user with a 240 MB download or an install they did not ask for.
- // `window-all-closed` quits this app, and the HUD is a window — with the default
- // `autoInstallOnAppQuit` simply closing the HUD would kick off an installer.
- autoUpdater.autoDownload = false;
- autoUpdater.autoInstallOnAppQuit = false;
- autoUpdater.logger = null;
- configured = true;
- }
+ // Never surprise the user with a 240 MB download or an install they did not ask for.
+ // `window-all-closed` quits this app, and the HUD is a window — with the default
+ // `autoInstallOnAppQuit` simply closing the HUD would kick off an installer.
+ //
+ // Reapplied on every call rather than set once behind a flag: these are three property
+ // writes, so memoising them buys nothing measurable, and a "configured" flag would mean
+ // anything that later reset them is never corrected — while making the guarantee hold only
+ // for whichever caller happened to come first.
+ autoUpdater.autoDownload = false;
+ autoUpdater.autoInstallOnAppQuit = false;
+ autoUpdater.logger = null;
return autoUpdater;
}