Skip to content

Commit

Permalink
fix not exciting when no notification daemon is available
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockListed committed Oct 8, 2023
1 parent 811a435 commit 5a04436
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashSet;
use std::time::Instant;
use std::{collections::HashSet, time::Duration};
use std::path::PathBuf;

use log::LevelFilter;
Expand Down Expand Up @@ -260,6 +261,8 @@ fn main_inner() {
}

fn main() {
const NOTIFY_TIMEOUT: Duration = Duration::from_micros(500);

let res = std::panic::catch_unwind(main_inner);

if let Err(err) = res {
Expand All @@ -271,13 +274,28 @@ fn main() {
"unknown panic"
};

let _ = std::process::Command::new("notify-send")
let child_started = Instant::now();

let mut child = std::process::Command::new("notify-send")
.args(&[
concat!("--app-name=", prog_name!()),
concat!(prog_name!(), " has panicked!"),
msg,
])
.status();
.spawn()
.unwrap();

loop {
let child_exited = child.try_wait().unwrap().is_some();
if child_exited {
break;
} else if child_started.elapsed() > NOTIFY_TIMEOUT {
log::error!("Couldn't contact notification daemon. Timeout");
break;
} else {
std::thread::sleep(Duration::from_millis(10));
}
}

log::error!("panic: {}", msg);

Expand Down

0 comments on commit 5a04436

Please sign in to comment.