with_options/
with_options.rs1use gntp::{GntpClient, NotificationType, NotifyOptions};
6use std::thread;
7use std::time::Duration;
8
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10 println!("=== Notification Options Example ===\n");
11
12 let mut client = GntpClient::new("Options Example");
14
15 let notification = NotificationType::new("message")
17 .with_display_name("Message");
18
19 println!("Registering...");
21 client.register(vec![notification])?;
22 println!("✓ Registered\n");
23
24 println!("Example 1: Normal notification (default priority)");
26 client.notify("message", "Normal", "This is a normal notification")?;
27 println!("✓ Sent (priority: 0)\n");
28 thread::sleep(Duration::from_secs(2));
29
30 println!("Example 2: High priority notification");
32 let high_priority = NotifyOptions::new()
33 .with_priority(2); client.notify_with_options(
36 "message",
37 "High Priority",
38 "This is a high priority notification!",
39 high_priority
40 )?;
41 println!("✓ Sent (priority: 2)\n");
42 thread::sleep(Duration::from_secs(2));
43
44 println!("Example 3: Low priority notification");
46 let low_priority = NotifyOptions::new()
47 .with_priority(-2); client.notify_with_options(
50 "message",
51 "Low Priority",
52 "This is a low priority notification",
53 low_priority
54 )?;
55 println!("✓ Sent (priority: -2)\n");
56 thread::sleep(Duration::from_secs(2));
57
58 println!("Example 4: Sticky notification (stays on screen)");
60 let sticky = NotifyOptions::new()
61 .with_sticky(true);
62
63 client.notify_with_options(
64 "message",
65 "Sticky Notification",
66 "This notification will stay on screen until dismissed",
67 sticky
68 )?;
69 println!("✓ Sent (sticky: true)\n");
70 thread::sleep(Duration::from_secs(2));
71
72 println!("Example 5: High priority AND sticky");
74 let critical = NotifyOptions::new()
75 .with_priority(2)
76 .with_sticky(true);
77
78 client.notify_with_options(
79 "message",
80 "Critical Alert!",
81 "High priority sticky notification - requires manual dismissal",
82 critical
83 )?;
84 println!("✓ Sent (priority: 2, sticky: true)\n");
85
86 println!("✅ Example completed!");
87 println!("\nNote:");
88 println!(" • Priority range: -2 (lowest) to 2 (highest)");
89 println!(" • Sticky notifications stay on screen until dismissed");
90 println!(" • You can combine priority + sticky");
91
92 Ok(())
93}