feat(update): add API endpoint to retrieve app version and update client-side calls

This commit is contained in:
t8y2 2026-05-05 16:01:38 +08:00
parent 3acd9280ac
commit 24537093ad
6 changed files with 23 additions and 10 deletions

View File

@ -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))

View File

@ -3,6 +3,10 @@ use dbx_core::update;
use crate::error::AppError;
pub async fn get_version() -> Json<serde_json::Value> {
Json(serde_json::json!({ "version": env!("CARGO_PKG_VERSION") }))
}
pub async fn check_for_updates() -> Result<Json<serde_json::Value>, AppError> {
let release = update::fetch_latest_release().await.map_err(AppError)?;
let info = update::build_update_info(release, env!("CARGO_PKG_VERSION"));

View File

@ -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();

View File

@ -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");

View File

@ -543,6 +543,11 @@ export async function checkForUpdates(): Promise<UpdateInfo> {
return get("/api/update/check");
}
export async function getAppVersion(): Promise<string> {
const res: { version: string } = await get("/api/version");
return res.version;
}
// ---------------------------------------------------------------------------
// Layout
// ---------------------------------------------------------------------------

View File

@ -230,6 +230,11 @@ export async function checkForUpdates(): Promise<UpdateInfo> {
return invoke("check_for_updates");
}
export async function getAppVersion(): Promise<string> {
const { getVersion } = await import("@tauri-apps/api/app");
return getVersion();
}
// --- Redis ---
export interface RedisKeyInfo {
key: string;