mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-03-28 14:13:40 +08:00
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.
This commit is contained in:
@@ -123,6 +123,24 @@ pub async fn open_zip_file_dialog<R: tauri::Runtime>(
|
||||
|
||||
// ─── Database backup management ─────────────────────────────
|
||||
|
||||
/// Manually create a database backup
|
||||
#[tauri::command]
|
||||
pub async fn create_db_backup(state: State<'_, AppState>) -> Result<String, String> {
|
||||
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<Vec<BackupEntry>, String> {
|
||||
|
||||
Reference in New Issue
Block a user