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.

feat(desktop): show the app version and update in the account menu

claude-opus-5-5-mediumadb58a072406
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.md
index 43ff741c..9ab7bda0 100644
--- a/apps/desktop/AGENTS.md
+++ b/apps/desktop/AGENTS.md
@@ -235,7 +235,9 @@ Gateway and runs Agents. The daemon exits with the app.
without a server says Back to Setup instead of Cancel.
- `src/shell/*.html`: app-owned pages (title bar, offline/setup page). They
have no network access and talk to the main process via `src/preload/shell.ts`.
-- `src/preload/index.ts`: the only SPA API, `window.lingerDesktop`.
+- `src/preload/index.ts`: the only SPA API, `window.lingerDesktop`. Its
+ `update` reads the Updater's state (without the release page URL) and runs
+ the tray's install and check, for the SPA's account menu.
- `src/shared/api.ts`, `src/shared/shell.ts`: preload contract types and IPC
channel names.
- `src/main/computer-daemon.ts`: ComputerDaemon. While the computer is
diff --git a/apps/desktop/src/main/desktop-ipc.test.ts b/apps/desktop/src/main/desktop-ipc.test.ts
index cb11b88e..96d4bb8d 100644
--- a/apps/desktop/src/main/desktop-ipc.test.ts
+++ b/apps/desktop/src/main/desktop-ipc.test.ts
@@ -1,6 +1,7 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { IPC } from "../shared/api.js";
+import type { UpdateState } from "./updater.js";
const handlers = vi.hoisted(
() => new Map<string, (event: unknown, ...args: unknown[]) => unknown>(),
@@ -16,6 +17,7 @@ vi.mock("electron", () => ({
}));
const { DesktopIpcModule } = await import("./desktop-ipc.js");
+const { EventBus } = await import("./modules.js");
const { stubModule, testHost } = await import("./test-support.js");
const SERVER = "http://localhost:3000";
@@ -32,22 +34,41 @@ const fixture = async (
servesWindow: vi.fn(localServer.servesWindow ?? (async () => true)),
signInWithAccount: vi.fn(localServer.signInWithAccount ?? (async () => {})),
};
+ let updateState: UpdateState = { kind: "idle" };
+ const updater = {
+ ...stubModule("Updater"),
+ state: () => updateState,
+ install: vi.fn(async () => {}),
+ check: vi.fn(async () => {}),
+ };
+ const send = vi.fn();
+ const windows = {
+ ...stubModule("WindowManager"),
+ webContents: () => ({ send }),
+ };
+ const bus = new EventBus();
const host = testHost(
[
stubModule("Enrollment"),
stubModule("PowerGuard"),
stubModule("ComputerDaemon"),
- stubModule("WindowManager"),
+ windows as never,
stubModule("WorkspaceGrants"),
+ updater as never,
local as never,
new DesktopIpcModule({ defaultDisplayName: "Desk" }),
],
{ serverUrl: SERVER },
+ bus,
);
await host.start();
const invoke = (channel: string, origin = SERVER) =>
handlers.get(channel)!({ senderFrame: { origin } });
- return { host, local, invoke };
+ const setUpdate = (state: UpdateState) => {
+ updateState = state;
+ bus.emit("update.changed", state.kind);
+ };
+ return { host, local, updater, send, setUpdate, invoke };
};
afterEach(() => handlers.clear());
@@ -98,3 +119,62 @@ describe("DesktopIpcModule local account", () => {
await f.host.stop("quit");
});
});
+
+describe("DesktopIpcModule updates", () => {
+ it("gives the page the update state without its release page URL", async () => {
+ const f = await fixture();
+ expect(await f.invoke(IPC.updateState)).toEqual({ kind: "idle" });
+ f.setUpdate({
+ kind: "available",
+ version: "0.2.0",
+ url: "https://github.com/example/linger/releases/tag/v0.2.0",
+ });
+ expect(await f.invoke(IPC.updateState)).toEqual({
+ kind: "available",
+ version: "0.2.0",
+ });
+ expect(f.send).toHaveBeenLastCalledWith(IPC.updateStateEvent, {
+ kind: "available",
+ version: "0.2.0",
+ });
+ await f.host.stop("quit");
+ });
+
+ it("pushes each change the tray shows", async () => {
+ const f = await fixture();
+ f.setUpdate({ kind: "downloading", version: "0.2.0" });
+ f.setUpdate({ kind: "ready", version: "0.2.0" });
+ f.setUpdate({ kind: "failed", error: "Update package does not match" });
+ expect(f.send.mock.calls).toEqual([
+ [IPC.updateStateEvent, { kind: "downloading", version: "0.2.0" }],
+ [IPC.updateStateEvent, { kind: "ready", version: "0.2.0" }],
+ [
+ IPC.updateStateEvent,
+ { kind: "failed", error: "Update package does not match" },
+ ],
+ ]);
+ await f.host.stop("quit");
+ f.setUpdate({ kind: "idle" });
+ expect(f.send).toHaveBeenCalledTimes(3);
+ });
+
+ it("installs and checks through the updater the tray uses", async () => {
+ const f = await fixture();
+ await f.invoke(IPC.updateInstall);
+ await f.invoke(IPC.updateCheck);
+ expect(f.updater.install).toHaveBeenCalledOnce();
+ expect(f.updater.check).toHaveBeenCalledOnce();
+ await f.host.stop("quit");
+ });
+
+ it("rejects update calls from any other origin", async () => {
+ const f = await fixture();
+ for (const channel of [IPC.updateState, IPC.updateInstall, IPC.updateCheck])
+ expect(() => f.invoke(channel, "https://evil.example.com")).toThrow(
+ "Not allowed",
+ );
+ expect(f.updater.install).not.toHaveBeenCalled();
+ expect(f.updater.check).not.toHaveBeenCalled();
+ await f.host.stop("quit");
+ });
+});
diff --git a/apps/desktop/src/main/desktop-ipc.ts b/apps/desktop/src/main/desktop-ipc.ts
index 24c5c042..85530677 100644
--- a/apps/desktop/src/main/desktop-ipc.ts
+++ b/apps/desktop/src/main/desktop-ipc.ts
@@ -5,6 +5,7 @@ import {
IPC,
type ComputerStatus,
type DesktopSettings,
+ type DesktopUpdateState,
type LocalAccountSignIn,
type WorkspaceGrantView,
} from "../shared/api.js";
@@ -19,6 +20,7 @@ import {
runDesktopPermissionStep,
type DesktopPermissionHost,
} from "./system-permissions.js";
+import type { UpdaterModule, UpdateState } from "./updater.js";
import type { WindowManagerModule } from "./window-manager.js";
import type { WorkspaceGrantsModule } from "./workspace-grants.js";
@@ -52,6 +54,13 @@ const permissionStepInput = z.discriminatedUnion("action", [
const view = (grant: WorkspaceGrant): WorkspaceGrantView => ({ ...grant });
+// The page learns what the tray shows; Install opens a release page itself,
+// so its URL stays in the main process.
+const updateView = (state: UpdateState): DesktopUpdateState =>
+ state.kind === "available"
+ ? { kind: state.kind, version: state.version }
+ : state;
+
// The preload API handlers. Every call must come from a frame on
// the configured server origin; inputs are validated with zod.
export class DesktopIpcModule implements Module {
@@ -63,6 +72,7 @@ export class DesktopIpcModule implements Module {
"ComputerDaemon",
"WindowManager",
"WorkspaceGrants",
+ "Updater",
];
readonly #defaultDisplayName: string;
// Set on macOS only.
@@ -84,6 +94,7 @@ export class DesktopIpcModule implements Module {
const windows = ctx.get<WindowManagerModule>("WindowManager");
const power = ctx.get<PowerGuardModule>("PowerGuard");
const localServer = ctx.get<LocalServerModule>("LocalServer");
+ const updater = ctx.get<UpdaterModule>("Updater");
const status = (): ComputerStatus => {
const computerId = ctx.config.get().computerId;
@@ -153,6 +164,10 @@ export class DesktopIpcModule implements Module {
}
});
+ handle(IPC.updateState, () => updateView(updater.state()));
+ handle(IPC.updateInstall, () => updater.install());
+ handle(IPC.updateCheck, () => updater.check());
+
const permissions = this.#permissions;
if (permissions)
handle(IPC.permissionAct, (step) =>
@@ -168,6 +183,11 @@ export class DesktopIpcModule implements Module {
ctx.bus.on("runtime.activity", push),
ctx.bus.on("power.changed", push),
ctx.bus.on("computer.changed", push),
+ ctx.bus.on("update.changed", () =>
+ windows
+ .webContents()
+ ?.send(IPC.updateStateEvent, updateView(updater.state())),
+ ),
);
}
diff --git a/apps/desktop/src/preload/index.ts b/apps/desktop/src/preload/index.ts
index a8b8f45e..dab39572 100644
--- a/apps/desktop/src/preload/index.ts
+++ b/apps/desktop/src/preload/index.ts
@@ -3,6 +3,7 @@ import { contextBridge, ipcRenderer } from "electron";
import {
IPC,
type ComputerStatus,
+ type DesktopUpdateState,
type LingerDesktopApi,
} from "../shared/api.js";
@@ -38,6 +39,19 @@ const api: LingerDesktopApi = {
available: () => ipcRenderer.invoke(IPC.localAccountAvailable),
signIn: () => ipcRenderer.invoke(IPC.localAccountSignIn),
},
+ update: {
+ getState: () => ipcRenderer.invoke(IPC.updateState),
+ onState: (callback) => {
+ const listener = (_event: unknown, state: DesktopUpdateState): void =>
+ callback(state);
+ ipcRenderer.on(IPC.updateStateEvent, listener);
+ return () => {
+ ipcRenderer.off(IPC.updateStateEvent, listener);
+ };
+ },
+ install: () => ipcRenderer.invoke(IPC.updateInstall),
+ check: () => ipcRenderer.invoke(IPC.updateCheck),
+ },
...(process.platform === "darwin"
? {
permissions: {
diff --git a/apps/desktop/src/shared/api.ts b/apps/desktop/src/shared/api.ts
index 8438e3aa..10b10ab1 100644
--- a/apps/desktop/src/shared/api.ts
+++ b/apps/desktop/src/shared/api.ts
@@ -53,6 +53,21 @@ export type DesktopPermissionStep =
}
| { readonly action: "relaunch"; readonly subject: "linger" };
+// The updater's progress as the page sees it; the same states the tray shows.
+export type DesktopUpdateState =
+ | { readonly kind: "idle" }
+ | { readonly kind: "checking" }
+ | {
+ readonly kind:
+ | "downloading"
+ | "ready"
+ | "waiting"
+ | "installing"
+ | "available";
+ readonly version: string;
+ }
+ | { readonly kind: "failed"; readonly error: string };
+
export interface LingerDesktopApi {
readonly version: string;
readonly platform: "darwin" | "win32" | "linux";
@@ -77,6 +92,16 @@ export interface LingerDesktopApi {
available(): Promise<boolean>;
signIn(): Promise<LocalAccountSignIn>;
};
+ // The app's own updates, as in the tray.
+ readonly update: {
+ getState(): Promise<DesktopUpdateState>;
+ onState(callback: (state: DesktopUpdateState) => void): () => void;
+ // Restart to Update, or open the release page of an update this
+ // installation cannot apply itself.
+ install(): Promise<void>;
+ // Try Again after a failure.
+ check(): Promise<void>;
+ };
// macOS only.
readonly permissions?: {
act(step: DesktopPermissionStep): Promise<void>;
@@ -96,4 +121,8 @@ export const IPC = {
permissionAct: "permission.act",
localAccountAvailable: "local-account.available",
localAccountSignIn: "local-account.sign-in",
+ updateState: "update.state",
+ updateStateEvent: "update.state.event",
+ updateInstall: "update.install",
+ updateCheck: "update.check",
} as const;
diff --git a/apps/web/src/features/auth/account-menu.test.tsx b/apps/web/src/features/auth/account-menu.test.tsx
new file mode 100644
index 00000000..3b819e95
--- /dev/null
+++ b/apps/web/src/features/auth/account-menu.test.tsx
@@ -0,0 +1,162 @@
+import { act, fireEvent, render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+import { AccountMenu } from "@/features/auth/account-menu";
+import type { DesktopUpdateState } from "@/features/auth/desktop-update";
+import type { TeamHubCurrentIdentity } from "@/features/teamhub/teamhub-types";
+
+const identity = {
+ account: { id: "account-1", email: "[email protected]" },
+ actors: [{ id: "actor-1", tenant_id: "tenant-1", display_name: "owner" }],
+} as unknown as TeamHubCurrentIdentity;
+
+const desktop = window as { lingerDesktop?: unknown };
+
+function installDesktop(state: DesktopUpdateState) {
+ let listener: ((next: DesktopUpdateState) => void) | undefined;
+ const off = vi.fn(() => {
+ listener = undefined;
+ });
+ const update = {
+ getState: vi.fn(async () => state),
+ onState: vi.fn((callback: (next: DesktopUpdateState) => void) => {
+ listener = callback;
+ return off;
+ }),
+ install: vi.fn(async () => {}),
+ check: vi.fn(async () => {}),
+ };
+ desktop.lingerDesktop = { version: "0.1.3", update };
+ return {
+ update,
+ off,
+ push: (next: DesktopUpdateState) => act(() => listener?.(next)),
+ };
+}
+
+function renderMenu() {
+ return render(
+ <AccountMenu
+ identity={identity}
+ tenantId="tenant-1"
+ isPending={false}
+ onLogout={vi.fn()}
+ onNavigate={vi.fn()}
+ onOpenSettings={vi.fn()}
+ />,
+ );
+}
+
+async function openMenu() {
+ fireEvent.click(screen.getByRole("button", { name: "Account menu" }));
+ return screen.getByRole("menu", { name: "Account menu" });
+}
+
+afterEach(() => {
+ delete desktop.lingerDesktop;
+});
+
+describe("AccountMenu desktop update", () => {
+ it("shows no version or update in a browser", async () => {
+ renderMenu();
+ const menu = await openMenu();
+ expect(menu).not.toHaveTextContent("Version");
+ expect(
+ screen.getAllByRole("menuitem").map((item) => item.textContent),
+ ).toEqual(["Settings", "Log out"]);
+ });
+
+ it("shows only the version while there is no update", async () => {
+ const { update } = installDesktop({ kind: "idle" });
+ renderMenu();
+ await vi.waitFor(() => expect(update.getState).toHaveBeenCalled());
+ const menu = await openMenu();
+ expect(menu).toHaveTextContent("Version 0.1.3");
+ expect(screen.queryByTestId("account-update-dot")).toBeNull();
+ expect(
+ screen.getAllByRole("menuitem").map((item) => item.textContent),
+ ).toEqual(["Settings", "Log out"]);
+ });
+
+ it("follows the download to Restart to Update and marks the avatar", async () => {
+ const { update, push } = installDesktop({
+ kind: "downloading",
+ version: "0.1.4",
+ });
+ renderMenu();
+ const menu = await openMenu();
+ await vi.waitFor(() =>
+ expect(menu).toHaveTextContent("Downloading Linger 0.1.4…"),
+ );
+ expect(screen.queryByRole("menuitem", { name: "Restart to Update" })).toBe(
+ null,
+ );
+ expect(screen.queryByTestId("account-update-dot")).toBeNull();
+
+ push({ kind: "ready", version: "0.1.4" });
+ expect(menu).toHaveTextContent("Linger 0.1.4 is ready to install");
+ expect(screen.getByTestId("account-update-dot")).toBeInTheDocument();
+ fireEvent.click(
+ screen.getByRole("menuitem", { name: "Restart to Update" }),
+ );
+ expect(update.install).toHaveBeenCalledOnce();
+ expect(update.check).not.toHaveBeenCalled();
+ });
+
+ it("offers the download page for an update the app cannot apply", async () => {
+ const { update } = installDesktop({ kind: "available", version: "0.1.4" });
+ renderMenu();
+ const menu = await openMenu();
+ await vi.waitFor(() =>
+ expect(menu).toHaveTextContent("Linger 0.1.4 is available"),
+ );
+ expect(screen.getByTestId("account-update-dot")).toBeInTheDocument();
+ fireEvent.click(screen.getByRole("menuitem", { name: "Download Update" }));
+ expect(update.install).toHaveBeenCalledOnce();
+ });
+
+ it("says why the update failed and checks again on Try Again", async () => {
+ const { update } = installDesktop({
+ kind: "failed",
+ error: "Update package does not match its checksum",
+ });
+ renderMenu();
+ const menu = await openMenu();
+ await vi.waitFor(() =>
+ expect(menu).toHaveTextContent(
+ "Update failed: Update package does not match its checksum",
+ ),
+ );
+ expect(screen.queryByTestId("account-update-dot")).toBeNull();
+ fireEvent.click(screen.getByRole("menuitem", { name: "Try Again" }));
+ expect(update.check).toHaveBeenCalledOnce();
+ expect(update.install).not.toHaveBeenCalled();
+ });
+
+ it("shows the version of a desktop build without the update bridge", async () => {
+ desktop.lingerDesktop = { version: "0.1.2" };
+ renderMenu();
+ const menu = await openMenu();
+ expect(menu).toHaveTextContent("Version 0.1.2");
+ expect(screen.queryByTestId("account-update-dot")).toBeNull();
+ });
+
+ it("subscribes once across rerenders and unsubscribes on unmount", async () => {
+ const { update, off } = installDesktop({ kind: "idle" });
+ const view = renderMenu();
+ view.rerender(
+ <AccountMenu
+ identity={identity}
+ tenantId="tenant-1"
+ isPending
+ onLogout={vi.fn()}
+ onNavigate={vi.fn()}
+ onOpenSettings={vi.fn()}
+ />,
+ );
+ expect(update.onState).toHaveBeenCalledOnce();
+ expect(off).not.toHaveBeenCalled();
+ view.unmount();
+ expect(off).toHaveBeenCalledOnce();
+ });
+});
diff --git a/apps/web/src/features/auth/account-menu.tsx b/apps/web/src/features/auth/account-menu.tsx
index 58342d0b..d387b491 100644
--- a/apps/web/src/features/auth/account-menu.tsx
+++ b/apps/web/src/features/auth/account-menu.tsx
@@ -1,9 +1,72 @@
-import { Logout01Icon, Settings01Icon } from "@hugeicons/core-free-icons";
+import {
+ Download04Icon,
+ Logout01Icon,
+ RefreshIcon,
+ Settings01Icon,
+} from "@hugeicons/core-free-icons";
-import { ActionMenu } from "@/components/ui/action-menu";
+import { ActionMenu, type ActionMenuItem } from "@/components/ui/action-menu";
import { Icon } from "@/components/ui/icon";
+import {
+ type DesktopUpdate,
+ useDesktopUpdate,
+} from "@/features/auth/desktop-update";
import { ActorAvatar } from "@/features/rooms/members/actor-avatar";
import type { TeamHubCurrentIdentity } from "@/features/teamhub/teamhub-types";
+import { cn } from "@/lib/cn";
+
+interface UpdatePresentation {
+ // One line under the version; none while nothing is happening.
+ readonly status?: string;
+ readonly tone?: "danger";
+ // A full error for the tooltip when the line is cut short.
+ readonly detail?: string;
+ readonly action?: { label: string; run: "install" | "check" };
+ // An update waits for the person: the avatar carries a dot.
+ readonly attention: boolean;
+}
+
+// What the account menu shows for the desktop app's updater state.
+function updatePresentation(state: DesktopUpdate["state"]): UpdatePresentation {
+ switch (state?.kind) {
+ case "checking":
+ return { status: "Checking for updates…", attention: false };
+ case "downloading":
+ return {
+ status: `Downloading Linger ${state.version}…`,
+ attention: false,
+ };
+ case "ready":
+ return {
+ status: `Linger ${state.version} is ready to install`,
+ action: { label: "Restart to Update", run: "install" },
+ attention: true,
+ };
+ case "waiting":
+ return {
+ status: `Updating to ${state.version} when tasks finish`,
+ attention: false,
+ };
+ case "installing":
+ return { status: `Updating to ${state.version}…`, attention: false };
+ case "available":
+ return {
+ status: `Linger ${state.version} is available`,
+ action: { label: "Download Update", run: "install" },
+ attention: true,
+ };
+ case "failed":
+ return {
+ status: `Update failed: ${state.error}`,
+ tone: "danger",
+ detail: state.error,
+ action: { label: "Try Again", run: "check" },
+ attention: false,
+ };
+ default:
+ return { attention: false };
+ }
+}
export function AccountMenu({
identity,
@@ -28,18 +91,48 @@ export function AccountMenu({
const name = currentActor?.display_name || identity.account.email;
const identifier = identity.account.email;
const inSettings = settingsOpen;
+ const desktop = useDesktopUpdate();
+ const update = updatePresentation(desktop?.state);
+ const action = desktop && update.action;
+ const updateItems: ActionMenuItem[] = action
+ ? [
+ {
+ label: action.label,
+ icon: (
+ <Icon
+ icon={
+ desktop.state?.kind === "available"
+ ? Download04Icon
+ : RefreshIcon
+ }
+ size={14}
+ />
+ ),
+ onSelect: action.run === "install" ? desktop.install : desktop.check,
+ },
+ ]
+ : [];
return (
<ActionMenu
label="Account menu"
placement="top-start"
buttonClassName={`flex size-11 items-center justify-center rounded-full outline-none transition-colors hover:bg-sidebar-muted aria-expanded:bg-sidebar-muted focus-visible:ring-2 focus-visible:ring-ring md:size-8 ${inSettings ? "bg-sidebar-muted" : ""}`}
trigger={
- <ActorAvatar
- actorId={currentActor?.id}
- kind="human"
- name={name}
- size="xs"
- />
+ <span className="relative flex">
+ <ActorAvatar
+ actorId={currentActor?.id}
+ kind="human"
+ name={name}
+ size="xs"
+ />
+ {desktop && update.attention ? (
+ <span
+ aria-hidden="true"
+ className="absolute -top-0.5 -right-0.5 size-2 rounded-full bg-(--app-unread) ring-2 ring-app-sidebar"
+ data-testid="account-update-dot"
+ />
+ ) : null}
+ </span>
}
header={
<>
@@ -49,14 +142,34 @@ export function AccountMenu({
<p className="truncate text-xs text-app-muted" title={identifier}>
{identifier}
</p>
+ {desktop ? (
+ <div className="mt-2 text-xs">
+ <p className="text-app-muted">Version {desktop.version}</p>
+ {update.status ? (
+ <p
+ className={cn(
+ "truncate",
+ update.tone === "danger"
+ ? "text-app-danger"
+ : "text-app-ink",
+ )}
+ title={update.detail ?? update.status}
+ >
+ {update.status}
+ </p>
+ ) : null}
+ </div>
+ ) : null}
</>
}
iconClassName="flex size-4 shrink-0 items-center justify-center text-muted-foreground"
itemClassName="flex min-h-[33px] w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-sm outline-none hover:bg-accent focus:bg-accent disabled:pointer-events-none disabled:opacity-50 max-md:min-h-11"
items={[
+ ...updateItems,
{
label: "Settings",
icon: <Icon icon={Settings01Icon} size={14} />,
+ separatorBefore: updateItems.length > 0,
onSelect: () => {
onNavigate();
onOpenSettings();
diff --git a/apps/web/src/features/auth/desktop-update.ts b/apps/web/src/features/auth/desktop-update.ts
new file mode 100644
index 00000000..85a3f9d3
--- /dev/null
+++ b/apps/web/src/features/auth/desktop-update.ts
@@ -0,0 +1,83 @@
+import { useEffect, useState } from "react";
+
+// The desktop app's updater (`window.lingerDesktop.update`), in the states
+// its tray shows.
+export type DesktopUpdateState =
+ | { readonly kind: "idle" }
+ | { readonly kind: "checking" }
+ | {
+ readonly kind:
+ | "downloading"
+ | "ready"
+ | "waiting"
+ | "installing"
+ | "available";
+ readonly version: string;
+ }
+ | { readonly kind: "failed"; readonly error: string };
+
+interface DesktopUpdateApi {
+ getState(): Promise<DesktopUpdateState>;
+ onState(callback: (state: DesktopUpdateState) => void): () => void;
+ install(): Promise<void>;
+ check(): Promise<void>;
+}
+
+interface DesktopShellApi {
+ readonly version?: string;
+ readonly update?: DesktopUpdateApi;
+}
+
+export interface DesktopUpdate {
+ // The running desktop app's version.
+ readonly version: string;
+ // Undefined until the desktop answers, and in builds without an updater
+ // bridge.
+ readonly state: DesktopUpdateState | undefined;
+ // Restart to Update, or open the download page when this installation
+ // cannot apply the update itself.
+ install(): void;
+ check(): void;
+}
+
+function desktopShellApi(): DesktopShellApi | undefined {
+ return typeof window === "undefined"
+ ? undefined
+ : (window as { lingerDesktop?: DesktopShellApi }).lingerDesktop;
+}
+
+/**
+ * The desktop app's version and update, or undefined in a browser. The
+ * desktop's updater decides everything; the page only shows its state and
+ * forwards the person's choice.
+ */
+export function useDesktopUpdate(): DesktopUpdate | undefined {
+ const [shell] = useState(desktopShellApi);
+ const [state, setState] = useState<DesktopUpdateState>();
+ const api = shell?.update;
+
+ useEffect(() => {
+ if (!api) return;
+ let active = true;
+ void api
+ .getState()
+ .then((next) => {
+ if (active) setState(next);
+ })
+ .catch(() => undefined);
+ const off = api.onState((next) => setState(next));
+ return () => {
+ active = false;
+ off();
+ };
+ }, [api]);
+
+ if (!shell?.version) return undefined;
+ return {
+ version: shell.version,
+ state,
+ // A failure arrives as the next state, which the menu shows.
+ install: () => void api?.install().catch(() => undefined),
+ check: () => void api?.check().catch(() => undefined),
+ };
+}
diff --git a/docs/desktop-release.md b/docs/desktop-release.md
index 8e8e2b4e..6dee1454 100644
--- a/docs/desktop-release.md
+++ b/docs/desktop-release.md
@@ -180,7 +180,12 @@ 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. The local
+state; after a failure "Try Updating Again" checks at once. The account menu
+in the window (the avatar at the bottom left) shows the app's version and the
+same state through `window.lingerDesktop.update`: "Restart to Update",
+"Download Update" for the release page, and "Try Again" call the same updater,
+and a dot on the avatar marks an update that is ready or available. A browser
+shows none of this. 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)).