Debian Codegraph @

examples/urgency.rs

raw symbols SCIP
1 #[cfg(target_os = "macos")]
2 fn main() {
3 println!("Urgency is not supported on macOS")
4 }
5
6 #[cfg(any(all(unix, not(target_os = "macos")), target_os = "windows"))]
7 fn main() -> Result<(), Box<dyn std::error::Error>> {
8 use notify_rust::{Notification, Urgency::*};
9
10 #[cfg(all(unix, not(target_os = "macos")))]
11 println!("Testing urgency on Linux/BSD (XDG)");
12 #[cfg(all(unix, not(target_os = "macos")))]
13 println!("Urgency is sent as a hint. Critical notifications should not timeout.\n");
14
15 #[cfg(target_os = "windows")]
16 println!("Testing urgency on Windows");
17 #[cfg(target_os = "windows")]
18 println!("Low/Normal → Default scenario, Critical → Reminder scenario (stays on screen)\n");
19
20 // Test all urgency levels
21 for urgency in &[Low, Normal, Critical] {
22 let mut notification = Notification::new();
23 notification
24 .summary(&format!("Urgency {:?}", urgency))
25 .body("This notification demonstrates urgency levels")
26 .urgency(*urgency);
27
28 #[cfg(all(unix, not(target_os = "macos")))]
29 notification.icon("firefox");
30
31 notification.show()?;
32 }
33
34 // Test urgency from string
35 let mut notification = Notification::new();
36 notification
37 .summary("Urgency from String")
38 .body("This uses 'high' which maps to Critical")
39 .urgency("high".try_into()?);
40
41 #[cfg(all(unix, not(target_os = "macos")))]
42 notification.icon("dialog-warning");
43
44 notification.show()?;
45
46 Ok(())
47 }