add handling of different time amounts + add default sound alert
This commit is contained in:
Binary file not shown.
+20
-5
@@ -1,5 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
env::{self, args},
|
env::{self, args},
|
||||||
|
path::Path,
|
||||||
process::Command,
|
process::Command,
|
||||||
thread::sleep,
|
thread::sleep,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
@@ -7,16 +8,30 @@ use std::{
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = args().collect();
|
let args: Vec<String> = args().collect();
|
||||||
let timeout_secs: u64 = args.get(1)
|
let timeout: u64 = args.get(1)
|
||||||
.expect("There should be 1 argument, which specifies amount of time (in seconds) for timer to work!")
|
.expect("There should be at least 1 argument, which specifies amount of time (in seconds) for timer to work!")
|
||||||
.parse()
|
.parse()
|
||||||
.expect("The first argument should be a non-negative number");
|
.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")
|
let mut sound_alert = Command::new("pw-play")
|
||||||
.arg(format!("{home}/Music/not_sussy_song.opus"))
|
.arg(alert_path)
|
||||||
.spawn()
|
.spawn()
|
||||||
.expect("pw-play utility should be installed");
|
.expect("pw-play utility should be installed");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user