From 7db3505efa25868eedda82b1c6c47c3f7a530586 Mon Sep 17 00:00:00 2001 From: Lakshmi Tanmay Date: Wed, 4 Nov 2026 18:25:08 +0530 Subject: [PATCH 1/4] fix(desktop): preserve launchers when AppImages switch to versionless names --- .../ElectronUpdater.launchPaths.test.ts | 165 ++++++++++++++++++ apps/desktop/src/electron/ElectronUpdater.ts | 27 ++- 2 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts diff --git a/apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts b/apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts new file mode 100644 index 000000000000..f5f994d798da --- /dev/null +++ b/apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts @@ -0,0 +1,165 @@ +// @effect-diagnostics nodeBuiltinImport:off - Native synchronous fixtures exercise updater event and relaunch ordering. +import * as NodeChildProcess from "node:child_process"; +import * as NodeFS from "node:fs"; +import * as NodeModule from "node:module"; +import * as NodeOS from "node:os"; +import * as NodePath from "node:path"; + +import { assert, describe, it } from "@effect/vitest"; +import * as Effect from "effect/Effect"; +import * as Exit from "effect/Exit"; +import { vi } from "vite-plus/test"; +import type { AppImageUpdater as AppImageUpdaterType } from "electron-updater"; + +const { getUpdater } = vi.hoisted(() => ({ getUpdater: vi.fn<() => AppImageUpdaterType>() })); +vi.mock("electron-updater", () => ({ + get autoUpdater() { + return getUpdater(); + }, +})); + +import * as ElectronUpdater from "./ElectronUpdater.ts"; + +const require = NodeModule.createRequire(import.meta.url); +const { AppImageUpdater } = require("electron-updater") as typeof import("electron-updater"); + +// Exercise the real synchronous installer without Electron's deferred app.quit lifecycle. +class FixtureUpdater extends AppImageUpdater { + readonly download: string; + + constructor(download: string) { + super(null, { version: "0.1.7" }); + this.download = download; + this.logger = null; + } + + protected override get installerPath() { + return this.download; + } + + override quitAndInstall(isSilent = false, isForceRunAfter = false) { + this.doInstall({ isSilent, isForceRunAfter, isAdminRightsRequired: false }); + } + + protected override spawnLog(destination: string) { + assert.equal( + NodeChildProcess.execFileSync(process.env.APPIMAGE!, { encoding: "utf8" }), + "updated\n", + ); + assert.equal(NodeChildProcess.execFileSync(destination, { encoding: "utf8" }), "updated\n"); + return Promise.resolve(true); + } +} + +function fixture(oldName: string, newName: string) { + const directory = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-appimage-launcher-")); + const oldPath = NodePath.join(directory, oldName); + const newPath = NodePath.join(directory, newName); + const cache = NodePath.join(directory, "cache"); + NodeFS.mkdirSync(cache); + const download = NodePath.join(cache, newName); + NodeFS.writeFileSync(oldPath, "#!/bin/sh\necho old\n", { mode: 0o755 }); + NodeFS.writeFileSync(download, "#!/bin/sh\necho updated\n", { mode: 0o755 }); + const launcher = NodePath.join(directory, "launcher.AppImage"); + NodeFS.symlinkSync(oldPath, launcher); + const updater = new FixtureUpdater(download); + getUpdater.mockReturnValue(updater); + const originalAppImage = process.env.APPIMAGE; + process.env.APPIMAGE = oldPath; + return { + directory, + oldPath, + newPath, + download, + launcher, + updater, + [Symbol.dispose]() { + if (originalAppImage === undefined) delete process.env.APPIMAGE; + else process.env.APPIMAGE = originalAppImage; + NodeFS.rmSync(directory, { recursive: true, force: true }); + }, + }; +} + +// oxlint-disable-next-line t3code/no-global-process-runtime -- Native shell fixtures require a Linux host. +describe.skipIf(process.platform !== "linux")("AppImage launch paths", () => { + it.live.each([ + ["T3-Code-0.1.7-x86_64.AppImage", "T3-Code-x86_64.AppImage"], + ["T3-Code-0.1.7-arm64.AppImage", "T3-Code-arm64.AppImage"], + ["T3-Code-0.1.7-nightly.20261104.1-x86_64.AppImage", "T3-Code-Nightly-x86_64.AppImage"], + ["T3-Code-0.1.7-nightly.20261104.1-arm64.AppImage", "T3-Code-Nightly-arm64.AppImage"], + ] as const)( + "keeps a launcher through the versioned-to-stable transition: %s", + ([oldName, newName]) => + Effect.gen(function* () { + using f = fixture(oldName, newName); + yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: false }); + assert.equal(NodeChildProcess.execFileSync(f.launcher, { encoding: "utf8" }), "updated\n"); + assert.equal(NodeFS.statSync(f.oldPath).mode & 0o777, 0o755); + assert.equal(NodeFS.readFileSync(f.newPath, "utf8"), "#!/bin/sh\necho updated\n"); + assert.equal(f.updater.listenerCount("appimage-filename-updated"), 0); + }), + ); + + it.live("keeps the transition alias through an in-place stable update", () => + Effect.gen(function* () { + using f = fixture("My T3-0.1.7.AppImage", "T3-Code-x86_64.AppImage"); + yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: true }); + process.env.APPIMAGE = f.newPath; + const nextDownload = NodePath.join(f.directory, "cache", "T3-Code-x86_64.AppImage"); + NodeFS.writeFileSync(nextDownload, "#!/bin/sh\necho updated\n", { mode: 0o755 }); + process.env.APPIMAGE = NodePath.join(f.directory, "T3-Code-x86_64.AppImage"); + getUpdater.mockReturnValue(new FixtureUpdater(nextDownload)); + yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: true }); + assert.equal(NodeChildProcess.execFileSync(f.launcher, { encoding: "utf8" }), "updated\n"); + assert.equal(NodeFS.readlinkSync(f.oldPath), NodePath.basename(f.newPath)); + }), + ); + + it.live("does not build alias chains between versioned releases", () => + Effect.gen(function* () { + using f = fixture("T3-Code-0.1.7.AppImage", "T3-Code-0.1.8.AppImage"); + yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: false }); + assert.isFalse(NodeFS.existsSync(f.oldPath)); + assert.throws(() => NodeFS.lstatSync(f.oldPath)); + assert.equal(NodeChildProcess.execFileSync(f.newPath, { encoding: "utf8" }), "updated\n"); + }), + ); + + it.live("preserves a custom versionless filename in place", () => + Effect.gen(function* () { + using f = fixture("My T3.AppImage", "T3-Code-x86_64.AppImage"); + yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: false }); + assert.equal(NodeChildProcess.execFileSync(f.launcher, { encoding: "utf8" }), "updated\n"); + assert.isFalse(NodeFS.existsSync(f.newPath)); + }), + ); + + it.live("leaves the alias usable after a relaunch failure and re-download retry", () => + Effect.gen(function* () { + using f = fixture("T3-Code-0.1.7.AppImage", "T3-Code-x86_64.AppImage"); + NodeFS.writeFileSync(f.download, "#!/bin/sh\nexit 1\n"); + const result = yield* Effect.exit( + ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: false }), + ); + assert.isTrue(Exit.isFailure(result)); + assert.equal(NodeFS.readFileSync(f.oldPath, "utf8"), "#!/bin/sh\nexit 1\n"); + assert.equal(f.updater.listenerCount("appimage-filename-updated"), 0); + NodeFS.writeFileSync(f.download, "#!/bin/sh\necho updated\n", { mode: 0o755 }); + yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: false }); + assert.equal(NodeChildProcess.execFileSync(f.launcher, { encoding: "utf8" }), "updated\n"); + }), + ); + + it.live("does not overwrite a path recreated during installation or abort relaunch", () => + Effect.gen(function* () { + using f = fixture("T3-Code-0.1.7.AppImage", "T3-Code-x86_64.AppImage"); + f.updater.on("appimage-filename-updated", () => + NodeFS.writeFileSync(f.oldPath, "other file"), + ); + yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: false }); + assert.equal(NodeFS.readFileSync(f.oldPath, "utf8"), "other file"); + assert.equal(NodeChildProcess.execFileSync(f.newPath, { encoding: "utf8" }), "updated\n"); + }), + ); +}); diff --git a/apps/desktop/src/electron/ElectronUpdater.ts b/apps/desktop/src/electron/ElectronUpdater.ts index 0cc22bb4b163..52eeefa62a07 100644 --- a/apps/desktop/src/electron/ElectronUpdater.ts +++ b/apps/desktop/src/electron/ElectronUpdater.ts @@ -1,3 +1,7 @@ +// @effect-diagnostics nodeBuiltinImport:off - The filename event must finish synchronously before updater relaunch. +import * as NodeFS from "node:fs"; +import * as NodePath from "node:path"; + import * as Context from "effect/Context"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; @@ -175,7 +179,28 @@ export const make = ElectronUpdater.of({ const channel = autoUpdater.channel; if (autoUpdater instanceof AppImageUpdater) relaunchWithoutInheritedDescriptors(autoUpdater); return Effect.try({ - try: () => autoUpdater.quitAndInstall(isSilent, isForceRunAfter), + try: () => { + const appImagePath = process.env.APPIMAGE; + const preserveAppImagePath = (destination: string) => { + const filename = NodePath.basename(destination); + // Only bridge to a name the updater will keep, avoiding growing alias chains. + if (appImagePath === undefined || /\d+\.\d+\.\d+/.test(filename)) return; + try { + // 6.8.9 emits synchronously after moving the file, before relaunch/exit. + NodeFS.symlinkSync(filename, appImagePath); + } catch { + autoUpdater.logger?.warn("Could not preserve the previous AppImage launch path."); + } + }; + if (appImagePath !== undefined) { + autoUpdater.on("appimage-filename-updated", preserveAppImagePath); + } + try { + autoUpdater.quitAndInstall(isSilent, isForceRunAfter); + } finally { + autoUpdater.removeListener("appimage-filename-updated", preserveAppImagePath); + } + }, catch: (cause) => new ElectronUpdaterQuitAndInstallError({ channel, From bc91c91b26d08b076cc56e6176865907e8c494ed Mon Sep 17 00:00:00 2001 From: Lakshmi Tanmay Date: Wed, 4 Nov 2026 18:44:33 +0530 Subject: [PATCH 2/4] test(desktop): keep one AppImage filename transition case --- .../ElectronUpdater.launchPaths.test.ts | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts b/apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts index f5f994d798da..e9feba0e8cff 100644 --- a/apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts +++ b/apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts @@ -83,22 +83,15 @@ function fixture(oldName: string, newName: string) { // oxlint-disable-next-line t3code/no-global-process-runtime -- Native shell fixtures require a Linux host. describe.skipIf(process.platform !== "linux")("AppImage launch paths", () => { - it.live.each([ - ["T3-Code-0.1.7-x86_64.AppImage", "T3-Code-x86_64.AppImage"], - ["T3-Code-0.1.7-arm64.AppImage", "T3-Code-arm64.AppImage"], - ["T3-Code-0.1.7-nightly.20261104.1-x86_64.AppImage", "T3-Code-Nightly-x86_64.AppImage"], - ["T3-Code-0.1.7-nightly.20261104.1-arm64.AppImage", "T3-Code-Nightly-arm64.AppImage"], - ] as const)( - "keeps a launcher through the versioned-to-stable transition: %s", - ([oldName, newName]) => - Effect.gen(function* () { - using f = fixture(oldName, newName); - yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: false }); - assert.equal(NodeChildProcess.execFileSync(f.launcher, { encoding: "utf8" }), "updated\n"); - assert.equal(NodeFS.statSync(f.oldPath).mode & 0o777, 0o755); - assert.equal(NodeFS.readFileSync(f.newPath, "utf8"), "#!/bin/sh\necho updated\n"); - assert.equal(f.updater.listenerCount("appimage-filename-updated"), 0); - }), + it.live("keeps a launcher through the versioned-to-stable transition", () => + Effect.gen(function* () { + using f = fixture("T3-Code-0.1.7-arm64.AppImage", "T3-Code-arm64.AppImage"); + yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: false }); + assert.equal(NodeChildProcess.execFileSync(f.launcher, { encoding: "utf8" }), "updated\n"); + assert.equal(NodeFS.statSync(f.oldPath).mode & 0o777, 0o755); + assert.equal(NodeFS.readFileSync(f.newPath, "utf8"), "#!/bin/sh\necho updated\n"); + assert.equal(f.updater.listenerCount("appimage-filename-updated"), 0); + }), ); it.live("keeps the transition alias through an in-place stable update", () => From 9863c3b87398f8c4d40382a62b858101425c5d8d Mon Sep 17 00:00:00 2001 From: Lakshmi Tanmay Date: Sat, 7 Nov 2026 17:32:51 +0530 Subject: [PATCH 3/4] fix(desktop): read AppImage paths through the host environment --- .../ElectronUpdater.launchPaths.test.ts | 40 +++++++----- apps/desktop/src/electron/ElectronUpdater.ts | 65 +++++++++---------- 2 files changed, 56 insertions(+), 49 deletions(-) diff --git a/apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts b/apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts index e9feba0e8cff..dc1336e8933d 100644 --- a/apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts +++ b/apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts @@ -6,17 +6,22 @@ import * as NodeOS from "node:os"; import * as NodePath from "node:path"; import { assert, describe, it } from "@effect/vitest"; +import * as HostProcess from "@t3tools/shared/HostProcess"; import * as Effect from "effect/Effect"; import * as Exit from "effect/Exit"; import { vi } from "vite-plus/test"; import type { AppImageUpdater as AppImageUpdaterType } from "electron-updater"; const { getUpdater } = vi.hoisted(() => ({ getUpdater: vi.fn<() => AppImageUpdaterType>() })); -vi.mock("electron-updater", () => ({ - get autoUpdater() { - return getUpdater(); - }, -})); +vi.mock("electron-updater", async (importOriginal) => { + const { AppImageUpdater } = await importOriginal(); + return { + AppImageUpdater, + get autoUpdater() { + return getUpdater(); + }, + }; +}); import * as ElectronUpdater from "./ElectronUpdater.ts"; @@ -40,15 +45,6 @@ class FixtureUpdater extends AppImageUpdater { override quitAndInstall(isSilent = false, isForceRunAfter = false) { this.doInstall({ isSilent, isForceRunAfter, isAdminRightsRequired: false }); } - - protected override spawnLog(destination: string) { - assert.equal( - NodeChildProcess.execFileSync(process.env.APPIMAGE!, { encoding: "utf8" }), - "updated\n", - ); - assert.equal(NodeChildProcess.execFileSync(destination, { encoding: "utf8" }), "updated\n"); - return Promise.resolve(true); - } } function fixture(oldName: string, newName: string) { @@ -64,6 +60,17 @@ function fixture(oldName: string, newName: string) { NodeFS.symlinkSync(oldPath, launcher); const updater = new FixtureUpdater(download); getUpdater.mockReturnValue(updater); + const prototype = AppImageUpdater.prototype as unknown as { + spawnLog: (destination: string, args?: Array) => Promise; + }; + const spawnLog = vi.spyOn(prototype, "spawnLog").mockImplementation((destination, args = []) => { + assert.equal(NodeChildProcess.execFileSync(oldPath, { encoding: "utf8" }), "updated\n"); + assert.equal( + NodeChildProcess.execFileSync(destination, args, { encoding: "utf8" }), + "updated\n", + ); + return Promise.resolve(true); + }); const originalAppImage = process.env.APPIMAGE; process.env.APPIMAGE = oldPath; return { @@ -74,6 +81,7 @@ function fixture(oldName: string, newName: string) { launcher, updater, [Symbol.dispose]() { + spawnLog.mockRestore(); if (originalAppImage === undefined) delete process.env.APPIMAGE; else process.env.APPIMAGE = originalAppImage; NodeFS.rmSync(directory, { recursive: true, force: true }); @@ -98,10 +106,10 @@ describe.skipIf(process.platform !== "linux")("AppImage launch paths", () => { Effect.gen(function* () { using f = fixture("My T3-0.1.7.AppImage", "T3-Code-x86_64.AppImage"); yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: true }); - process.env.APPIMAGE = f.newPath; + const env = yield* HostProcess.Environment; + env.APPIMAGE = f.newPath; const nextDownload = NodePath.join(f.directory, "cache", "T3-Code-x86_64.AppImage"); NodeFS.writeFileSync(nextDownload, "#!/bin/sh\necho updated\n", { mode: 0o755 }); - process.env.APPIMAGE = NodePath.join(f.directory, "T3-Code-x86_64.AppImage"); getUpdater.mockReturnValue(new FixtureUpdater(nextDownload)); yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: true }); assert.equal(NodeChildProcess.execFileSync(f.launcher, { encoding: "utf8" }), "updated\n"); diff --git a/apps/desktop/src/electron/ElectronUpdater.ts b/apps/desktop/src/electron/ElectronUpdater.ts index 52eeefa62a07..a0b5fb2c3533 100644 --- a/apps/desktop/src/electron/ElectronUpdater.ts +++ b/apps/desktop/src/electron/ElectronUpdater.ts @@ -2,6 +2,7 @@ import * as NodeFS from "node:fs"; import * as NodePath from "node:path"; +import * as HostProcess from "@t3tools/shared/HostProcess"; import * as Context from "effect/Context"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; @@ -171,44 +172,42 @@ export const make = ElectronUpdater.of({ catch: (cause) => new ElectronUpdaterDownloadUpdateError({ channel, cause }), }).pipe(Effect.asVoid); }), - quitAndInstall: Effect.fn("ElectronUpdater.quitAndInstall")(function ({ + quitAndInstall: Effect.fn("ElectronUpdater.quitAndInstall")(function* ({ isSilent, isForceRunAfter, }) { - return Effect.suspend(() => { - const channel = autoUpdater.channel; - if (autoUpdater instanceof AppImageUpdater) relaunchWithoutInheritedDescriptors(autoUpdater); - return Effect.try({ - try: () => { - const appImagePath = process.env.APPIMAGE; - const preserveAppImagePath = (destination: string) => { - const filename = NodePath.basename(destination); - // Only bridge to a name the updater will keep, avoiding growing alias chains. - if (appImagePath === undefined || /\d+\.\d+\.\d+/.test(filename)) return; - try { - // 6.8.9 emits synchronously after moving the file, before relaunch/exit. - NodeFS.symlinkSync(filename, appImagePath); - } catch { - autoUpdater.logger?.warn("Could not preserve the previous AppImage launch path."); - } - }; - if (appImagePath !== undefined) { - autoUpdater.on("appimage-filename-updated", preserveAppImagePath); - } + const appImagePath = (yield* HostProcess.Environment).APPIMAGE; + const channel = autoUpdater.channel; + if (autoUpdater instanceof AppImageUpdater) relaunchWithoutInheritedDescriptors(autoUpdater); + return yield* Effect.try({ + try: () => { + const preserveAppImagePath = (destination: string) => { + const filename = NodePath.basename(destination); + // Only bridge to a name the updater will keep, avoiding growing alias chains. + if (appImagePath === undefined || /\d+\.\d+\.\d+/.test(filename)) return; try { - autoUpdater.quitAndInstall(isSilent, isForceRunAfter); - } finally { - autoUpdater.removeListener("appimage-filename-updated", preserveAppImagePath); + // 6.8.9 emits synchronously after moving the file, before relaunch/exit. + NodeFS.symlinkSync(filename, appImagePath); + } catch { + autoUpdater.logger?.warn("Could not preserve the previous AppImage launch path."); } - }, - catch: (cause) => - new ElectronUpdaterQuitAndInstallError({ - channel, - isSilent, - isForceRunAfter, - cause, - }), - }); + }; + if (appImagePath !== undefined) { + autoUpdater.on("appimage-filename-updated", preserveAppImagePath); + } + try { + autoUpdater.quitAndInstall(isSilent, isForceRunAfter); + } finally { + autoUpdater.removeListener("appimage-filename-updated", preserveAppImagePath); + } + }, + catch: (cause) => + new ElectronUpdaterQuitAndInstallError({ + channel, + isSilent, + isForceRunAfter, + cause, + }), }); }), on: Effect.fn("ElectronUpdater.on")(function (eventName, listener) { From d3f30ff0f571cf54e1d31e174f47d4c1de7418e9 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 00:33:35 +0000 Subject: [PATCH 4/4] test(desktop): keep AppImage launcher tests that exercise the alias Drop cases that only re-test electron-updater's own behaviour, run the transition case through the relaunch path so it fails without the fix, and skip registering the listener when APPIMAGE is unset. Co-Authored-By: Claude Opus 5.5 --- .../ElectronUpdater.launchPaths.test.ts | 48 +------------------ apps/desktop/src/electron/ElectronUpdater.ts | 12 ++--- 2 files changed, 7 insertions(+), 53 deletions(-) diff --git a/apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts b/apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts index dc1336e8933d..2f411c9b3fdb 100644 --- a/apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts +++ b/apps/desktop/src/electron/ElectronUpdater.launchPaths.test.ts @@ -6,9 +6,7 @@ import * as NodeOS from "node:os"; import * as NodePath from "node:path"; import { assert, describe, it } from "@effect/vitest"; -import * as HostProcess from "@t3tools/shared/HostProcess"; import * as Effect from "effect/Effect"; -import * as Exit from "effect/Exit"; import { vi } from "vite-plus/test"; import type { AppImageUpdater as AppImageUpdaterType } from "electron-updater"; @@ -74,10 +72,8 @@ function fixture(oldName: string, newName: string) { const originalAppImage = process.env.APPIMAGE; process.env.APPIMAGE = oldPath; return { - directory, oldPath, newPath, - download, launcher, updater, [Symbol.dispose]() { @@ -94,26 +90,10 @@ describe.skipIf(process.platform !== "linux")("AppImage launch paths", () => { it.live("keeps a launcher through the versioned-to-stable transition", () => Effect.gen(function* () { using f = fixture("T3-Code-0.1.7-arm64.AppImage", "T3-Code-arm64.AppImage"); - yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: false }); - assert.equal(NodeChildProcess.execFileSync(f.launcher, { encoding: "utf8" }), "updated\n"); - assert.equal(NodeFS.statSync(f.oldPath).mode & 0o777, 0o755); - assert.equal(NodeFS.readFileSync(f.newPath, "utf8"), "#!/bin/sh\necho updated\n"); - assert.equal(f.updater.listenerCount("appimage-filename-updated"), 0); - }), - ); - - it.live("keeps the transition alias through an in-place stable update", () => - Effect.gen(function* () { - using f = fixture("My T3-0.1.7.AppImage", "T3-Code-x86_64.AppImage"); - yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: true }); - const env = yield* HostProcess.Environment; - env.APPIMAGE = f.newPath; - const nextDownload = NodePath.join(f.directory, "cache", "T3-Code-x86_64.AppImage"); - NodeFS.writeFileSync(nextDownload, "#!/bin/sh\necho updated\n", { mode: 0o755 }); - getUpdater.mockReturnValue(new FixtureUpdater(nextDownload)); yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: true }); assert.equal(NodeChildProcess.execFileSync(f.launcher, { encoding: "utf8" }), "updated\n"); assert.equal(NodeFS.readlinkSync(f.oldPath), NodePath.basename(f.newPath)); + assert.equal(f.updater.listenerCount("appimage-filename-updated"), 0); }), ); @@ -121,37 +101,11 @@ describe.skipIf(process.platform !== "linux")("AppImage launch paths", () => { Effect.gen(function* () { using f = fixture("T3-Code-0.1.7.AppImage", "T3-Code-0.1.8.AppImage"); yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: false }); - assert.isFalse(NodeFS.existsSync(f.oldPath)); assert.throws(() => NodeFS.lstatSync(f.oldPath)); assert.equal(NodeChildProcess.execFileSync(f.newPath, { encoding: "utf8" }), "updated\n"); }), ); - it.live("preserves a custom versionless filename in place", () => - Effect.gen(function* () { - using f = fixture("My T3.AppImage", "T3-Code-x86_64.AppImage"); - yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: false }); - assert.equal(NodeChildProcess.execFileSync(f.launcher, { encoding: "utf8" }), "updated\n"); - assert.isFalse(NodeFS.existsSync(f.newPath)); - }), - ); - - it.live("leaves the alias usable after a relaunch failure and re-download retry", () => - Effect.gen(function* () { - using f = fixture("T3-Code-0.1.7.AppImage", "T3-Code-x86_64.AppImage"); - NodeFS.writeFileSync(f.download, "#!/bin/sh\nexit 1\n"); - const result = yield* Effect.exit( - ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: false }), - ); - assert.isTrue(Exit.isFailure(result)); - assert.equal(NodeFS.readFileSync(f.oldPath, "utf8"), "#!/bin/sh\nexit 1\n"); - assert.equal(f.updater.listenerCount("appimage-filename-updated"), 0); - NodeFS.writeFileSync(f.download, "#!/bin/sh\necho updated\n", { mode: 0o755 }); - yield* ElectronUpdater.make.quitAndInstall({ isSilent: true, isForceRunAfter: false }); - assert.equal(NodeChildProcess.execFileSync(f.launcher, { encoding: "utf8" }), "updated\n"); - }), - ); - it.live("does not overwrite a path recreated during installation or abort relaunch", () => Effect.gen(function* () { using f = fixture("T3-Code-0.1.7.AppImage", "T3-Code-x86_64.AppImage"); diff --git a/apps/desktop/src/electron/ElectronUpdater.ts b/apps/desktop/src/electron/ElectronUpdater.ts index a0b5fb2c3533..73e876026ca8 100644 --- a/apps/desktop/src/electron/ElectronUpdater.ts +++ b/apps/desktop/src/electron/ElectronUpdater.ts @@ -181,20 +181,20 @@ export const make = ElectronUpdater.of({ if (autoUpdater instanceof AppImageUpdater) relaunchWithoutInheritedDescriptors(autoUpdater); return yield* Effect.try({ try: () => { + if (appImagePath === undefined) + return autoUpdater.quitAndInstall(isSilent, isForceRunAfter); + // electron-updater 6.8.9 emits this synchronously after moving the file, before relaunch. const preserveAppImagePath = (destination: string) => { const filename = NodePath.basename(destination); - // Only bridge to a name the updater will keep, avoiding growing alias chains. - if (appImagePath === undefined || /\d+\.\d+\.\d+/.test(filename)) return; + // A versioned name is replaced by the next update, so aliasing it would build chains. + if (/\d+\.\d+\.\d+/.test(filename)) return; try { - // 6.8.9 emits synchronously after moving the file, before relaunch/exit. NodeFS.symlinkSync(filename, appImagePath); } catch { autoUpdater.logger?.warn("Could not preserve the previous AppImage launch path."); } }; - if (appImagePath !== undefined) { - autoUpdater.on("appimage-filename-updated", preserveAppImagePath); - } + autoUpdater.on("appimage-filename-updated", preserveAppImagePath); try { autoUpdater.quitAndInstall(isSilent, isForceRunAfter); } finally {