Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

cua-spaces: compact T3-style update button in the sidebar (#5404)

Francesco Bonaccic4170c2a2dc5
diff --git a/apps/cua-spaces-web/src/bridge/adapters/demo.ts b/apps/cua-spaces-web/src/bridge/adapters/demo.ts
index 97a5b77cd0..6843b0f51c 100644
--- a/apps/cua-spaces-web/src/bridge/adapters/demo.ts
+++ b/apps/cua-spaces-web/src/bridge/adapters/demo.ts
@@ -94,7 +94,7 @@ export interface DemoOptions {
/** The machine the demo runs on: a Mac on Apple silicon unless set (the
* Electron shell passes its own system and architecture). */
platform?: DemoPlatform;
- /** Where the updater is at start (`?demo=update-ready`, `?demo=update-downloading`). */
+ /** Where the updater is at start (`?demo=update-ready`, `?demo=update-downloading`, `?demo=update-error`). */
update?: Partial<UpdateState>;
/** A This Mac prompt to show (`?demo=nudge-second-agent`, `?demo=nudge-risky`). */
nudge?: "second-agent" | "risky";
@@ -122,7 +122,7 @@ const DEMO_NOTES = "https://github.com/trycua/cua/releases/tag/cua-spaces-v0.9.3
* `?demo=mac-host` (New Space options and the Keyvault's Settings rows in the
* SwiftUI host's shape), `?demo=unenrolled` (this device not enrolled),
* `?demo=agents-readonly` (Cua can't write Hermes's config),
- * `?demo=update-ready` (an update is downloaded), `?demo=update-downloading`,
+ * `?demo=update-ready` (an update is downloaded), `?demo=update-downloading`, `?demo=update-error`,
* and `?demo=low-disk` / `?demo=disk-full` (This Mac almost out of space). */
export function demoOptionsFromSearch(search: string): DemoOptions {
const flags = new Set((new URLSearchParams(search).get("demo") ?? "").split(",").filter(Boolean));
@@ -151,7 +151,9 @@ export function demoOptionsFromSearch(search: string): DemoOptions {
? { update: { status: "downloaded" as const, version: "0.9.3", percent: 100, notesUrl: DEMO_NOTES } }
: flags.has("update-downloading")
? { update: { status: "downloading" as const, version: "0.9.3", percent: 42, notesUrl: DEMO_NOTES } }
- : {}),
+ : flags.has("update-error")
+ ? { update: { status: "error" as const, message: "The network connection was lost." } }
+ : {}),
};
}
diff --git a/apps/cua-spaces-web/src/bridge/adapters/demo/settings.ts b/apps/cua-spaces-web/src/bridge/adapters/demo/settings.ts
index ccf7c1377a..cd707d4718 100644
--- a/apps/cua-spaces-web/src/bridge/adapters/demo/settings.ts
+++ b/apps/cua-spaces-web/src/bridge/adapters/demo/settings.ts
@@ -209,9 +209,11 @@ export function createDemoSettings(ctx: DemoSettingsContext): Handlers {
},
"update.get": () => ({ ...update }),
- "update.install": () => {
+ "update.install": async () => {
// Nothing downloaded: nothing to install, and the state says so.
if (update.status !== "downloaded") return { ...update };
+ // Installing takes a moment before the relaunch.
+ await wait(stepMs);
// The real host relaunches into the new version.
update = { ...update, status: "idle", currentVersion: update.version ?? update.currentVersion, version: null, notesUrl: null };
emit({ type: "update.changed" });
diff --git a/apps/cua-spaces-web/src/components/shell/relay-allowance-notice.tsx b/apps/cua-spaces-web/src/components/shell/relay-allowance-notice.tsx
index 29868e3e95..c5205b1035 100644
--- a/apps/cua-spaces-web/src/components/shell/relay-allowance-notice.tsx
+++ b/apps/cua-spaces-web/src/components/shell/relay-allowance-notice.tsx
@@ -24,17 +24,6 @@ const subscribe = (l: () => void) => {
return () => listeners.delete(l);
};
-/**
- * Whether the allowance notice is on screen now. The update indicator
- * (`update-indicator.tsx`) steps back to an icon while it is, so the two
- * prompts are never both open at once.
- */
-export function useRelayAllowanceShowing(): boolean {
- const notice = useRelayUsageView()?.notice;
- const dismissed = useSyncExternalStore(subscribe, readDismissed, () => null);
- return Boolean(notice) && dismissed !== notice?.dismissKey;
-}
-
/**
* The relay allowance for the month: one line above every page with
* Upgrade, until dismissed (for that month and reason: the core's
diff --git a/apps/cua-spaces-web/src/components/shell/sidebar.tsx b/apps/cua-spaces-web/src/components/shell/sidebar.tsx
index 2ba838c6df..67a1923093 100644
--- a/apps/cua-spaces-web/src/components/shell/sidebar.tsx
+++ b/apps/cua-spaces-web/src/components/shell/sidebar.tsx
@@ -2,7 +2,7 @@
// Copyright (c) 2026 Cua AI, Inc.
import { Link } from "@tanstack/react-router";
-import { useEffect, useRef, useState, type PointerEvent } from "react";
+import { useEffect, useRef, useState, type PointerEvent, type ReactNode } from "react";
import { Loader2Icon, LogOutIcon, TriangleAlertIcon } from "lucide-react";
@@ -21,7 +21,7 @@ import { SIDEBAR_DEFAULT, useUiStore } from "@/stores/ui";
import { Shortcut } from "@/components/ui/kbd";
import { SignInLink } from "@/components/sign-in-link";
import { useNavItems } from "./nav";
-import { SidebarUpdateIndicator } from "./update-indicator";
+import { SidebarUpdateButton } from "./update-indicator";
import { SidebarGetStarted } from "@/components/getting-started";
export function Sidebar() {
@@ -78,9 +78,8 @@ export function Sidebar() {
</nav>
<div className="mt-auto">
<SidebarCreating spaces={spaces ?? []} />
- <SidebarUpdateIndicator />
<SidebarGetStarted />
- <AccountFooter />
+ <AccountFooter trailing={<SidebarUpdateButton />} />
</div>
<ResizeHandle />
</aside>
@@ -121,8 +120,9 @@ function SidebarCreating({ spaces }: { spaces: Space[] }) {
/** The account and its sign-in, every state in one place (the core's
* `signIn.footer`): signed in as, waiting for the browser with the code,
* Open again and Cancel, or why it failed with Try again and a toast. And a
- * way back into a first run left halfway. */
-export function AccountFooter() {
+ * way back into a first run left halfway. `trailing` (the update button)
+ * sits at the far right of its first row. */
+export function AccountFooter({ trailing }: { trailing?: ReactNode }) {
const { core } = useBridge();
const { data: session, signIn, signOut, cancelSignIn, openExternal } = useSession();
const plan = useRelayUsageView()?.planCard;
@@ -145,7 +145,7 @@ export function AccountFooter() {
// The last attempt used a code: another code would not help.
const triedCode = useRef(false);
if (footer?.state === "waiting" && footer.code) triedCode.current = true;
- if (!session || !footer) return <div className="mt-auto h-12 border-t" />;
+ if (!session || !footer) return <div className="mt-auto flex h-12 items-center justify-end border-t px-3">{trailing}</div>;
const unfinished = !session.onboarding.completed;
const run = (f: () => Promise<unknown>, what: string) =>
@@ -204,6 +204,7 @@ export function AccountFooter() {
</Button>
</Tooltip>
) : null}
+ {trailing}
</div>
) : footer.state === "starting" || footer.state === "waiting" ? (
// The code to confirm, the page to open again if the tab was
@@ -211,7 +212,8 @@ export function AccountFooter() {
<div>
<p className="flex items-center gap-2 text-xs" role="status">
<Loader2Icon className="size-3.5 shrink-0 animate-spin text-muted-foreground" aria-hidden />
- <span className="truncate">{footer.text}</span>
+ <span className="min-w-0 flex-1 truncate">{footer.text}</span>
+ <span className="shrink-0">{trailing}</span>
</p>
<div className="mt-1 flex flex-wrap items-center gap-x-1 pl-5.5 text-2xs text-muted-foreground">
{footer.code ? (
@@ -285,6 +287,7 @@ export function AccountFooter() {
{footer.detailsLabel}
</button>
) : null}
+ <span className="ml-auto">{trailing}</span>
</div>
{details && footer.detail ? (
<pre className="mt-2 max-h-28 overflow-auto rounded-md bg-muted px-2 py-1.5 font-mono text-2xs break-words whitespace-pre-wrap text-muted-foreground select-text">
@@ -295,11 +298,14 @@ export function AccountFooter() {
) : (
<div className="flex items-center justify-between gap-2">
<span className="truncate text-xs text-muted-foreground">{footer.text}</span>
- {footer.actionLabel ? (
- <Button variant="outline" size="sm" onClick={startSignIn}>
- {footer.actionLabel}
- </Button>
- ) : null}
+ <div className="flex shrink-0 items-center gap-1.5">
+ {footer.actionLabel ? (
+ <Button variant="outline" size="sm" onClick={startSignIn}>
+ {footer.actionLabel}
+ </Button>
+ ) : null}
+ {trailing}
+ </div>
</div>
)}
</div>
diff --git a/apps/cua-spaces-web/src/components/shell/update-copy.test.ts b/apps/cua-spaces-web/src/components/shell/update-copy.test.ts
index ee0ef88b14..f46878171e 100644
--- a/apps/cua-spaces-web/src/components/shell/update-copy.test.ts
+++ b/apps/cua-spaces-web/src/components/shell/update-copy.test.ts
@@ -4,14 +4,19 @@
import { describe, expect, it } from "vitest";
import type { UpdateState } from "@/bridge";
-import { restartWarning, runsInProgress, updateView } from "./update-copy";
+import { restartWarning, runsInProgress, updateTooltip, updateView } from "./update-copy";
const base: UpdateState = { status: "idle", currentVersion: "0.9.2", version: null, percent: null, notesUrl: null, message: null };
describe("updateView", () => {
- it("is quiet while idle, checking or failed", () => {
+ it("is quiet while idle or checking", () => {
expect(updateView(undefined)).toBeNull();
- for (const status of ["idle", "checking", "error"] as const) expect(updateView({ ...base, status, message: "offline" })).toBeNull();
+ for (const status of ["idle", "checking"] as const) expect(updateView({ ...base, status })).toBeNull();
+ });
+
+ it("says a failed step will be retried", () => {
+ expect(updateView({ ...base, status: "error", message: "The network is offline." })).toEqual({ kind: "error", label: "Couldn't update: The network is offline. Cua Spaces tries again later." });
+ expect(updateView({ ...base, status: "error" })).toEqual({ kind: "error", label: "Couldn't update. Cua Spaces tries again later." });
});
it("says it is downloading, with the percent when the host has one", () => {
@@ -24,6 +29,15 @@ describe("updateView", () => {
expect(updateView({ ...base, status: "downloaded", version: "0.9.3", percent: 100 })).toEqual({ kind: "ready", label: "Update ready", detail: "Cua Spaces 0.9.3" });
expect(updateView({ ...base, status: "downloaded" })).toEqual({ kind: "ready", label: "Update ready", detail: "A new version of Cua Spaces" });
});
+
+ it("says it is installing while Restart to update runs", () => {
+ expect(updateView({ ...base, status: "downloaded", version: "0.9.3" }, true)).toEqual({ kind: "installing", label: "Installing update 0.9.3…" });
+ });
+
+ it("tooltips name the next step when ready", () => {
+ expect(updateTooltip({ kind: "ready", label: "Update ready", detail: "Cua Spaces 0.9.3" })).toBe("Update ready: restart to install");
+ expect(updateTooltip({ kind: "downloading", label: "Downloading update 0.9.3 (42%)", percent: 42 })).toBe("Downloading update 0.9.3 (42%)");
+ });
});
describe("restart guard", () => {
diff --git a/apps/cua-spaces-web/src/components/shell/update-copy.ts b/apps/cua-spaces-web/src/components/shell/update-copy.ts
index fd610cb9d2..31963c84b0 100644
--- a/apps/cua-spaces-web/src/components/shell/update-copy.ts
+++ b/apps/cua-spaces-web/src/components/shell/update-copy.ts
@@ -3,17 +3,20 @@
import type { UpdateState } from "@/bridge";
-/** What the in-app update indicator shows for the host's updater. It is quiet:
- * only a found, a downloading or a downloaded update shows anything. */
+/** What the sidebar's update button shows for the host's updater. It is
+ * quiet: idle and checking show nothing. */
export type UpdateView =
| { kind: "downloading"; label: string; percent: number | null }
- | { kind: "ready"; label: string; detail: string };
+ | { kind: "ready"; label: string; detail: string }
+ | { kind: "installing"; label: string }
+ | { kind: "error"; label: string };
const versionText = (version: string | null) => (version ? ` ${version}` : "");
-/** The indicator for `state`; null when there is nothing to show (idle,
- * checking, or a failed background step: the next check tries again). */
-export function updateView(state: UpdateState | undefined): UpdateView | null {
+/** The button for `state` (`installing`: "Restart to update" is running);
+ * null when there is nothing to show. A failed step shows a muted icon:
+ * the next check tries again on its own. */
+export function updateView(state: UpdateState | undefined, installing = false): UpdateView | null {
if (!state) return null;
switch (state.status) {
case "available":
@@ -22,12 +25,20 @@ export function updateView(state: UpdateState | undefined): UpdateView | null {
return { kind: "downloading", label: `Downloading update${versionText(state.version)}${percent === null ? "…" : ` (${percent}%)`}`, percent };
}
case "downloaded":
+ if (installing) return { kind: "installing", label: `Installing update${versionText(state.version)}…` };
return { kind: "ready", label: "Update ready", detail: state.version ? `Cua Spaces ${state.version}` : "A new version of Cua Spaces" };
+ case "error":
+ return { kind: "error", label: `Couldn't update${state.message ? `: ${state.message.replace(/\.$/, "")}` : ""}. Cua Spaces tries again later.` };
default:
return null;
}
}
+/** The button's tooltip. */
+export function updateTooltip(view: UpdateView): string {
+ return view.kind === "ready" ? `${view.label}: restart to install` : view.label;
+}
+
/** Work a restart would cut short: the runs still working. */
export function runsInProgress(runs: readonly { status: string }[] | undefined): number {
return runs?.filter((r) => r.status === "running").length ?? 0;
diff --git a/apps/cua-spaces-web/src/components/shell/update-indicator.test.tsx b/apps/cua-spaces-web/src/components/shell/update-indicator.test.tsx
index 950dce2e2f..66722615b0 100644
--- a/apps/cua-spaces-web/src/components/shell/update-indicator.test.tsx
+++ b/apps/cua-spaces-web/src/components/shell/update-indicator.test.tsx
@@ -2,28 +2,22 @@
// Copyright (c) 2026 Cua AI, Inc.
import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
-import { afterEach, describe, expect, it, vi } from "vitest";
+import { afterEach, describe, expect, it } from "vitest";
import { createDemoAdapter } from "@/bridge/adapters/demo";
import { noCore } from "@/bridge/__tests__/testCore";
import { BridgeProvider, type DataAdapter, type UpdateState } from "@/bridge";
-const upsell = vi.hoisted(() => ({ open: false }));
-vi.mock("./relay-allowance-notice", () => ({ useRelayAllowanceShowing: () => upsell.open }));
+import { SidebarUpdateButton, TopBarUpdateIndicator } from "./update-indicator";
-import { SidebarUpdateIndicator, TopBarUpdateIndicator } from "./update-indicator";
-
-afterEach(() => {
- cleanup();
- upsell.open = false;
-});
+afterEach(cleanup);
const NOTES = "https://github.com/trycua/cua/releases/tag/cua-spaces-v0.9.3";
const ready: Partial<UpdateState> = { status: "downloaded", version: "0.9.3", percent: 100, notesUrl: NOTES };
/** The demo host with an updater in `update`, recording what the page asks of it. */
function host(update: Partial<UpdateState> | undefined, opts: { quiet?: boolean } = {}) {
- const demo = createDemoAdapter({ latencyMs: 0, update });
+ const demo = createDemoAdapter({ latencyMs: 0, stepMs: 0, update });
const calls: string[] = [];
const opened: string[] = [];
const adapter: DataAdapter = {
@@ -39,7 +33,7 @@ function host(update: Partial<UpdateState> | undefined, opts: { quiet?: boolean
return demo.call(op, args);
},
};
- const view = (ui = <SidebarUpdateIndicator />) =>
+ const view = (ui = <SidebarUpdateButton />) =>
render(
<BridgeProvider adapter={adapter} core={noCore}>
{ui}
@@ -48,7 +42,13 @@ function host(update: Partial<UpdateState> | undefined, opts: { quiet?: boolean
return { demo, calls, opened, view };
}
-describe("<SidebarUpdateIndicator>", () => {
+/** Opens the ready button's popover. */
+async function openReady() {
+ fireEvent.click(await screen.findByRole("button", { name: "Update ready: restart to install" }));
+ return screen.findByRole("dialog");
+}
+
+describe("<SidebarUpdateButton>", () => {
it("shows nothing while up to date", async () => {
const { view, calls } = host(undefined);
view();
@@ -57,53 +57,71 @@ describe("<SidebarUpdateIndicator>", () => {
expect(document.querySelector("[data-update-indicator]")).toBeNull();
});
- it("shows the download quietly, with its percent and no button", async () => {
+ it("is one quiet icon while downloading, named with the version and percent, with no dot", async () => {
const { view } = host({ status: "downloading", version: "0.9.3", percent: 42 });
view();
- const row = await screen.findByRole("status");
- expect(row.textContent).toBe("Downloading update 0.9.3 (42%)");
- expect(screen.queryByRole("button")).toBeNull();
+ const button = await screen.findByRole("button", { name: "Downloading update 0.9.3 (42%)" });
+ expect(button.getAttribute("data-update-icon")).toBe("downloading");
+ expect(document.querySelector("[data-update-dot]")).toBeNull();
+ // No text in the sidebar: the name is the tooltip and the label.
+ expect(screen.queryByText(/Downloading/)).toBeNull();
});
- it("when ready, offers Restart to update and a What's new link to the release notes", async () => {
+ it("when ready, adds one dot; a click offers Restart to update and a What's new link", async () => {
const { view, calls, opened } = host(ready, { quiet: true });
view();
- expect(await screen.findByText("Update ready")).toBeTruthy();
- expect(screen.getByText("Cua Spaces 0.9.3")).toBeTruthy();
+ await screen.findByRole("button", { name: "Update ready: restart to install" });
+ expect(document.querySelectorAll("[data-update-dot]")).toHaveLength(1);
+ const popover = await openReady();
+ expect(popover.textContent).toContain("Cua Spaces 0.9.3");
fireEvent.click(screen.getByText("What's new"));
await waitFor(() => expect(opened).toEqual([NOTES]));
// Nothing installed until the click.
expect(calls).not.toContain("update.install");
fireEvent.click(screen.getByRole("button", { name: "Restart to update" }));
await waitFor(() => expect(calls).toContain("update.install"));
- // The demo host relaunched into 0.9.3: the indicator is gone.
+ // The demo host relaunched into 0.9.3: the button is gone.
await waitFor(() => expect(document.querySelector("[data-update-indicator]")).toBeNull());
});
+ it("spins while Restart to update runs", async () => {
+ const demo = createDemoAdapter({ latencyMs: 0, stepMs: 200, update: ready });
+ const adapter: DataAdapter = { ...demo, call: (op, args) => (op === "agents.runs" ? (Promise.resolve([]) as ReturnType<typeof demo.call>) : demo.call(op, args)) };
+ render(
+ <BridgeProvider adapter={adapter} core={noCore}>
+ <SidebarUpdateButton />
+ </BridgeProvider>,
+ );
+ await openReady();
+ fireEvent.click(screen.getByRole("button", { name: "Restart to update" }));
+ expect(await screen.findByRole("button", { name: "Installing update 0.9.3…" })).toBeTruthy();
+ });
+
it("asks before restarting while an agent is running; Not now changes nothing, Restart anyway installs", async () => {
const { view, calls } = host(ready);
view();
// The demo has a run in progress.
await waitFor(() => expect(calls).toContain("agents.runs"));
await act(() => new Promise((r) => setTimeout(r, 20)));
- fireEvent.click(await screen.findByRole("button", { name: "Restart to update" }));
+ await openReady();
+ fireEvent.click(screen.getByRole("button", { name: "Restart to update" }));
const dialog = await screen.findByRole("alertdialog");
expect(dialog.textContent).toContain("Restarting Cua Spaces now stops");
fireEvent.click(screen.getByRole("button", { name: "Not now" }));
await waitFor(() => expect(screen.queryByRole("alertdialog")).toBeNull());
expect(calls).not.toContain("update.install");
+ await openReady();
fireEvent.click(screen.getByRole("button", { name: "Restart to update" }));
fireEvent.click(await screen.findByRole("button", { name: "Restart anyway" }));
await waitFor(() => expect(calls).toContain("update.install"));
});
- it("steps back to an icon while an upgrade prompt is open", async () => {
- upsell.open = true;
- const { view } = host(ready);
+ it("is a muted icon after a failed step, saying why", async () => {
+ const { view } = host({ status: "error", message: "The network connection was lost." });
view();
- expect(await screen.findByRole("button", { name: "Update ready: restart to install" })).toBeTruthy();
- expect(screen.queryByText("Restart to update")).toBeNull();
- expect(screen.queryByText("What's new")).toBeNull();
+ const button = await screen.findByRole("button", { name: "Couldn't update: The network connection was lost. Cua Spaces tries again later." });
+ fireEvent.click(button);
+ expect(screen.queryByRole("dialog")).toBeNull();
});
it("shows nothing on a host with no updater (the call is unsupported)", async () => {
@@ -111,7 +129,7 @@ describe("<SidebarUpdateIndicator>", () => {
const adapter: DataAdapter = { ...demo, call: (op, args) => (op === "update.get" ? Promise.reject(Object.assign(new Error("unsupported"), { code: "unsupported" })) : demo.call(op, args)) } as DataAdapter;
render(
<BridgeProvider adapter={adapter} core={noCore}>
- <SidebarUpdateIndicator />
+ <SidebarUpdateButton />
</BridgeProvider>,
);
await act(() => new Promise((r) => setTimeout(r, 10)));
@@ -120,7 +138,7 @@ describe("<SidebarUpdateIndicator>", () => {
});
describe("<TopBarUpdateIndicator>", () => {
- it("is one icon with the same name, for when the sidebar is closed", async () => {
+ it("is the same button, for when the sidebar is closed", async () => {
const { view } = host(ready);
view(<TopBarUpdateIndicator />);
expect(await screen.findByRole("button", { name: "Update ready: restart to install" })).toBeTruthy();
diff --git a/apps/cua-spaces-web/src/components/shell/update-indicator.tsx b/apps/cua-spaces-web/src/components/shell/update-indicator.tsx
index e1ac17aab8..fa02fd21e5 100644
--- a/apps/cua-spaces-web/src/components/shell/update-indicator.tsx
+++ b/apps/cua-spaces-web/src/components/shell/update-indicator.tsx
@@ -1,21 +1,21 @@
// SPDX-License-Identifier: FSL-1.1-MIT
// Copyright (c) 2026 Cua AI, Inc.
-import { CheckIcon, DownloadIcon, RotateCwIcon } from "lucide-react";
-import { useState } from "react";
+import { Popover as PopoverPrimitive } from "@base-ui/react/popover";
+import { DownloadIcon, LoaderCircleIcon } from "lucide-react";
+import { useState, type ReactElement } from "react";
import { useAgents, useSession, useUpdate } from "@/bridge";
import { Button } from "@/components/ui/button";
import { ConfirmDialog } from "@/components/ui/alert-dialog";
-import { Menu } from "@/components/ui/menu";
import { toast } from "@/components/ui/toast";
+import { Tooltip } from "@/components/ui/tooltip";
import { cn } from "@/lib/utils";
-import { useRelayAllowanceShowing } from "./relay-allowance-notice";
-import { restartWarning, runsInProgress, updateView, type UpdateView } from "./update-copy";
+import { restartWarning, runsInProgress, updateTooltip, updateView, type UpdateView } from "./update-copy";
/**
- * Everything the indicator needs: what the host's updater shows, and the two
- * actions. "Restart to update" asks first while an agent is running, and the
+ * Everything the button needs (also the Machines page's "Restart to update"
+ * issue action): what the host's updater shows, and the two actions. "Restart to update" asks first while an agent is running, and the
* host restarts only on this call: nothing here restarts on its own.
*/
export function useUpdateIndicator() {
@@ -23,7 +23,8 @@ export function useUpdateIndicator() {
const { data: agents } = useAgents();
const { openExternal } = useSession();
const [asking, setAsking] = useState(false);
- const view = updateView(data?.state);
+ const installing = data?.installing ?? false;
+ const view = updateView(data?.state, installing);
const running = runsInProgress(agents?.runs);
const notesUrl = data?.state.notesUrl ?? null;
@@ -33,7 +34,7 @@ export function useUpdateIndicator() {
return {
view,
running,
- installing: data?.installing ?? false,
+ installing,
asking,
setAsking,
restart: () => (running > 0 ? setAsking(true) : restartNow()),
@@ -42,17 +43,9 @@ export function useUpdateIndicator() {
};
}
-function ReadyIcon() {
- return (
- <span className="relative grid size-4 place-items-center" aria-hidden>
- <RotateCwIcon className="size-4" strokeWidth={1.75} />
- <span className="absolute -right-1 -bottom-1 grid size-2.5 place-items-center rounded-full bg-foreground text-background ring-2 ring-sidebar">
- <CheckIcon className="size-2" strokeWidth={3} />
- </span>
- </span>
- );
-}
+type UpdateButtonUi = ReturnType<typeof useUpdateIndicator>;
+/** The download arrow in a ring that fills with the download. */
function ProgressRing({ percent }: { percent: number | null }) {
const r = 7;
const c = 2 * Math.PI * r;
@@ -60,99 +53,122 @@ function ProgressRing({ percent }: { percent: number | null }) {
<span className="relative grid size-5 place-items-center" aria-hidden>
<svg viewBox="0 0 20 20" className={cn("absolute inset-0 size-full -rotate-90", percent === null && "animate-spin")}>
<circle cx="10" cy="10" r={r} fill="none" className="stroke-current/20" strokeWidth="1.5" />
- <circle cx="10" cy="10" r={r} fill="none" stroke="currentColor" strokeLinecap="round" strokeWidth="1.5" strokeDasharray={c} strokeDashoffset={c * (1 - (percent ?? 25) / 100)} className="motion-reduce:transition-none" />
+ <circle cx="10" cy="10" r={r} fill="none" stroke="currentColor" strokeLinecap="round" strokeWidth="1.5" strokeDasharray={c} strokeDashoffset={c * (1 - (percent ?? 25) / 100)} className="transition-[stroke-dashoffset] duration-300 motion-reduce:transition-none" />
</svg>
- <DownloadIcon className="size-2.5" />
+ <DownloadIcon className="size-2.5" strokeWidth={2} />
</span>
);
}
-export function RestartDialog({ ui }: { ui: ReturnType<typeof useUpdateIndicator> }) {
- const w = restartWarning(ui.running);
+/** The same arrow, with one accent dot: the update is ready. */
+function ReadyIcon() {
return (
- <ConfirmDialog open={ui.asking} onOpenChange={ui.setAsking} title={w.title} description={w.description} confirmLabel={w.confirm} cancelLabel={w.cancel} destructive onConfirm={ui.restartNow} />
+ <span className="relative grid size-4 place-items-center" aria-hidden>
+ <DownloadIcon className="size-4" strokeWidth={1.75} />
+ <span data-update-dot="" className="absolute -top-0.5 -right-0.5 size-1.5 rounded-full bg-brand ring-2 ring-sidebar" />
+ </span>
);
}
-/**
- * The sidebar's update line, above the account: quiet while it downloads,
- * and a "Restart to update" with a "What's new" link once it is ready. While
- * the relay allowance notice (an upgrade prompt) is open it shrinks to an
- * icon, so the two are never both open.
- */
-export function SidebarUpdateIndicator() {
- const ui = useUpdateIndicator();
- const upsellOpen = useRelayAllowanceShowing();
- if (!ui.view) return null;
- if (ui.view.kind === "downloading") return <DownloadingRow view={ui.view} />;
+function UpdateIcon({ view }: { view: UpdateView }) {
+ switch (view.kind) {
+ case "downloading":
+ return <ProgressRing percent={view.percent} />;
+ case "ready":
+ return <ReadyIcon />;
+ case "installing":
+ return <LoaderCircleIcon className="size-4 animate-spin" strokeWidth={1.75} aria-hidden />;
+ case "error":
+ return <DownloadIcon className="size-4 opacity-50" strokeWidth={1.75} aria-hidden />;
+ }
+}
+
+export function RestartDialog({ ui }: { ui: UpdateButtonUi }) {
+ const w = restartWarning(ui.running);
+ return <ConfirmDialog open={ui.asking} onOpenChange={ui.setAsking} title={w.title} description={w.description} confirmLabel={w.confirm} cancelLabel={w.cancel} destructive onConfirm={ui.restartNow} />;
+}
+
+/** What a click on the ready button opens: Restart to update, and What's new. */
+function ReadyPopover({ ui, view, trigger, tip, side }: { ui: UpdateButtonUi; view: Extract<UpdateView, { kind: "ready" }>; trigger: ReactElement; tip: string; side: "top" | "bottom" }) {
+ const [open, setOpen] = useState(false);
return (
- <div data-update-indicator="ready" className="border-t px-3 py-2.5">
- {upsellOpen ? (
- <UpdateMenu ui={ui} compact />
- ) : (
- <>
- <div className="flex items-center gap-2.5">
- <span className="text-muted-foreground">
- <ReadyIcon />
- </span>
- <div className="min-w-0 flex-1 leading-tight">
- <div className="truncate text-xs font-medium">{ui.view.label}</div>
- <div className="truncate text-2xs text-muted-foreground">{ui.view.detail}</div>
- </div>
- </div>
- <div className="mt-2 flex items-center gap-3">
- <Button size="sm" variant="outline" className="min-w-0 flex-1" data-update-restart="" disabled={ui.installing} onClick={ui.restart}>
+ <PopoverPrimitive.Root open={open} onOpenChange={setOpen}>
+ <Tooltip content={tip} side={side}>
+ <PopoverPrimitive.Trigger render={trigger} />
+ </Tooltip>
+ <PopoverPrimitive.Portal>
+ <PopoverPrimitive.Positioner side={side} align="end" sideOffset={6} className="z-50 outline-none">
+ <PopoverPrimitive.Popup
+ data-update-popover=""
+ className="glass w-56 origin-(--transform-origin) rounded-lg border p-3 text-popover-foreground shadow-float outline-none transition-[opacity,scale] data-ending-style:scale-95 data-ending-style:opacity-0 data-starting-style:scale-95 data-starting-style:opacity-0"
+ >
+ <PopoverPrimitive.Title className="text-xs font-medium">{view.label}</PopoverPrimitive.Title>
+ <PopoverPrimitive.Description className="text-2xs text-muted-foreground">{view.detail}</PopoverPrimitive.Description>
+ <Button
+ size="sm"
+ className="mt-2.5 w-full"
+ data-update-restart=""
+ disabled={ui.installing}
+ onClick={() => {
+ setOpen(false);
+ ui.restart();
+ }}
+ >
Restart to update
</Button>
{ui.whatsNew ? (
- <button type="button" data-update-whats-new="" onClick={ui.whatsNew} className="shrink-0 text-2xs text-muted-foreground underline decoration-dotted underline-offset-4 hover:text-foreground">
+ <button
+ type="button"
+ data-update-whats-new=""
+ onClick={ui.whatsNew}
+ className="mt-2 block w-full text-center text-2xs text-muted-foreground underline decoration-dotted underline-offset-4 hover:text-foreground"
+ >
What's new
</button>
) : null}
- </div>
- </>
- )}
- <RestartDialog ui={ui} />
- </div>
+ </PopoverPrimitive.Popup>
+ </PopoverPrimitive.Positioner>
+ </PopoverPrimitive.Portal>
+ </PopoverPrimitive.Root>
);
}
-function DownloadingRow({ view }: { view: Extract<UpdateView, { kind: "downloading" }> }) {
- return (
- <div data-update-indicator="downloading" role="status" className="flex items-center gap-2.5 border-t px-3 py-2.5 text-muted-foreground">
- <ProgressRing percent={view.percent} />
- <span className="min-w-0 flex-1 truncate text-2xs">{view.label}</span>
- </div>
- );
-}
-
-/** One icon with the same actions in a menu: the top bar (sidebar closed) and the compact sidebar. */
-function UpdateMenu({ ui, compact = false }: { ui: ReturnType<typeof useUpdateIndicator>; compact?: boolean }) {
- if (!ui.view) return null;
- const tip = ui.view.kind === "ready" ? `${ui.view.label}: restart to install` : ui.view.label;
- const items = ui.view.kind === "ready" ? [{ label: "Restart to update", onSelect: ui.restart, disabled: ui.installing }, ...(ui.whatsNew ? [{ label: "What's new", onSelect: ui.whatsNew }] : [])] : [];
- const icon = ui.view.kind === "ready" ? <ReadyIcon /> : <ProgressRing percent={ui.view.percent} />;
+/**
+ * The update button: a small icon, hidden while up to date. Downloading
+ * fills a ring around the arrow; ready adds one accent dot, and a click
+ * opens Restart to update and What's new; installing spins; a failed step
+ * is a muted arrow whose tooltip says why. Its tooltip names the state.
+ */
+function UpdateButton({ side }: { side: "top" | "bottom" }) {
+ const ui = useUpdateIndicator();
+ const { view } = ui;
+ if (!view) return null;
+ const tip = updateTooltip(view);
const button = (
- <Button variant="ghost" size="icon-sm" aria-label={tip} title={tip} data-update-icon="" className={cn("text-muted-foreground", compact && "w-full justify-start gap-2 px-1.5")}>
- {icon}
- {compact ? <span className="truncate text-2xs">{ui.view.label}</span> : null}
+ <Button variant="ghost" size="icon-sm" aria-label={tip} data-update-icon={view.kind} className={cn("text-muted-foreground hover:text-foreground", view.kind === "ready" && "text-foreground")}>
+ <UpdateIcon view={view} />
</Button>
);
return (
- <>
- {items.length > 0 ? <Menu trigger={button} items={items} /> : button}
+ <span data-update-indicator={view.kind} className="inline-flex" role={view.kind === "downloading" || view.kind === "installing" ? "status" : undefined}>
+ {view.kind === "ready" ? (
+ <ReadyPopover ui={ui} view={view} tip={tip} side={side} trigger={button} />
+ ) : (
+ <Tooltip content={tip} side={side}>
+ {button}
+ </Tooltip>
+ )}
<RestartDialog ui={ui} />
- </>
+ </span>
);
}
-/** The top bar's update icon, shown only while the sidebar (and its line) is closed. */
+/** The update button in the sidebar's footer row. */
+export function SidebarUpdateButton() {
+ return <UpdateButton side="top" />;
+}
+
+/** The same button in the top bar, shown only while the sidebar is closed. */
export function TopBarUpdateIndicator() {
- const ui = useUpdateIndicator();
- if (!ui.view) return null;
- return (
- <span data-update-indicator={ui.view.kind}>
- <UpdateMenu ui={ui} />
- </span>
- );
+ return <UpdateButton side="bottom" />;
}