upgrade.ts 803 B

12345678910111213141516171819202122232425
  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. const latest = await Installation.latest().catch(() => {})
  8. if (!latest) return
  9. if (Installation.VERSION === latest) return
  10. if (config.autoupdate === false || Flag.OPENCODE_DISABLE_AUTOUPDATE) {
  11. return
  12. }
  13. if (config.autoupdate === "notify") {
  14. await Bus.publish(Installation.Event.UpdateAvailable, { version: latest })
  15. return
  16. }
  17. const method = await Installation.method()
  18. if (method === "unknown") return
  19. await Installation.upgrade(method, latest)
  20. .then(() => Bus.publish(Installation.Event.Updated, { version: latest }))
  21. .catch(() => {})
  22. }