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: boolKeep notification on screen until dismissed
priority: i8Priority level (-2 = very low, 0 = normal, 2 = emergency)
icon: Option<Resource>Optional icon for this specific notification
Implementations§
Source§impl NotifyOptions
impl NotifyOptions
Sourcepub fn new() -> Self
pub fn new() -> Self
Create new notification options with defaults
Examples found in repository?
examples/with_options.rs (line 37)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 println!("=== Notification Options Example ===\n");
17
18 // Create GNTP client
19 let mut client = GntpClient::new("Options Example");
20
21 // Define notification type
22 let notification = NotificationType::new("message").with_display_name("Message");
23
24 // Register
25 println!("Registering...");
26 client.register(vec![notification])?;
27 println!("✓ Registered\n");
28
29 // Example 1: Normal priority notification
30 println!("Example 1: Normal notification (default priority)");
31 client.notify("message", "Normal", "This is a normal notification")?;
32 println!("✓ Sent (priority: 0)\n");
33 thread::sleep(Duration::from_secs(2));
34
35 // Example 2: High priority notification
36 println!("Example 2: High priority notification");
37 let high_priority = NotifyOptions::new().with_priority(2); // Highest priority: 2
38
39 client.notify_with_options(
40 "message",
41 "High Priority",
42 "This is a high priority notification!",
43 high_priority,
44 )?;
45 println!("✓ Sent (priority: 2)\n");
46 thread::sleep(Duration::from_secs(2));
47
48 // Example 3: Low priority notification
49 println!("Example 3: Low priority notification");
50 let low_priority = NotifyOptions::new().with_priority(-2); // Lowest priority: -2
51
52 client.notify_with_options(
53 "message",
54 "Low Priority",
55 "This is a low priority notification",
56 low_priority,
57 )?;
58 println!("✓ Sent (priority: -2)\n");
59 thread::sleep(Duration::from_secs(2));
60
61 // Example 4: Sticky notification (stays on screen)
62 println!("Example 4: Sticky notification (stays on screen)");
63 let sticky = NotifyOptions::new().with_sticky(true);
64
65 client.notify_with_options(
66 "message",
67 "Sticky Notification",
68 "This notification will stay on screen until dismissed",
69 sticky,
70 )?;
71 println!("✓ Sent (sticky: true)\n");
72 thread::sleep(Duration::from_secs(2));
73
74 // Example 5: High priority + sticky
75 println!("Example 5: High priority AND sticky");
76 let critical = NotifyOptions::new().with_priority(2).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
examples/android.rs (line 98)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 println!("=== Growl for Android Example ===\n");
17
18 // Get Android device IP from environment
19 let android_host = env::var("ANDROID_HOST").unwrap_or_else(|_| {
20 println!("⚠ ANDROID_HOST not set, using default");
21 println!(" Set with: set ANDROID_HOST=192.168.1.100\n");
22 "192.168.1.100".to_string()
23 });
24
25 println!("Target Android device: {}", android_host);
26
27 // Create client optimized for Android
28 let mut client = GntpClient::new("Android Example")
29 .with_host(&android_host)
30 .with_port(23053)
31 .with_icon_mode(IconMode::DataUrl) // Best for Android
32 .with_debug(false);
33
34 // Try to load icon (optional)
35 let icon = match Resource::from_file("icon.png") {
36 Ok(icon) => {
37 println!("✓ Icon loaded: icon.png");
38 Some(icon)
39 }
40 Err(_) => {
41 println!("ℹ No icon found (optional)");
42 None
43 }
44 };
45
46 // Define notification type with icon
47 let mut notification =
48 NotificationType::new("android").with_display_name("Android Notification");
49
50 if let Some(icon) = icon {
51 notification = notification.with_icon(icon);
52 println!("✓ Icon attached to notification");
53 }
54
55 println!();
56
57 // Register with retry (Android may need retry due to network)
58 println!("Registering with Growl for Android...");
59 let mut register_ok = false;
60
61 for attempt in 1..=3 {
62 match client.register(vec![notification.clone()]) {
63 Ok(_) => {
64 println!(
65 "✓ Registered successfully{}\n",
66 if attempt > 1 {
67 format!(" (attempt {})", attempt)
68 } else {
69 String::new()
70 }
71 );
72 register_ok = true;
73 break;
74 }
75 Err(e) => {
76 if attempt < 3 {
77 println!("⚠ Attempt {} failed, retrying... ({})", attempt, e);
78 std::thread::sleep(std::time::Duration::from_secs(2));
79 } else {
80 eprintln!("❌ Registration failed after 3 attempts: {}", e);
81 eprintln!("\nTroubleshooting:");
82 eprintln!(" 1. Is Growl for Android running?");
83 eprintln!(" 2. Is {} the correct IP address?", android_host);
84 eprintln!(" 3. Are both devices on the same network?");
85 eprintln!(" 4. Check Android firewall settings");
86 return Err(e.into());
87 }
88 }
89 }
90 }
91
92 if !register_ok {
93 return Err("Registration failed".into());
94 }
95
96 // Send notification with options
97 println!("Sending notification...");
98 let options = NotifyOptions::new()
99 .with_sticky(false) // Don't make it sticky on mobile
100 .with_priority(1); // High priority
101
102 match client.notify_with_options(
103 "android",
104 "Hello Android!",
105 "This notification was sent from Rust",
106 options,
107 ) {
108 Ok(_) => {
109 println!("✓ Notification sent\n");
110 println!("✅ Check your Android device for the notification!");
111 }
112 Err(e) => {
113 eprintln!("❌ Failed to send: {}", e);
114 return Err(e.into());
115 }
116 }
117
118 Ok(())
119}Sourcepub fn with_sticky(self, sticky: bool) -> Self
pub fn with_sticky(self, sticky: bool) -> Self
Set sticky mode (notification stays until dismissed)
Examples found in repository?
examples/with_options.rs (line 63)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 println!("=== Notification Options Example ===\n");
17
18 // Create GNTP client
19 let mut client = GntpClient::new("Options Example");
20
21 // Define notification type
22 let notification = NotificationType::new("message").with_display_name("Message");
23
24 // Register
25 println!("Registering...");
26 client.register(vec![notification])?;
27 println!("✓ Registered\n");
28
29 // Example 1: Normal priority notification
30 println!("Example 1: Normal notification (default priority)");
31 client.notify("message", "Normal", "This is a normal notification")?;
32 println!("✓ Sent (priority: 0)\n");
33 thread::sleep(Duration::from_secs(2));
34
35 // Example 2: High priority notification
36 println!("Example 2: High priority notification");
37 let high_priority = NotifyOptions::new().with_priority(2); // Highest priority: 2
38
39 client.notify_with_options(
40 "message",
41 "High Priority",
42 "This is a high priority notification!",
43 high_priority,
44 )?;
45 println!("✓ Sent (priority: 2)\n");
46 thread::sleep(Duration::from_secs(2));
47
48 // Example 3: Low priority notification
49 println!("Example 3: Low priority notification");
50 let low_priority = NotifyOptions::new().with_priority(-2); // Lowest priority: -2
51
52 client.notify_with_options(
53 "message",
54 "Low Priority",
55 "This is a low priority notification",
56 low_priority,
57 )?;
58 println!("✓ Sent (priority: -2)\n");
59 thread::sleep(Duration::from_secs(2));
60
61 // Example 4: Sticky notification (stays on screen)
62 println!("Example 4: Sticky notification (stays on screen)");
63 let sticky = NotifyOptions::new().with_sticky(true);
64
65 client.notify_with_options(
66 "message",
67 "Sticky Notification",
68 "This notification will stay on screen until dismissed",
69 sticky,
70 )?;
71 println!("✓ Sent (sticky: true)\n");
72 thread::sleep(Duration::from_secs(2));
73
74 // Example 5: High priority + sticky
75 println!("Example 5: High priority AND sticky");
76 let critical = NotifyOptions::new().with_priority(2).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
examples/android.rs (line 99)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 println!("=== Growl for Android Example ===\n");
17
18 // Get Android device IP from environment
19 let android_host = env::var("ANDROID_HOST").unwrap_or_else(|_| {
20 println!("⚠ ANDROID_HOST not set, using default");
21 println!(" Set with: set ANDROID_HOST=192.168.1.100\n");
22 "192.168.1.100".to_string()
23 });
24
25 println!("Target Android device: {}", android_host);
26
27 // Create client optimized for Android
28 let mut client = GntpClient::new("Android Example")
29 .with_host(&android_host)
30 .with_port(23053)
31 .with_icon_mode(IconMode::DataUrl) // Best for Android
32 .with_debug(false);
33
34 // Try to load icon (optional)
35 let icon = match Resource::from_file("icon.png") {
36 Ok(icon) => {
37 println!("✓ Icon loaded: icon.png");
38 Some(icon)
39 }
40 Err(_) => {
41 println!("ℹ No icon found (optional)");
42 None
43 }
44 };
45
46 // Define notification type with icon
47 let mut notification =
48 NotificationType::new("android").with_display_name("Android Notification");
49
50 if let Some(icon) = icon {
51 notification = notification.with_icon(icon);
52 println!("✓ Icon attached to notification");
53 }
54
55 println!();
56
57 // Register with retry (Android may need retry due to network)
58 println!("Registering with Growl for Android...");
59 let mut register_ok = false;
60
61 for attempt in 1..=3 {
62 match client.register(vec![notification.clone()]) {
63 Ok(_) => {
64 println!(
65 "✓ Registered successfully{}\n",
66 if attempt > 1 {
67 format!(" (attempt {})", attempt)
68 } else {
69 String::new()
70 }
71 );
72 register_ok = true;
73 break;
74 }
75 Err(e) => {
76 if attempt < 3 {
77 println!("⚠ Attempt {} failed, retrying... ({})", attempt, e);
78 std::thread::sleep(std::time::Duration::from_secs(2));
79 } else {
80 eprintln!("❌ Registration failed after 3 attempts: {}", e);
81 eprintln!("\nTroubleshooting:");
82 eprintln!(" 1. Is Growl for Android running?");
83 eprintln!(" 2. Is {} the correct IP address?", android_host);
84 eprintln!(" 3. Are both devices on the same network?");
85 eprintln!(" 4. Check Android firewall settings");
86 return Err(e.into());
87 }
88 }
89 }
90 }
91
92 if !register_ok {
93 return Err("Registration failed".into());
94 }
95
96 // Send notification with options
97 println!("Sending notification...");
98 let options = NotifyOptions::new()
99 .with_sticky(false) // Don't make it sticky on mobile
100 .with_priority(1); // High priority
101
102 match client.notify_with_options(
103 "android",
104 "Hello Android!",
105 "This notification was sent from Rust",
106 options,
107 ) {
108 Ok(_) => {
109 println!("✓ Notification sent\n");
110 println!("✅ Check your Android device for the notification!");
111 }
112 Err(e) => {
113 eprintln!("❌ Failed to send: {}", e);
114 return Err(e.into());
115 }
116 }
117
118 Ok(())
119}Sourcepub fn with_priority(self, priority: i8) -> Self
pub fn with_priority(self, priority: i8) -> Self
Set priority (-2 to 2)
-2= Very Low-1= Moderate0= Normal (default)1= High2= Emergency
Examples found in repository?
examples/with_options.rs (line 37)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 println!("=== Notification Options Example ===\n");
17
18 // Create GNTP client
19 let mut client = GntpClient::new("Options Example");
20
21 // Define notification type
22 let notification = NotificationType::new("message").with_display_name("Message");
23
24 // Register
25 println!("Registering...");
26 client.register(vec![notification])?;
27 println!("✓ Registered\n");
28
29 // Example 1: Normal priority notification
30 println!("Example 1: Normal notification (default priority)");
31 client.notify("message", "Normal", "This is a normal notification")?;
32 println!("✓ Sent (priority: 0)\n");
33 thread::sleep(Duration::from_secs(2));
34
35 // Example 2: High priority notification
36 println!("Example 2: High priority notification");
37 let high_priority = NotifyOptions::new().with_priority(2); // Highest priority: 2
38
39 client.notify_with_options(
40 "message",
41 "High Priority",
42 "This is a high priority notification!",
43 high_priority,
44 )?;
45 println!("✓ Sent (priority: 2)\n");
46 thread::sleep(Duration::from_secs(2));
47
48 // Example 3: Low priority notification
49 println!("Example 3: Low priority notification");
50 let low_priority = NotifyOptions::new().with_priority(-2); // Lowest priority: -2
51
52 client.notify_with_options(
53 "message",
54 "Low Priority",
55 "This is a low priority notification",
56 low_priority,
57 )?;
58 println!("✓ Sent (priority: -2)\n");
59 thread::sleep(Duration::from_secs(2));
60
61 // Example 4: Sticky notification (stays on screen)
62 println!("Example 4: Sticky notification (stays on screen)");
63 let sticky = NotifyOptions::new().with_sticky(true);
64
65 client.notify_with_options(
66 "message",
67 "Sticky Notification",
68 "This notification will stay on screen until dismissed",
69 sticky,
70 )?;
71 println!("✓ Sent (sticky: true)\n");
72 thread::sleep(Duration::from_secs(2));
73
74 // Example 5: High priority + sticky
75 println!("Example 5: High priority AND sticky");
76 let critical = NotifyOptions::new().with_priority(2).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
examples/android.rs (line 100)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 println!("=== Growl for Android Example ===\n");
17
18 // Get Android device IP from environment
19 let android_host = env::var("ANDROID_HOST").unwrap_or_else(|_| {
20 println!("⚠ ANDROID_HOST not set, using default");
21 println!(" Set with: set ANDROID_HOST=192.168.1.100\n");
22 "192.168.1.100".to_string()
23 });
24
25 println!("Target Android device: {}", android_host);
26
27 // Create client optimized for Android
28 let mut client = GntpClient::new("Android Example")
29 .with_host(&android_host)
30 .with_port(23053)
31 .with_icon_mode(IconMode::DataUrl) // Best for Android
32 .with_debug(false);
33
34 // Try to load icon (optional)
35 let icon = match Resource::from_file("icon.png") {
36 Ok(icon) => {
37 println!("✓ Icon loaded: icon.png");
38 Some(icon)
39 }
40 Err(_) => {
41 println!("ℹ No icon found (optional)");
42 None
43 }
44 };
45
46 // Define notification type with icon
47 let mut notification =
48 NotificationType::new("android").with_display_name("Android Notification");
49
50 if let Some(icon) = icon {
51 notification = notification.with_icon(icon);
52 println!("✓ Icon attached to notification");
53 }
54
55 println!();
56
57 // Register with retry (Android may need retry due to network)
58 println!("Registering with Growl for Android...");
59 let mut register_ok = false;
60
61 for attempt in 1..=3 {
62 match client.register(vec![notification.clone()]) {
63 Ok(_) => {
64 println!(
65 "✓ Registered successfully{}\n",
66 if attempt > 1 {
67 format!(" (attempt {})", attempt)
68 } else {
69 String::new()
70 }
71 );
72 register_ok = true;
73 break;
74 }
75 Err(e) => {
76 if attempt < 3 {
77 println!("⚠ Attempt {} failed, retrying... ({})", attempt, e);
78 std::thread::sleep(std::time::Duration::from_secs(2));
79 } else {
80 eprintln!("❌ Registration failed after 3 attempts: {}", e);
81 eprintln!("\nTroubleshooting:");
82 eprintln!(" 1. Is Growl for Android running?");
83 eprintln!(" 2. Is {} the correct IP address?", android_host);
84 eprintln!(" 3. Are both devices on the same network?");
85 eprintln!(" 4. Check Android firewall settings");
86 return Err(e.into());
87 }
88 }
89 }
90 }
91
92 if !register_ok {
93 return Err("Registration failed".into());
94 }
95
96 // Send notification with options
97 println!("Sending notification...");
98 let options = NotifyOptions::new()
99 .with_sticky(false) // Don't make it sticky on mobile
100 .with_priority(1); // High priority
101
102 match client.notify_with_options(
103 "android",
104 "Hello Android!",
105 "This notification was sent from Rust",
106 options,
107 ) {
108 Ok(_) => {
109 println!("✓ Notification sent\n");
110 println!("✅ Check your Android device for the notification!");
111 }
112 Err(e) => {
113 eprintln!("❌ Failed to send: {}", e);
114 return Err(e.into());
115 }
116 }
117
118 Ok(())
119}Trait Implementations§
Source§impl Default for NotifyOptions
impl Default for NotifyOptions
Source§fn default() -> NotifyOptions
fn default() -> NotifyOptions
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for NotifyOptions
impl RefUnwindSafe for NotifyOptions
impl Send for NotifyOptions
impl Sync for NotifyOptions
impl Unpin for NotifyOptions
impl UnsafeUnpin for NotifyOptions
impl UnwindSafe for NotifyOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more