pub struct Notification { /* private fields */ }Expand description
One notification, built and then posted.
Notification::new("Session finished")
.body("refactor-parser: 214 tests passed")
.key(format!("session/{id}"))
.channel("Sessions")
.presentation(NotificationPresentation::WhenInactive)
.post();Nothing here names the application or its icon. The platform puts those on from the application’s own bundle, which is where the window’s icon comes from as well.
Implementations§
Source§impl Notification
impl Notification
pub fn new(title: impl Into<String>) -> Self
Sourcepub fn key(self, key: impl Into<String>) -> Self
pub fn key(self, key: impl Into<String>) -> Self
The application’s own name for this notification.
Posting again under the same key replaces the one already showing, so a session
whose state keeps changing has one notification that is kept current rather than a
pile of them. The key is also what comes back when the user presses it, and what
withdraw_notification takes.
Without one the Renderer names it, and a notification named that way can be neither replaced nor withdrawn.
Sourcepub fn channel(self, channel: impl Into<String>) -> Self
pub fn channel(self, channel: impl Into<String>) -> Self
The group the user can turn off on its own, in the application’s own words.
Android lists these in its settings, so the name is something a person reads. Empty is the application’s default group. A platform without groups ignores it.
Sourcepub fn action_1(self, label: impl Into<String>) -> Self
pub fn action_1(self, label: impl Into<String>) -> Self
The first button. Pressing it reports action 1, and does not bring the window up: a button on a notification exists to be dealt with without opening anything.
Sourcepub fn action_2(self, label: impl Into<String>) -> Self
pub fn action_2(self, label: impl Into<String>) -> Self
The second button, which reports action 2. Two is the most every platform shows the same way.
Sourcepub fn importance(self, importance: NotificationImportance) -> Self
pub fn importance(self, importance: NotificationImportance) -> Self
How much this matters. What that is worth in sound or in getting through Do Not Disturb is the platform’s answer.
Sourcepub fn presentation(self, presentation: NotificationPresentation) -> Self
pub fn presentation(self, presentation: NotificationPresentation) -> Self
Whether it is shown while the application’s window is the active one.
Sourcepub fn post(self)
pub fn post(self)
Hands the notification over.
From a component or an event handler it goes out with the batch that call produces.
From any other thread it waits in the Host and the Host asks for a frame, which is
what NotificationSender::post does as well.