@@ -2410,8 +2426,9 @@ export default function LegacyLayout(props: ParentProps) {
}
function UpdateAvailableToast(props: {
- version: string
- install: () => void
+ description: string
+ action: string
+ run: () => void
language: ReturnType
}) {
let toastId: number | undefined
@@ -2421,11 +2438,11 @@ function UpdateAvailableToast(props: {
persistent: true,
icon: "download",
title: props.language.t("toast.update.title"),
- description: props.language.t("toast.update.description", { version: props.version }),
+ description: props.description,
actions: [
{
- label: props.language.t("toast.update.action.installRestart"),
- onClick: props.install,
+ label: props.action,
+ onClick: props.run,
},
{
label: props.language.t("toast.update.action.notYet"),
diff --git a/packages/app/src/updater.ts b/packages/app/src/updater.ts
index 228743488cc3..d7b70928dc05 100644
--- a/packages/app/src/updater.ts
+++ b/packages/app/src/updater.ts
@@ -10,8 +10,40 @@ export type UpdaterState =
| { status: "installing"; version: string }
| { status: "error"; message: string }
+// A newer OpenCode 1 release wins; OpenCode 2.0 is only offered once OpenCode 1 is up to date.
+export type MajorUpdateState =
+ | { status: "unavailable" }
+ // OpenCode 2 downloads in the background, like an OpenCode 1 update. Nothing is offered yet.
+ | { status: "downloading" }
+ // Downloaded. The user is asked, and nothing installs until they choose. `quit` is false where OpenCode 2 cannot
+ // install while the app quits, so only a restart is offered. `stopped` is set once a restart failed after the app's
+ // servers shut down: the app has to restart before it works again.
+ | { status: "ready"; quit: boolean; stopped?: boolean }
+ // The user chose to upgrade when the app quits, and the install is being armed. On macOS this lasts as long as the
+ // system updater needs to unpack and verify OpenCode 2.
+ | { status: "scheduling" }
+ // The user chose to upgrade when the app quits.
+ | { status: "scheduled"; stopped?: boolean }
+ // The user chose to restart. The app is shutting down to install OpenCode 2.
+ | { status: "installing" }
+
+// Why a window opens the offer by itself: it is the one window that does so right after the app starts, or the user
+// asked for the offer while no window was open.
+export type MajorUpdatePrompt = "launch" | "asked" | undefined
+
+export type MajorUpdaterPlatform = {
+ state: Accessor
+ /** Asks the app whether this window opens the offer by itself. At most one window per launch gets an answer. */
+ prompt(): Promise
+ /** Quits, installs OpenCode 2 and opens it. */
+ restart(): Promise
+ /** Installs OpenCode 2 when the app next quits. */
+ schedule(): Promise
+}
+
export type UpdaterPlatform = {
state: Accessor
check(): Promise
install(): Promise
+ major?: MajorUpdaterPlatform
}
diff --git a/packages/desktop/src/main/index.ts b/packages/desktop/src/main/index.ts
index 183fc634db01..570b1cc3fbdd 100644
--- a/packages/desktop/src/main/index.ts
+++ b/packages/desktop/src/main/index.ts
@@ -175,6 +175,8 @@ const main = Effect.gen(function* () {
app.quit()
})
}
+ // The updater starts once the app is ready. Until then nothing can be armed.
+ const upgrade = { armed: () => false, stopped: false }
try {
setDefaultCACertificates([...new Set([...getCACertificates("default"), ...getCACertificates("system")])])
@@ -221,9 +223,19 @@ const main = Effect.gen(function* () {
emitDeepLinks([url])
})
- app.on("before-quit", () => {
+ app.on("before-quit", (event) => {
setAppQuitting()
- void stopSidecars()
+ const stopping = stopSidecars()
+ // An armed OpenCode 2 installer starts the moment the app has quit, and it replaces the files the servers run
+ // from. That quit waits, once, until the servers are gone. Every other quit goes on as before.
+ if (upgrade.stopped || !upgrade.armed()) return
+ event.preventDefault()
+ void stopping
+ .catch((error) => logger.error("failed to stop servers before the upgrade", error))
+ .finally(() => {
+ upgrade.stopped = true
+ app.quit()
+ })
})
app.on("will-quit", () => {
@@ -272,12 +284,26 @@ const main = Effect.gen(function* () {
registerRendererProtocol()
setDockIcon()
const updater = setupAutoUpdater(stopSidecars)
+ // macOS is left out: its installer waits for the app to exit by itself, and holding a quit there can cancel a logout.
+ upgrade.armed = () => {
+ if (process.platform === "darwin") return false
+ const status = updater.major.getState().status
+ return status === "scheduling" || status === "scheduled"
+ }
+ const trigger = (id: string) => {
+ const win = getLastFocusedWindow()
+ if (win) sendMenuCommand(win, id)
+ }
+ const showUpdater = () =>
+ showUpdaterDialog(updater, true, () => {
+ if (BrowserWindow.getAllWindows().length > 0) return trigger("update.open")
+ // macOS keeps running with every window closed. A new window asks the updater as it starts, and opens the offer.
+ updater.major.ask()
+ restoreMainWindows()
+ })
const menuDeps = {
- trigger: (id: string) => {
- const win = getLastFocusedWindow()
- if (win) sendMenuCommand(win, id)
- },
- checkForUpdates: () => void showUpdaterDialog(updater, true),
+ trigger,
+ checkForUpdates: () => void showUpdater(),
relaunch,
}
registerIpcHandlers({
@@ -303,7 +329,7 @@ const main = Effect.gen(function* () {
checkAppExists: (appName) => checkAppExists(appName),
resolveAppPath: async (appName) => resolveAppPath(appName),
updater,
- showUpdater: () => showUpdaterDialog(updater, true),
+ showUpdater,
setBackgroundColor: (color) => setBackgroundColor(color),
exportDebugLogs: () => exportDebugLogs(),
recordFatalRendererError: (error) => writeLog("renderer", "fatal renderer error", { ...error }, "error"),
diff --git a/packages/desktop/src/main/ipc.ts b/packages/desktop/src/main/ipc.ts
index d8abfc1ceb3b..c21d70b41a74 100644
--- a/packages/desktop/src/main/ipc.ts
+++ b/packages/desktop/src/main/ipc.ts
@@ -82,18 +82,23 @@ export function registerIpcHandlers(deps: Deps) {
ipcMain.handle("resolve-app-path", (_event: IpcMainInvokeEvent, appName: string) => deps.resolveAppPath(appName))
ipcMain.handle("updater-subscribe", (event) => {
const id = event.sender.id
- updaterSubscriptions.set(
- id,
- deps.updater.subscribe((state) => {
- if (event.sender.isDestroyed()) return updaterSubscriptions.delete(id)
- event.sender.send("updater-state", state)
- }),
- )
+ const send = (channel: string) => (state: unknown) => {
+ if (event.sender.isDestroyed()) return updaterSubscriptions.delete(id)
+ event.sender.send(channel, state)
+ }
+ const unsubscribe = [
+ deps.updater.subscribe(send("updater-state")),
+ deps.updater.major.subscribe(send("updater-major-state")),
+ ]
+ updaterSubscriptions.set(id, () => unsubscribe.forEach((stop) => stop()))
event.sender.once("destroyed", () => updaterSubscriptions.delete(id))
})
ipcMain.handle("updater-unsubscribe", (event) => updaterSubscriptions.delete(event.sender.id))
- ipcMain.handle("updater-check", () => deps.updater.check())
+ ipcMain.handle("updater-check", () => deps.updater.checkNow())
ipcMain.handle("updater-install", () => deps.updater.install())
+ ipcMain.handle("updater-major-prompt", () => deps.updater.major.prompt())
+ ipcMain.handle("updater-major-restart", () => deps.updater.major.restart())
+ ipcMain.handle("updater-major-schedule", () => deps.updater.major.schedule())
ipcMain.handle("set-background-color", (_event: IpcMainInvokeEvent, color: string) => deps.setBackgroundColor(color))
ipcMain.handle("export-debug-logs", () => deps.exportDebugLogs())
ipcMain.handle("set-force-focus", (event: IpcMainInvokeEvent, enabled: boolean) =>
diff --git a/packages/desktop/src/main/updater-controller.test.ts b/packages/desktop/src/main/updater-controller.test.ts
index ff3f7d1dfd83..2d43bee9bc50 100644
--- a/packages/desktop/src/main/updater-controller.test.ts
+++ b/packages/desktop/src/main/updater-controller.test.ts
@@ -1,5 +1,11 @@
import { describe, expect, test } from "bun:test"
-import { createUpdaterController, type UpdaterBackend, type UpdaterReadyRecord } from "./updater-controller"
+import {
+ createUpdaterController,
+ LAUNCH_WINDOW,
+ type MajorUpdaterBackend,
+ type UpdaterBackend,
+ type UpdaterReadyRecord,
+} from "./updater-controller"
function setup(input?: { currentVersion?: string; ready?: UpdaterReadyRecord }) {
const calls: string[] = []
@@ -109,3 +115,564 @@ describe("updater controller", () => {
expect(failed.getState()).toEqual({ status: "ready", version: "2.0.0" })
})
})
+
+type MajorFeed = { isUpdateAvailable?: boolean; updateInfo?: { version?: string } }
+
+// Every fake records its call first. A hook then decides how the call ends, so a test can hold a call open with a
+// deferred promise and settle it later.
+function setupMajor(input?: {
+ update?: () => boolean
+ check?: () => Promise | undefined
+ feed?: () => MajorFeed | Promise
+ download?: () => Promise
+ stage?: () => Promise
+ installOnQuit?: () => Promise
+ // A package that cannot install while the app quits.
+ restartOnly?: boolean
+ quitAndInstall?: () => void
+ stop?: () => Promise
+ now?: () => number
+}) {
+ const calls: string[] = []
+ const major: MajorUpdaterBackend = {
+ async checkForUpdates() {
+ calls.push("major check")
+ return (await input?.feed?.()) ?? { isUpdateAvailable: true, updateInfo: { version: "2.2.7" } }
+ },
+ async downloadUpdate() {
+ calls.push("major download")
+ await input?.download?.()
+ },
+ cancelDownload() {
+ calls.push("major cancel")
+ },
+ async stage() {
+ calls.push("major stage")
+ return (await input?.stage?.()) ?? false
+ },
+ async installOnQuit() {
+ calls.push("major install on quit")
+ await input?.installOnQuit?.()
+ },
+ disarm() {
+ calls.push("major disarm")
+ },
+ quitAndInstall() {
+ calls.push("major install")
+ input?.quitAndInstall?.()
+ },
+ }
+ const controller = createUpdaterController({
+ enabled: true,
+ currentVersion: "1.19.5",
+ backend: {
+ async checkForUpdates() {
+ calls.push("check")
+ await input?.check?.()
+ return { isUpdateAvailable: input?.update?.() ?? false, updateInfo: { version: "1.19.6" } }
+ },
+ async downloadUpdate() {
+ calls.push("download")
+ },
+ quitAndInstall() {
+ calls.push("install")
+ },
+ },
+ major: input?.restartOnly ? { ...major, installOnQuit: undefined } : major,
+ persistence: { get: () => undefined, set() {}, clear() {} },
+ stop: async () => {
+ calls.push("stop")
+ await input?.stop?.()
+ },
+ now: input?.now,
+ })
+ const states: string[] = []
+ controller.major.subscribe((state) => states.push(state.status))
+ const updates: string[] = []
+ controller.subscribe((state) => updates.push(state.status))
+ // The background download is not awaited by a check, so tests wait for the offer to settle.
+ const settled = async () => {
+ for (const _ of Array.from({ length: 20 })) await Promise.resolve()
+ }
+ // Starts the app with OpenCode 1 up to date and OpenCode 2 downloaded.
+ const offer = async () => {
+ await controller.start()
+ await settled()
+ }
+ return { controller, calls, states, updates, settled, offer }
+}
+
+describe("major updater", () => {
+ test("downloads OpenCode 2 once OpenCode 1 is up to date, then offers it", async () => {
+ const app = setupMajor()
+
+ await app.offer()
+
+ expect(app.controller.getState()).toEqual({ status: "up-to-date" })
+ expect(app.controller.major.getState()).toEqual({ status: "ready", quit: true })
+ expect(app.states).toEqual(["unavailable", "downloading", "ready"])
+ expect(app.calls).toEqual(["check", "major check", "major download"])
+ })
+
+ test("installs nothing until the user chooses", async () => {
+ const app = setupMajor()
+ await app.offer()
+
+ expect(app.calls).not.toContain("major install")
+ expect(app.calls).not.toContain("major install on quit")
+ expect(app.calls).not.toContain("major stage")
+ expect(app.calls).not.toContain("stop")
+ })
+
+ test("a newer OpenCode 1 release comes first", async () => {
+ const app = setupMajor({ update: () => true })
+
+ await app.offer()
+
+ expect(app.controller.getState()).toEqual({ status: "ready", version: "1.19.6" })
+ expect(app.controller.major.getState()).toEqual({ status: "unavailable" })
+ expect(app.calls).toEqual(["check", "download"])
+ await expect(app.controller.major.restart()).rejects.toThrow("OpenCode 2 is not ready to install")
+ await expect(app.controller.major.schedule()).rejects.toThrow("OpenCode 2 is not ready to install")
+ })
+
+ test("never offers OpenCode 2 without a feed for it", async () => {
+ const controller = createUpdaterController({
+ enabled: true,
+ currentVersion: "1.19.5",
+ backend: {
+ checkForUpdates: async () => ({ isUpdateAvailable: false }),
+ downloadUpdate: async () => {},
+ quitAndInstall() {},
+ },
+ persistence: { get: () => undefined, set() {}, clear() {} },
+ stop: async () => {},
+ })
+
+ await controller.start()
+
+ expect(controller.major.getState()).toEqual({ status: "unavailable" })
+ })
+
+ test("a failed download stays quiet and the next check tries again", async () => {
+ const failure = { fail: true }
+ const app = setupMajor({
+ download: async () => {
+ if (failure.fail) throw new Error("net::ERR_INTERNET_DISCONNECTED")
+ },
+ })
+ await app.offer()
+ expect(app.states).toEqual(["unavailable", "downloading", "unavailable"])
+ expect(app.updates).not.toContain("error")
+
+ failure.fail = false
+ await app.controller.check()
+ await app.settled()
+
+ expect(app.controller.major.getState()).toEqual({ status: "ready", quit: true })
+ })
+
+ test("stays unavailable when the feed has no OpenCode 2 release", async () => {
+ const app = setupMajor({ feed: () => ({ isUpdateAvailable: false }) })
+
+ await app.offer()
+
+ expect(app.controller.major.getState()).toEqual({ status: "unavailable" })
+ })
+
+ test("never offers a release older than OpenCode 2", async () => {
+ const feed = { version: "1.20.0" as string | undefined }
+ const app = setupMajor({ feed: () => ({ isUpdateAvailable: true, updateInfo: { version: feed.version } }) })
+
+ await app.offer()
+ feed.version = "0.9.0"
+ await app.controller.check()
+ await app.settled()
+ feed.version = undefined
+ await app.controller.check()
+ await app.settled()
+
+ expect(app.controller.major.getState()).toEqual({ status: "unavailable" })
+ expect(app.calls).not.toContain("major download")
+
+ feed.version = "3.0.0"
+ await app.controller.check()
+ await app.settled()
+
+ expect(app.controller.major.getState()).toEqual({ status: "ready", quit: true })
+ })
+
+ test("offers a restart only where OpenCode 2 cannot install while the app quits", async () => {
+ const app = setupMajor({ restartOnly: true })
+
+ await app.offer()
+
+ expect(app.controller.major.getState()).toEqual({ status: "ready", quit: false })
+ await expect(app.controller.major.schedule()).rejects.toThrow("OpenCode 2 is not ready to install")
+ expect(app.controller.major.getState()).toEqual({ status: "ready", quit: false })
+ })
+})
+
+describe("major updater and OpenCode 1 releases", () => {
+ test("a newer OpenCode 1 release withdraws an offer that was already made", async () => {
+ const release = { out: false }
+ const app = setupMajor({ update: () => release.out })
+ await app.offer()
+ expect(app.controller.major.getState()).toEqual({ status: "ready", quit: true })
+
+ release.out = true
+ await app.controller.check()
+
+ expect(app.controller.getState()).toEqual({ status: "ready", version: "1.19.6" })
+ expect(app.controller.major.getState()).toEqual({ status: "unavailable" })
+ expect(app.calls.slice(-3)).toEqual(["major cancel", "major disarm", "download"])
+ })
+
+ test("an OpenCode 1 release found while OpenCode 2 downloads cancels it and waits for it to end", async () => {
+ const download = Promise.withResolvers()
+ const release = { out: false }
+ const app = setupMajor({ update: () => release.out, download: () => download.promise })
+ await app.offer()
+ expect(app.controller.major.getState()).toEqual({ status: "downloading" })
+
+ release.out = true
+ const checking = app.controller.check()
+ await app.settled()
+
+ // Both updaters share the system updater on macOS, so the OpenCode 1 download must not start yet.
+ expect(app.calls).toEqual(["check", "major check", "major download", "check", "major cancel", "major disarm"])
+ expect(app.controller.getState()).toEqual({ status: "checking" })
+ expect(app.controller.major.getState()).toEqual({ status: "unavailable" })
+
+ download.reject(new Error("cancelled"))
+ await checking
+ await app.settled()
+
+ expect(app.calls.slice(-1)).toEqual(["download"])
+ expect(app.controller.getState()).toEqual({ status: "ready", version: "1.19.6" })
+ expect(app.controller.major.getState()).toEqual({ status: "unavailable" })
+ expect(app.updates).not.toContain("error")
+ expect(app.states).toEqual(["unavailable", "downloading", "unavailable"])
+ })
+
+ test("an OpenCode 2 download that finishes after it was withdrawn is not offered", async () => {
+ const download = Promise.withResolvers()
+ const release = { out: false }
+ const app = setupMajor({ update: () => release.out, download: () => download.promise })
+ await app.offer()
+
+ release.out = true
+ const checking = app.controller.check()
+ await app.settled()
+ download.resolve()
+ await checking
+ await app.settled()
+
+ expect(app.controller.getState()).toEqual({ status: "ready", version: "1.19.6" })
+ expect(app.controller.major.getState()).toEqual({ status: "unavailable" })
+ await expect(app.controller.major.restart()).rejects.toThrow("OpenCode 2 is not ready to install")
+ })
+
+ test("an OpenCode 1 release found while the OpenCode 2 feed answers stops the download before it starts", async () => {
+ const answer = Promise.withResolvers<{ isUpdateAvailable: boolean; updateInfo: { version: string } }>()
+ const release = { out: false }
+ const app = setupMajor({ update: () => release.out, feed: () => answer.promise })
+ await app.offer()
+ expect(app.controller.major.getState()).toEqual({ status: "downloading" })
+
+ release.out = true
+ const checking = app.controller.check()
+ await app.settled()
+ expect(app.calls).toEqual(["check", "major check", "check", "major cancel", "major disarm"])
+
+ answer.resolve({ isUpdateAvailable: true, updateInfo: { version: "2.2.7" } })
+ await checking
+
+ expect(app.calls).not.toContain("major download")
+ expect(app.calls.slice(-1)).toEqual(["download"])
+ expect(app.controller.getState()).toEqual({ status: "ready", version: "1.19.6" })
+ expect(app.controller.major.getState()).toEqual({ status: "unavailable" })
+ })
+
+ test("upgrade on quit chosen while a check is in flight keeps an OpenCode 1 release from downloading", async () => {
+ const answer = Promise.withResolvers()
+ const release = { out: false }
+ const app = setupMajor({ update: () => release.out, check: () => (release.out ? answer.promise : undefined) })
+ await app.offer()
+
+ release.out = true
+ const checking = app.controller.check()
+ await app.controller.major.schedule()
+ answer.resolve()
+ await checking
+
+ expect(app.controller.getState()).toEqual({ status: "idle" })
+ expect(app.controller.major.getState()).toEqual({ status: "scheduled" })
+ expect(app.calls).not.toContain("download")
+ expect(app.calls).not.toContain("major disarm")
+ })
+
+ test("an OpenCode 1 release found while upgrade on quit is still being armed does not download", async () => {
+ const answer = Promise.withResolvers()
+ const armed = Promise.withResolvers()
+ const release = { out: false }
+ const app = setupMajor({
+ update: () => release.out,
+ check: () => (release.out ? answer.promise : undefined),
+ installOnQuit: () => armed.promise,
+ })
+ await app.offer()
+
+ release.out = true
+ const checking = app.controller.check()
+ const scheduling = app.controller.major.schedule()
+ answer.resolve()
+ await checking
+ expect(app.controller.major.getState()).toEqual({ status: "scheduling" })
+ armed.resolve()
+ await scheduling
+
+ expect(app.controller.major.getState()).toEqual({ status: "scheduled" })
+ expect(app.calls).not.toContain("download")
+ })
+
+ test("stops checking for OpenCode 1 releases once the user chose OpenCode 2", async () => {
+ const app = setupMajor()
+ await app.offer()
+ await app.controller.major.schedule()
+
+ await app.controller.check()
+
+ expect(app.calls.filter((call) => call === "check")).toHaveLength(1)
+ })
+
+ test("a check the user asked for waits for OpenCode 2 to download", async () => {
+ const download = Promise.withResolvers()
+ const app = setupMajor({ download: () => download.promise })
+ const answered: string[] = []
+
+ const checking = app.controller.checkNow().then((state) => answered.push(state.status))
+ await app.settled()
+
+ expect(app.controller.getState()).toEqual({ status: "up-to-date" })
+ expect(app.controller.major.getState()).toEqual({ status: "downloading" })
+ expect(answered).toEqual([])
+
+ download.resolve()
+ await checking
+
+ expect(answered).toEqual(["up-to-date"])
+ expect(app.controller.major.getState()).toEqual({ status: "ready", quit: true })
+ })
+})
+
+describe("major updater upgrade on quit", () => {
+ test("arms the install and keeps the app running", async () => {
+ const app = setupMajor()
+ await app.offer()
+
+ await app.controller.major.schedule()
+
+ expect(app.states).toEqual(["unavailable", "downloading", "ready", "scheduling", "scheduled"])
+ expect(app.calls).toEqual(["check", "major check", "major download", "major install on quit"])
+ })
+
+ test("that cannot be armed leaves the offer as it was", async () => {
+ const app = setupMajor({
+ installOnQuit: async () => {
+ throw new Error("cache missing")
+ },
+ })
+ await app.offer()
+
+ await expect(app.controller.major.schedule()).rejects.toThrow("cache missing")
+ expect(app.controller.major.getState()).toEqual({ status: "ready", quit: true })
+ })
+
+ test("is armed once when chosen twice", async () => {
+ const armed = Promise.withResolvers()
+ const app = setupMajor({ installOnQuit: () => armed.promise })
+ await app.offer()
+
+ const first = app.controller.major.schedule()
+ const second = app.controller.major.schedule()
+ armed.resolve()
+ await Promise.all([first, second])
+ await app.controller.major.schedule()
+
+ expect(app.calls.filter((call) => call === "major install on quit")).toHaveLength(1)
+ expect(app.controller.major.getState()).toEqual({ status: "scheduled" })
+ })
+})
+
+describe("major updater restart", () => {
+ test("stages OpenCode 2, stops the app and installs", async () => {
+ const app = setupMajor()
+ await app.offer()
+
+ await app.controller.major.restart()
+
+ expect(app.calls).toEqual(["check", "major check", "major download", "major stage", "stop", "major install"])
+ expect(app.controller.major.getState()).toEqual({ status: "installing" })
+ })
+
+ test("still works after upgrade on quit was chosen, without staging again", async () => {
+ const app = setupMajor()
+ await app.offer()
+ await app.controller.major.schedule()
+
+ await app.controller.major.restart()
+
+ expect(app.calls.slice(-3)).toEqual(["major install on quit", "stop", "major install"])
+ })
+
+ test("called twice starts the installer once", async () => {
+ const stopped = Promise.withResolvers()
+ const app = setupMajor({ stop: () => stopped.promise })
+ await app.offer()
+
+ const first = app.controller.major.restart()
+ const second = app.controller.major.restart()
+ expect(app.controller.major.getState()).toEqual({ status: "installing" })
+ stopped.resolve()
+ await Promise.all([first, second])
+ await app.controller.major.restart()
+
+ expect(second).toBe(first)
+ expect(app.calls.filter((call) => call === "stop")).toHaveLength(1)
+ expect(app.calls.filter((call) => call === "major install")).toHaveLength(1)
+ expect(app.controller.major.getState()).toEqual({ status: "installing" })
+ })
+
+ test("keeps the servers running when OpenCode 2 cannot be staged", async () => {
+ const app = setupMajor({
+ stage: async () => {
+ throw new Error("Code signature did not pass validation")
+ },
+ })
+ await app.offer()
+
+ await expect(app.controller.major.restart()).rejects.toThrow("Code signature did not pass validation")
+
+ expect(app.calls).not.toContain("stop")
+ expect(app.calls).not.toContain("major install")
+ expect(app.controller.major.getState()).toEqual({ status: "ready", quit: true })
+ })
+
+ test("returns to the offer and says the servers are stopped when stopping them fails", async () => {
+ const app = setupMajor({
+ stop: async () => {
+ throw new Error("stop failed")
+ },
+ })
+ await app.offer()
+
+ await expect(app.controller.major.restart()).rejects.toThrow("stop failed")
+
+ expect(app.calls).not.toContain("major install")
+ expect(app.controller.major.getState()).toEqual({ status: "ready", quit: true, stopped: true })
+ })
+
+ test("returns to the offer when the installer cannot start, and can try again", async () => {
+ const failure = { fail: true }
+ const app = setupMajor({
+ quitAndInstall: () => {
+ if (failure.fail) throw new Error("No update filepath provided, can't quit and install")
+ },
+ })
+ await app.offer()
+
+ await expect(app.controller.major.restart()).rejects.toThrow("No update filepath provided")
+ expect(app.controller.major.getState()).toEqual({ status: "ready", quit: true, stopped: true })
+
+ failure.fail = false
+ await app.controller.major.restart()
+
+ expect(app.calls.filter((call) => call === "major install")).toHaveLength(2)
+ expect(app.controller.major.getState()).toEqual({ status: "installing" })
+ })
+
+ test("stays armed for the next quit when staging cannot be taken back", async () => {
+ const app = setupMajor({
+ stage: async () => true,
+ stop: async () => {
+ throw new Error("stop failed")
+ },
+ })
+ await app.offer()
+
+ await expect(app.controller.major.restart()).rejects.toThrow("stop failed")
+
+ expect(app.controller.major.getState()).toEqual({ status: "scheduled", stopped: true })
+ })
+
+ test("that fails after upgrade on quit was chosen keeps the install armed", async () => {
+ const app = setupMajor({
+ quitAndInstall: () => {
+ throw new Error("installer missing")
+ },
+ })
+ await app.offer()
+ await app.controller.major.schedule()
+
+ await expect(app.controller.major.restart()).rejects.toThrow("installer missing")
+
+ expect(app.controller.major.getState()).toEqual({ status: "scheduled", stopped: true })
+ expect(app.calls).not.toContain("major disarm")
+ })
+})
+
+describe("major updater prompt", () => {
+ test("opens the offer in one window per launch", async () => {
+ const app = setupMajor({ now: () => 0 })
+ await app.offer()
+
+ expect([app.controller.major.prompt(), app.controller.major.prompt()]).toEqual(["launch", undefined])
+ })
+
+ test("measures the launch window once for the whole app, not for each window", async () => {
+ const clock = { now: 1000 }
+ const app = setupMajor({ now: () => clock.now })
+ await app.offer()
+
+ // The download took longer than the launch window. A window that opens or reloads hours later asks again.
+ clock.now = 1000 + LAUNCH_WINDOW + 1
+ expect(app.controller.major.prompt()).toBeUndefined()
+ clock.now = 1000 + 6 * 60 * 60 * 1000
+ expect(app.controller.major.prompt()).toBeUndefined()
+ })
+
+ test("still opens at the very end of the launch window", async () => {
+ const clock = { now: 1000 }
+ const app = setupMajor({ now: () => clock.now })
+ await app.offer()
+
+ clock.now = 1000 + LAUNCH_WINDOW
+ expect(app.controller.major.prompt()).toBe("launch")
+ })
+
+ test("opens the offer the user asked for in the next window, whenever that is", async () => {
+ const clock = { now: 0 }
+ const app = setupMajor({ now: () => clock.now })
+ await app.offer()
+ clock.now = LAUNCH_WINDOW * 100
+
+ app.controller.major.ask()
+
+ expect([app.controller.major.prompt(), app.controller.major.prompt()]).toEqual(["asked", undefined])
+ })
+
+ test("forgets what the user asked for when the offer is withdrawn", async () => {
+ const release = { out: false }
+ const clock = { now: 0 }
+ const app = setupMajor({ update: () => release.out, now: () => clock.now })
+ await app.offer()
+ clock.now = LAUNCH_WINDOW * 100
+ app.controller.major.ask()
+
+ release.out = true
+ await app.controller.check()
+
+ expect(app.controller.major.prompt()).toBeUndefined()
+ })
+})
diff --git a/packages/desktop/src/main/updater-controller.ts b/packages/desktop/src/main/updater-controller.ts
index a0ae1a892745..6d537b75890b 100644
--- a/packages/desktop/src/main/updater-controller.ts
+++ b/packages/desktop/src/main/updater-controller.ts
@@ -1,15 +1,35 @@
-import type { UpdaterState } from "@opencode-ai/app/updater"
+import type { MajorUpdatePrompt, MajorUpdateState, UpdaterState } from "@opencode-ai/app/updater"
-export type { UpdaterState } from "@opencode-ai/app/updater"
+export type { MajorUpdatePrompt, MajorUpdateState, UpdaterState } from "@opencode-ai/app/updater"
export type UpdaterReadyRecord = { version: string }
+// The offer opens by itself only this soon after the app starts. Later than this, the user is already working.
+export const LAUNCH_WINDOW = 30 * 1000
+
+// OpenCode 1 only offers the next major release. A feed that answers with anything older is ignored.
+const MAJOR_VERSION = 2
+
export type UpdaterBackend = {
checkForUpdates(): Promise<{ isUpdateAvailable?: boolean; updateInfo?: { version?: string } } | null | undefined>
downloadUpdate(): Promise
+ // Throws when the installer could not start, so the app keeps running.
quitAndInstall(): void
}
+export type MajorUpdaterBackend = UpdaterBackend & {
+ // Aborts a download in flight, which then rejects.
+ cancelDownload(): void
+ // Hands the downloaded OpenCode 2 to the platform installer, so quitAndInstall has nothing left to wait for. Resolves
+ // true where that cannot be taken back: on macOS, an update that Squirrel has staged installs at the next quit.
+ stage(): Promise
+ // Arms the install for the next quit and resolves once it is certain to run. Missing where an install cannot run
+ // while the app quits; Upgrade on quit is not offered there.
+ installOnQuit?: () => Promise
+ // Takes installOnQuit back, where the platform can.
+ disarm(): void
+}
+
type UpdaterPersistence = {
get(): UpdaterReadyRecord | undefined | Promise
set(value: UpdaterReadyRecord): void | Promise
@@ -20,13 +40,26 @@ export function createUpdaterController(input: {
enabled: boolean
currentVersion: string
backend: UpdaterBackend
+ // Reads the OpenCode 2 feed. Without it, OpenCode 2 is never offered.
+ major?: MajorUpdaterBackend
persistence: UpdaterPersistence
stop: () => Promise
+ // Milliseconds on a clock that only moves forward. The launch window is measured from the first reading.
+ now?: () => number
log?: (message: string, data?: object) => void
}) {
+ const now = input.now ?? (() => performance.now())
+ const started = now()
let state: UpdaterState = input.enabled ? { status: "idle" } : { status: "disabled" }
+ let major: MajorUpdateState = { status: "unavailable" }
let pending: Promise | undefined
+ let preparing: Promise | undefined
+ let scheduling: Promise | undefined
+ let installing: Promise | undefined
+ let prompted = false
+ let asked = false
const listeners = new Set<(state: UpdaterState) => void>()
+ const majorListeners = new Set<(state: MajorUpdateState) => void>()
const transition = (next: UpdaterState) => {
input.log?.("updater state changed", { from: state.status, to: next.status })
@@ -35,9 +68,61 @@ export function createUpdaterController(input: {
return state
}
+ const transitionMajor = (next: MajorUpdateState) => {
+ input.log?.("major updater state changed", { from: major.status, to: next.status })
+ major = next
+ majorListeners.forEach((listener) => listener(major))
+ return major
+ }
+
+ // Once the user picks OpenCode 2, an OpenCode 1 release must not download over it.
+ const chosen = () => major.status === "scheduling" || major.status === "scheduled" || major.status === "installing"
+
+ // Downloads OpenCode 2 ahead of the offer, the way an OpenCode 1 update downloads. A failure stays quiet and the next
+ // check tries again, because the user has not asked for anything yet.
+ const prepare = () => {
+ const backend = input.major
+ if (!backend || preparing || major.status !== "unavailable") return
+ transitionMajor({ status: "downloading" })
+ preparing = backend
+ .checkForUpdates()
+ .then(async (result) => {
+ if (!result?.isUpdateAvailable || !isMajor(result.updateInfo?.version)) return false
+ // A newer OpenCode 1 release can withdraw the offer while the feed answers.
+ if (major.status !== "downloading") return false
+ await backend.downloadUpdate()
+ return true
+ })
+ .catch((error) => {
+ input.log?.("major update download failed", { message: error instanceof Error ? error.message : String(error) })
+ return false
+ })
+ .then((downloaded) => {
+ preparing = undefined
+ // A newer OpenCode 1 release can withdraw the offer while OpenCode 2 downloads.
+ if (major.status !== "downloading") return
+ transitionMajor(
+ downloaded ? { status: "ready", quit: backend.installOnQuit !== undefined } : { status: "unavailable" },
+ )
+ })
+ }
+
+ // A newer OpenCode 1 release wins. The two updaters must never download at the same time, so this resolves only once
+ // the OpenCode 2 download has ended.
+ const withdraw = async () => {
+ asked = false
+ if (major.status !== "unavailable") {
+ transitionMajor({ status: "unavailable" })
+ input.major?.cancelDownload()
+ input.major?.disarm()
+ }
+ await preparing
+ }
+
const check = () => {
if (!input.enabled) return Promise.resolve(state)
if (state.status === "ready") return Promise.resolve(state)
+ if (chosen()) return Promise.resolve(state)
if (pending) return pending
pending = (async () => {
@@ -46,9 +131,13 @@ export function createUpdaterController(input: {
const version = result?.updateInfo?.version
if (!result?.isUpdateAvailable || !version || version === input.currentVersion) {
await input.persistence.clear()
+ prepare()
return transition({ status: "up-to-date" })
}
+ // The user can pick OpenCode 2 while the feed answers.
+ if (chosen()) return transition({ status: "idle" })
+ await withdraw()
transition({ status: "downloading", version })
await input.backend.downloadUpdate()
await input.persistence.set({ version })
@@ -76,6 +165,13 @@ export function createUpdaterController(input: {
return check()
},
check,
+ // A check the user asked for. It also waits for OpenCode 2 to finish downloading, so the answer is never "up to
+ // date" while the upgrade is still on its way.
+ async checkNow() {
+ await check()
+ await preparing
+ return state
+ },
async install() {
if (state.status !== "ready") throw new Error("Update is not ready to install")
const version = state.version
@@ -91,7 +187,80 @@ export function createUpdaterController(input: {
throw error
})
},
+ major: {
+ getState: () => major,
+ subscribe(listener: (state: MajorUpdateState) => void) {
+ majorListeners.add(listener)
+ listener(major)
+ return () => majorListeners.delete(listener)
+ },
+ // Whether the calling window opens the offer by itself. Every window asks once the offer exists, and the answer
+ // is decided here, so a window that opens or reloads later never starts a launch window of its own.
+ prompt(): MajorUpdatePrompt {
+ if (asked) {
+ asked = false
+ return "asked"
+ }
+ if (prompted || now() - started > LAUNCH_WINDOW) return
+ prompted = true
+ return "launch"
+ },
+ // The user asked for the offer while no window could show it. The next window to prompt opens it.
+ ask() {
+ asked = true
+ },
+ // Nothing installs until the user picks one of these two.
+ restart() {
+ const backend = input.major
+ // The installer must start once, so every later call joins the first.
+ if (installing) return installing
+ if (!backend || (major.status !== "ready" && major.status !== "scheduled"))
+ return Promise.reject(new Error("OpenCode 2 is not ready to install"))
+ const failed = { state: major, stopped: false }
+ transitionMajor({ status: "installing" })
+ installing = (async () => {
+ if (failed.state.status === "ready" && (await backend.stage())) failed.state = { status: "scheduled" }
+ failed.stopped = true
+ await input.stop()
+ backend.quitAndInstall()
+ })().catch((error) => {
+ installing = undefined
+ // The servers are gone by now, so the app has to restart before it works again.
+ transitionMajor(failed.stopped ? { ...failed.state, stopped: true } : failed.state)
+ throw error
+ })
+ return installing
+ },
+ schedule() {
+ const backend = input.major
+ if (scheduling) return scheduling
+ if (major.status === "scheduled") return Promise.resolve()
+ if (!backend?.installOnQuit || major.status !== "ready")
+ return Promise.reject(new Error("OpenCode 2 is not ready to install"))
+ const offer = major
+ transitionMajor({ status: "scheduling" })
+ scheduling = backend
+ .installOnQuit()
+ .then(
+ () => {
+ transitionMajor({ status: "scheduled" })
+ },
+ (error) => {
+ transitionMajor(offer)
+ throw error
+ },
+ )
+ .finally(() => {
+ scheduling = undefined
+ })
+ return scheduling
+ },
+ },
}
}
+function isMajor(version: string | undefined) {
+ return Number(version?.split(".")[0]) >= MAJOR_VERSION
+}
+
export type UpdaterController = ReturnType
diff --git a/packages/desktop/src/main/updater.ts b/packages/desktop/src/main/updater.ts
index 08350917c1b6..241427654488 100644
--- a/packages/desktop/src/main/updater.ts
+++ b/packages/desktop/src/main/updater.ts
@@ -1,7 +1,12 @@
-import { app, dialog } from "electron"
-import pkg from "electron-updater"
-import { UPDATER_ENABLED } from "./constants"
-import { createUpdaterController, type UpdaterReadyRecord } from "./updater-controller"
+import electron, { app, dialog } from "electron"
+import pkg, { type AppUpdater, type CancellationToken } from "electron-updater"
+import { CHANNEL, UPDATER_ENABLED } from "./constants"
+import {
+ createUpdaterController,
+ type MajorUpdaterBackend,
+ type UpdaterBackend,
+ type UpdaterReadyRecord,
+} from "./updater-controller"
import { getLogger } from "./logging"
import { getStore } from "./store"
import { setAppQuitting } from "./windows"
@@ -10,6 +15,87 @@ import { nativeT } from "./native-translations"
const { autoUpdater } = pkg
const key = "ready"
+// OpenCode 2 desktop keeps the app ID, so its installer replaces OpenCode 1 in place.
+// OpenCode 1 reads GitHub releases; this is the feed OpenCode 2 publishes to.
+const MAJOR_FEED = "https://opencode.ai/update/api/latest/desktop/opencode/"
+
+// A second updater, so switching feeds can never make the OpenCode 1 updater download OpenCode 2.
+function majorUpdater() {
+ // Both updaters take their cache folder name from app-update.yml, and both feeds name their installers alike. In one
+ // folder each updater would overwrite, delete and install the other's download. electron-updater 6.8.9 has no option
+ // for the folder: AppUpdater.getOrCreateDownloadHelper reads it from this internal field, so the OpenCode 2 updater
+ // reads the same config under its own folder name. Without the field there is no safe folder and no OpenCode 2 offer.
+ // Check this again whenever electron-updater changes.
+ const config: { value: Promise<{ updaterCacheDirName?: string }> } | undefined = Reflect.get(
+ autoUpdater,
+ "configOnDisk",
+ )
+ if (!config) throw new Error("electron-updater cannot give the OpenCode 2 download its own folder")
+ // autoUpdater is already the right updater for this platform and package type, so build another of the same class.
+ const Updater = autoUpdater.constructor as new (options: { provider: "generic"; url: string }) => AppUpdater
+ const updater = new Updater({ provider: "generic", url: MAJOR_FEED })
+ Reflect.set(updater, "configOnDisk", {
+ get value() {
+ return config.value.then((disk) => ({
+ ...disk,
+ updaterCacheDirName: `${disk.updaterCacheDirName ?? app.getName()}-major`,
+ }))
+ },
+ })
+ updater.logger = getLogger()
+ updater.channel = "latest"
+ // Setting the channel allows downgrades. This feed must only ever move the app forward.
+ updater.allowDowngrade = false
+ updater.allowPrerelease = false
+ updater.autoDownload = false
+ updater.autoInstallOnAppQuit = false
+ // The OpenCode 2 feed has no block maps against an OpenCode 1 install, so a differential download could only fail
+ // before the full one starts. On macOS it would also keep a second copy of the archive.
+ updater.disableDifferentialDownload = true
+ return updater
+}
+
+// On macOS only Squirrel can install, and it first fetches, unpacks and verifies the archive. electron-updater resolves
+// as soon as it has handed the archive over, so this waits for Squirrel itself to report the staged update, or the
+// error that stopped it. A staged update installs at the next quit and cannot be handed back.
+function squirrel(updater: AppUpdater) {
+ const staged = Promise.withResolvers()
+ const done = () => staged.resolve()
+ const refused = () => staged.reject(new Error("Squirrel found no update to stage"))
+ electron.autoUpdater.once("update-downloaded", done)
+ electron.autoUpdater.once("update-not-available", refused)
+ electron.autoUpdater.once("error", staged.reject)
+ return Promise.all([updater.downloadUpdate(), staged.promise]).finally(() => {
+ electron.autoUpdater.off("update-downloaded", done)
+ electron.autoUpdater.off("update-not-available", refused)
+ electron.autoUpdater.off("error", staged.reject)
+ })
+}
+
+function quitAndInstall(updater: AppUpdater) {
+ // quitAndInstall closes all windows before emitting before-quit, so
+ // flag the quit first to keep window ids persisted for restore.
+ setAppQuitting()
+ // electron-updater reports an installer that could not start as an error event and then returns normally.
+ const failures: unknown[] = []
+ const fail = (error: Error) => {
+ failures.push(error)
+ }
+ updater.on("error", fail)
+ try {
+ updater.quitAndInstall()
+ } catch (error) {
+ failures.push(error)
+ } finally {
+ updater.off("error", fail)
+ }
+ if (failures.length === 0) return
+ // The install failed and the app keeps running; clear the flag so
+ // deliberate window closes prune ids again.
+ setAppQuitting(false)
+ throw failures[0]
+}
+
export function setupAutoUpdater(stop: () => Promise) {
const logger = getLogger()
autoUpdater.logger = logger
@@ -25,27 +111,55 @@ export function setupAutoUpdater(stop: () => Promise) {
currentVersion: app.getVersion(),
})
+ const backend: UpdaterBackend = {
+ checkForUpdates: () => autoUpdater.checkForUpdates(),
+ downloadUpdate: () => autoUpdater.downloadUpdate(),
+ quitAndInstall: () => quitAndInstall(autoUpdater),
+ }
+
+ const majorBackend = (): MajorUpdaterBackend => {
+ // Built on the first OpenCode 2 check. While an OpenCode 1 release is the update to install, this updater does not
+ // exist, so on macOS it cannot listen to the system updater that the OpenCode 1 release goes through.
+ const lazy: { updater?: AppUpdater; download?: CancellationToken } = {}
+ const updater = () => (lazy.updater ??= majorUpdater())
+ // electron-updater only arms its install on quit while a download finishes. The installer is already in the cache,
+ // so downloading again returns at once and arms it.
+ const arm = () => {
+ updater().autoInstallOnAppQuit = true
+ return (process.platform === "darwin" ? squirrel(updater()) : updater().downloadUpdate()).catch((error) => {
+ updater().autoInstallOnAppQuit = false
+ throw error
+ })
+ }
+ return {
+ checkForUpdates: async () => updater().checkForUpdates(),
+ downloadUpdate: () => {
+ lazy.download = new pkg.CancellationToken()
+ return updater().downloadUpdate(lazy.download)
+ },
+ cancelDownload: () => lazy.download?.cancel(),
+ stage: async () => {
+ if (process.platform !== "darwin") return false
+ await arm()
+ return true
+ },
+ // A .deb, .rpm or pacman package installs behind a password prompt, which must not appear after the windows have
+ // closed. Only a restart is offered there.
+ installOnQuit: process.platform !== "linux" || autoUpdater instanceof pkg.AppImageUpdater ? arm : undefined,
+ disarm: () => {
+ if (lazy.updater) lazy.updater.autoInstallOnAppQuit = false
+ },
+ quitAndInstall: () => quitAndInstall(updater()),
+ }
+ }
+
const store = getStore("opencode.updater")
return createUpdaterController({
enabled: UPDATER_ENABLED,
currentVersion: app.getVersion(),
- backend: {
- checkForUpdates: () => autoUpdater.checkForUpdates(),
- downloadUpdate: () => autoUpdater.downloadUpdate(),
- quitAndInstall: () => {
- // quitAndInstall closes all windows before emitting before-quit, so
- // flag the quit first to keep window ids persisted for restore.
- setAppQuitting()
- try {
- autoUpdater.quitAndInstall()
- } catch (error) {
- // The install failed and the app keeps running; clear the flag so
- // deliberate window closes prune ids again.
- setAppQuitting(false)
- throw error
- }
- },
- },
+ backend,
+ // Only the release channel ships OpenCode 1 desktop builds.
+ major: UPDATER_ENABLED && CHANNEL === "prod" ? majorBackend() : undefined,
persistence: {
get() {
const value = store.get(key)
@@ -60,8 +174,15 @@ export function setupAutoUpdater(stop: () => Promise) {
})
}
-export async function showUpdaterDialog(controller: ReturnType, alertOnFail: boolean) {
- const state = await controller.check()
+export async function showUpdaterDialog(
+ controller: ReturnType,
+ alertOnFail: boolean,
+ offerMajor: () => void,
+) {
+ const state = await controller.checkNow()
+ // With no OpenCode 1 release left to install, checking for updates opens the OpenCode 2 offer instead.
+ const major = controller.major.getState().status
+ if (alertOnFail && state.status !== "ready" && major !== "unavailable" && major !== "downloading") return offerMajor()
if (state.status === "error") {
if (!alertOnFail) return
await dialog.showMessageBox({
diff --git a/packages/desktop/src/preload/index.ts b/packages/desktop/src/preload/index.ts
index dae18b0716a4..bb651712b900 100644
--- a/packages/desktop/src/preload/index.ts
+++ b/packages/desktop/src/preload/index.ts
@@ -1,14 +1,35 @@
import { contextBridge, ipcRenderer, webUtils } from "electron"
import type { ElectronAPI, WslServersEvent } from "./types"
-import type { UpdaterState } from "@opencode-ai/app/updater"
+import type { MajorUpdateState, UpdaterState } from "@opencode-ai/app/updater"
const updaterCallbacks = new Set<(state: UpdaterState) => void>()
+const majorCallbacks = new Set<(state: MajorUpdateState) => void>()
let updaterState: UpdaterState | undefined
+let majorState: MajorUpdateState | undefined
let updaterSubscription: Promise | undefined
const updaterHandler = (_: unknown, state: UpdaterState) => {
updaterState = state
updaterCallbacks.forEach((callback) => callback(state))
}
+const majorHandler = (_: unknown, state: MajorUpdateState) => {
+ majorState = state
+ majorCallbacks.forEach((callback) => callback(state))
+}
+// One main-process subscription feeds both the OpenCode 1 updater and the OpenCode 2 offer.
+const subscribeUpdater = () => {
+ if (updaterSubscription) return updaterSubscription
+ ipcRenderer.on("updater-state", updaterHandler)
+ ipcRenderer.on("updater-major-state", majorHandler)
+ updaterSubscription = ipcRenderer.invoke("updater-subscribe")
+ return updaterSubscription
+}
+const unsubscribeUpdater = () => {
+ if (updaterCallbacks.size > 0 || majorCallbacks.size > 0) return
+ ipcRenderer.removeListener("updater-state", updaterHandler)
+ ipcRenderer.removeListener("updater-major-state", majorHandler)
+ updaterSubscription = undefined
+ void ipcRenderer.invoke("updater-unsubscribe")
+}
const api: ElectronAPI = {
killSidecar: () => ipcRenderer.invoke("kill-sidecar"),
@@ -40,21 +61,28 @@ const api: ElectronAPI = {
subscribe: async (cb) => {
updaterCallbacks.add(cb)
if (updaterState) cb(updaterState)
- if (!updaterSubscription) {
- ipcRenderer.on("updater-state", updaterHandler)
- updaterSubscription = ipcRenderer.invoke("updater-subscribe")
- }
- await updaterSubscription
+ await subscribeUpdater()
return () => {
updaterCallbacks.delete(cb)
- if (updaterCallbacks.size > 0) return
- ipcRenderer.removeListener("updater-state", updaterHandler)
- updaterSubscription = undefined
- void ipcRenderer.invoke("updater-unsubscribe")
+ unsubscribeUpdater()
}
},
check: () => ipcRenderer.invoke("updater-check"),
install: () => ipcRenderer.invoke("updater-install"),
+ major: {
+ subscribe: async (cb) => {
+ majorCallbacks.add(cb)
+ if (majorState) cb(majorState)
+ await subscribeUpdater()
+ return () => {
+ majorCallbacks.delete(cb)
+ unsubscribeUpdater()
+ }
+ },
+ prompt: () => ipcRenderer.invoke("updater-major-prompt"),
+ restart: () => ipcRenderer.invoke("updater-major-restart"),
+ schedule: () => ipcRenderer.invoke("updater-major-schedule"),
+ },
},
consumeInitialDeepLinks: () => ipcRenderer.invoke("consume-initial-deep-links"),
getDefaultServerUrl: () => ipcRenderer.invoke("get-default-server-url"),
diff --git a/packages/desktop/src/preload/types.ts b/packages/desktop/src/preload/types.ts
index 20c39097d31d..ce8fed3b839b 100644
--- a/packages/desktop/src/preload/types.ts
+++ b/packages/desktop/src/preload/types.ts
@@ -1,6 +1,6 @@
import type { DesktopMenuAction } from "@opencode-ai/app/desktop-menu"
import type { WslServersPlatform } from "@opencode-ai/app/wsl/types"
-import type { UpdaterState } from "@opencode-ai/app/updater"
+import type { MajorUpdatePrompt, MajorUpdateState, UpdaterState } from "@opencode-ai/app/updater"
import type { DesktopNativeBundle } from "@opencode-ai/app/i18n/desktop-native"
export type {
WslDistroProbe,
@@ -27,6 +27,12 @@ export type UpdaterAPI = {
subscribe: (cb: (state: UpdaterState) => void) => Promise<() => void>
check: () => Promise
install: () => Promise
+ major: {
+ subscribe: (cb: (state: MajorUpdateState) => void) => Promise<() => void>
+ prompt: () => Promise
+ restart: () => Promise
+ schedule: () => Promise
+ }
}
export type LinuxDisplayBackend = "wayland" | "auto"
diff --git a/packages/desktop/src/renderer/index.tsx b/packages/desktop/src/renderer/index.tsx
index 496060e0d665..68c22dfc7fc5 100644
--- a/packages/desktop/src/renderer/index.tsx
+++ b/packages/desktop/src/renderer/index.tsx
@@ -15,7 +15,7 @@ import {
useWslServers,
useLanguage,
} from "@opencode-ai/app"
-import type { UpdaterState } from "@opencode-ai/app/updater"
+import type { MajorUpdateState, UpdaterState } from "@opencode-ai/app/updater"
import * as Sentry from "@sentry/solid"
import type { AsyncStorage } from "@solid-primitives/storage"
import { createMemoryHistory, MemoryRouter, type BaseRouterProps } from "@solidjs/router"
@@ -62,6 +62,8 @@ if (import.meta.env.VITE_SENTRY_DSN) {
const [updaterState, setUpdaterState] = createSignal({ status: "disabled" })
void window.api.updater.subscribe(setUpdaterState)
+const [majorUpdateState, setMajorUpdateState] = createSignal({ status: "unavailable" })
+void window.api.updater.major.subscribe(setMajorUpdateState)
const deepLinkEvent = "opencode:deep-link"
@@ -238,6 +240,12 @@ const createPlatform = (windowState: DesktopWindowState): Platform => {
state: updaterState,
check: () => window.api.updater.check(),
install: () => window.api.updater.install(),
+ major: {
+ state: majorUpdateState,
+ prompt: () => window.api.updater.major.prompt(),
+ restart: () => window.api.updater.major.restart(),
+ schedule: () => window.api.updater.major.schedule(),
+ },
},
exportDebugLogs: () => window.api.exportDebugLogs(),