add handling of different time amounts + add default sound alert
This commit is contained in:
BIN
assets/not_sussy_song.opus
Normal file
BIN
assets/not_sussy_song.opus
Normal file
Binary file not shown.
25
src/main.rs
25
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<String> = 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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user