summaryrefslogtreecommitdiffhomepage
path: root/packages/tauri/src/updater.ts
diff options
context:
space:
mode:
authorBrendan Allan <[email protected]>2025-12-09 17:16:24 +0800
committerBrendan Allan <[email protected]>2025-12-09 17:16:24 +0800
commit78547f3c5909b66a9d0e86f4ae3dde7e082b6bbc (patch)
tree57f0d58f577adfd3c11d71138a3a1b94e4ddde2d /packages/tauri/src/updater.ts
parentd32671224f43f483ea5b4e05c159a80c071618e6 (diff)
downloadopencode-78547f3c5909b66a9d0e86f4ae3dde7e082b6bbc.tar.gz
opencode-78547f3c5909b66a9d0e86f4ae3dde7e082b6bbc.zip
desktop: move updater logic to js
Diffstat (limited to 'packages/tauri/src/updater.ts')
-rw-r--r--packages/tauri/src/updater.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/packages/tauri/src/updater.ts b/packages/tauri/src/updater.ts
new file mode 100644
index 000000000..e2bf04743
--- /dev/null
+++ b/packages/tauri/src/updater.ts
@@ -0,0 +1,37 @@
+import { check, DownloadEvent } from '@tauri-apps/plugin-updater';
+import { relaunch } from '@tauri-apps/plugin-process';
+import { ask, message } from '@tauri-apps/plugin-dialog';
+
+export async function runUpdater(onDownloadEvent?:(progress: DownloadEvent) => void) {
+ let update;
+ try {
+ update = await check();
+ } catch {
+ await message("Failed to check for updates")
+ return false
+ }
+
+ if (!update) return;
+ if (update.version <= update.currentVersion) return;
+
+ try {
+ await update.download(onDownloadEvent);
+ } catch {
+ return false
+ }
+
+ const shouldUpdate = await ask(`Version ${update.version} of OpenCode is available, would you like to install it?`)
+ if (!shouldUpdate) return;
+
+ try {
+ await update.install();
+ } catch {
+ await message("Failed to install update")
+ return false
+ }
+
+ const shouldRestart = await ask("Update installed successfully, would you like to restart OpenCode?");
+ if(shouldRestart) await relaunch()
+
+ return true;
+}