Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/app/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { ServerSDKProvider } from "@/context/server-sdk"
import { ServerSyncProvider, useServerSync } from "@/context/server-sync"
import { GlobalProvider, useGlobal } from "@/context/global"
import { HighlightsProvider } from "@/context/highlights"
import { MajorUpdateProvider } from "@/context/major-update"
import { LanguageProvider, type Locale, useLanguage } from "@/context/language"
import { LayoutProvider } from "@/context/layout"
import { ModelsProvider } from "@/context/models"
Expand Down Expand Up @@ -316,7 +317,9 @@ function SharedProviders(props: ParentProps) {
<BodyDesignClass />
<CommandProvider>
<DesktopCommands />
<HighlightsProvider>{props.children}</HighlightsProvider>
<HighlightsProvider>
<MajorUpdateProvider>{props.children}</MajorUpdateProvider>
</HighlightsProvider>
</CommandProvider>
</>
)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
190 changes: 190 additions & 0 deletions packages/app/src/components/dialog-major-update.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import { ButtonV2 } from "@opencode-ai/ui/v2/button-v2"
import { Dialog, DialogFooter, DialogHeader, DialogTitleGroup } from "@opencode-ai/ui/v2/dialog-v2"
import { Spinner } from "@opencode-ai/ui/spinner"
import { useDialog } from "@opencode-ai/ui/context/dialog"
import { createEffect, createMemo, For, onMount, Show } from "solid-js"
import announcementImage from "@/assets/upgrade/opencode-2-0.png"
import { ExternalLink } from "@/components/external-link"
import { useLanguage } from "@/context/language"
import type { MajorUpdaterPlatform } from "@/updater"
import { showToast } from "@/utils/toast"

export const V2_ANNOUNCEMENT_URL = "https://anoma.ly/notes/opencode-2-0"
export const MAJOR_INSTRUCTIONS = "https://opencode.ai/v2/docs"

const ROW: Record<string, { class: string; path: string }> = {
new: { class: "text-v2-text-text-accent", path: "M7 3V11M3 7H11" },
kept: { class: "text-v2-state-fg-success", path: "M3 7.4L5.8 10L11 4" },
breaks: { class: "text-v2-state-fg-warning", path: "M7 3V7.8M7 9.6V11" },
}

// The card image ships with the app and is decoded before the dialog opens. The dialog shows this same element, so
// nothing loads again and the card never paints without its image.
export function preloadMajorUpdateImage() {
const image = new Image()
image.alt = ""
image.className = "size-full object-contain"
image.src = announcementImage
return image.decode().then(
() => image,
() => image,
)
}

