From 3590df68b8e2d6e01fed74696f7d01ca404a605c Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 26 Feb 2026 21:53:59 +0800 Subject: [PATCH] fix: treat missing db file as error in manual backup to prevent false success toast backup_database_file() returning Ok(None) was silently resolved as null on the frontend, bypassing try/catch and showing a success toast without actually creating a backup file. Now None is converted to an explicit Err so the frontend correctly displays an error toast. --- src-tauri/src/commands/import_export.rs | 18 ++++++++++++++++++ src/lib/api/settings.ts | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/src-tauri/src/commands/import_export.rs b/src-tauri/src/commands/import_export.rs index 42ee6b20..ae7dab36 100644 --- a/src-tauri/src/commands/import_export.rs +++ b/src-tauri/src/commands/import_export.rs @@ -123,6 +123,24 @@ pub async fn open_zip_file_dialog( // ─── Database backup management ───────────────────────────── +/// Manually create a database backup +#[tauri::command] +pub async fn create_db_backup(state: State<'_, AppState>) -> Result { + let db = state.db.clone(); + tauri::async_runtime::spawn_blocking(move || match db.backup_database_file()? { + Some(path) => Ok(path + .file_name() + .map(|f| f.to_string_lossy().into_owned()) + .unwrap_or_default()), + None => Err(AppError::Config( + "Database file not found, backup skipped".to_string(), + )), + }) + .await + .map_err(|e| format!("Backup failed: {e}"))? + .map_err(|e: AppError| e.to_string()) +} + /// List all database backup files #[tauri::command] pub fn list_db_backups() -> Result, String> { diff --git a/src/lib/api/settings.ts b/src/lib/api/settings.ts index 567e78f7..6adb9bb8 100644 --- a/src/lib/api/settings.ts +++ b/src/lib/api/settings.ts @@ -223,6 +223,10 @@ export interface BackupEntry { } export const backupsApi = { + async createDbBackup(): Promise { + return await invoke("create_db_backup"); + }, + async listDbBackups(): Promise { return await invoke("list_db_backups"); },