libobs_wrapper\crash_handler/
dialog.rs

1use arboard::Clipboard;
2use dialog::{Choice, DialogBox};
3
4use super::ObsCrashHandler;
5
6pub struct DialogCrashHandler {
7    _private: (),
8}
9
10impl DialogCrashHandler {
11    pub fn new() -> Self {
12        Self { _private: () }
13    }
14}
15
16impl ObsCrashHandler for DialogCrashHandler {
17    fn handle_crash(&self, message: String) {
18        eprintln!("OBS crashed: {}", message);
19        let res =
20            dialog::Question::new("OBS has crashed. Do you want to copy the error to clipboard?")
21                .title("OBS Crash Handler")
22                .show();
23
24        if let Err(e) = res {
25            eprintln!("Failed to show crash handler dialog: {e:?}");
26            return;
27        }
28
29        let res = res.unwrap();
30        if res == Choice::No {
31            return;
32        }
33
34        let clipboard = Clipboard::new();
35        if let Err(e) = clipboard {
36            eprintln!("Failed to create clipboard: {e:?}");
37            return;
38        }
39
40        let mut clipboard = clipboard.unwrap();
41        if let Err(e) = clipboard.set_text(message.clone()) {
42            eprintln!("Failed to copy crash message to clipboard: {e:?}");
43            return;
44        }
45    }
46}