From 6ff254ddf44f565d33ba1b55997427b72a3ed9e5 Mon Sep 17 00:00:00 2001 From: ayabusa Date: Sun, 3 Mar 2024 15:32:53 +0100 Subject: [PATCH] added a progress bar --- src-tauri/src/main.rs | 25 +++++++++++++++++++++---- src/event_handler.js | 2 -- src/index.html | 5 ++++- src/progress.html | 16 ++++++++++++++++ src/progress.js | 8 ++++++++ src/styles.css | 11 +++++++++++ 6 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 src/progress.html create mode 100644 src/progress.js diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 9e960bf..a8b241c 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -35,9 +35,9 @@ async fn select_folder_button(app: tauri::AppHandle) { } #[tauri::command] -fn slice_button(app: tauri::AppHandle, chapter: &str){ +async fn slice_button(app: tauri::AppHandle, chapter: String){ // Try to format the chapters and panic if it was not able to - let formated_chapters = match format_chapter(chapter) { + let formated_chapters = match format_chapter(&chapter) { Ok(res) => res, Err(error) => panic!("Problem slicing chapter: {:?}", error), }; @@ -52,6 +52,15 @@ fn slice_button(app: tauri::AppHandle, chapter: &str){ Err(error) => panic!("Problem creating directory : {:?}", error), };*/ + // create the progress window + let _about_window = tauri::WindowBuilder::new( + &app, + "progress", /* the unique window label */ + tauri::WindowUrl::App("progress.html".into()) + ).build().expect("failed to create progress window"); + _about_window.set_title("Slicing progress").unwrap(); + _about_window.set_size(Size::Physical(PhysicalSize { width: 400, height: 100 })).unwrap(); + for i in 0..time_codes.len(){ let args: Vec; let mut output_file: PathBuf = PathBuf::from(&FOLDER_PATH.lock().unwrap().to_owned()); @@ -67,12 +76,20 @@ fn slice_button(app: tauri::AppHandle, chapter: &str){ time_codes[i+1].to_owned(), //format!("{:?}", output_file), output_file.display().to_string()]; - }else { - args = vec!["-version".to_owned()]; + }else { // case for the last song + args = vec!["-i".to_owned(), + FILE_PATH.lock().unwrap().to_owned(), + "-ss".to_owned(), + time_codes[i].to_owned(), + //format!("{:?}", output_file), + output_file.display().to_string()]; } // launch the final ffmpeg command launch_ffmpeg(app.clone(), args); + + // update progress bar on frontend + app.emit_all("progress_state_changed", Payload { message: format!("{}", (i+1)*100/time_codes.len()) }).unwrap(); } } diff --git a/src/event_handler.js b/src/event_handler.js index 351a683..61e0529 100644 --- a/src/event_handler.js +++ b/src/event_handler.js @@ -1,7 +1,5 @@ const { listen } = window.__TAURI__.event -document.getElementById("fileLocation").innerHTML = "hey"; - // listen for file location from rust backend const unlistenfile = await listen('file_path_changed', (event) => { document.getElementById("fileLocation").innerHTML = event.payload.message; diff --git a/src/index.html b/src/index.html index bbf3237..bdf1a27 100644 --- a/src/index.html +++ b/src/index.html @@ -25,7 +25,10 @@
- +
diff --git a/src/progress.html b/src/progress.html new file mode 100644 index 0000000..5d50de8 --- /dev/null +++ b/src/progress.html @@ -0,0 +1,16 @@ + + + + + + + + Slicing progress + + + +

Slicing : 0%

+
+ +
+ \ No newline at end of file diff --git a/src/progress.js b/src/progress.js new file mode 100644 index 0000000..78f9792 --- /dev/null +++ b/src/progress.js @@ -0,0 +1,8 @@ +const { listen } = window.__TAURI__.event + +// listen for progress update from rust backend +const unlistenprogress = await listen('progress_state_changed', (event) => { + document.getElementById("progress_label").innerHTML = "Slicing : "+event.payload.message+"%"; + document.getElementById("progress_bar").value = event.payload.message; + console.log("changing progress bar state to : ", event.payload.message); +}) \ No newline at end of file diff --git a/src/styles.css b/src/styles.css index 909445b..c4dd4eb 100644 --- a/src/styles.css +++ b/src/styles.css @@ -139,4 +139,15 @@ button { @-webkit-keyframes scroll { from { background-position: 0 0, 50px 50px, 50px 0; } to { background-position: -100px -100px, -50px -50px, -50px -100px; } +} + +progress::-moz-progress-bar { background: #d88939; } +progress::-webkit-progress-value { background: #d88939; } +progress { + color: #d88939; + width: 100%; +} + +.progress_center { + text-align: center; } \ No newline at end of file