mitsuami_core/services/notifications.rs
1//! Notifications: what an app tells the user outside its windows.
2
3/// A message the platform shows outside the app's windows (macOS's
4/// Notification Center, GNOME's and Plasma's notifications, Windows'
5/// toasts), and keeps in its list until the user clears it.
6#[derive(Clone, Debug, PartialEq, Eq)]
7pub struct Notification {
8 /// Names it: a notification with the same id replaces it, and
9 /// [`withdraw_notification`](super::withdraw_notification) takes it
10 /// away. The core gives one to a notification the app didn't name,
11 /// so backends always have one.
12 pub id: Option<String>,
13 pub title: String,
14 pub body: Option<String>,
15}
16
17impl Notification {
18 pub fn new(title: impl Into<String>) -> Notification {
19 Notification { id: None, title: title.into(), body: None }
20 }
21
22 /// The text under the title.
23 pub fn body(mut self, body: impl Into<String>) -> Notification {
24 self.body = Some(body.into());
25 self
26 }
27
28 /// Names it, so a later one with the same id replaces it (a download's
29 /// progress, a count of unread messages) and the app can withdraw it
30 /// or tell which one the user clicked.
31 pub fn id(mut self, id: impl Into<String>) -> Notification {
32 self.id = Some(id.into());
33 self
34 }
35}