summaryrefslogtreecommitdiffhomepage
path: root/packages/tauri/src
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
parentd32671224f43f483ea5b4e05c159a80c071618e6 (diff)
downloadopencode-78547f3c5909b66a9d0e86f4ae3dde7e082b6bbc.tar.gz
opencode-78547f3c5909b66a9d0e86f4ae3dde7e082b6bbc.zip
desktop: move updater logic to js
Diffstat (limited to 'packages/tauri/src')
-rw-r--r--packages/tauri/src/index.tsx12
-rw-r--r--packages/tauri/src/updater.ts37
2 files changed, 46 insertions, 3 deletions
diff --git a/packages/tauri/src/index.tsx b/packages/tauri/src/index.tsx
index 9371b4826..17a45a5e9 100644
--- a/packages/tauri/src/index.tsx
+++ b/packages/tauri/src/index.tsx
@@ -1,6 +1,8 @@
// @refresh reload
import { render } from "solid-js/web"
import { DesktopInterface, PlatformProvider, Platform } from "@opencode-ai/desktop"
+import { runUpdater } from "./updater";
+import { onMount } from "solid-js";
const root = document.getElementById("root")
if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
@@ -12,10 +14,14 @@ if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
const platform: Platform = {}
render(
- () => (
- <PlatformProvider value={platform}>
+ () => {
+ onMount(() => {
+ if(window.__OPENCODE__.updaterEnabled) runUpdater();
+ });
+
+ return <PlatformProvider value={platform}>
<DesktopInterface />
</PlatformProvider>
- ),
+ },
root!,
)
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;
+}