diff --git a/package-lock.json b/package-lock.json index 147fe33..84feaf7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "brancato", - "version": "0.7.1", + "version": "0.7.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "brancato", - "version": "0.7.1", + "version": "0.7.2", "dependencies": { "@algolia/autocomplete-js": "^1.5.3", "@algolia/autocomplete-theme-classic": "^1.5.3", diff --git a/package.json b/package.json index 02d10a7..995056d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "brancato", - "version": "0.7.1", + "version": "0.7.2", "private": true, "dependencies": { "@algolia/autocomplete-js": "^1.5.3", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index b1d07a8..e6ebcb2 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -274,7 +274,7 @@ dependencies = [ [[package]] name = "brancato" -version = "0.7.1" +version = "0.7.2" dependencies = [ "directories", "execute", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 344da86..ecdceef 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "brancato" -version = "0.7.1" +version = "0.7.2" description = "A tool for stage-managing your life" authors = ["Ryan Killeen"] license = "" diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 95a6f80..7fb66df 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -10,7 +10,7 @@ mod workflows; use app_config::{set_custom_user_config_path, AppConfig}; use serde::Serialize; -use std::{env, path::PathBuf, sync::Mutex}; +use std::{path::PathBuf, sync::Mutex}; use tauri::{ api::dialog::blocking::FileDialogBuilder, AppHandle, CustomMenuItem, GlobalShortcutManager, Manager, RunEvent, State, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem, @@ -75,6 +75,40 @@ fn get_state( return state; } +fn set_default_path( + mut dialog_builder: FileDialogBuilder, + default_path: PathBuf, +) -> FileDialogBuilder { + if default_path.is_file() || !default_path.exists() { + if let (Some(parent), Some(file_name)) = (default_path.parent(), default_path.file_name()) { + dialog_builder = dialog_builder.set_directory(parent); + dialog_builder = dialog_builder.set_file_name(&file_name.to_string_lossy().to_string()); + } else { + dialog_builder = dialog_builder.set_directory(default_path); + } + dialog_builder + } else { + dialog_builder.set_directory(default_path) + } +} + +#[tauri::command] +async fn select_file(default_path: Option) -> Option { + let dialog = match default_path { + Some(default_path) => { + let file_exists = std::path::Path::exists(&default_path); + if file_exists { + set_default_path(FileDialogBuilder::new(), default_path) + } else { + FileDialogBuilder::new() + } + } + None => FileDialogBuilder::new(), + }; + + dialog.pick_file() +} + #[tauri::command] fn set_user_config_path(app_config_state: State>) -> Option { let folder_path = FileDialogBuilder::new().pick_folder(); @@ -202,6 +236,7 @@ fn main() { run_workflow, open_settings, set_shortcut, + select_file, set_user_config_path ]) .setup(|app_handle| { diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index b0c70e2..cbcb9a6 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "package": { "productName": "brancato", - "version": "0.7.1" + "version": "0.7.2" }, "build": { "distDir": "../build", diff --git a/src/forms/workflow-action.tsx b/src/forms/workflow-action.tsx index d9094a1..a0f7cf8 100644 --- a/src/forms/workflow-action.tsx +++ b/src/forms/workflow-action.tsx @@ -1,5 +1,5 @@ import { useFieldArray, UseFieldArrayRemove } from "react-hook-form"; -import { dialog } from "@tauri-apps/api"; +import { invoke } from "@tauri-apps/api"; import { NestedInputProps } from "./workflow-array"; type Props = { @@ -37,10 +37,11 @@ const WorkflowAction = ({