2025-10-31 19:07:36 +00:00
|
|
|
import { Bus } from "@/bus"
|
2026-04-16 01:26:24 +00:00
|
|
|
import { Config } from "@/config"
|
2026-04-11 03:26:16 +00:00
|
|
|
import { AppRuntime } from "@/effect/app-runtime"
|
2026-04-25 17:29:52 +00:00
|
|
|
import { Flag } from "@opencode-ai/core/flag/flag"
|
2025-10-31 19:07:36 +00:00
|
|
|
import { Installation } from "@/installation"
|
2026-04-25 17:29:52 +00:00
|
|
|
import { InstallationVersion } from "@opencode-ai/core/installation/version"
|
2025-10-31 19:07:36 +00:00
|
|
|
|
|
|
|
|
export async function upgrade() {
|
2026-04-13 17:11:05 +00:00
|
|
|
const config = await AppRuntime.runPromise(Config.Service.use((cfg) => cfg.getGlobal()))
|
2026-04-21 19:30:15 +00:00
|
|
|
if (config.autoupdate === false || Flag.OPENCODE_DISABLE_AUTOUPDATE) return
|
2026-04-27 03:54:59 +00:00
|
|
|
const method = await Installation.method()
|
|
|
|
|
const latest = await Installation.latest(method).catch(() => {})
|
2025-10-31 19:07:36 +00:00
|
|
|
if (!latest) return
|
2025-11-22 22:26:46 +00:00
|
|
|
|
2026-03-22 23:12:40 +00:00
|
|
|
if (Flag.OPENCODE_ALWAYS_NOTIFY_UPDATE) {
|
|
|
|
|
await Bus.publish(Installation.Event.UpdateAvailable, { version: latest })
|
2025-11-24 20:32:38 +00:00
|
|
|
return
|
|
|
|
|
}
|
2026-03-22 23:12:40 +00:00
|
|
|
|
2026-04-16 06:03:03 +00:00
|
|
|
if (InstallationVersion === latest) return
|
2026-03-22 23:12:40 +00:00
|
|
|
|
2026-04-16 06:03:03 +00:00
|
|
|
const kind = Installation.getReleaseType(InstallationVersion, latest)
|
2026-03-22 23:12:40 +00:00
|
|
|
|
|
|
|
|
if (config.autoupdate === "notify" || kind !== "patch") {
|
2025-11-22 22:26:46 +00:00
|
|
|
await Bus.publish(Installation.Event.UpdateAvailable, { version: latest })
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-31 19:07:36 +00:00
|
|
|
if (method === "unknown") return
|
2026-04-27 03:54:59 +00:00
|
|
|
await Installation.upgrade(method, latest)
|
2025-10-31 19:07:36 +00:00
|
|
|
.then(() => Bus.publish(Installation.Event.Updated, { version: latest }))
|
|
|
|
|
.catch(() => {})
|
|
|
|
|
}
|