diff --git a/assets/not_sussy_song.opus b/assets/not_sussy_song.opus new file mode 100644 index 0000000..1c28973 Binary files /dev/null and b/assets/not_sussy_song.opus differ diff --git a/src/main.rs b/src/main.rs index 6397b68..4f2f98b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use std::{ env::{self, args}, + path::Path, process::Command, thread::sleep, time::Duration, @@ -7,16 +8,30 @@ use std::{ fn main() { let args: Vec = args().collect(); - let timeout_secs: u64 = args.get(1) - .expect("There should be 1 argument, which specifies amount of time (in seconds) for timer to work!") + let timeout: u64 = args.get(1) + .expect("There should be at least 1 argument, which specifies amount of time (in seconds) for timer to work!") .parse() .expect("The first argument should be a non-negative number"); - let home = env::var("HOME").unwrap(); + let measurement: char = args + .get(2) + .map_or('s', |arg| arg.chars().next().unwrap_or('s')); + let sleeping_amount: Duration = match measurement { + 's' => Duration::from_secs(timeout), + 'm' => Duration::from_mins(timeout), + _ => panic!("Invalid measurement of time! For now, only 's' and 'm' are supported"), + }; + let alert_path = args.get(3).map_or("assets/not_sussy_song.opus", |path| { + assert!( + Path::new(path).exists(), + "The path provided should point to an existing file" + ); + path + }); - sleep(Duration::from_secs(timeout_secs)); + sleep(sleeping_amount); let mut sound_alert = Command::new("pw-play") - .arg(format!("{home}/Music/not_sussy_song.opus")) + .arg(alert_path) .spawn() .expect("pw-play utility should be installed");