}
#[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),
};
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());
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();
}
}
--- /dev/null
+<!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
--- /dev/null
+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
@-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