(title: &str, msg: &str, forever: bool)
| 257 | /// forever: may not work |
| 258 | #[cfg(target_os = "linux")] |
| 259 | pub fn system_message(title: &str, msg: &str, forever: bool) -> ResultType<()> { |
| 260 | let cmds: HashMap<&str, Vec<&str>> = HashMap::from([ |
| 261 | ("notify-send", [title, msg].to_vec()), |
| 262 | ( |
| 263 | "zenity", |
| 264 | [ |
| 265 | "--info", |
| 266 | "--timeout", |
| 267 | if forever { "0" } else { "3" }, |
| 268 | "--title", |
| 269 | title, |
| 270 | "--text", |
| 271 | msg, |
| 272 | ] |
| 273 | .to_vec(), |
| 274 | ), |
| 275 | ("kdialog", ["--title", title, "--msgbox", msg].to_vec()), |
| 276 | ( |
| 277 | "xmessage", |
| 278 | [ |
| 279 | "-center", |
| 280 | "-timeout", |
| 281 | if forever { "0" } else { "3" }, |
| 282 | title, |
| 283 | msg, |
| 284 | ] |
| 285 | .to_vec(), |
| 286 | ), |
| 287 | ]); |
| 288 | for (k, v) in cmds { |
| 289 | if Command::new(k).args(v).spawn().is_ok() { |
| 290 | return Ok(()); |
| 291 | } |
| 292 | } |
| 293 | crate::bail!("failed to post system message"); |
| 294 | } |
| 295 | |
| 296 | #[cfg(test)] |
| 297 | mod tests { |
no outgoing calls
no test coverage detected