NotifyOptions

Struct NotifyOptions 

Source
pub struct NotifyOptions {
    pub sticky: bool,
    pub priority: i8,
    pub icon: Option<Resource>,
}
Expand description

Options for sending notifications

Allows customization of notification behavior and appearance.

§Example

let icon = Resource::from_file("icon.png")?;
 
let options = NotifyOptions::new()
    .with_sticky(true)
    .with_priority(2)
    .with_icon(icon);

Fields§

§sticky: bool

Keep notification on screen until dismissed

§priority: i8

Priority level (-2 = very low, 0 = normal, 2 = emergency)

§icon: Option<Resource>

Optional icon for this specific notification

Implementations§

Source§

impl NotifyOptions

Source

pub fn new() -> Self

Create new notification options with defaults

Examples found in repository?
examples/with_options.rs (line 32)
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}
More examples
Hide additional examples
examples/android.rs (line 87)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    println!("=== Growl for Android Example ===\n");
11    
12    // Get Android device IP from environment
13    let android_host = env::var("ANDROID_HOST")
14        .unwrap_or_else(|_| {
15            println!("⚠ ANDROID_HOST not set, using default");
16            println!("  Set with: set ANDROID_HOST=192.168.1.100\n");
17            "192.168.1.100".to_string()
18        });
19    
20    println!("Target Android device: {}", android_host);
21    
22    // Create client optimized for Android
23    let mut client = GntpClient::new("Android Example")
24        .with_host(&android_host)
25        .with_port(23053)
26        .with_icon_mode(IconMode::DataUrl) // Best for Android
27        .with_debug(false);
28    
29    // Try to load icon (optional)
30    let icon = match Resource::from_file("icon.png") {
31        Ok(icon) => {
32            println!("✓ Icon loaded: icon.png");
33            Some(icon)
34        }
35        Err(_) => {
36            println!("ℹ No icon found (optional)");
37            None
38        }
39    };
40    
41    // Define notification type with icon
42    let mut notification = NotificationType::new("android")
43        .with_display_name("Android Notification");
44    
45    if let Some(icon) = icon {
46        notification = notification.with_icon(icon);
47        println!("✓ Icon attached to notification");
48    }
49    
50    println!();
51    
52    // Register with retry (Android may need retry due to network)
53    println!("Registering with Growl for Android...");
54    let mut register_ok = false;
55    
56    for attempt in 1..=3 {
57        match client.register(vec![notification.clone()]) {
58            Ok(_) => {
59                println!("✓ Registered successfully{}\n", 
60                    if attempt > 1 { format!(" (attempt {})", attempt) } else { String::new() });
61                register_ok = true;
62                break;
63            }
64            Err(e) => {
65                if attempt < 3 {
66                    println!("⚠ Attempt {} failed, retrying... ({})", attempt, e);
67                    std::thread::sleep(std::time::Duration::from_secs(2));
68                } else {
69                    eprintln!("❌ Registration failed after 3 attempts: {}", e);
70                    eprintln!("\nTroubleshooting:");
71                    eprintln!("  1. Is Growl for Android running?");
72                    eprintln!("  2. Is {} the correct IP address?", android_host);
73                    eprintln!("  3. Are both devices on the same network?");
74                    eprintln!("  4. Check Android firewall settings");
75                    return Err(e.into());
76                }
77            }
78        }
79    }
80    
81    if !register_ok {
82        return Err("Registration failed".into());
83    }
84    
85    // Send notification with options
86    println!("Sending notification...");
87    let options = NotifyOptions::new()
88        .with_sticky(false) // Don't make it sticky on mobile
89        .with_priority(1);  // High priority
90    
91    match client.notify_with_options(
92        "android",
93        "Hello Android!",
94        "This notification was sent from Rust",
95        options
96    ) {
97        Ok(_) => {
98            println!("✓ Notification sent\n");
99            println!("✅ Check your Android device for the notification!");
100        }
101        Err(e) => {
102            eprintln!("❌ Failed to send: {}", e);
103            return Err(e.into());
104        }
105    }
106    
107    Ok(())
108}
Source

pub fn with_sticky(self, sticky: bool) -> Self

Set sticky mode (notification stays until dismissed)

