(ctx: PluginInput, enabled: boolean)
| 17 | const PACKAGE_NAME = "@tarquinen/opencode-dcp" |
| 18 | |
| 19 | export function startAutoUpdate(ctx: PluginInput, enabled: boolean): void { |
| 20 | if (!enabled) return |
| 21 | |
| 22 | const controller = new AbortController() |
| 23 | const timeout = setTimeout(() => controller.abort(), 10_000) |
| 24 | void checkAutoUpdate(controller.signal) |
| 25 | .then((result) => { |
| 26 | if (!result.updated) return |
| 27 | setTimeout(() => { |
| 28 | ctx.client.tui.showToast({ |
| 29 | body: { |
| 30 | title: "DCP update ready", |
| 31 | message: `Updated ${result.name} from ${result.current} to ${result.latest}. Restart OpenCode to finish.`, |
| 32 | variant: "info", |
| 33 | duration: 7000, |
| 34 | }, |
| 35 | }) |
| 36 | }, 5000) |
| 37 | }) |
| 38 | .catch(() => {}) |
| 39 | .finally(() => clearTimeout(timeout)) |
| 40 | } |
| 41 | |
| 42 | export async function checkAutoUpdate(signal: AbortSignal): Promise<UpdateResult> { |
| 43 | const packageDir = await findPackageDir(PACKAGE_NAME) |
no test coverage detected