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"
|
2025-10-31 19:07:36 +00:00
|
|
|
import { Flag } from "@/flag/flag"
|
|
|
|
|
import { Installation } from "@/installation"
|
2026-04-16 06:03:03 +00:00
|
|
|
import { InstallationVersion } from "@/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-11 03:26:16 +00:00
|
|
|
const method = await AppRuntime.runPromise(Installation.Service.use((svc) => svc.method()))
|
|
|
|
|
const latest = await AppRuntime.runPromise(Installation.Service.use((svc) => svc.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
|
|
|
if (config.autoupdate === false || Flag.OPENCODE_DISABLE_AUTOUPDATE) return
|
|
|
|
|
|
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-11 03:26:16 +00:00
|
|
|
await AppRuntime.runPromise(Installation.Service.use((svc) => svc.upgrade(method, latest)))
|
2025-10-31 19:07:36 +00:00
|
|
|
.then(() => Bus.publish(Installation.Event.Updated, { version: latest }))
|
|
|
|
|
.catch(() => {})
|
|
|
|
|
}
|