pub struct Notification<'a> {
pub app_id: &'a str,
pub title: &'a str,
pub message: &'a str,
pub icon: MessageIcon,
pub timeout: i32,
}Expand description
Notification.
Shows a brief message to the user without blocking their interaction with the application.
Fields§
§app_id: &'a strApplication identifier used by notification backends.
This is a best-effort hint: some backends may ignore it, and some only honor the first value seen by the process/session.
title: &'a strThe title of the notification.
message: &'a strThe message to display in the notification.
icon: MessageIconThe icon to show in the notification.
timeout: i32Timeout in milliseconds after which the notification should automatically close.
A value less than or equal to 0 means that the notification will not automatically close.
This is a best-effort hint: some backends may ignore it and use their own default timeout, or may not support timeouts at all.
Implementations§
Source§impl<'a> Notification<'a>
impl<'a> Notification<'a>
Sourcepub const SHORT_TIMEOUT: i32 = 5000
pub const SHORT_TIMEOUT: i32 = 5000
Short timeout duration in milliseconds for notification popups.
Sourcepub const LONG_TIMEOUT: i32 = 10000
pub const LONG_TIMEOUT: i32 = 10000
Long timeout duration in milliseconds for notification popups.
Sourcepub fn setup(app_id: &str)
pub fn setup(app_id: &str)
Perform any necessary setup for notifications, such as registering the application with the notification system.
This step is optional, when skipped the library will attempt to perform any necessary setup automatically when showing the first notification, but this method can be used to ensure that the setup is done at a specific time in the application lifecycle.
§Linux
When using the libnotify backend, this registers the application with the notification system using the provided application identifier.
§Windows
When using the winrt-toast backend, this creates a Start Menu shortcut for the application with the provided application identifier, which is required for showing toast notifications on Windows.
It is recommended to call this method during application initialization before showing any notifications or the first notification may be skipped due to delays in the shortcut creation process.
Examples found in repository?
3fn main() {
4 rustydialogs::Notification::setup(APP_ID);
5
6 // winrt-toast: Takes almost three seconds to show the first notification due to registration delays.
7 // All Notifications shown before the first one may be ignored...
8
9 let notify = rustydialogs::Notification {
10 app_id: APP_ID,
11 title: "Rusty Dialogs",
12 message: "This is a native notification.",
13 icon: rustydialogs::MessageIcon::Info,
14 timeout: rustydialogs::Notification::SHORT_TIMEOUT,
15 };
16
17 notify.show();
18 println!("Notification shown");
19
20 // winrt-toast: Wait a bit to ensure the notification is visible before the program exits.
21 std::thread::sleep(std::time::Duration::from_millis(100));
22}Sourcepub fn show(&self)
pub fn show(&self)
Show the notification.
Examples found in repository?
3fn main() {
4 rustydialogs::Notification::setup(APP_ID);
5
6 // winrt-toast: Takes almost three seconds to show the first notification due to registration delays.
7 // All Notifications shown before the first one may be ignored...
8
9 let notify = rustydialogs::Notification {
10 app_id: APP_ID,
11 title: "Rusty Dialogs",
12 message: "This is a native notification.",
13 icon: rustydialogs::MessageIcon::Info,
14 timeout: rustydialogs::Notification::SHORT_TIMEOUT,
15 };
16
17 notify.show();
18 println!("Notification shown");
19
20 // winrt-toast: Wait a bit to ensure the notification is visible before the program exits.
21 std::thread::sleep(std::time::Duration::from_millis(100));
22}Trait Implementations§
Source§impl<'a> Clone for Notification<'a>
impl<'a> Clone for Notification<'a>
Source§fn clone(&self) -> Notification<'a>
fn clone(&self) -> Notification<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more