mirror of
https://github.com/ayabusa/Rusty-slicer.git
synced 2025-07-28 21:54:31 +00:00
adding file select
This commit is contained in:
1522
src-tauri/Cargo.lock
generated
1522
src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -11,9 +11,11 @@ edition = "2021"
|
||||
tauri-build = { version = "1.5", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "1.5", features = ["shell-open"] }
|
||||
tauri = { version = "1.5", features = [ "api-all"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
native-dialog = "0.7.0"
|
||||
lazy_static = "1.4.0"
|
||||
|
||||
[features]
|
||||
# this feature is used for production builds or when `devPath` points to the filesystem
|
||||
|
@@ -1,22 +1,64 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||
/*#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||
use native_dialog::FileDialog;
|
||||
use tauri::{AppHandle, Manager};
|
||||
use std::sync::Mutex;
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
// define file and folder path variable, don't know if it's the right way of doing it
|
||||
lazy_static! {
|
||||
static ref FILE_PATH: Mutex<String> = Mutex::new("".to_string());
|
||||
static ref FOLDER_PATH: Mutex<String> = Mutex::new("".to_string());
|
||||
}
|
||||
|
||||
#[derive(Clone, serde::Serialize)]
|
||||
struct Payload {
|
||||
message: String,
|
||||
}
|
||||
|
||||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||
#[tauri::command]
|
||||
async fn select_file_button(app: tauri::AppHandle) {
|
||||
let _ = app.emit_all("my_event", ());
|
||||
FILE_PATH.lock().unwrap().replace_range(.., &choose_file());
|
||||
println!("{}",FILE_PATH.lock().unwrap());
|
||||
}
|
||||
*/
|
||||
|
||||
#[tauri::command]
|
||||
fn slice() {
|
||||
println!("I was invoked from JS!");
|
||||
async fn select_folder_button() {
|
||||
FOLDER_PATH.lock().unwrap().replace_range(.., &choose_folder());
|
||||
println!("{}",FOLDER_PATH.lock().unwrap());
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn debug_call(message: &str){
|
||||
println!("[DBG] {}", message);
|
||||
}
|
||||
|
||||
// prompt user file chooser using native_dialogue crate
|
||||
fn choose_file() -> String{
|
||||
println!("Let's choose a file !");
|
||||
let path = FileDialog::new()
|
||||
.show_open_single_file()
|
||||
.unwrap();
|
||||
format!("{:?}", path) // turn the FileDialog into a string
|
||||
}
|
||||
|
||||
fn choose_folder() -> String{
|
||||
println!("Let's choose a folder !");
|
||||
let path = FileDialog::new()
|
||||
.show_open_single_dir()
|
||||
.unwrap();
|
||||
format!("{:?}", path) // turn the FileDialog into a string
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("launched");
|
||||
// generate the tauri app
|
||||
tauri::Builder::default()
|
||||
//.invoke_handler(tauri::generate_handler![greet])
|
||||
.invoke_handler(tauri::generate_handler![select_file_button, select_folder_button, debug_call])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@@ -10,9 +10,9 @@
|
||||
},
|
||||
"tauri": {
|
||||
"allowlist": {
|
||||
"all": false,
|
||||
"all": true,
|
||||
"shell": {
|
||||
"all": false,
|
||||
"all": true,
|
||||
"open": true
|
||||
}
|
||||
},
|
||||
|
Reference in New Issue
Block a user