From fdf05245a951ded406ccf8cc5560228aa0c749f1 Mon Sep 17 00:00:00 2001 From: Marc Seiler Date: Fri, 11 Sep 2026 00:10:35 -0400 Subject: [PATCH] feat: in-app update checks and one-click install The updater plugin, signing key and manifest were all wired up but nothing in the frontend ever called check(), so the "you'll see a notification" promise in the docs was never true. - updaterStore wraps check / downloadAndInstall / relaunch with idle/checking/available/downloading/ready/error states and download progress. Background checks (15s after launch, then every 6h) are silent; only an available update changes the UI. - Settings > Updates card: current version, last checked, "Check for updates automatically" toggle (new autoCheckUpdates setting, default on), release notes, progress bar, Install & Restart. - Green dot on the sidebar Settings icon while an update is pending. - updater_can_self_update (Rust) reports whether the install can replace itself; Linux .deb/.rpm get a link to Releases instead of a button. - Tighten the desktop capability to updater:allow-check, updater:allow-download-and-install and process:allow-restart. - examples/updater_probe.rs downloads and signature-verifies the latest release against the real manifest; verified against v0.4.0. --- AGENTS.md | 14 ++ README.md | 2 +- bun.lock | 3 + .../docs/getting-started/installation.md | 6 +- package.json | 1 + src-tauri/Cargo.lock | 11 ++ src-tauri/Cargo.toml | 1 + src-tauri/capabilities/desktop.json | 4 +- src-tauri/examples/updater_probe.rs | 51 ++++++ src-tauri/src/lib.rs | 4 + src-tauri/src/updater_info.rs | 34 ++++ src/lib/components/IconSidebar.svelte | 9 +- src/lib/components/UpdatesCard.svelte | 119 +++++++++++++ src/lib/stores/settings.svelte.ts | 7 + src/lib/stores/updater.svelte.ts | 167 ++++++++++++++++++ src/routes/+layout.svelte | 7 + src/routes/settings/+page.svelte | 2 + tests/screenshots/capture-all-pages.spec.ts | 9 + 18 files changed, 446 insertions(+), 5 deletions(-) create mode 100644 src-tauri/examples/updater_probe.rs create mode 100644 src-tauri/src/updater_info.rs create mode 100644 src/lib/components/UpdatesCard.svelte create mode 100644 src/lib/stores/updater.svelte.ts diff --git a/AGENTS.md b/AGENTS.md index 0c25b93..efe1259 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -45,6 +45,20 @@ the user's login shell. Do not spawn processes before that call, and keep the Surface backend errors verbatim in the UI (`Failed to load X: ${e}`) — a generic message hid this exact problem for a long time. +### In-app updater + +`updaterStore` (`src/lib/stores/updater.svelte.ts`) wraps `@tauri-apps/plugin-updater`. +The root layout calls `init()` once; checks run 15s after launch and every 6h when +`settings.autoCheckUpdates` is on. Background checks are *silent* — only an +available update changes UI state, so offline/private setups never see errors. +The manifest is `update.json` on gh-pages (published from tauri-action's +`latest.json` by `release-please.yml`) with the GitHub Releases URL as fallback. +Linux `.deb`/`.rpm` cannot self-update; `updater_can_self_update` (Rust) reports +this via the `APPIMAGE` env var and the UI links to Releases instead. + +To verify a published release end-to-end (manifest, download, signature) without +installing anything: `cd src-tauri && cargo run --example updater_probe`. + ### Component Library (`src/lib/components/ui/`) - **DataTable**: Powerful table with sorting, filtering, column visibility, drag-and-drop, and batch actions. diff --git a/README.md b/README.md index 5d7d754..0e9a9bd 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ Kore uses GitHub Actions for automated testing and releases. ### Setting Up Auto-Updates -The Tauri updater requires signed binaries. To set this up: +The in-app updater checks `https://devtheops.github.io/kore/update.json` (falling back to the `latest.json` asset on the latest GitHub Release) and verifies downloads against the public key below. To set up signing for a fork: 1. **Generate signing keys**: diff --git a/bun.lock b/bun.lock index 07b6e42..000b467 100644 --- a/bun.lock +++ b/bun.lock @@ -17,6 +17,7 @@ "@tauri-apps/plugin-fs": "~2.5.0", "@tauri-apps/plugin-notification": "~2.4.0", "@tauri-apps/plugin-opener": "^2.5.5", + "@tauri-apps/plugin-process": "^2.3.1", "@tauri-apps/plugin-updater": "~2.11.0", "@tauri-apps/plugin-websocket": "~2.4.3", "@types/js-yaml": "^4.0.9", @@ -314,6 +315,8 @@ "@tauri-apps/plugin-opener": ["@tauri-apps/plugin-opener@2.5.5", "", { "dependencies": { "@tauri-apps/api": "^2.11.0" } }, "sha512-xvzGai5aQds8j8R8RsUK/lW6pGG50YgOYIPLzvkqmkwAj7dfySOD7sGtejRzvVdMmv1EQfKVEFh1MvmDp8QR0g=="], + "@tauri-apps/plugin-process": ["@tauri-apps/plugin-process@2.3.1", "", { "dependencies": { "@tauri-apps/api": "^2.8.0" } }, "sha512-nCa4fGVaDL/B9ai03VyPOjfAHRHSBz5v6F/ObsB73r/dA3MHHhZtldaDMIc0V/pnUw9ehzr2iEG+XkSEyC0JJA=="], + "@tauri-apps/plugin-updater": ["@tauri-apps/plugin-updater@2.11.0", "", { "dependencies": { "@tauri-apps/api": "^2.11.0" } }, "sha512-AE36XkOoSna24G40jZMY15nzAnkXEPL/73tGoseGrtGOHuI/cZwWzHpZFLjKXDPgzYZ435z1gHu28LgrsBwIxQ=="], "@tauri-apps/plugin-websocket": ["@tauri-apps/plugin-websocket@2.4.3", "", { "dependencies": { "@tauri-apps/api": "^2.11.0" } }, "sha512-c85ykljg6AzY6Zw4KpYsEBaLirjPIs6m8xxC6hZcdwAchckaBU368US+oSsa5B43PjSLukjwD5vOOqzYYnswWA=="], diff --git a/docs/src/content/docs/getting-started/installation.md b/docs/src/content/docs/getting-started/installation.md index 5afb58b..0072e49 100644 --- a/docs/src/content/docs/getting-started/installation.md +++ b/docs/src/content/docs/getting-started/installation.md @@ -67,6 +67,8 @@ sudo dpkg -i kore_*.deb ## Updating -Kore includes a built-in auto-updater. When a new version is available you will see a notification in the app. Click **Update** to download and install in the background. +Kore checks for updates shortly after launch and every six hours. When a new version is available, a green dot appears on the **Settings** icon in the sidebar; open **Settings → Updates** to read the release notes and click **Install & Restart**. Updates are downloaded from GitHub Releases and verified against Kore's signing key before they are applied. -Alternatively, download the latest installer from the [Releases page](https://github.com/DEVtheOPS/kore/releases/latest) and install it over the existing version. +Turn off automatic checks with **Check for updates automatically** in the same card — you can still check manually with **Check Now**. + +Linux `.deb` / `.rpm` installs cannot replace themselves: Kore shows the new version and links to the [Releases page](https://github.com/DEVtheOPS/kore/releases/latest) so you can install the package with your package manager. AppImage, macOS, and Windows installs update in place. diff --git a/package.json b/package.json index 62adc6c..07e4c57 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "@tauri-apps/plugin-fs": "~2.5.0", "@tauri-apps/plugin-notification": "~2.4.0", "@tauri-apps/plugin-opener": "^2.5.5", + "@tauri-apps/plugin-process": "^2.3.1", "@tauri-apps/plugin-updater": "~2.11.0", "@tauri-apps/plugin-websocket": "~2.4.3", "@types/js-yaml": "^4.0.9", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 8f19830..59bcc63 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2600,6 +2600,7 @@ dependencies = [ "tauri-plugin-fs", "tauri-plugin-notification", "tauri-plugin-opener", + "tauri-plugin-process", "tauri-plugin-updater", "tauri-plugin-websocket", "tempfile", @@ -5251,6 +5252,16 @@ dependencies = [ "zbus", ] +[[package]] +name = "tauri-plugin-process" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d55511a7bf6cd70c8767b02c97bf8134fa434daf3926cfc1be0a0f94132d165a" +dependencies = [ + "tauri", + "tauri-plugin", +] + [[package]] name = "tauri-plugin-updater" version = "2.11.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index b21dcbb..30f6656 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -43,6 +43,7 @@ fix-path-env = { git = "https://github.com/tauri-apps/fix-path-env-rs", version [target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies] tauri-plugin-updater = "2" +tauri-plugin-process = "2" [profile.dev] incremental = true # Compile your binary in smaller steps. diff --git a/src-tauri/capabilities/desktop.json b/src-tauri/capabilities/desktop.json index e662205..84b7b9f 100644 --- a/src-tauri/capabilities/desktop.json +++ b/src-tauri/capabilities/desktop.json @@ -9,7 +9,9 @@ "main" ], "permissions": [ - "updater:default", + "updater:allow-check", + "updater:allow-download-and-install", + "process:allow-restart", "websocket:default" ] } diff --git a/src-tauri/examples/updater_probe.rs b/src-tauri/examples/updater_probe.rs new file mode 100644 index 0000000..02dc250 --- /dev/null +++ b/src-tauri/examples/updater_probe.rs @@ -0,0 +1,51 @@ +#![allow(clippy::expect_used)] +//! Manual probe: `cargo run --example updater_probe` downloads and verifies +//! the latest release against the real manifest and public key. +use tauri_plugin_updater::UpdaterExt; + +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_updater::Builder::new().build()) + .setup(|app| { + let handle = app.handle().clone(); + tauri::async_runtime::spawn(async move { + let updater = handle + .updater_builder() + .version_comparator(|_current, _remote| true) + .build() + .expect("build updater"); + match updater.check().await { + Ok(Some(u)) => { + eprintln!("[probe] available {} -> {}", u.current_version, u.version); + let mut total = 0usize; + match u + .download( + |chunk, len| { + total += chunk; + if let Some(len) = len { + if total % (5 << 20) < chunk { + eprintln!("[probe] {}/{}", total, len); + } + } + }, + || eprintln!("[probe] download finished"), + ) + .await + { + Ok(bytes) => eprintln!( + "[probe] downloaded + signature verified: {} bytes", + bytes.len() + ), + Err(e) => eprintln!("[probe] download/verify FAILED: {e}"), + } + } + Ok(None) => eprintln!("[probe] no update"), + Err(e) => eprintln!("[probe] check failed: {e}"), + } + handle.exit(0); + }); + Ok(()) + }) + .run(tauri::generate_context!()) + .expect("run"); +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index b5a10a7..850d054 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -5,6 +5,7 @@ mod image_utils; mod import; mod input_validation; mod k8s; +mod updater_info; #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { @@ -37,6 +38,7 @@ pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_websocket::init()) .plugin(tauri_plugin_updater::Builder::new().build()) + .plugin(tauri_plugin_process::init()) .plugin(tauri_plugin_notification::init()) .plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_dialog::init()) @@ -145,6 +147,8 @@ pub fn run() { import::import_add_cluster, // Image processing image_utils::process_icon_file, + // Updater + updater_info::updater_can_self_update, // Legacy config config::import_kubeconfig ]) diff --git a/src-tauri/src/updater_info.rs b/src-tauri/src/updater_info.rs new file mode 100644 index 0000000..f96a236 --- /dev/null +++ b/src-tauri/src/updater_info.rs @@ -0,0 +1,34 @@ +//! Whether the running install can replace itself via the built-in updater. +//! +//! The updater ships an AppImage for Linux, so .deb/.rpm installs must upgrade +//! through their package manager. Tauri's own updater detects AppImage via the +//! `APPIMAGE` environment variable set by the AppImage runtime. + +#[tauri::command] +pub fn updater_can_self_update() -> bool { + can_self_update( + cfg!(target_os = "linux"), + std::env::var_os("APPIMAGE").is_some(), + ) +} + +fn can_self_update(is_linux: bool, is_appimage: bool) -> bool { + !is_linux || is_appimage +} + +#[cfg(test)] +mod tests { + use super::can_self_update; + + #[test] + fn linux_requires_appimage() { + assert!(can_self_update(true, true)); + assert!(!can_self_update(true, false)); + } + + #[test] + fn other_platforms_always_self_update() { + assert!(can_self_update(false, false)); + assert!(can_self_update(false, true)); + } +} diff --git a/src/lib/components/IconSidebar.svelte b/src/lib/components/IconSidebar.svelte index e662934..c834817 100644 --- a/src/lib/components/IconSidebar.svelte +++ b/src/lib/components/IconSidebar.svelte @@ -2,6 +2,7 @@ import { Home, Plus, Settings as SettingsIcon, MoreVertical } from "lucide-svelte"; import { clustersStore } from "$lib/stores/clusters.svelte"; import { bookmarksStore } from "$lib/stores/bookmarks.svelte"; + import { updaterStore } from "$lib/stores/updater.svelte"; import { page } from "$app/stores"; import Menu from "$lib/components/ui/Menu.svelte"; import type { MenuItem } from "$lib/components/ui/Menu.svelte"; @@ -165,9 +166,15 @@ href="/settings" class="flex items-center justify-center h-16 hover:bg-bg-main transition-colors relative" class:bg-bg-main={isActive("/settings")} - title="Settings" + title={updaterStore.available ? `Settings — update v${updaterStore.info?.version} available` : "Settings"} > + {#if updaterStore.available} + + {/if} diff --git a/src/lib/components/UpdatesCard.svelte b/src/lib/components/UpdatesCard.svelte new file mode 100644 index 0000000..8734528 --- /dev/null +++ b/src/lib/components/UpdatesCard.svelte @@ -0,0 +1,119 @@ + + + +
+
+ +
+
+
+

