From 795c4ffef1ad3b4aa8c08ce2b10a5bdddf3f05f8 Mon Sep 17 00:00:00 2001 From: Terren <11605395+terreng@users.noreply.github.com> Date: Sat, 22 Oct 2022 12:06:15 -0400 Subject: [PATCH] File picker dialog, quit button --- index.html | 7 ++++--- main.js | 19 +++++++++++++++---- src-tauri/src/main.rs | 7 ++++++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index fde8bb60..696e9068 100644 --- a/index.html +++ b/index.html @@ -9,6 +9,7 @@ const invoke = window.__TAURI__.invoke; const listen = window.__TAURI__.event.listen; const emit = window.__TAURI__.event.emit; + const dialog = window.__TAURI__.dialog;
@@ -20,7 +21,7 @@ diff --git a/main.js b/main.js index 6763a1dc..e75b28f4 100644 --- a/main.js +++ b/main.js @@ -791,10 +791,21 @@ function updateCurrentPath() { } function chooseFolder() { - window.api.showPicker(current_path).then(function(chosen_path) { - if (chosen_path && chosen_path.length > 0) current_path = chosen_path[0]; - updateCurrentPath(); - }) + var dialog_options = { + directory: true, + multiple: false + }; + + if (current_path) { + dialog_options.defaultPath = current_path; + } + + dialog.open(dialog_options).then(function(selected) { + if (selected) { + current_path = selected; + updateCurrentPath(); + } + }); } function htmlescape(str) { diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 070715d5..351ed41b 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -27,7 +27,7 @@ fn savepath() -> String { fn main() { tauri::Builder::default() - .invoke_handler(tauri::generate_handler![init, saveconfig]) + .invoke_handler(tauri::generate_handler![init, saveconfig, quit]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } @@ -53,4 +53,9 @@ fn saveconfig(config: Value) { let f = File::create(savepath() + "config.json").expect("Unable to create file"); let mut f = BufWriter::new(f); f.write_all(data.as_bytes()).expect("Unable to write data"); +} + +#[tauri::command] +fn quit(handle: tauri::AppHandle) { + handle.exit(0); } \ No newline at end of file