fix path resolution

This commit is contained in:
2025-09-28 19:04:37 +03:00
parent 9391d1eb34
commit bbf00939a9
2 changed files with 44 additions and 10 deletions

View File

@@ -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.

View File

@@ -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);