Debian Codegraph @

examples/hints.rs

raw symbols SCIP
1 #![allow(unused_imports, dead_code)]
2 use std::{thread::sleep, time::Duration};
3
4 #[cfg(all(feature = "images_no_default_features", unix, not(target_os = "macos")))]
5 use notify_rust::Image;
6 use notify_rust::{Hint, Notification, Urgency::*};
7
8 fn freeze(message: &str) {
9 println!("{message}\n");
10 let mut _devnull = String::new();
11 let _ = std::io::stdin().read_line(&mut _devnull);
12 }
13
14 #[cfg(any(target_os = "windows", target_os = "macos"))]
15 fn main() {
16 println!("this is an xdg only feature")
17 }
18
19 #[cfg(all(unix, not(target_os = "macos")))]
20 fn main() -> Result<(), Box<dyn std::error::Error>> {
21 println!("Pay close attention to the output of:");
22 println!("$ dbus-monitor \"interface=org.freedesktop.Notifications\"");
23
24 freeze("actionicons");
25 Notification::new().hint(Hint::ActionIcons(true)).show()?;
26
27 freeze("urgency: low, medium, high");
28 Notification::new()
29 .summary("low")
30 .hint(Hint::Urgency(Low))
31 .show()?;
32 Notification::new()
33 .summary("normal")
34 .hint(Hint::Urgency(Normal))
35 .show()?;
36 Notification::new()
37 .summary("critical")
38 .hint(Hint::Urgency(Critical))
39 .show()?;
40
41 freeze("category");
42 Notification::new()
43 .hint(Hint::Category("device.removed".into()))
44 .show()?;
45
46 freeze("DesktopEntry");
47 Notification::new()
48 .summary("desktop entry")
49 .hint(Hint::DesktopEntry("firefox".into()))
50 .show()?;
51
52 freeze("ImagePath");
53 Notification::new()
54 .summary("iconpath")
55 .hint(Hint::ImagePath(
56 "/usr/share/icons/hicolor/128x128/apps/firefox.png".into(),
57 ))
58 .show()?;
59
60 freeze("Resident");
61 Notification::new()
62 .summary("resident")
63 .hint(Hint::Resident(true))
64 .show()?;
65
66 freeze("SoundFile");
67 Notification::new()
68 .summary("soundfile")
69 .hint(Hint::SoundFile(
70 "/usr/share/sounds/alsa/Front_Left.wav".to_owned(),
71 ))
72 .hint(Hint::SoundName("system sound".to_owned()))
73 .hint(Hint::SuppressSound(false))
74 .show()?;
75
76 freeze("Transient");
77 Notification::new()
78 .summary("transient")
79 .hint(Hint::Transient(false))
80 .show()?;
81
82 freeze("X and Y");
83 Notification::new()
84 .hint(Hint::X(200))
85 .hint(Hint::Y(200))
86 .show()?;
87
88 #[cfg(all(feature = "images_no_default_features", unix, not(target_os = "macos")))]
89 {
90 freeze("ImageData");
91 let mut image_data = vec![0; 128 * 128 * 3];
92 for i in 0..128 * 128 * 3 {
93 image_data[i] = (i % 256) as u8;
94 }
95 Notification::new()
96 .hint(Hint::ImageData(
97 Image::from_rgb(128, 128, image_data).unwrap(),
98 ))
99 .summary("You should see stripes in this notification");
100 }
101
102 Ok(())
103
104 // freeze("Custom");
105 // Notification::new().hint(Hint::Custom("foo","bar")).show();
106 }