notifications/
notification.rs1use crate::private_prelude::*;
2
3#[derive(Serialize, Deserialize)]
4pub(crate) struct Notification {
5 pub(crate) id: u32,
6 pub(crate) app_name: String,
7 pub(crate) icon: Option<String>,
8 pub(crate) summary: String,
9 pub(crate) body: String,
10 pub(crate) actions: Vec<Arc<Action>>,
11 pub(crate) urgency: Urgency,
12 pub(crate) timeout: i32,
13}
14
15#[derive(Clone)]
17pub struct NotificationHandle {
18 pub(crate) inner: Arc<Notification>,
19 pub(crate) service: NotificationService,
20}
21
22impl NotificationHandle {
23 pub fn id(&self) -> u32 {
25 self.inner.id
26 }
27
28 pub fn app_name(&self) -> String {
30 self.inner.app_name.clone()
31 }
32
33 pub fn icon(&self) -> Option<String> {
38 self.inner.icon.clone()
39 }
40
41 pub fn summary(&self) -> String {
43 self.inner.summary.clone()
44 }
45
46 pub fn body(&self) -> String {
48 self.inner.body.clone()
49 }
50
51 pub fn actions(&self) -> Vec<ActionHandle> {
53 self.inner
54 .actions
55 .iter()
56 .map(|a| ActionHandle {
57 inner: a.clone(),
58 service: self.service.clone(),
59 })
60 .collect()
61 }
62
63 pub fn urgency(&self) -> Urgency {
65 self.inner.urgency
66 }
67
68 pub fn timeout(&self) -> i32 {
70 self.inner.timeout
71 }
72
73 pub async fn dismiss(&self) -> Result<()> {
79 self.service.dismiss_notification(self.id()).await?;
80 Ok(())
81 }
82
83 pub fn on_closed<F>(&self, callback: F) -> usize
88 where
89 F: Fn(&CloseReason) + Send + Sync + 'static,
90 {
91 let this_id = self.id();
92 self.service
93 .inner
94 .on_notification_closed
95 .connect(move |(id, reason)| {
96 if *id == this_id {
97 callback(reason)
98 }
99 })
100 }
101}