From 24537093adc24cb70e867d6ce225edeb409e3716 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Tue, 5 May 2026 16:01:38 +0800 Subject: [PATCH] feat(update): add API endpoint to retrieve app version and update client-side calls --- src-web/src/main.rs | 1 + src-web/src/routes/update.rs | 4 ++++ src/App.vue | 17 +++++++---------- src/lib/api.ts | 1 + src/lib/http.ts | 5 +++++ src/lib/tauri.ts | 5 +++++ 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src-web/src/main.rs b/src-web/src/main.rs index aaf894d03..1ef3761d2 100644 --- a/src-web/src/main.rs +++ b/src-web/src/main.rs @@ -137,6 +137,7 @@ async fn main() { .route("/import/progress/{importId}", get(routes::table_import::import_progress)) .route("/import/cancel", post(routes::table_import::cancel_import)) // Update + .route("/version", get(routes::update::get_version)) .route("/update/check", get(routes::update::check_for_updates)) // Layout .route("/layout/sidebar", post(routes::layout::save_sidebar_layout).get(routes::layout::load_sidebar_layout)) diff --git a/src-web/src/routes/update.rs b/src-web/src/routes/update.rs index 7c0a2b8e3..2cad13a62 100644 --- a/src-web/src/routes/update.rs +++ b/src-web/src/routes/update.rs @@ -3,6 +3,10 @@ use dbx_core::update; use crate::error::AppError; +pub async fn get_version() -> Json { + Json(serde_json::json!({ "version": env!("CARGO_PKG_VERSION") })) +} + pub async fn check_for_updates() -> Result, AppError> { let release = update::fetch_latest_release().await.map_err(AppError)?; let info = update::build_update_info(release, env!("CARGO_PKG_VERSION")); diff --git a/src/App.vue b/src/App.vue index 813c9f365..e4c455250 100644 --- a/src/App.vue +++ b/src/App.vue @@ -332,9 +332,9 @@ onMounted(async () => { } if (!needsAuth.value || authenticated.value) initApp(); api - .checkForUpdates() - .then((info) => { - appVersion.value = info.current_version; + .getAppVersion() + .then((v) => { + appVersion.value = v; }) .catch(() => {}); return; @@ -342,13 +342,10 @@ onMounted(async () => { initApp(); setupFileDrop().catch(() => {}); checkUpdates({ silent: true }); - import("@tauri-apps/api/app") - .then(({ getVersion }) => { - getVersion() - .then((v) => { - appVersion.value = v; - }) - .catch(() => {}); + api + .getAppVersion() + .then((v) => { + appVersion.value = v; }) .catch(() => {}); setupTauriListeners(); diff --git a/src/lib/api.ts b/src/lib/api.ts index 860c27845..a5af8a87d 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -109,6 +109,7 @@ export const deleteHistoryEntry = forward("deleteHistoryEntry"); // Updates export const checkForUpdates = forward("checkForUpdates"); +export const getAppVersion = forward("getAppVersion"); // Layout export const saveSidebarLayout = forward("saveSidebarLayout"); diff --git a/src/lib/http.ts b/src/lib/http.ts index 8ffcb27e9..dc570df50 100644 --- a/src/lib/http.ts +++ b/src/lib/http.ts @@ -543,6 +543,11 @@ export async function checkForUpdates(): Promise { return get("/api/update/check"); } +export async function getAppVersion(): Promise { + const res: { version: string } = await get("/api/version"); + return res.version; +} + // --------------------------------------------------------------------------- // Layout // --------------------------------------------------------------------------- diff --git a/src/lib/tauri.ts b/src/lib/tauri.ts index b0d82aa4b..1f959c079 100644 --- a/src/lib/tauri.ts +++ b/src/lib/tauri.ts @@ -230,6 +230,11 @@ export async function checkForUpdates(): Promise { return invoke("check_for_updates"); } +export async function getAppVersion(): Promise { + const { getVersion } = await import("@tauri-apps/api/app"); + return getVersion(); +} + // --- Redis --- export interface RedisKeyInfo { key: string;