From bbf00939a993714447d403d71bbda9833ecc7e91 Mon Sep 17 00:00:00 2001 From: dxrknesss Date: Sun, 28 Sep 2025 19:04:37 +0300 Subject: [PATCH] fix path resolution --- README.md | 8 ++++++++ src/main.rs | 46 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5d4f3e8..d96c289 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,17 @@ ct - custom timer # Prerequisites +- cargo - zenity - pipewire +# Installing + +1. Execute `cargo b --release` +2. Then, you can symlink executable file target/release/ct to wherever you feel comfortable. + +Don't move it, though, since this will break the app! + # Summary ct is a timer application that play sound and display dialogue (with unconfigurable text, for now) on completion. diff --git a/src/main.rs b/src/main.rs index 4234d78..6ead7d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,19 +22,45 @@ fn main() { '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 - }); let current_exe_path = env::current_exe().unwrap().canonicalize().unwrap(); - Daemonize::new() - .working_directory(current_exe_path.parent().unwrap()) - .start() + let root = current_exe_path + .parent() + .unwrap() + .parent() + .unwrap() + .parent() .unwrap(); + let alert_path = args.get(3).map_or_else( + || { + let default = "assets/not_sussy_song.opus"; + let default_path = root.join(default); + if !default_path.exists() { + let _ = Command::new("zenity") + .args([ + "--error", + &format!( + "--text=Bundled alarm sound wasn't found! path: {}", + default_path.to_str().unwrap() + ), + ]) + .spawn() + .unwrap() + .wait(); + panic!("Didn't find bundled sound"); + } + default + }, + |path| { + assert!( + Path::new(path).exists(), + "The path provided should point to an existing file" + ); + path + }, + ); + + Daemonize::new().working_directory(root).start().unwrap(); sleep(sleeping_amount);