--- src-tauri/src/main.rs +++ src-tauri/src/main.rs @@ -40,40 +40,42 @@ } #[tauri::command] -fn write_text_file(app: AppHandle, contents: String, is_sum: bool) -> Result<(), String> { +fn write_text_file(app: AppHandle, contents: String, is_sum: bool) -> Result { let (name, ext) = if is_sum { ("Summarum Sheet", "sum") } else { ("Text file", "txt") }; if let Some(p) = app .dialog() .file() .add_filter(name, &[ext]) .blocking_save_file() { write_atomic(&p.into_path().map_err(|e| e.to_string())?, &contents)?; + Ok(true) + } else { + Ok(false) } - Ok(()) } #[tauri::command] -fn write_image_file(app: AppHandle, data_base64: String) -> Result<(), String> { +fn write_image_file(app: AppHandle, data_base64: String) -> Result { if let Some(p) = app .dialog() .file() .add_filter("PNG Image", &["png"]) .blocking_save_file() { let path = p.into_path().map_err(|e| e.to_string())?; use std::io::Write; let bytes = base64_decode(&data_base64)?; let tmp = path.with_extension("tmp"); std::fs::File::create(&tmp) .and_then(|mut f| f.write_all(&bytes)) .map_err(|e| e.to_string())?; fs::rename(&tmp, path).map_err(|e| e.to_string())?; + Ok(true) + } else { + Ok(false) } - Ok(()) } fn base64_decode(s: &str) -> Result, String> {