with_options/
with_options.rs

1// examples/with_options.rs
2// GNTP with notification options (priority, sticky)
3// Run with: cargo run --example with_options
4
5use 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    // Create GNTP client
13    let mut client = GntpClient::new("Options Example");
14    
15    // Define notification type
16    let notification = NotificationType::new("message")
17        .with_display_name("Message");
18    
19    // Register
20    println!("Registering...");
21    client.register(vec![notification])?;
22    println!("✓ Registered\n");
23    
24    // Example 1: Normal priority notification
25    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    // Example 2: High priority notification
31    println!("Example 2: High priority notification");
32    let high_priority = NotifyOptions::new()
33        .with_priority(2);  // Highest priority: 2
34    
35    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    // Example 3: Low priority notification
45    println!("Example 3: Low priority notification");
46    let low_priority = NotifyOptions::new()
47        .with_priority(-2);  // Lowest priority: -2
48    
49    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    // Example 4: Sticky notification (stays on screen)
59    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    // Example 5: High priority + sticky
73    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}