// The desktop offer for OpenCode 2.0. OpenCode 2 is already downloaded when this opens, so the choices are when to
// install it: now, when the app quits, or later.
export function DialogMajorUpdate(props: {
major: MajorUpdaterPlatform
image?: HTMLImageElement
later: () => void
// Reports a restart or an upgrade on quit that failed. The card can be closed by then, so it does not show the toast.
failed: () => void
}) {
const dialog = useDialog()
const language = useLanguage()
const status = () => props.major.state().status
// The install is starting or being armed. Nothing can be chosen until that ends.
const busy = () => status() === "installing" || status() === "scheduling"
// While busy, the card keeps the layout the user chose from.
const scheduled = createMemo<boolean>((previous) => (busy() ? previous : status() === "scheduled"), false)
const quit = createMemo<boolean>((previous) => {
const state = props.major.state()
return state.status === "ready" ? state.quit : previous
}, true)

// Solid builds this dialog from a template in another document. An image that moves between documents loads again,
// so the decoded image joins the card only once the card is in the page.
let media: HTMLDivElement | undefined
onMount(() => {
if (props.image) media?.append(props.image)
})

// A newer OpenCode 1 release withdraws the offer, so there is nothing left to choose here.
createEffect(() => {
if (status() === "unavailable" || status() === "downloading") dialog.close()
})

const restart = () => void props.major.restart().catch(props.failed)
const schedule = () =>
void props.major.schedule().then(() => {
dialog.close()
showToast({ variant: "success", icon: "circle-check", title: language.t("dialog.update.major.scheduled") })
}, props.failed)

// The card can open by itself while the user types, and after a check that took minutes. Focus therefore never
// starts on a button that installs: a key press meant for something else must not restart the app.
return (
<Show
when={!scheduled()}
fallback={
<Dialog fit>
<DialogHeader>
<DialogTitleGroup
title={language.t("titlebar.update")}
description={
<span class="pt-1" data-component="major-update" data-status="scheduled">
{language.t("dialog.update.major.scheduled")}
</span>
}
/>
</DialogHeader>
<DialogFooter>
<ButtonV2 variant="ghost" autofocus onClick={() => dialog.close()}>
{language.t("common.close")}
</ButtonV2>
<ButtonV2 variant="contrast" disabled={busy()} onClick={restart}>
{language.t(
status() === "installing"
? "settings.updates.action.installing"
: "dialog.update.major.action.restartNow",
)}
</ButtonV2>
</DialogFooter>
</Dialog>
}
>
<Dialog fit containerClass="!w-[min(calc(100vw-32px),720px)]">
<div class="flex w-full outline-none" tabindex="-1" autofocus>
<div class="flex min-w-0 flex-1 flex-col">
<DialogHeader hideClose>
<DialogTitleGroup
title={language.t("dialog.update.major.title")}
description={
<span class="flex flex-col gap-3 pt-1" data-component="major-update" data-status="ready">
<span>{language.t("dialog.update.major.lead")}</span>
<span class="flex flex-col gap-1.5">
<For
each={[
{ kind: "new", text: language.t("dialog.update.major.new.browser") },
{ kind: "new", text: language.t("dialog.update.major.new.background") },
{ kind: "new", text: language.t("dialog.update.major.new.plugins") },
{ kind: "new", text: language.t("dialog.update.major.new.sessions") },
{ kind: "new", text: language.t("dialog.update.major.new.pair") },
{ kind: "kept", text: language.t("dialog.update.major.keeps.data") },
{ kind: "breaks", text: language.t("dialog.update.major.plugins") },
]}
>
{(item) => (
<span class="flex items-center gap-2 text-v2-text-text-base">
<svg
width="14"
height="14"
viewBox="0 0 14 14"
fill="none"
aria-hidden="true"
class={ROW[item.kind].class}
>
<path d={ROW[item.kind].path} stroke="currentColor" stroke-width="1.4" />
</svg>
{item.text}
</span>
)}
</For>
</span>
<ExternalLink href={V2_ANNOUNCEMENT_URL} class="!text-v2-text-text-accent !no-underline">
{language.t("common.learnMore")}
</ExternalLink>
</span>
}
/>
</DialogHeader>
<div class="flex-1" />
<DialogFooter>
{/* Translated labels can be longer than the row, so the buttons wrap instead of shrinking. */}
<div class="flex min-w-0 flex-1 flex-wrap justify-end gap-2">
<ButtonV2
variant="ghost"
class="shrink-0 whitespace-nowrap"
disabled={busy()}
onClick={() => {
props.later()
dialog.close()
}}
>
{language.t("desktop.updater.dialog.later")}
</ButtonV2>
<Show when={quit()}>
<ButtonV2 variant="neutral" class="shrink-0 whitespace-nowrap" disabled={busy()} onClick={schedule}>
<Show when={status() === "scheduling"}>
<Spinner class="size-3.5 shrink-0" />
</Show>
{language.t("dialog.update.major.action.quit")}
</ButtonV2>
</Show>
<ButtonV2 variant="contrast" class="shrink-0 whitespace-nowrap" disabled={busy()} onClick={restart}>
{language.t(
status() === "installing"
? "settings.updates.action.installing"
: "dialog.update.major.action.restart",
)}
</ButtonV2>
</div>
</DialogFooter>
</div>
{/* A narrow window has no room for the image beside the text. */}
<div class="w-[280px] shrink-0 self-stretch bg-[#080807] max-md:hidden" ref={media} />
</div>
</Dialog>
</Show>
)
}
11 changes: 11 additions & 0 deletions packages/app/src/components/titlebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { LayoutRoute, useLayout } from "@/context/layout"
import { usePlatform } from "@/context/platform"
import { useCommand } from "@/context/command"
import { useLanguage } from "@/context/language"
import { useMajorUpdate } from "@/context/major-update"
import { useSettings } from "@/context/settings"
import { WindowsAppMenu } from "./windows-app-menu"
import { applyPath, backPath, forwardPath } from "./titlebar-history"
Expand Down Expand Up @@ -68,6 +69,7 @@ export function Titlebar(props: { update?: TitlebarUpdate; debugTools?: { visibl
const language = useLanguage()
const settings = useSettings()
const server = useServer()
const major = useMajorUpdate()
const navigate = useNavigate()
const location = useLocation()
const params = useParams()
Expand Down Expand Up @@ -124,6 +126,15 @@ export function Titlebar(props: { update?: TitlebarUpdate; debugTools?: { visibl
const updateState = createMemo<TitlebarUpdatePillState>(() => {
const installing = props.update?.installing() ?? false
const version = props.update?.version()
// An OpenCode 1 release keeps the pill. Otherwise the pill opens the OpenCode 2.0 offer.
if (version === undefined && !installing && major.visible())
return {
visible: true,
installing: false,
label: language.t("titlebar.update"),
ariaLabel: language.t("toast.update.title"),
onInstall: () => void major.open(),
}
return {
visible: version !== undefined || installing,
installing,
Expand Down
11 changes: 11 additions & 0 deletions packages/app/src/components/updater-action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@ describe("updaterAction", () => {
label: "settings.updates.action.installing",
})
})

test("shows the OpenCode 2 download instead of another check", () => {
expect(updaterAction({ status: "up-to-date" }, "downloading")).toEqual({
label: "settings.updates.action.downloading",
})
expect(updaterAction({ status: "up-to-date" }, "ready")).toEqual({
label: "settings.updates.action.checkNow",
run: "check",
})
expect(updaterAction({ status: "checking" }, "downloading")).toEqual({ label: "settings.updates.action.checking" })
})
})
14 changes: 11 additions & 3 deletions packages/app/src/components/updater-action.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { createMemo } from "solid-js"
import type { UpdaterState } from "@/updater"
import type { MajorUpdateState, UpdaterState } from "@/updater"
import { usePlatform } from "@/context/platform"
import { useLanguage } from "@/context/language"
import { useMajorUpdate } from "@/context/major-update"
import { showToast } from "@/utils/toast"

export function updaterAction(state: UpdaterState | undefined) {
export function updaterAction(state: UpdaterState | undefined, major?: MajorUpdateState["status"]) {
if (!state) return { label: "settings.updates.action.checkNow" as const }
switch (state.status) {
case "checking":
Expand All @@ -18,14 +19,18 @@ export function updaterAction(state: UpdaterState | undefined) {
case "disabled":
return { label: "settings.updates.action.checkNow" as const }
default:
// OpenCode 2 downloads once OpenCode 1 is up to date, and a check waits for that download. Another check could
// only wait with it.
if (major === "downloading") return { label: "settings.updates.action.downloading" as const }
return { label: "settings.updates.action.checkNow" as const, run: "check" as const }
}
}

export function useUpdaterAction() {
const platform = usePlatform()
const language = useLanguage()
const action = createMemo(() => updaterAction(platform.updater?.state()))
const major = useMajorUpdate()
const action = createMemo(() => updaterAction(platform.updater?.state(), major.status()))

return {
action,
Expand All @@ -35,6 +40,9 @@ export function useUpdaterAction() {
if (run !== "check") return

const state = await platform.updater?.check()
// With no OpenCode 1 release left to install, checking for updates opens the OpenCode 2.0 offer instead. The
// check is run from Settings, which stays open underneath.
if (state?.status !== "ready" && major.offered()) return major.open({ stack: true })
if (state?.status === "up-to-date") {
showToast({
variant: "success",
Expand Down
9 changes: 9 additions & 0 deletions packages/app/src/context/highlights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ export const { use: useHighlights, provider: HighlightsProvider } = createSimple
to: undefined as string | undefined,
})
const state = { started: false }
// For other dialogs that open by themselves, so they can give way: `started` once it is known whether release notes
// may open in this window, `notes` when they may.
const [decision, setDecision] = createStore({ started: false, notes: false })
let timer: ReturnType<typeof setTimeout> | undefined

const clearTimer = () => {
Expand Down Expand Up @@ -209,6 +212,10 @@ export const { use: useHighlights, provider: HighlightsProvider } = createSimple
state.started = true

const previous = store.version
setDecision({
started: true,
notes: !!previous && previous !== platform.version && settings.general.releaseNotes(),
})
if (!previous) {
setStore("version", platform.version)
return
Expand All @@ -222,6 +229,8 @@ export const { use: useHighlights, provider: HighlightsProvider } = createSimple

return {
ready,
started: () => decision.started,
notes: () => decision.notes,
from: () => range.from,
to: () => range.to,
get last() {
Expand Down
63 changes: 63 additions & 0 deletions packages/app/src/context/major-update.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { describe, expect, test } from "bun:test"
import { LATER_DURATION, majorUpdateAutoOpen, majorUpdateOffered, majorUpdateVisible } from "./major-update"

describe("major update offer", () => {
const now = Date.UTC(2026, 10, 13)

test("shows only once OpenCode 2 is downloaded", () => {
expect(majorUpdateVisible("unavailable", undefined, now)).toBe(false)
expect(majorUpdateVisible("downloading", undefined, now)).toBe(false)
expect(majorUpdateVisible("ready", undefined, now)).toBe(true)
})

test("stays hidden for a week after Later, then returns", () => {
const laterUntil = now + LATER_DURATION

expect(majorUpdateVisible("ready", laterUntil, now)).toBe(false)
expect(majorUpdateVisible("ready", laterUntil, laterUntil - 1)).toBe(false)
expect(majorUpdateVisible("ready", laterUntil, laterUntil)).toBe(true)
})

test("shows nothing once the user chose to upgrade", () => {
expect(majorUpdateVisible("scheduling", undefined, now)).toBe(false)
expect(majorUpdateVisible("scheduled", undefined, now)).toBe(false)
expect(majorUpdateVisible("installing", undefined, now)).toBe(false)
})

test("can be opened from the moment OpenCode 2 is downloaded, whatever the user chose", () => {
expect(majorUpdateOffered("unavailable")).toBe(false)
expect(majorUpdateOffered("downloading")).toBe(false)
expect(majorUpdateOffered("ready")).toBe(true)
expect(majorUpdateOffered("scheduling")).toBe(true)
expect(majorUpdateOffered("scheduled")).toBe(true)
expect(majorUpdateOffered("installing")).toBe(true)
})
})

describe("major update offer opening by itself", () => {
const launch = { prompt: "launch" as const, visible: true, notes: false, dialog: false }

test("opens in the window the app picked right after launch", () => {
expect(majorUpdateAutoOpen(launch)).toBe(true)
})

test("stays closed in every window the app did not pick", () => {
expect(majorUpdateAutoOpen({ ...launch, prompt: undefined })).toBe(false)
})

test("stays closed after Later", () => {
expect(majorUpdateAutoOpen({ ...launch, visible: false })).toBe(false)
})

test("gives way to release notes for an OpenCode 1 update", () => {
expect(majorUpdateAutoOpen({ ...launch, notes: true })).toBe(false)
})

test("never replaces a dialog that is already open", () => {
expect(majorUpdateAutoOpen({ ...launch, dialog: true })).toBe(false)
})

test("always opens when the user asked for it", () => {
expect(majorUpdateAutoOpen({ prompt: "asked", visible: false, notes: true, dialog: true })).toBe(true)
})
})
Loading
Loading