notifications/action.rs
1use crate::private_prelude::*;
2
3#[derive(Serialize, Deserialize)]
4pub(crate) struct Action {
5 pub(crate) notification_id: u32,
6 pub(crate) label: String,
7 pub(crate) action_key: String,
8}
9
10/// A handle which represents a notification action.
11///
12/// Notification actions are typically presented as buttons in UI that allow user to
13/// interact with the application which sent the notification.
14#[derive(Clone)]
15pub struct ActionHandle {
16 pub(crate) inner: Arc<Action>,
17 pub(crate) service: NotificationService,
18}
19
20impl ActionHandle {
21 /// Returns the ID of the notification this action belongs to.
22 pub fn notification_id(&self) -> u32 {
23 self.inner.notification_id
24 }
25
26 /// Returns the localized string which should be displayed to the user.
27 pub fn label(&self) -> String {
28 self.inner.label.clone()
29 }
30
31 /// Returns the identifier of the action.
32 ///
33 /// `"default"` means that the action is default.
34 pub fn action_key(&self) -> String {
35 self.inner.action_key.clone()
36 }
37
38 /// Invoke the action.
39 ///
40 /// It is a shortcut to [`NotificationService::invoke_action`].
41 ///
42 /// # Errors
43 /// Returns [`Error::DBusError`]
44 pub async fn invoke(&self) -> Result<()> {
45 self.service
46 .invoke_action(self.inner.notification_id, &self.inner.action_key)
47 .await?;
48
49 Ok(())
50 }
51}