upgrade.ts 657 B

1234567891011121314151617
  1. import { Bus } from "@/bus"
  2. import { Config } from "@/config/config"
  3. import { Flag } from "@/flag/flag"
  4. import { Installation } from "@/installation"
  5. export async function upgrade() {
  6. const config = await Config.global()
  7. if (config.autoupdate === false || Flag.OPENCODE_DISABLE_AUTOUPDATE) return
  8. const latest = await Installation.latest().catch(() => {})
  9. if (!latest) return
  10. if (Installation.VERSION === latest) return
  11. const method = await Installation.method()
  12. if (method === "unknown") return
  13. await Installation.upgrade(method, latest)
  14. .then(() => Bus.publish(Installation.Event.Updated, { version: latest }))
  15. .catch(() => {})
  16. }