fix(desktop): Check for Updates always says what happened (#57296)

This commit is contained in:
Kit Langton
2026-10-19 22:41:42 -07:00
committed by GitHub
Unverified
parent 635146377e
commit 675c0d9d78
2 changed files with 35 additions and 18 deletions
+27 -18
View File
@@ -1,7 +1,7 @@
import { Button } from "@opencode/ui/button"
import { Dialog, DialogFooter, DialogHeader, DialogTitleGroup } from "@opencode/ui/dialog"
import { Icon } from "@opencode/ui/icon"
import { showToast } from "@opencode/ui/toast"
import { showToast, toaster } from "@opencode/ui/toast"
import type { DialogHandle, IpcClient, SetupContext } from "../sdk"
import type { Updater } from "./contract"
import type definition from "./index"
@@ -29,29 +29,38 @@ export function install(ctx: Context, client: Client) {
}
export async function check(ctx: Context, client: Client) {
const checking = showToast({ variant: "loading", title: ctx.t("action.checking") })
const state = await client
.check({ signal: ctx.signal })
.catch((cause: unknown) => requestFailed(ctx, cause))
.finally(() => toaster.dismiss(checking))
if (!state || ctx.signal.aborted) return
if (state.status === "download-required") {
install(ctx, client)
return
}
if (state.status === "up-to-date") {
showToast({
variant: "success",
icon: () => <Icon name="circle-check" />,
title: ctx.t("toast.latest.title"),
description: ctx.t("toast.latest.description", { version: ctx.build.version }),
})
}
if (state.status === "error") {
showToast({ title: ctx.t("common.requestFailed"), description: state.message })
// Every settled check says what happened; only an install already underway stays quiet.
switch (state.status) {
case "download-required":
return install(ctx, client)
case "up-to-date":
return void showToast({
variant: "success",
icon: () => <Icon name="circle-check" />,
title: ctx.t("toast.latest.title"),
description: ctx.t("toast.latest.description", { version: ctx.build.version }),
})
case "ready":
return void showToast({
title: ctx.t("dialog.ready.title"),
description: ctx.t("dialog.ready.message", { version: state.version }),
persistent: true,
actions: [
{ label: ctx.t("dialog.restart"), variant: "primary", onClick: () => install(ctx, client) },
{ label: ctx.t("dialog.later"), variant: "secondary", onClick: "dismiss" },
],
})
case "error":
return void showToast({ title: ctx.t("common.requestFailed"), description: state.message })
}
}
@@ -256,6 +256,14 @@ describe("updater", () => {
expect(app.state()).toEqual({ status: "download-required", version: "2.0.0" })
})
// Check for Updates reports what this resolves to, so a staged update must come back as ready, not silently.
test("a manual check while an update is staged resolves to the staged version", async () => {
const app = await setup({ checks: ["2.0.0"] })
await app.start()
expect(await app.check()).toEqual({ status: "ready", version: "2.0.0" })
})
test("concurrent checks share one platform check", async () => {
const app = await setup()