Skip to content

Commit

Permalink
File picker dialog, quit button
Browse files Browse the repository at this point in the history
  • Loading branch information
terreng committed Oct 26, 2024
1 parent ba0be3e commit 795c4ff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
7 changes: 4 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
</script>
</head>
<body style="visibility: hidden;" ondragenter="dragEnter(event)" ondragover="dragOver(event)" ondragleave="dragLeave(event)" ondrop="dragDrop(event)">
Expand All @@ -20,7 +21,7 @@
</div>

<div class="container" id="main_container">
<a id="update_banner" target="_blank" onclick="window.api.openExternal(this.href);event.preventDefault()">
<a id="update_banner" target="_blank">
<div id="update_banner_text"></div>
<div aria-label="{lang.ignore_update}" onclick="ignoreUpdate();event.stopPropagation();return false;"><i class="material-icons" aria-hidden="true">close</i></div>
</a>
Expand All @@ -29,8 +30,8 @@
</div>

<div class="button_row" id="main_actions">
<div tabindex="0" class="button left" id="stop_and_quit_button" onclick="window.api.quit()" aria-label="{lang.stop_and_quit}" role="button">{lang.stop_and_quit}</div>
<div tabindex="0" class="button primary" onclick="addServer()" aria-label="{lang.new_server}" role="button">{lang.new_server}</div>
<div class="button left" id="stop_and_quit_button" onclick="window.api.quit()">Stop & Quit</div>
<div class="button primary" onclick="addServer()">New Server</div>
</div>

<!--Global settings-->
Expand Down
19 changes: 15 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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);
}

0 comments on commit 795c4ff

Please sign in to comment.