Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
f57bfb9
commit before merge from main
shueja Dec 19, 2023
f37bfb8
Merge remote-tracking branch 'origin/main' into feature/open-and-auto…
shueja Dec 19, 2023
6a31856
window title shows document name
shueja Dec 20, 2023
6252a3b
Files update on path rename/delete
shueja Dec 20, 2023
9c457f2
Merge remote-tracking branch 'origin/main' into feature/open-and-auto…
shueja Dec 20, 2023
c87812f
rename openFileDialog to open_file_dialog
shueja Dec 20, 2023
f4125fd
format ts
shueja Dec 20, 2023
3ad37b9
Avoid loading undefined contents when opening file
shueja Dec 20, 2023
da2f391
removed unused imports
shueja Dec 20, 2023
d9374da
remove unused rust function
shueja Dec 20, 2023
318d997
remove console logs
shueja Dec 20, 2023
ddb226f
remove unused file open functions
shueja Dec 20, 2023
397e677
format
shueja Dec 20, 2023
bb78600
Increase error checking on handling file load
shueja Dec 26, 2023
0155d38
fixed a bug making closing impossible on unsaved files
shueja Dec 26, 2023
857efe3
format
shueja Dec 26, 2023
0c3be6a
line breaks between functions
shueja Dec 26, 2023
bf8086a
cleanup checks for save location
shueja Dec 26, 2023
116025c
change font on save info panel
shueja Dec 27, 2023
41d629b
clean up error handling, move toast to root
Dec 28, 2023
6af91b5
format
Dec 28, 2023
3b10041
remove debug artifacts
Dec 28, 2023
ece25a0
remove toasts when switching paths
Dec 28, 2023
15fbca7
[Open File] Warm for unsaved changes
Dec 28, 2023
921ae79
add save warnings, clarify generateAndExport cases
Dec 28, 2023
a1f8dc1
add relative paths
Dec 28, 2023
7159979
Add copy to clipboard button
Dec 28, 2023
273d9af
add windows support for relative paths
Dec 28, 2023
70ababf
fix tooltip on copy clipoard
Dec 28, 2023
a8938e2
correct grammar
Dec 28, 2023
d2b7688
add linux relative path support
Dec 28, 2023
6cab2cc
format
Dec 28, 2023
1fddfcd
add path sep for relative format
Dec 28, 2023
061ebfd
add open in files app button in drawer
Dec 28, 2023
ab7441a
format
Dec 28, 2023
7a8d392
fix tauri warnings
Dec 28, 2023
c58feea
remove setTrajectory to avoid losing a traj
Dec 28, 2023
5182014
add controlIntervalCount init
Dec 29, 2023
1286869
format
Dec 29, 2023
932d789
clean up console statements
Dec 29, 2023
8526b0c
replace all instances of relative traj dir
Dec 29, 2023
cb1abdc
Merge branch 'main' into feature/open-and-auto-save
Dec 30, 2023
4feecc8
Merge main
Jan 1, 2024
cb0ddc9
Merge branch 'main' of https://github.com/SleipnirGroup/Choreo into f…
shueja Jan 1, 2024
96b5cca
Merge branch 'feature/open-and-auto-save' of https://github.com/Sleip…
shueja Jan 1, 2024
64a18fc
format
Jan 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ license = "BSD-3-Clause"
tauri-build = { version = "1.4", features = [] }

[dependencies]
tauri = { version = "1.4", features = [ "dialog-confirm", "dialog-save", "dialog-open", "dialog-save", "fs-all", "shell-open", "devtools" ] }
tauri = { version = "1.4", features = [ "window-close", "window-set-title", "path-all", "dialog", "dialog-confirm", "dialog-save", "dialog-open", "dialog-ask", "fs-all", "shell-open", "devtools"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
trajoptlib = { git = "https://github.com/SleipnirGroup/TrajoptLib.git", rev = "c9f8140e92dff07b2edb9c7034fea4d18dc46c9a" }
open = "3"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
78 changes: 77 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use trajoptlib::{SwervePathBuilder, HolonomicTrajectory, SwerveDrivetrain, SwerveModule, InitialGuessPoint};
use tauri::{api::{dialog::blocking::FileDialogBuilder, file}, Manager};
use std::{fs, path::Path};
// A way to make properties that exist on all enum variants accessible from the generic variant
// I have no idea how it works but it came from
// https://users.rust-lang.org/t/generic-referencing-enum-inner-data/66342/9
Expand All @@ -18,6 +20,79 @@ use trajoptlib::{SwervePathBuilder, HolonomicTrajectory, SwerveDrivetrain, Swerv
// };
// }


#[derive(Clone, serde::Serialize, Debug)]
struct OpenFileEventPayload<'a> {
dir: Option<&'a str>,
name: Option<&'a str>,
contents: Option<&'a str>,
adjacent_gradle: bool
}

#[tauri::command]
async fn contains_build_gradle(dir: Option<&Path>) -> Result<bool, &'static str> {
dir.map_or_else(|| Err("Directory does not exist"),
|dir_path| {
let mut found_build_gradle = false;
for entry in dir_path.read_dir().expect("read_dir call failed") {
if let Ok(other_file) = entry {
found_build_gradle |= other_file.file_name().eq("build.gradle")
}
}
Ok(found_build_gradle)}
)
}
#[tauri::command]
async fn open_file_dialog(app_handle: tauri::AppHandle){
let file_path = FileDialogBuilder::new()
.set_title("Open a .chor file")
.add_filter("Choreo Save File", &["chor"]).pick_file();
match file_path{
Some(path)=>{
let dir = path.parent();
let name = path.file_name();
let adjacent_gradle = contains_build_gradle(dir).await;
if dir.is_some() && name.is_some() && adjacent_gradle.is_ok() {
let _ = app_handle.emit_all("open-file",
OpenFileEventPayload {
dir: dir.unwrap().as_os_str().to_str(),
name: name.unwrap().to_str(),
contents: file::read_string(path.clone()).ok().as_deref(),
adjacent_gradle: adjacent_gradle.unwrap_or(false)});

}

},
None=>{}
}
}

#[tauri::command]
async fn delete_file(dir: String, name: String) {
let dir_path = Path::new(&dir);
let name_path = Path::join(dir_path, name);
let _ = fs::remove_file(name_path);
}

#[tauri::command]
async fn save_file(dir: String, name: String, contents: String) -> Result<(), &'static str> {
let dir_path = Path::new(&dir);
let name_path = Path::join(dir_path, name);
if name_path.is_relative() {
return Err("Dir needs to be absolute");
}
let _ = fs::create_dir_all(dir_path);
if fs::write(name_path, contents).is_err() {
return Err("Failed file writing");
}
Ok(())
}

#[tauri::command]
async fn open_file_app(dir: String) {
let _ = open::that(dir);
}

#[allow(non_snake_case)]
#[derive(serde::Serialize, serde::Deserialize)]
struct ChoreoWaypoint {
Expand Down Expand Up @@ -280,7 +355,8 @@ async fn generate_trajectory(

fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![generate_trajectory, cancel])
.invoke_handler(tauri::generate_handler![
generate_trajectory, cancel, open_file_dialog, save_file, contains_build_gradle, delete_file, open_file_app])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
12 changes: 7 additions & 5 deletions src-tauri/tauri.conf.in.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@
"all": false,
"open": true
},
"path": {
"all": true
},
"fs": {
"all": true
},
"dialog": {
"confirm": true,
"open": true,
"save": true
"save": true,
"ask": true
},
"window": {
"setTitle": true
},
"path": {
"all": true
"setTitle": true,
"close": true
}
},
"bundle": {
Expand Down
Loading