]> git.ayabusa.dev Git - rusty-slicer.git/commitdiff
Rusty slicer is now dummy proof
authorayabusa <lebgpub@gmail.com>
Fri, 8 Mar 2024 15:00:34 +0000 (16:00 +0100)
committerayabusa <lebgpub@gmail.com>
Fri, 8 Mar 2024 15:00:34 +0000 (16:00 +0100)
src-tauri/Cargo.lock
src-tauri/Cargo.toml
src-tauri/src/main.rs
src-tauri/tauri.conf.json
src/about.html
src/event_handler.js
src/fonts/FiraSans-Bold.ttf [new file with mode: 0644]
src/index.html
src/main.js
src/styles.css

index f52e0f29259f5e8e434e97a50f0104bde8083807..345338041b61cb382456593149e053efb4adb653 100644 (file)
@@ -3176,6 +3176,18 @@ version = "1.0.14"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
 
+[[package]]
+name = "rusty-slicer"
+version = "0.0.1"
+dependencies = [
+ "lazy_static",
+ "native-dialog",
+ "serde",
+ "serde_json",
+ "tauri",
+ "tauri-build",
+]
+
 [[package]]
 name = "ryu"
 version = "1.0.17"
@@ -3969,18 +3981,6 @@ dependencies = [
  "utf-8",
 ]
 
-[[package]]
-name = "test-tauri"
-version = "0.0.0"
-dependencies = [
- "lazy_static",
- "native-dialog",
- "serde",
- "serde_json",
- "tauri",
- "tauri-build",
-]
-
 [[package]]
 name = "thin-slice"
 version = "0.1.1"
index 40ab74342b3be6beef84c4ff9a483f5645538c18..6d0e5d35ab0f510ac622be240545fea3260845ac 100644 (file)
@@ -1,8 +1,8 @@
 [package]
-name = "test-tauri"
-version = "0.0.0"
-description = "A Tauri App"
-authors = ["you"]
+name = "rusty-slicer"
+version = "0.0.1"
+description = "An app to slice your playlist into multiple files"
+authors = ["Ayabusa"]
 edition = "2021"
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
index aa9f7dd904d65ad3904f7aff5f5d76380a60793f..3dc6eebf0ee117eb606d1abd1516fc1903ca7d38 100644 (file)
@@ -3,7 +3,7 @@
 
 use native_dialog::FileDialog;
 use tauri::{Manager, PhysicalSize, Size};
-use std::{io::{Error, ErrorKind}, path::PathBuf, sync::Mutex};
+use std::{env, io::{Error, ErrorKind}, path::PathBuf, sync::Mutex};
 
 #[macro_use]
 extern crate lazy_static;
