2025-10-31 19:07:36 +00:00
|
|
|
import { Bus } from "@/bus"
|
|
|
|
|
import { Config } from "@/config/config"
|
|
|
|
|
import { Flag } from "@/flag/flag"
|
|
|
|
|
import { Installation } from "@/installation"
|
|
|
|
|
|
|
|
|
|
export async function upgrade() {
|
2026-03-26 17:07:01 +00:00
|
|
|
const config = await Config.getGlobal()
|
2025-12-02 23:43:20 +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
|
|
|
|
|
|
|
|
if (Installation.VERSION === latest) return
|
|
|
|
|
if (config.autoupdate === false || Flag.OPENCODE_DISABLE_AUTOUPDATE) return
|
|
|
|
|
|
|
|
|
|
const kind = Installation.getReleaseType(Installation.VERSION, latest)
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
await Installation.upgrade(method, latest)
|
|
|
|
|
.then(() => Bus.publish(Installation.Event.Updated, { version: latest }))
|
|
|
|
|
.catch(() => {})
|
|
|
|
|
}
|