Examples found in repository?
examples/with_options.rs (line 61)
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}
More examples
Hide additional examples
examples/android.rs (line 88)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    println!("=== Growl for Android Example ===\n");
11    
12    // Get Android device IP from environment
13    let android_host = env::var("ANDROID_HOST")
14        .unwrap_or_else(|_| {
15            println!("⚠ ANDROID_HOST not set, using default");
16            println!("  Set with: set ANDROID_HOST=192.168.1.100\n");
17            "192.168.1.100".to_string()
18        });
19    
20    println!("Target Android device: {}", android_host);
21    
22    // Create client optimized for Android
23    let mut client = GntpClient::new("Android Example")
24        .with_host(&android_host)
25        .with_port(23053)
26        .with_icon_mode(IconMode::DataUrl) // Best for Android
27        .with_debug(false);
28    
29    // Try to load icon (optional)
30    let icon = match Resource::from_file("icon.png") {
31        Ok(icon) => {
32            println!("✓ Icon loaded: icon.png");
33            Some(icon)
34        }
35        Err(_) => {
36            println!("ℹ No icon found (optional)");
37            None
38        }
39    };
40    
41    // Define notification type with icon
42    let mut notification = NotificationType::new("android")
43        .with_display_name("Android Notification");
44    
45    if let Some(icon) = icon {
46        notification = notification.with_icon(icon);
47        println!("✓ Icon attached to notification");
48    }
49    
50    println!();
51    
52    // Register with retry (Android may need retry due to network)
53    println!("Registering with Growl for Android...");
54    let mut register_ok = false;
55    
56    for attempt in 1..=3 {
57        match client.register(vec![notification.clone()]) {
58            Ok(_) => {
59                println!("✓ Registered successfully{}\n", 
60                    if attempt > 1 { format!(" (attempt {})", attempt) } else { String::new() });
61                register_ok = true;
62                break;
63            }
64            Err(e) => {
65                if attempt < 3 {
66                    println!("⚠ Attempt {} failed, retrying... ({})", attempt, e);
67                    std::thread::sleep(std::time::Duration::from_secs(2));
68                } else {
69                    eprintln!("❌ Registration failed after 3 attempts: {}", e);
70                    eprintln!("\nTroubleshooting:");
71                    eprintln!("  1. Is Growl for Android running?");
72                    eprintln!("  2. Is {} the correct IP address?", android_host);
73                    eprintln!("  3. Are both devices on the same network?");
74                    eprintln!("  4. Check Android firewall settings");
75                    return Err(e.into());
76                }
77            }
78        }
79    }
80    
81    if !register_ok {
82        return Err("Registration failed".into());
83    }
84    
85    // Send notification with options
86    println!("Sending notification...");
87    let options = NotifyOptions::new()
88        .with_sticky(false) // Don't make it sticky on mobile
89        .with_priority(1);  // High priority
90    
91    match client.notify_with_options(
92        "android",
93        "Hello Android!",
94        "This notification was sent from Rust",
95        options
96    ) {
97        Ok(_) => {
98            println!("✓ Notification sent\n");
99            println!("✅ Check your Android device for the notification!");
100        }
101        Err(e) => {
102            eprintln!("❌ Failed to send: {}", e);
103            return Err(e.into());
104        }
105    }
106    
107    Ok(())
108}
Source

pub fn with_priority(self, priority: i8) -> Self

Set priority (-2 to 2)

  • -2 = Very Low
  • -1 = Moderate
  • 0 = Normal (default)
  • 1 = High
  • 2 = Emergency
Examples found in repository?
examples/with_options.rs (line 33)
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}
More examples
Hide additional examples
examples/android.rs (line 89)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    println!("=== Growl for Android Example ===\n");
11    
12    // Get Android device IP from environment
13    let android_host = env::var("ANDROID_HOST")
14        .unwrap_or_else(|_| {
15            println!("⚠ ANDROID_HOST not set, using default");
16            println!("  Set with: set ANDROID_HOST=192.168.1.100\n");
17            "192.168.1.100".to_string()
18        });
19    
20    println!("Target Android device: {}", android_host);
21    
22    // Create client optimized for Android
23    let mut client = GntpClient::new("Android Example")
24        .with_host(&android_host)
25        .with_port(23053)
26        .with_icon_mode(IconMode::DataUrl) // Best for Android
27        .with_debug(false);
28    
29    // Try to load icon (optional)
30    let icon = match Resource::from_file("icon.png") {
31        Ok(icon) => {
32            println!("✓ Icon loaded: icon.png");
33            Some(icon)
34        }
35        Err(_) => {
36            println!("ℹ No icon found (optional)");
37            None
38        }
39    };
40    
41    // Define notification type with icon
42    let mut notification = NotificationType::new("android")
43        .with_display_name("Android Notification");
44    
45    if let Some(icon) = icon {
46        notification = notification.with_icon(icon);
47        println!("✓ Icon attached to notification");
48    }
49    
50    println!();
51    
52    // Register with retry (Android may need retry due to network)
53    println!("Registering with Growl for Android...");
54    let mut register_ok = false;
55    
56    for attempt in 1..=3 {
57        match client.register(vec![notification.clone()]) {
58            Ok(_) => {
59                println!("✓ Registered successfully{}\n", 
60                    if attempt > 1 { format!(" (attempt {})", attempt) } else { String::new() });
61                register_ok = true;
62                break;
63            }
64            Err(e) => {
65                if attempt < 3 {
66                    println!("⚠ Attempt {} failed, retrying... ({})", attempt, e);
67                    std::thread::sleep(std::time::Duration::from_secs(2));
68                } else {
69                    eprintln!("❌ Registration failed after 3 attempts: {}", e);
70                    eprintln!("\nTroubleshooting:");
71                    eprintln!("  1. Is Growl for Android running?");
72                    eprintln!("  2. Is {} the correct IP address?", android_host);
73                    eprintln!("  3. Are both devices on the same network?");
74                    eprintln!("  4. Check Android firewall settings");
75                    return Err(e.into());
76                }
77            }
78        }
79    }
80    
81    if !register_ok {
82        return Err("Registration failed".into());
83    }
84    
85    // Send notification with options
86    println!("Sending notification...");
87    let options = NotifyOptions::new()
88        .with_sticky(false) // Don't make it sticky on mobile
89        .with_priority(1);  // High priority
90    
91    match client.notify_with_options(
92        "android",
93        "Hello Android!",
94        "This notification was sent from Rust",
95        options
96    ) {
97        Ok(_) => {
98            println!("✓ Notification sent\n");
99            println!("✅ Check your Android device for the notification!");
100        }
101        Err(e) => {
102            eprintln!("❌ Failed to send: {}", e);
103            return Err(e.into());
104        }
105    }
106    
107    Ok(())
108}
Source

pub fn with_icon(self, icon: Resource) -> Self

Set icon for this notification

Trait Implementations§

Source§

impl Default for NotifyOptions

Source§

fn default() -> NotifyOptions

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.