@@ -36,11 +36,30 @@ async fn select_folder_button(app: tauri::AppHandle) {
 
 #[tauri::command]
 async fn slice_button(app: tauri::AppHandle, chapter: String, fileformat: String){
+    // Check the user selected a file and a folder
+    let mut cancel_slicing = false;
+    if FILE_PATH.lock().unwrap().to_owned() == "" || FILE_PATH.lock().unwrap().to_owned() == "None"{
+        println!("error no file selected, slicing aborted");
+        app.emit_all("backend_error", Payload { message: "file_empty".to_owned() }).unwrap();
+        cancel_slicing = true;
+    }
+    if FOLDER_PATH.lock().unwrap().to_owned() == "" || FOLDER_PATH.lock().unwrap().to_owned() == "None"{
+        println!("error no folder selected, slicing aborted");
+        app.emit_all("backend_error", Payload { message: "folder_empty".to_owned() }).unwrap();
+        cancel_slicing = true;
+    }
+    if cancel_slicing == true { return; }
+
     // Try to format the chapters and panic if it was not able to
     let formated_chapters = match format_chapter(&chapter) {
         Ok(res) => res,
-        Err(error) => panic!("Problem slicing chapter: {:?}", error),
+        Err(_error) => {
+            println!("error formating chapters, slicing aborted");
+            app.emit_all("backend_error", Payload { message: "formating_issue".to_owned() }).unwrap();
+            return;
+        },
     };
+
     let time_codes: Vec<String> = formated_chapters.0;
     let title_names: Vec<String> = formated_chapters.1;
 
@@ -126,6 +145,7 @@ fn format_chapter(chapter: &str) -> Result<(Vec<String>, Vec<String>), Error>{
     let lines: Vec<&str> = chapter.split("\n").collect();
     let mut time_code: Vec<String> = vec![];
     let mut title_names: Vec<String> = vec![];
+    if lines.len() < 2 { return Err(Error::new(ErrorKind::Other, "Lines are empty")); }
 
     for l in lines.iter(){
         if l.is_empty() { break; }
@@ -133,12 +153,24 @@ fn format_chapter(chapter: &str) -> Result<(Vec<String>, Vec<String>), Error>{
         if splited_line.len()<2 || splited_line[1] == "" { // To avoid blank title
             return Err(Error::new(ErrorKind::Other, "No title associated with the time code")); 
         }
+        if !is_time_code_valid(&splited_line[0].to_owned()){
+            return Err(Error::new(ErrorKind::Other, "one or multiple time code is invalid"));
+        }
         time_code.push(splited_line[0].to_owned());
         title_names.push(splited_line[1..].join(" - "));
     }
     Ok((time_code, title_names))
 }
 
+/// return true if the time code is valid, and false otherwise
+fn is_time_code_valid(time_code: &String) -> bool{
+    let allowed_char = "0123456789:";
+    for c in time_code.chars(){
+        if !allowed_char.contains(c) { return false; }
+    }
+    true
+}
+
 // prompt user file chooser using native_dialogue crate
 fn choose_file() -> String{
     println!("Let's choose a file !");
@@ -188,6 +220,7 @@ fn launch_ffmpeg(app: tauri::AppHandle, args: Vec<String>) {
 }
 
 fn main() {
+    env::set_var("WEBKIT_DISABLE_COMPOSITING_MODE", "1");
     // generate the tauri app
     tauri::Builder::default()
         .invoke_handler(tauri::generate_handler![select_file_button, select_folder_button, debug_call, slice_button, about_button])
index 29da87855b7a7d8533de3365b2dc3177608b3fad..0d5074ef6b42949812839b10bf69cc973ace3135 100644 (file)
@@ -6,7 +6,7 @@
   },
   "package": {
     "productName": "rusty-slicer",
-    "version": "0.0.0"
+    "version": "0.0.1"
   },
   "tauri": {
     "allowlist": {
index 67d727d139c75162b6a9596243cf6d1d52fa77a9..8a0f0a85aa17f5cbd6a454855429bf3c192a19fd 100644 (file)
@@ -18,7 +18,7 @@
         <a href="https://crates.io/crates/native-dialog" target="_blank">Native Dialog crate</a> <br> to open file select dialog (Really easy to use) <br>
         <a href="https://crates.io/crates/lazy_static" target="_blank">Lazy static crate</a> <br> to create global variables more easly <br>
         <a href="https://codepen.io/algcifaldi" target="_blank">Amanda Cifaldi</a> <br> For the animated background template <br>
-
+        <a href="https://mozilla.github.io/Fira/" target="_blank">Fira Sans</a> <br> By Erik Spiekermann is a clean font <br>
         </b>
     </p>
     <h2 class="credit"> About Me </h2>
index 61e05296f81c876b36cc520aa6753e30cc074162..f9555b2ba6f034a3267dce02aff8c5d97b48810c 100644 (file)
@@ -2,12 +2,34 @@ const { listen } = window.__TAURI__.event
 
 // listen for file location from rust backend
 const unlistenfile = await listen('file_path_changed', (event) => {
+  document.getElementById("fileLocation").style.color = "white";
   document.getElementById("fileLocation").innerHTML = event.payload.message;
   console.log("changing file label to : ", event.payload.message);
 })
 
 // listen for folder location from rust backend
 const unlistenfolder = await listen('folder_path_changed', (event) => {
+  document.getElementById("folderLocation").style.color = "white";
   document.getElementById("folderLocation").innerHTML = event.payload.message;
   console.log("changing folder label to : ", event.payload.message);
+})
+
+// listen for error from rust backend
+const unlistenerror = await listen('backend_error', (event) => {
+  switch (event.payload.message) {
+    case "file_empty":
+      document.getElementById("fileLocation").style.color = "red";
+      document.getElementById("fileLocation").innerHTML = "please select an input file"
+      console.log("please select an input file");
+      break;
+    case "folder_empty":
+      document.getElementById("folderLocation").style.color = "red";
+      document.getElementById("folderLocation").innerHTML = "please select an output folder"
+      console.log("please select an output folder");
+      break;
+      case "formating_issue":
+        document.getElementById("errorLabel").innerHTML = "error: wrong chapter format. use 0:13 - my title"
+        console.log("error: wrong chapter format. use \n0:00 - first song title \n2:13 - second song title \n3:45 - third song title \n...");
+        break;
+  }
 })
\ No newline at end of file
diff --git a/src/fonts/FiraSans-Bold.ttf b/src/fonts/FiraSans-Bold.ttf
new file mode 100644 (file)
index 0000000..e3593fb
Binary files /dev/null and b/src/fonts/FiraSans-Bold.ttf differ
index caa0da7ec5f17f7a06d38002915b2df0ed2d9851..1d05135ae19a7c09f0bd226eefff437f5f156c9e 100644 (file)
@@ -29,6 +29,7 @@
 0:00 - my first song
 3:30 - another one
 13:37 - one more time - Daft punk</textarea>
+          <p id="errorLabel" style="color: red;"></p>
         </div>
 
         <div class="select-file">
index de17f8012e42e354bd2fb93ebce80f35a7456e60..2de8342eb216b73d6976a7ca668083767461b68c 100644 (file)
@@ -11,6 +11,7 @@ function select_folder_button_pressed(){
 }
 
 function slice_button_pressed(){
+    document.getElementById("errorLabel").innerHTML = "";
     invoke("slice_button", {chapter: document.getElementById("chapterList").value, fileformat: document.getElementById("fileFormatSelect").value})
 }
 
index c4dd4ebb8823325600fd7c571249d02cc9435bd8..80b8e396343732b088ed9866b6a6d8b4371ccc30 100644 (file)
@@ -1,5 +1,10 @@
+@font-face {
+  font-family: FiraSans-extrabold;
+  src: url(fonts/FiraSans-Bold.ttf);
+}
+
 :root {
-  font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
+  font-family: FiraSans-extrabold, Inter, Avenir, Helvetica, Arial, sans-serif;
 
   color: #f6f6f6;
   background-color: #292829;