Updates

+

+ Kore {updaterStore.currentVersion ? `v${updaterStore.currentVersion}` : ''} + · + Last checked: {formatChecked(updaterStore.lastChecked)} +

+
+ + + + {#if updaterStore.error} +
{updaterStore.error}
+ {/if} + + {#if updaterStore.available && updaterStore.info} +
+
+ v{updaterStore.info.version} available + {#if updaterStore.info.date} + {new Date(updaterStore.info.date).toLocaleDateString()} + {/if} +
+ + {#if updaterStore.info.body} +
{updaterStore.info.body}
+ {/if} + + {#if updaterStore.status === 'downloading'} +
+
+
+
+
+ Downloading{updaterStore.progress != null ? ` ${updaterStore.progress}%` : '...'} +
+
+ {:else if updaterStore.status === 'ready'} +
+ Update installed. Restart to finish. + +
+ {:else if updaterStore.canSelfUpdate} + + {:else} +
+

+ This install was made with a system package (.deb/.rpm), so it can't update itself. Download the new + package from GitHub Releases and install it with your package manager. +

+ +
+ {/if} +
+ {:else} +
+ + {#if updaterStore.status === 'up-to-date'} + You're on the latest version. + {/if} +
+ {/if} +
+
+
diff --git a/src/lib/stores/settings.svelte.ts b/src/lib/stores/settings.svelte.ts index c2a0206..fa3cb77 100644 --- a/src/lib/stores/settings.svelte.ts +++ b/src/lib/stores/settings.svelte.ts @@ -5,6 +5,7 @@ export interface Settings { theme: Theme; codeTheme: CodeTheme; refreshInterval: number; + autoCheckUpdates: boolean; } class SettingsStore { @@ -12,6 +13,7 @@ class SettingsStore { theme: 'kore', codeTheme: 'same-as-app', refreshInterval: 5000, + autoCheckUpdates: true, }); constructor() { @@ -43,6 +45,11 @@ class SettingsStore { this.save(); } + setAutoCheckUpdates(enabled: boolean) { + this.value.autoCheckUpdates = enabled; + this.save(); + } + get effectiveCodeTheme(): Theme { if (this.value.codeTheme === 'same-as-app') { return this.value.theme; diff --git a/src/lib/stores/updater.svelte.ts b/src/lib/stores/updater.svelte.ts new file mode 100644 index 0000000..93f9196 --- /dev/null +++ b/src/lib/stores/updater.svelte.ts @@ -0,0 +1,167 @@ +import { check, type Update } from '@tauri-apps/plugin-updater'; +import { relaunch } from '@tauri-apps/plugin-process'; +import { getVersion } from '@tauri-apps/api/app'; +import { invoke } from '@tauri-apps/api/core'; +import { settingsStore } from './settings.svelte'; + +export type UpdaterStatus = + | 'idle' + | 'checking' + | 'up-to-date' + | 'available' + | 'downloading' + | 'ready' + | 'error'; + +export interface UpdateInfo { + version: string; + currentVersion: string; + date?: string; + body?: string; +} + +const CHECK_INTERVAL_MS = 6 * 60 * 60 * 1000; +const STARTUP_DELAY_MS = 15_000; +const RELEASES_URL = 'https://github.com/DEVtheOPS/kore/releases/latest'; + +class UpdaterStore { + status = $state('idle'); + info = $state(null); + error = $state(null); + currentVersion = $state(''); + lastChecked = $state(null); + downloaded = $state(0); + contentLength = $state(null); + /** False when the running binary cannot replace itself (e.g. Linux .deb/.rpm). */ + canSelfUpdate = $state(true); + releasesUrl = RELEASES_URL; + + private update: Update | null = null; + private timer: ReturnType | null = null; + private startupTimer: ReturnType | null = null; + + get available(): boolean { + return this.status === 'available' || this.status === 'downloading' || this.status === 'ready'; + } + + get progress(): number | null { + if (!this.contentLength) return null; + return Math.min(100, Math.round((this.downloaded / this.contentLength) * 100)); + } + + async init() { + if (!isTauri()) return; + try { + this.currentVersion = await getVersion(); + } catch (e) { + console.error('Failed to read app version', e); + } + try { + this.canSelfUpdate = await invoke('updater_can_self_update'); + } catch (e) { + console.error('Failed to query self-update support', e); + } + this.scheduleAutoChecks(); + } + + /** (Re)start or stop the periodic check according to the user's setting. */ + scheduleAutoChecks() { + this.stopAutoChecks(); + if (!settingsStore.value.autoCheckUpdates) return; + this.startupTimer = setTimeout(() => this.check(true), STARTUP_DELAY_MS); + this.timer = setInterval(() => this.check(true), CHECK_INTERVAL_MS); + } + + stopAutoChecks() { + if (this.startupTimer) clearTimeout(this.startupTimer); + if (this.timer) clearInterval(this.timer); + this.startupTimer = null; + this.timer = null; + } + + /** + * Check the update endpoints. `silent` suppresses the transient + * checking / up-to-date / error states so background checks never disturb + * the UI; only an available update changes what the user sees. + */ + async check(silent = false) { + if (!isTauri()) return; + if (this.status === 'downloading' || this.status === 'ready') return; + + if (!silent) { + this.status = 'checking'; + this.error = null; + } + + try { + const update = await check(); + this.lastChecked = new Date(); + if (update) { + this.update = update; + this.info = { + version: update.version, + currentVersion: update.currentVersion, + date: update.date, + body: update.body, + }; + this.status = 'available'; + } else { + this.update = null; + this.info = null; + if (!silent) this.status = 'up-to-date'; + } + } catch (e) { + console.error('Update check failed', e); + if (!silent) { + this.error = `Update check failed: ${e}`; + this.status = 'error'; + } + } + } + + async downloadAndInstall() { + if (!this.update || !this.canSelfUpdate) return; + + this.status = 'downloading'; + this.error = null; + this.downloaded = 0; + this.contentLength = null; + + try { + await this.update.downloadAndInstall((event) => { + switch (event.event) { + case 'Started': + this.contentLength = event.data.contentLength ?? null; + break; + case 'Progress': + this.downloaded += event.data.chunkLength; + break; + case 'Finished': + if (this.contentLength) this.downloaded = this.contentLength; + break; + } + }); + this.status = 'ready'; + } catch (e) { + console.error('Update install failed', e); + this.error = `Update failed: ${e}`; + this.status = 'error'; + } + } + + async restart() { + if (this.status !== 'ready') return; + try { + await relaunch(); + } catch (e) { + console.error('Relaunch failed', e); + this.error = `Restart failed: ${e}. Please quit and reopen Kore.`; + } + } +} + +function isTauri(): boolean { + return typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window; +} + +export const updaterStore = new UpdaterStore(); diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 756f864..305e1a5 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -3,11 +3,18 @@ import IconSidebar from "$lib/components/IconSidebar.svelte"; import ClusterImportModal from "$lib/components/ClusterImportModal.svelte"; import { settingsStore } from "$lib/stores/settings.svelte"; + import { updaterStore } from "$lib/stores/updater.svelte"; + import { onMount } from "svelte"; let { children } = $props(); let importModalOpen = $state(false); + onMount(() => { + updaterStore.init(); + return () => updaterStore.stopAutoChecks(); + }); + $effect(() => { if (typeof document !== "undefined") { const root = document.documentElement; diff --git a/src/routes/settings/+page.svelte b/src/routes/settings/+page.svelte index e42d187..1b94be2 100644 --- a/src/routes/settings/+page.svelte +++ b/src/routes/settings/+page.svelte @@ -1,6 +1,7 @@