Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(desktop): move the local services to a newer app's source on launch

claude-opus-5-5-medium8d3e5fcb837b
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.md
index e29c3796..31e5720c 100644
--- a/apps/desktop/AGENTS.md
+++ b/apps/desktop/AGENTS.md
@@ -169,7 +169,14 @@ Gateway and runs Agents. The daemon exits with the app.
when the instance's `user.env` changed. A source folder removed since, or
one the installer no longer accepts as a Linger checkout (such as one the
earlier Simplex app unpacked), is unpacked again from the app's package
- first and replaces the recorded one. A Quick Install that stopped
+ first and replaces the recorded one. The record also names the app
+ version that unpacked the source; when this app brings another source
+ package (it was installed over an older one), that launch unpacks it and
+ resumes on it, with the "Updating Linger" page instead of the older
+ interface, then prunes the older folder. A failure shows the start failure
+ page, whose Retry tries again. An app older than the recorded version
+ (a downgrade) leaves the services on their newer source and logs
+ `local_server.source_newer_than_app`. A Quick Install that stopped
before the computer enrolled is not resumed: setup shows again and Install
finishes it, reusing a finished job only while its origin answers (a stopped
server gets a new job, which starts the services again). The start failure
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts
index f887828d..2c822a8f 100644
--- a/apps/desktop/src/main/index.ts
+++ b/apps/desktop/src/main/index.ts
@@ -186,6 +186,7 @@ async function main(): Promise<void> {
const home = lingerHome();
const localServer = new LocalServerModule({
home,
+ version: VERSION,
macosVersion: () => process.getSystemVersion(),
installerDirectory: path.join(here, "../installer"),
...(__SOURCE_ARCHIVE__ ? { sourceArchive: __SOURCE_ARCHIVE__ } : {}),
@@ -216,7 +217,6 @@ async function main(): Promise<void> {
? updateInstallFor(process.platform, process.execPath, existsSync)
: undefined,
downloadDirectory: path.join(userData, "updates"),
- services: localServer,
announce: (state) => {
if (!Notification.isSupported()) return;
const notice = new Notification(updateNotice(state));
diff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.ts
index 18440a42..e8349d55 100644
--- a/apps/desktop/src/main/local-server.test.ts
+++ b/apps/desktop/src/main/local-server.test.ts
@@ -306,6 +306,7 @@ const installerApi = (
};
const TEAMHUB = "http://127.0.0.1:4100";
+const APP_VERSION = "0.17.0";
const KEY = Buffer.from(Array.from({ length: 32 }, (_, i) => i));
const server = (origin: string): LocalServerIdentity => ({
origin,
@@ -372,6 +373,7 @@ const fixture = (
}) as typeof fetch;
const module = new LocalServerModule({
home,
+ version: APP_VERSION,
installerDirectory,
platform: "linux",
arch: "x64",
@@ -663,6 +665,7 @@ describe("LocalServerModule", () => {
home: f.home,
repo,
origin: "http://localhost:3000",
+ version: APP_VERSION,
});
await f.host.stop("quit");
});
@@ -1120,6 +1123,7 @@ describe("LocalServerModule", () => {
const bundled = (sha256: string) =>
new LocalServerModule({
home: f.home,
+ version: APP_VERSION,
installerDirectory: path.join(f.root, "installer"),
platform: "linux",
arch: "x64",
@@ -1180,6 +1184,7 @@ describe("LocalServerModule", () => {
const install = async () => {
await new LocalServerModule({
home: f.home,
+ version: APP_VERSION,
installerDirectory: path.join(f.root, "installer"),
platform: "linux",
arch: "x64",
@@ -1254,6 +1259,7 @@ describe("LocalServerModule", () => {
const install = async (glibcVersion = "2.35") => {
await new LocalServerModule({
home: f.home,
+ version: APP_VERSION,
installerDirectory: path.join(f.root, "installer"),
platform: "linux",
arch: "x64",
@@ -1353,6 +1359,7 @@ describe("LocalServerModule", () => {
);
await new LocalServerModule({
home: f.home,
+ version: APP_VERSION,
installerDirectory: installer,
platform: "darwin",
arch: "arm64",
@@ -2312,15 +2319,16 @@ describe("LocalServerModule after a restart", () => {
await f.host.stop("quit");
});
- it("moves the services to the source package of an updated app when asked", async () => {
- const root = tempDirectory();
- const archive = sourceArchive(root);
- const f = fixture(
+ // The services an app installed over this one unpacked: the record names
+ // their source folder and the app that unpacked it.
+ const installedBy = (archive: ReturnType<typeof sourceArchive>) =>
+ fixture(
{
sourceArchive: {
url: "https://cdn.example/linger.tar.gz",
sha256: archive.sha256,
},
+ // The services still answer, as when only the app was replaced.
fetch: (async () => new Response(archive.bytes)) as typeof fetch,
},
enrolled,
@@ -2337,30 +2345,147 @@ describe("LocalServerModule after a restart", () => {
);
},
);
+
+ it("moves the services to the source package of an app installed over an older one", async () => {
+ const root = tempDirectory();
+ const archive = sourceArchive(root);
+ const f = installedBy(archive);
await f.host.start();
await vi.waitFor(() => expect(f.module.status().phase).toBe("ready"));
const sources = path.join(f.home, "desktop", "source");
- const previous = path.join(sources, "previous");
const current = path.join(sources, archive.sha256.slice(0, 16));
- const before = installerArgs(f.home);
- expect(before[before.indexOf("--source-repo") + 1]).toBe(previous);
- expect(f.module.sourceUpdateAvailable()).toBe(true);
- await f.module.updateSource();
- expect(f.showUpdating).toHaveBeenCalledOnce();
- expect(f.loadServer).toHaveBeenCalledOnce();
- expect(f.module.sourceUpdateAvailable()).toBe(false);
- expect(f.module.status().phase).toBe("ready");
const args = installerArgs(f.home);
+ expect(args).toContain("--resume");
expect(args[args.indexOf("--source-repo") + 1]).toBe(current);
+ // The window leaves the older interface while they restart.
+ expect(f.showUpdating).toHaveBeenCalledOnce();
+ expect(f.setServer).toHaveBeenCalledWith("http://localhost:3000");
expect(
JSON.parse(
readFileSync(path.join(f.home, "desktop", "local-server.json"), "utf8"),
),
- ).toMatchObject({ repo: current });
+ ).toEqual({
+ home: f.home,
+ repo: current,
+ origin: "http://localhost:3000",
+ version: APP_VERSION,
+ });
expect(readdirSync(sources)).toEqual([path.basename(current)]);
await f.host.stop("quit");
});
+ it("shows the start failure when moving to the newer source package fails", async () => {
+ const root = tempDirectory();
+ const archive = sourceArchive(root);
+ const f = installedBy(archive);
+ writeFileSync(path.join(f.home, "resume-fails"), "");
+ await f.host.start();
+ await vi.waitFor(() => expect(f.module.status().phase).toBe("failed"));
+ expect(f.showStartFailed).toHaveBeenCalledWith("Native teamhub stopped");
+ // Try Again moves them once more.
+ rmSync(path.join(f.home, "resume-fails"));
+ f.bus.emit("local-server.retry");
+ await vi.waitFor(() => expect(f.module.status().phase).toBe("ready"));
+ const args = installerArgs(f.home);
+ expect(args[args.indexOf("--source-repo") + 1]).toBe(
+ path.join(f.home, "desktop", "source", archive.sha256.slice(0, 16)),
+ );
+ await f.host.stop("quit");
+ });
+
+ it("starts the services on their own source package when it is this app's", async () => {
+ const root = tempDirectory();
+ const archive = sourceArchive(root);
+ const repo = (home: string) =>
+ path.join(home, "desktop", "source", archive.sha256.slice(0, 16));
+ const download = vi.fn(
+ async (_url: string | URL | Request) =>
+ new Response(null, { status: 503 }),
+ );
+ const f = fixture(
+ {
+ sourceArchive: {
+ url: "https://cdn.example/linger.tar.gz",
+ sha256: archive.sha256,
+ },
+ fetch: download as typeof fetch,
+ },
+ enrolled,
+ (home) => {
+ unpackedSource(repo(home));
+ writeFileSync(
+ path.join(home, "desktop", "local-server.json"),
+ JSON.stringify({
+ home,
+ repo: repo(home),
+ origin: "http://localhost:3000",
+ version: APP_VERSION,
+ }),
+ );
+ },
+ );
+ await f.host.start();
+ await vi.waitFor(() => expect(f.module.status().phase).toBe("ready"));
+ const args = installerArgs(f.home);
+ expect(args[args.indexOf("--source-repo") + 1]).toBe(repo(f.home));
+ expect(f.showUpdating).not.toHaveBeenCalled();
+ expect(
+ download.mock.calls.some(([url]) =>
+ String(url).startsWith("https://cdn.example/"),
+ ),
+ ).toBe(false);
+ await f.host.stop("quit");
+ });
+
+ it("leaves services a newer app unpacked on their source package", async () => {
+ const warn = vi.spyOn(silentLog, "warn");
+ const root = tempDirectory();
+ const archive = sourceArchive(root);
+ const f = fixture(
+ {
+ sourceArchive: {
+ url: "https://cdn.example/linger.tar.gz",
+ sha256: archive.sha256,
+ },
+ fetch: (async () => new Response(archive.bytes)) as typeof fetch,
+ },
+ enrolled,
+ (home) => {
+ const sources = path.join(home, "desktop", "source");
+ unpackedSource(path.join(sources, "newer"));
+ writeFileSync(
+ path.join(home, "desktop", "local-server.json"),
+ JSON.stringify({
+ home,
+ repo: path.join(sources, "newer"),
+ origin: "http://localhost:3000",
+ version: "0.18.0",
+ }),
+ );
+ },
+ );
+ await f.host.start();
+ await vi.waitFor(() => expect(f.module.status().phase).toBe("ready"));
+ const newer = path.join(f.home, "desktop", "source", "newer");
+ const args = installerArgs(f.home);
+ expect(args[args.indexOf("--source-repo") + 1]).toBe(newer);
+ expect(f.showUpdating).not.toHaveBeenCalled();
+ expect(readdirSync(path.join(f.home, "desktop", "source"))).toEqual([
+ "newer",
+ ]);
+ expect(
+ JSON.parse(
+ readFileSync(path.join(f.home, "desktop", "local-server.json"), "utf8"),
+ ),
+ ).toMatchObject({ repo: newer, version: "0.18.0" });
+ expect(warn).toHaveBeenCalledWith("local_server.source_newer_than_app", {
+ installed: "0.18.0",
+ app: APP_VERSION,
+ });
+ warn.mockRestore();
+ await f.host.stop("quit");
+ });
+
it("reports a failed restart", async () => {
const f = fixture({}, enrolled, (home) => {
record(home);
@@ -2468,7 +2593,6 @@ describe("LocalServerModule after a restart", () => {
expect(
existsSync(path.join(repo(f.home), "scripts/source-native.mjs")),
).toBe(true);
- expect(f.module.sourceUpdateAvailable()).toBe(false);
await f.host.stop("quit");
});
@@ -2510,7 +2634,6 @@ describe("LocalServerModule after a restart", () => {
),
).toMatchObject({ repo: current });
expect(readdirSync(sources)).toEqual([path.basename(current)]);
- expect(f.module.sourceUpdateAvailable()).toBe(false);
await f.host.stop("quit");
});
@@ -2564,7 +2687,12 @@ describe("LocalServerModule after a restart", () => {
JSON.parse(
readFileSync(path.join(f.home, "desktop", "local-server.json"), "utf8"),
),
- ).toEqual({ home: chosen, repo: current, origin: "http://localhost:3000" });
+ ).toEqual({
+ home: chosen,
+ repo: current,
+ origin: "http://localhost:3000",
+ version: APP_VERSION,
+ });
expect(readdirSync(path.dirname(current))).toEqual([
path.basename(current),
]);
diff --git a/apps/desktop/src/main/local-server.ts b/apps/desktop/src/main/local-server.ts
index 7ef8be21..23e07775 100644
--- a/apps/desktop/src/main/local-server.ts
+++ b/apps/desktop/src/main/local-server.ts
@@ -65,6 +65,7 @@ import {
import type { Module, ModuleContext } from "./modules.js";
import { sameOrigin } from "./navigation.js";
import { humanTenant, type EnrollmentModule } from "./enrollment.js";
+import { compareVersions } from "./update-manifest.js";
import type { WindowManagerModule } from "./window-manager.js";
import {
installerKeyChanges,
@@ -286,6 +287,8 @@ export interface LocalServerOptions {
// The desktop keeps its Node runtime and its record here wherever the
// installation goes.
readonly home: string;
+ // This app's version, recorded with the source package it unpacks.
+ readonly version: string;
// The bundled installer (installer.js, web/, native-process-worker.mjs).
readonly installerDirectory: string;
readonly sourceArchive?: SourceArchive;
@@ -421,10 +424,6 @@ export class LocalServerModule implements Module {
#locationError: string | undefined;
#node: Promise<string> | undefined;
#abort = new AbortController();
- // The running installation when this app brings a newer source package;
- // the services move to it once the person chooses to update.
- #outdated: LocalRecord | undefined;
- #updating: Promise<void> | undefined;
#offRetry: (() => void) | undefined;
#offReset: (() => void) | undefined;
#offDaemon: (() => void) | undefined;
@@ -906,6 +905,7 @@ export class LocalServerModule implements Module {
home,
repo,
origin: job.origin,
+ version: this.#options.version,
});
await this.#pruneSources(home, [repo]);
this.#home = home;
@@ -2040,32 +2040,44 @@ export class LocalServerModule implements Module {
}
// Runs the installer headless against the saved instance; it starts only
- // the services that are not running and asks for nothing. A newer source
- // package in an updated app waits for the person (updateSource) while the
- // installed one is still there.
+ // the services that are not running and asks for nothing. When this app
+ // brings a newer source package (it was installed over an older one), the
+ // services move to it first: the window and the Computer already are this
+ // version, and the older services would serve the older interface.
async #resume(record: LocalRecord, signal: AbortSignal): Promise<void> {
this.#origin = record.origin;
const windows = this.#ctx?.get<WindowManagerModule>("WindowManager");
try {
- this.#set("preparing", "Starting Linger on this computer…");
- // The window would show the server as unreachable until it is back.
- if (!(await this.#reachable(record.origin))) windows?.showStarting();
- const newer = this.#newerSource(record);
+ const update = this.#sourceUpdate(record);
+ if (update) {
+ // The services restart even if they still answer.
+ this.#set("preparing", "Updating Linger on this computer…");
+ windows?.showUpdating();
+ } else {
+ this.#set("preparing", "Starting Linger on this computer…");
+ // The window would show the server as unreachable until it is back.
+ if (!(await this.#reachable(record.origin))) windows?.showStarting();
+ }
// A source folder the installer no longer runs is unpacked again from
// this app's package: one removed since (by hand, or a cleanup that an
// uninstall left half done), or one the earlier Simplex app unpacked.
const repo =
this.#options.sourceArchive &&
!this.#options.checkout &&
- !(await validateSourceRepository(record.repo).then(
- () => true,
- () => false,
- ))
+ (update ||
+ !(await validateSourceRepository(record.repo).then(
+ () => true,
+ () => false,
+ )))
? await this.#ensureSource(record.home, signal)
: record.repo;
await this.#runResume(record, repo, signal);
if (repo !== record.repo) await this.#moved(record, repo);
- this.#outdated = newer && repo === record.repo ? record : undefined;
+ if (update)
+ this.#ctx?.log.info("local_server.source_updated", {
+ source: path.basename(repo),
+ from: record.version,
+ });
this.#ready(record.origin);
this.#set("ready", "Linger is running on this computer.");
} catch (error) {
@@ -2087,7 +2099,6 @@ export class LocalServerModule implements Module {
try {
await rm(this.#recordFile(), { force: true });
this.#origin = undefined;
- this.#outdated = undefined;
this.#set("idle", "");
ctx.log.info("local_server.reset");
await ctx.get<EnrollmentModule>("Enrollment").unenroll();
@@ -2104,62 +2115,37 @@ export class LocalServerModule implements Module {
return answers(this.#options.fetch ?? fetch, origin);
}
- // Whether this app brings a source package the running services do not
- // use yet.
- sourceUpdateAvailable(): boolean {
- return this.#outdated !== undefined;
- }
-
- // Moves the services to this app's source package. The window shows that
- // Linger is updating while they restart, then the server again.
- updateSource(): Promise<void> {
- const record = this.#outdated;
- if (!record) return Promise.resolve();
- this.#updating ??= this.#updateSource(record).finally(() => {
- this.#updating = undefined;
- });
- return this.#updating;
- }
-
- async #updateSource(record: LocalRecord): Promise<void> {
- const signal = this.#abort.signal;
- const windows = this.#ctx?.get<WindowManagerModule>("WindowManager");
- windows?.showUpdating();
- try {
- this.#set("preparing", "Updating Linger on this computer…");
- const repo = await this.#ensureSource(record.home, signal);
- await this.#runResume(record, repo, signal);
- await this.#moved(record, repo);
- this.#outdated = undefined;
- this.#set("ready", "Linger is running on this computer.");
- this.#ctx?.log.info("local_server.source_updated", {
- source: path.basename(repo),
- });
- } catch (error) {
- if (signal.aborted) return;
- this.#ctx?.log.warn("local_server.update_failed", {
- error: error instanceof Error ? error.message : String(error),
+ // Whether the services run another source package than this app brings,
+ // one that an older app unpacked. An older app installed over a newer one
+ // leaves its services as they are: the newer services may have changed
+ // the data in ways the older ones do not know.
+ #sourceUpdate(record: LocalRecord): boolean {
+ const archive = this.#options.sourceArchive;
+ if (
+ this.#options.checkout ||
+ !archive ||
+ path.basename(record.repo) === archive.sha256.slice(0, 16)
+ )
+ return false;
+ if (
+ record.version &&
+ compareVersions(record.version, this.#options.version) > 0
+ ) {
+ this.#ctx?.log.warn("local_server.source_newer_than_app", {
+ installed: record.version,
+ app: this.#options.version,
});
- this.#set(
- "failed",
- error instanceof Error ? error.message : String(error),
- );
- } finally {
- if (!signal.aborted) windows?.loadServer();
+ return false;
}
- }
-
- #newerSource(record: LocalRecord): boolean {
- const archive = this.#options.sourceArchive;
- return (
- !this.#options.checkout &&
- !!archive &&
- path.basename(record.repo) !== archive.sha256.slice(0, 16)
- );
+ return true;
}
async #moved(record: LocalRecord, repo: string): Promise<void> {
- await this.#writeRecord({ ...record, repo });
+ await this.#writeRecord({
+ ...record,
+ repo,
+ version: this.#options.version,
+ });
await this.#pruneSources(record.home, [repo]);
}
@@ -2271,6 +2257,9 @@ export class LocalServerModule implements Module {
: this.#options.home,
repo: value.repo,
origin: value.origin,
+ ...(typeof value.version === "string"
+ ? { version: value.version }
+ : {}),
}
: undefined;
} catch {
@@ -2329,6 +2318,9 @@ interface LocalRecord {
readonly home: string;
readonly repo: string;
readonly origin: string;
+ // The version of the app that unpacked `repo`; a record without one was
+ // written by an app older than any that reads it.
+ readonly version?: string;
}
// This computer as the server's Local Computers list reports it.
diff --git a/apps/desktop/src/main/tray-menu.test.ts b/apps/desktop/src/main/tray-menu.test.ts
index 6c74d8c9..b165a1f8 100644
--- a/apps/desktop/src/main/tray-menu.test.ts
+++ b/apps/desktop/src/main/tray-menu.test.ts
@@ -71,29 +71,6 @@ describe("trayMenu", () => {
});
});
- it("offers to update the services on this computer", () => {
- const menu = (kind: "ready" | "waiting" | "installing") =>
- trayMenu({
- status: { tone: "online", label: "Online" },
- preventSleep: false,
- enrolled: true,
- update: { kind, version: "0.16.20", services: true },
- })[1];
- expect(menu("ready")).toEqual({
- kind: "action",
- action: "install-update",
- label: "Update Linger on This Computer",
- });
- expect(menu("waiting")).toEqual({
- kind: "label",
- label: "Updating When Tasks Finish",
- });
- expect(menu("installing")).toEqual({
- kind: "label",
- label: "Updating Linger on This Computer…",
- });
- });
-
it("shows a download in progress", () => {
const items = trayMenu({
status: { tone: "online", label: "Online" },
@@ -168,10 +145,5 @@ describe("updateNotice", () => {
title: "Update available",
body: "Linger 0.17.0 is available. Click to open its download page.",
});
- expect(
- updateNotice({ kind: "ready", version: "0.16.7", services: true }).body,
- ).toBe(
- "Click to update Linger on this computer. It restarts in about a minute.",
- );
});
});
diff --git a/apps/desktop/src/main/tray-menu.ts b/apps/desktop/src/main/tray-menu.ts
index 99a9b70b..148f8ac2 100644
--- a/apps/desktop/src/main/tray-menu.ts
+++ b/apps/desktop/src/main/tray-menu.ts
@@ -1,5 +1,5 @@
import type { StatusSummary } from "./status.js";
-import type { UpdateState } from "./updater.js";
+import type { AnnouncedUpdate, UpdateState } from "./updater.js";
export type TrayAction =
| "enroll"
@@ -87,24 +87,16 @@ const updateItems = (update: TrayMenuState["update"]): TrayMenuItem[] => {
{
kind: "action",
action: "install-update",
- label: update.services
- ? "Update Linger on This Computer"
- : `Restart to Update (${update.version})`,
+ label: `Restart to Update (${update.version})`,
},
];
case "waiting":
return [
{
kind: "label",
- label: update.services
- ? "Updating When Tasks Finish"
- : `Updating to ${update.version} When Tasks Finish`,
+ label: `Updating to ${update.version} When Tasks Finish`,
},
];
- case "installing":
- return update.services
- ? [{ kind: "label", label: "Updating Linger on This Computer…" }]
- : [];
case "available":
return [
{
@@ -134,7 +126,7 @@ const updateItems = (update: TrayMenuState["update"]): TrayMenuItem[] => {
// The notification for an update once it is ready or available; clicking it
// does what the tray's update item does.
-export function updateNotice(update: UpdateState): {
+export function updateNotice(update: AnnouncedUpdate): {
title: string;
body: string;
} {
@@ -143,13 +135,8 @@ export function updateNotice(update: UpdateState): {
title: "Update available",
body: `Linger ${update.version} is available. Click to open its download page.`,
};
- if (update.kind === "ready" && !update.services)
- return {
- title: "Update ready",
- body: `Linger ${update.version} is downloaded. Click to restart Linger and update.`,
- };
return {
title: "Update ready",
- body: "Click to update Linger on this computer. It restarts in about a minute.",
+ body: `Linger ${update.version} is downloaded. Click to restart Linger and update.`,
};
}
diff --git a/apps/desktop/src/main/updater.test.ts b/apps/desktop/src/main/updater.test.ts
index f3052ce2..af9ab210 100644
--- a/apps/desktop/src/main/updater.test.ts
+++ b/apps/desktop/src/main/updater.test.ts
@@ -407,52 +407,6 @@ describe("UpdaterModule for a download", () => {
});
});
-describe("UpdaterModule with services on this computer", () => {
- it("offers the services update the app brings and still checks for a newer app", async () => {
- const feed = release("0.16.7");
- let available = false;
- let updates = 0;
- const { updater, host, announced } = await setup(feed, {
- services: {
- sourceUpdateAvailable: () => available,
- updateSource: async () => {
- updates += 1;
- available = false;
- },
- },
- });
- available = true;
- host.ctx.bus.emit("local-server.changed");
- const services = { kind: "ready", version: "0.16.7", services: true };
- expect(updater.state()).toEqual(services);
- expect(announced).toEqual([services]);
-
- await updater.check();
- expect(feed.requested).toHaveLength(2);
- expect(updater.state()).toEqual(services);
- expect(announced).toHaveLength(1);
-
- await updater.install();
- expect(updates).toBe(1);
- expect(updater.state()).toEqual({ kind: "idle" });
- await host.stop("quit");
- });
-
- it("replaces the services update with a newer app, which brings its own", async () => {
- const feed = release("0.17.0");
- const { updater, host } = await setup(feed, {
- services: {
- sourceUpdateAvailable: () => true,
- updateSource: async () => {},
- },
- });
- expect(updater.state()).toMatchObject({ services: true });
- await updater.check();
- expect(updater.state()).toEqual({ kind: "ready", version: "0.17.0" });
- await host.stop("quit");
- });
-});
-
describe("updateInstallFor", () => {
it("swaps the macOS bundle, runs the Windows setup and links elsewhere", () => {
const none = () => false;
diff --git a/apps/desktop/src/main/updater.ts b/apps/desktop/src/main/updater.ts
index 9fd89fca..b8b55ade 100644
--- a/apps/desktop/src/main/updater.ts
+++ b/apps/desktop/src/main/updater.ts
@@ -26,24 +26,10 @@ export type UpdateState =
| { readonly kind: "idle" }
| { readonly kind: "checking" }
| { readonly kind: "downloading"; readonly version: string }
- // `services`: the new version is the one this app brings for the
- // services on this computer, applied without restarting the app.
- | {
- readonly kind: "ready";
- readonly version: string;
- readonly services?: boolean;
- }
+ | { readonly kind: "ready"; readonly version: string }
// Restart was chosen while tasks ran; it happens once they finish.
- | {
- readonly kind: "waiting";
- readonly version: string;
- readonly services?: boolean;
- }
- | {
- readonly kind: "installing";
- readonly version: string;
- readonly services?: boolean;
- }
+ | { readonly kind: "waiting"; readonly version: string }
+ | { readonly kind: "installing"; readonly version: string }
// A newer release this installation cannot apply itself; `url` is its
// release page.
| {
@@ -53,6 +39,11 @@ export type UpdateState =
}
| { readonly kind: "failed"; readonly error: string };
+export type AnnouncedUpdate = Extract<
+ UpdateState,
+ { kind: "ready" | "available" }
+>;
+
// How this installation takes a newer release.
export type UpdateInstall =
// macOS: the installed Linger.app, swapped for the release's app archive.
@@ -78,11 +69,8 @@ export interface UpdaterOptions {
// running, replaces the files and starts the new version.
readonly quit: () => Promise<void>;
readonly openExternal: (url: string) => Promise<void>;
- // The services this app runs on this computer. Their updates come with
- // the app: a newer app brings a newer version for them.
- readonly services?: LocalServices;
// Tells the person once per version that an update is ready or available.
- readonly announce?: (state: UpdateState) => void;
+ readonly announce?: (state: AnnouncedUpdate) => void;
readonly fetch?: typeof fetch;
readonly extract?: (archive: string, directory: string) => Promise<void>;
readonly spawn?: SpawnSetup;
@@ -92,12 +80,6 @@ export interface UpdaterOptions {
readonly retryDelayMs?: number;
}
-export interface LocalServices {
- // Whether this app brings a newer version than the services run.
- sourceUpdateAvailable(): boolean;
- updateSource(): Promise<void>;
-}
-
export interface SetupProcess {
once(event: "spawn", listener: () => void): unknown;
once(event: "error", listener: (error: Error) => void): unknown;
@@ -152,12 +134,6 @@ export class UpdaterModule implements Module {
async start(ctx: ModuleContext): Promise<void> {
this.#ctx = ctx;
- if (this.#options.services) {
- this.#unsubscribe.push(
- ctx.bus.on("local-server.changed", () => this.#offerServices()),
- );
- this.#offerServices();
- }
if (!this.#options.install) return;
void this.#cleanup();
const schedule = (delay: number): void => {
@@ -185,16 +161,14 @@ export class UpdaterModule implements Module {
}
// Fetches and verifies the manifest, then downloads a newer package. Only
- // one check runs at a time; a downloaded update is not checked again. A
- // services update on offer is replaced by a newer app, which brings its own.
+ // one check runs at a time; a downloaded update is not checked again.
check(): Promise<void> {
if (!this.#options.install) return Promise.resolve();
const state = this.#state;
const settled =
state.kind === "idle" ||
state.kind === "failed" ||
- state.kind === "available" ||
- (state.kind === "ready" && state.services);
+ state.kind === "available";
if (!settled) return this.#checking ?? Promise.resolve();
this.#checking = this.#check().finally(() => (this.#checking = undefined));
return this.#checking;
@@ -212,11 +186,7 @@ export class UpdaterModule implements Module {
const runtime = this.#ctx!.get<ComputerDaemonModule>("ComputerDaemon");
if (runtime.running() > 0) {
if (state.kind === "waiting") return;
- this.#setState({
- kind: "waiting",
- version: state.version,
- ...(state.services ? { services: true } : {}),
- });
+ this.#setState({ kind: "waiting", version: state.version });
const off = this.#ctx!.bus.on("runtime.activity", (running) => {
if (running !== 0) return;
off();
@@ -225,17 +195,6 @@ export class UpdaterModule implements Module {
this.#unsubscribe.push(off);
return;
}
- if (state.services) {
- this.#setState({
- kind: "installing",
- version: state.version,
- services: true,
- });
- await this.#options.services?.updateSource();
- this.#setState({ kind: "idle" });
- this.#offerServices();
- return;
- }
this.#setState({ kind: "installing", version: state.version });
this.#ctx!.log.info("update.installing", { version: state.version });
try {
@@ -251,26 +210,6 @@ export class UpdaterModule implements Module {
}
}
- // "Update Linger on This Computer", offered once the app
- // brings a newer version than they run.
- #offerServices(): void {
- const services = this.#options.services;
- if (!services) return;
- const kind = this.#state.kind;
- if (services.sourceUpdateAvailable()) {
- if (kind === "idle" || kind === "failed") {
- this.#setState({
- kind: "ready",
- version: this.#options.version,
- services: true,
- });
- this.#announce("services");
- }
- } else if (kind === "ready" && this.#state.services) {
- this.#setState({ kind: "idle" });
- }
- }
-
async #check(): Promise<void> {
const ctx = this.#ctx!;
const install = this.#options.install!;
@@ -288,7 +227,7 @@ export class UpdaterModule implements Module {
// offer until one is.
if (!bytes || !signature) {
ctx.log.info("update.no_manifest", { feed });
- this.#settle();
+ this.#setState({ kind: "idle" });
return;
}
const manifest = verifyManifest(
@@ -305,18 +244,17 @@ export class UpdaterModule implements Module {
compareVersions(manifest.version, this.#options.version) <= 0 ||
!pkg
) {
- this.#settle();
+ this.#setState({ kind: "idle" });
return;
}
const version = manifest.version;
if (install.kind === "download") {
ctx.log.info("update.available", { version });
- this.#setState({
+ this.#announce({
kind: "available",
version,
url: releasePageUrl(feed, version),
});
- this.#announce(version);
return;
}
this.#setState({ kind: "downloading", version });
@@ -328,20 +266,12 @@ export class UpdaterModule implements Module {
: { path: file, pkg };
if (install.kind === "app-bundle") await rm(file, { force: true });
ctx.log.info("update.ready", { version });
- this.#setState({ kind: "ready", version });
- this.#announce(version);
+ this.#announce({ kind: "ready", version });
} catch (error) {
this.#fail("update.check_failed", error);
- this.#offerServices();
}
}
- // Nothing newer: back to idle, or to the services update on offer.
- #settle(): void {
- this.#setState({ kind: "idle" });
- this.#offerServices();
- }
-
// Follows redirects: GitHub sends release files from another host. The
// signature and the checksums, not the host, decide what is trusted.
// Undefined when the file does not exist.
@@ -486,10 +416,12 @@ export class UpdaterModule implements Module {
}
}
- #announce(key: string): void {
- if (this.#announced.has(key)) return;
- this.#announced.add(key);
- this.#options.announce?.(this.#state);
+ // Sets the state and tells the person once per version.
+ #announce(state: AnnouncedUpdate): void {
+ this.#setState(state);
+ if (this.#announced.has(state.version)) return;
+ this.#announced.add(state.version);
+ this.#options.announce?.(state);
}
#fail(event: string, error: unknown): void {
diff --git a/docs/desktop-release.md b/docs/desktop-release.md
index 56371457..87e85018 100644
--- a/docs/desktop-release.md
+++ b/docs/desktop-release.md
@@ -177,9 +177,10 @@ how Linger was installed:
| Linux | The same as the portable folder. |
A system notification announces each new version once, and the tray shows the
-state; after a failure "Try Updating Again" checks at once. Without a newer app, the tray
-still offers to update the local services when they have a newer source; a
-newer app replaces that offer, because it brings its own source.
+state; after a failure "Try Updating Again" checks at once. The local
+services need no update of their own: the first launch of a newer app moves
+them to its source package (see LocalServer in
+[the desktop guide](../apps/desktop/AGENTS.md)).
`updateFeedUrl` in the desktop config (`config.json` in the app's data
folder) points the app at another releases URL with the same layout, such as