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 Default for DialogCrashHandler {
11    fn default() -> Self {
12        Self::new()
13    }
14}
15
16impl DialogCrashHandler {
17    pub fn new() -> Self {
18        Self { _private: () }
19    }
20}
21
22impl ObsCrashHandler for DialogCrashHandler {
23    fn handle_crash(&self, message: String) {
24        eprintln!("OBS crashed: {}", message);
25        let res =
26            dialog::Question::new("OBS has crashed. Do you want to copy the error to clipboard?")
27                .title("OBS Crash Handler")
28                .show();
29
30        if let Err(e) = res {
31            eprintln!("Failed to show crash handler dialog: {e:?}");
32            return;
33        }
34
35        let res = res.unwrap();
36        if res == Choice::No {
37            return;
38        }
39
40        let clipboard = Clipboard::new();
41        if let Err(e) = clipboard {
42            eprintln!("Failed to create clipboard: {e:?}");
43            return;
44        }
45
46        let mut clipboard = clipboard.unwrap();
47        if let Err(e) = clipboard.set_text(message.clone()) {
48            eprintln!("Failed to copy crash message to clipboard: {e:?}");
49        }
50    }
51}