Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add timeout to panic notification #149

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashSet;
use std::path::PathBuf;
use std::time::Instant;
use std::{collections::HashSet, time::Duration};

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

fn main() {
const NOTIFY_TIMEOUT: Duration = Duration::from_millis(250);

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
Loading