Mountain/IPC/WindServiceHandlers/NativeHost/
ShowSaveDialog.rs1#![allow(unused_variables, dead_code, unused_imports)]
2
3use serde_json::{Value, json};
7use tauri::AppHandle;
8use tauri_plugin_dialog::DialogExt;
9
10pub async fn Fn(ApplicationHandle:AppHandle, Arguments:Vec<Value>) -> Result<Value, String> {
11 let Options = Arguments.first().cloned().unwrap_or(Value::Null);
12
13 let Title = Options.get("title").and_then(Value::as_str).unwrap_or("Save").to_string();
14
15 let DefaultPath = Options.get("defaultPath").and_then(Value::as_str).map(str::to_string);
16
17 let Handle = ApplicationHandle.clone();
18
19 let Joined = tokio::task::spawn_blocking(move || -> Option<String> {
20 let mut Builder = Handle.dialog().file().set_title(&Title);
21 if let Some(Path) = DefaultPath.as_deref() {
22 Builder = Builder.set_directory(Path);
23 }
24 Builder.blocking_save_file().map(|P| P.to_string())
25 })
26 .await;
27
28 match Joined {
29 Ok(Some(Path)) => Ok(json!({ "canceled": false, "filePath": Path })),
30
31 Ok(None) => Ok(json!({ "canceled": true })),
32
33 Err(Error) => Err(format!("showSaveDialog join error: {}", Error)),
34 }
35}