From 5f4cd892de7c2ab47b7f3ba414977b31c83697d8 Mon Sep 17 00:00:00 2001 From: Hona <10430890+Hona@users.noreply.github.com> Date: Sun, 30 Aug 2026 17:01:28 +0000 Subject: [PATCH] fix(desktop): prevent update downgrades --- .../desktop/src/main/updater/config.test.ts | 18 ++++++++++++++++++ packages/desktop/src/main/updater/config.ts | 11 +++++++++++ packages/desktop/src/main/updater/platform.ts | 5 ++--- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 packages/desktop/src/main/updater/config.test.ts create mode 100644 packages/desktop/src/main/updater/config.ts diff --git a/packages/desktop/src/main/updater/config.test.ts b/packages/desktop/src/main/updater/config.test.ts new file mode 100644 index 000000000000..c484035a8ae3 --- /dev/null +++ b/packages/desktop/src/main/updater/config.test.ts @@ -0,0 +1,18 @@ +import { expect, test } from "bun:test" +import { configureStableUpdates } from "./config" + +test("stable updates do not install older releases", () => { + const client = { + channel: null, + allowPrerelease: null, + allowDowngrade: true, + } + + configureStableUpdates(client) + + expect(client).toEqual({ + channel: "latest", + allowPrerelease: false, + allowDowngrade: false, + }) +}) diff --git a/packages/desktop/src/main/updater/config.ts b/packages/desktop/src/main/updater/config.ts new file mode 100644 index 000000000000..3dd2d00707b7 --- /dev/null +++ b/packages/desktop/src/main/updater/config.ts @@ -0,0 +1,11 @@ +type UpdateClient = { + channel: string | null + allowPrerelease: boolean | null + allowDowngrade: boolean +} + +export function configureStableUpdates(client: UpdateClient) { + client.channel = "latest" + client.allowPrerelease = false + client.allowDowngrade = false +} diff --git a/packages/desktop/src/main/updater/platform.ts b/packages/desktop/src/main/updater/platform.ts index 8033870365d9..8a07a9b85a99 100644 --- a/packages/desktop/src/main/updater/platform.ts +++ b/packages/desktop/src/main/updater/platform.ts @@ -2,6 +2,7 @@ import { app, autoUpdater } from "electron" import pkg from "electron-updater" import { Effect } from "effect" import { setAppQuitting } from "../windows" +import { configureStableUpdates } from "./config" import type { Platform } from "./index" const updateClient = pkg.autoUpdater @@ -15,9 +16,7 @@ export const make = Effect.gen(function* () { error: (...args) => runFork(Effect.logError(...args)), debug: (...args) => runFork(Effect.logDebug(...args)), } - updateClient.channel = "latest" - updateClient.allowPrerelease = false - updateClient.allowDowngrade = true + configureStableUpdates(updateClient) updateClient.autoDownload = false updateClient.autoInstallOnAppQuit = process.platform === "darwin" yield* Effect.logInfo("auto updater configured", {