blocking_dialog/linux/
alert.rs1use super::is_kdialog_available;
5use crate::{BlockingAlertDialog, BlockingDialogError, BlockingDialogLevel};
6use raw_window_handle::HasWindowHandle;
7use std::process::Command;
8
9fn get_kdialog_level_flag(level: BlockingDialogLevel) -> &'static str {
10 match level {
11 BlockingDialogLevel::Info => "--msgbox",
12 BlockingDialogLevel::Warning => "--sorry",
13 BlockingDialogLevel::Error => "--error",
14 }
15}
16
17fn get_zenity_level_flag(level: BlockingDialogLevel) -> &'static str {
18 match level {
19 BlockingDialogLevel::Info => "--info",
20 BlockingDialogLevel::Warning => "--warning",
21 BlockingDialogLevel::Error => "--error",
22 }
23}
24
25impl<'a, W: HasWindowHandle> BlockingAlertDialog<'a, W> {
26 pub fn show(&self) -> Result<(), BlockingDialogError> {
27 let _ = if is_kdialog_available() {
28 Command::new("kdialog")
29 .arg("--title")
30 .arg(self.title)
31 .arg(get_kdialog_level_flag(self.level))
32 .arg(self.message)
33 .status()?
34 } else {
35 Command::new("zenity")
36 .arg(get_zenity_level_flag(self.level))
37 .arg("--title")
38 .arg(self.title)
39 .arg("--text")
40 .arg(self.message)
41 .status()?
42 };
43
44 Ok(())
45 }
46}