Skip to main content

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        let res = match res {
31            Ok(choice) => choice,
32            Err(e) => {
33                eprintln!("Failed to show crash handler dialog: {e:?}");
34                return;
35            }
36        };
37        if res == Choice::No {
38            return;
39        }
40
41        let clipboard = Clipboard::new();
42        let mut clipboard = match clipboard {
43            Ok(clipboard) => clipboard,
44            Err(e) => {
45                eprintln!("Failed to create clipboard: {e:?}");
46                return;
47            }
48        };
49        if let Err(e) = clipboard.set_text(message.clone()) {
50            eprintln!("Failed to copy crash message to clipboard: {e:?}");
51        }
52    }
53}