Replace the three error styles with one Error type and one Result alias in error.rs. The error crosses IPC as the same plain string as before. The message text does not change. Move the shared file mechanics to fsutil.rs. These are the reserved-name check, the link and junction check, the limited reads, and the atomic writes. Each module keeps its own path rules, limits, and messages. The plugin settings writer now flushes its file to disk before the rename. Remove the current_root_path and list_entries wrappers and an unused mime value. Use named windows-sys constants for the process, file, drive, and error codes. Add a test that compares the command lists in lib.rs, build.rs, and the capability files. The settings capability must be a subset of the full list. In Cargo.toml, set the author, keep only the rlib crate type, and remove the unused thiserror dependency. Remove panic = "abort" from the release profile. A panic on a worker thread then stops only that thread. It does not stop the editor with unsaved buffers.
17 lines
1.0 KiB
Rust
17 lines
1.0 KiB
Rust
use tauri_plugin_dialog::DialogExt;
|
|
|
|
use crate::error::{Error, Result};
|
|
|
|
#[tauri::command]
|
|
pub async fn theme_export(app: tauri::AppHandle, contents: String, default_name: String) -> Result<Option<String>> {
|
|
if contents.len() > 1_048_576 { return Err("The theme exceeds the 1 MB limit.".into()); }
|
|
serde_json::from_str::<serde_json::Value>(&contents).map_err(|_| "The theme contains invalid JSON.")?;
|
|
let name = std::path::Path::new(&default_name).file_name().and_then(|name| name.to_str()).unwrap_or("theme.json").to_string();
|
|
tauri::async_runtime::spawn_blocking(move || -> Result<Option<String>> {
|
|
let Some(file) = app.dialog().file().set_title("Export theme").add_filter("Theme JSON", &["json"]).set_file_name(name).blocking_save_file() else { return Ok(None); };
|
|
let path = file.into_path().map_err(Error::from_display)?;
|
|
std::fs::write(&path, contents).map_err(|error| format!("Could not export the theme: {error}"))?;
|
|
Ok(Some(path.to_string_lossy().into_owned()))
|
|
}).await?
|
|
}
|