]> git.ayabusa.dev Git - rusty-slicer.git/commitdiff
added a progress bar
authorayabusa <lebgpub@gmail.com>
Sun, 3 Mar 2024 14:32:53 +0000 (15:32 +0100)
committerayabusa <lebgpub@gmail.com>
Sun, 3 Mar 2024 14:32:53 +0000 (15:32 +0100)
src-tauri/src/main.rs
src/event_handler.js
src/index.html
src/progress.html [new file with mode: 0644]
src/progress.js [new file with mode: 0644]
src/styles.css

index 9e960bf0dbdb9953d96c19f22fc4477c978cc1c2..a8b241cf0f0f13f79faaf022f1b31b8fd4d974b6 100644 (file)
@@ -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<String>;
         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();
     }
 }
 
index 351a683562c0ba7a32538940912e15e131bd0310..61e05296f81c876b36cc520aa6753e30cc074162 100644 (file)
@@ -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;
index bbf3237f4834efff947dc672f5c7efb842336a4a..bdf1a27b357a5586221cd237839652ebfd400f6a 100644 (file)
         </div>
 
         <div>
-          <textarea id="chapterList" rows="30">nothing for now</textarea>
+          <textarea id="chapterList" rows="30">
+0:00 - my first song
+3:30 - another one
+13:37 - one more time - Daft punk</textarea>
         </div>
 
         <div class="select-file">
diff --git a/src/progress.html b/src/progress.html
new file mode 100644 (file)
index 0000000..5d50de8
--- /dev/null
@@ -0,0 +1,16 @@
+<!doctype html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8" />
+  <link rel="stylesheet" href="styles.css" />
+  <script type="module" src="/progress.js" defer></script>
+  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+  <title>Slicing progress</title>
+</head>
+
+<body>
+    <p class="credit" id="progress_label"> Slicing : 0% </p> 
+    <div class="progress_center">
+        <progress value="0" max="100" id="progress_bar"></progress>
+    </div>
+</body>
\ No newline at end of file
diff --git a/src/progress.js b/src/progress.js
new file mode 100644 (file)
index 0000000..78f9792
--- /dev/null
@@ -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
index 909445b218ab38052c4dba8301a47e29b598f010..c4dd4ebb8823325600fd7c571249d02cc9435bd8 100644 (file)
@@ -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