Skip to content

Commit d83929a

Browse files
t3dotggclaude
andauthored
feat(web): one sidebar click updates every machine and provider (#18053)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent f498b35 commit d83929a

11 files changed

Lines changed: 917 additions & 111 deletions

‎apps/web/src/components/ProviderUpdatesAction.tsx‎

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@ import { stackedThreadToast, toastManager } from "./ui/toast";
1515
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
1616

1717
/**
18-
* Updates every outdated provider on every connected machine at once, then
19-
* reports the results in one toast. Each server queues updates that share an
20-
* installer, so sending them all together is safe. The server still checks
21-
* permissions: a session that cannot operate a machine gets a failure line for
22-
* it. Renders nothing when no machine has a one-click update.
18+
* Every outdated provider with a one-click update on every connected machine,
19+
* plus a function that updates them all and reports the results in one toast.
20+
* Each server queues updates that share an installer, so sending them all
21+
* together is safe. The server still checks permissions: a session that
22+
* cannot operate a machine gets a failure line for it. The returned promise
23+
* settles when every update has finished.
2324
*/
24-
export function ProviderUpdatesAction() {
25+
export function useProviderUpdates() {
2526
const { environments } = useEnvironments();
2627
const updateProvider = useAtomCommand(serverEnvironment.updateProvider, {
2728
reportFailure: false,
2829
});
29-
const pending = useRef(false);
30-
const [isPending, setIsPending] = useState(false);
3130
const machines = useMemo(
3231
() =>
3332
environments.flatMap((environment) => {
@@ -44,6 +43,41 @@ export function ProviderUpdatesAction() {
4443
}),
4544
[environments],
4645
);
46+
47+
const updateAll = async () => {
48+
const runs = await Promise.all(
49+
machines.flatMap(({ environmentId, label, candidates }) =>
50+
candidates.map(async (candidate): Promise<ProviderUpdateRun> => ({
51+
machineLabel: label,
52+
driver: candidate.driver,
53+
instanceId: candidate.instanceId,
54+
result: await updateProvider({
55+
environmentId,
56+
input: { provider: candidate.driver, instanceId: candidate.instanceId },
57+
}),
58+
})),
59+
),
60+
);
61+
const view = getProviderUpdateRunToastView(runs);
62+
if (view) {
63+
toastManager.add(
64+
stackedThreadToast({
65+
...view,
66+
description: <span className="whitespace-pre-line">{view.description}</span>,
67+
}),
68+
);
69+
}
70+
};
71+
72+
return { machines, updateAll };
73+
}
74+
75+
/** Provider settings button for {@link useProviderUpdates}. Renders nothing
76+
when no machine has a one-click update. */
77+
export function ProviderUpdatesAction() {
78+
const { machines, updateAll } = useProviderUpdates();
79+
const pending = useRef(false);
80+
const [isPending, setIsPending] = useState(false);
4781
// Candidates leave the list as soon as their servers report them queued, so
4882
// keep the button while the run is in flight.
4983
if (machines.length === 0 && !isPending) {
@@ -55,28 +89,7 @@ export function ProviderUpdatesAction() {
5589
pending.current = true;
5690
setIsPending(true);
5791
try {
58-
const runs = await Promise.all(
59-
machines.flatMap(({ environmentId, label, candidates }) =>
60-
candidates.map(async (candidate): Promise<ProviderUpdateRun> => ({
61-
machineLabel: label,
62-
driver: candidate.driver,
63-
instanceId: candidate.instanceId,
64-
result: await updateProvider({
65-
environmentId,
66-
input: { provider: candidate.driver, instanceId: candidate.instanceId },
67-
}),
68-
})),
69-
),
70-
);
71-
const view = getProviderUpdateRunToastView(runs);
72-
if (view) {
73-
toastManager.add(
74-
stackedThreadToast({
75-
...view,
76-
description: <span className="whitespace-pre-line">{view.description}</span>,
77-
}),
78-
);
79-
}
92+
await updateAll();
8093
} finally {
8194
pending.current = false;
8295
setIsPending(false);

‎apps/web/src/components/ServerUpdateAction.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ type UpdateButtonProps = Pick<ComponentProps<typeof Button>, "variant" | "size"
6565
readonly appearance?: "button" | "icon";
6666
};
6767

68-
function useServerUpdate() {
68+
/** Updates one server and waits until it is back on the target version.
69+
Reports its own success or failure toast; never rejects. */
70+
export function useServerUpdate() {
6971
const updateServer = useAtomCommand(serverEnvironment.updateServer, { reportFailure: false });
7072
return async (target: ServerUpdateTarget, failureTitle = "Server update failed") => {
7173
const { environmentId, serverLabel, selfUpdate, targetVersion } = target;
@@ -164,7 +166,9 @@ export function ServerUpdatesAction({
164166
);
165167
}
166168

167-
function canUpdateServer(result: AsyncResult.AsyncResult<AuthSessionState, unknown>): boolean {
169+
export function canUpdateServer(
170+
result: AsyncResult.AsyncResult<AuthSessionState, unknown>,
171+
): boolean {
168172
if (result._tag !== "Success" || !result.value.authenticated) return false;
169173
return sessionGrantsScope(result.value, AuthEnvironmentMaintainScope);
170174
}

‎apps/web/src/components/sidebar/DesktopUpdateStatusIcon.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RefreshIcon } from "~/components/ui/refresh-icon";
2-
import { CheckIcon, DownloadIcon, RotateCwIcon } from "lucide-react";
2+
import { CheckIcon, CircleArrowUpIcon, DownloadIcon, RotateCwIcon } from "lucide-react";
33
import type { AnimationEventHandler } from "react";
44

55
const DOWNLOAD_PROGRESS_RADIUS = 14;
@@ -10,7 +10,10 @@ export type DesktopUpdateStatusIconState =
1010
| "checking"
1111
| "available"
1212
| "downloading"
13-
| "downloaded";
13+
| "downloaded"
14+
// Other machines or providers have updates. Matches the server update icon
15+
// in Connections settings; the download arrow stays for this app's own file.
16+
| "everything";
1417

1518
function normalizeDesktopUpdateDownloadPercent(percent: number | null): number {
1619
if (percent === null || !Number.isFinite(percent)) return 0;
@@ -115,6 +118,7 @@ export function DesktopUpdateStatusIcon({
115118
return <DesktopUpdateDownloadingIcon percent={downloadPercent ?? null} />;
116119
}
117120
if (status === "downloaded") return <DesktopUpdateDownloadedIcon />;
121+
if (status === "everything") return <CircleArrowUpIcon className="size-4" />;
118122

119123
return (
120124
<RefreshIcon

0 commit comments

Comments
 (0)