ashpd/desktop/
notification.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
//! # Examples
//!
//! ```rust,no_run
//! use std::{thread, time};
//!
//! use ashpd::desktop::{
//!     notification::{Action, Button, Notification, NotificationProxy, Priority},
//!     Icon,
//! };
//! use futures_util::StreamExt;
//! use zbus::zvariant::Value;
//!
//! async fn run() -> ashpd::Result<()> {
//!     let proxy = NotificationProxy::new().await?;
//!
//!     let notification_id = "org.gnome.design.Contrast";
//!     proxy
//!         .add_notification(
//!             notification_id,
//!             Notification::new("Contrast")
//!                 .default_action("open")
//!                 .default_action_target(100)
//!                 .body("color copied to clipboard")
//!                 .priority(Priority::High)
//!                 .icon(Icon::with_names(&["dialog-question-symbolic"]))
//!                 .button(Button::new("Copy", "copy").target(32))
//!                 .button(Button::new("Delete", "delete").target(40)),
//!         )
//!         .await?;
//!
//!     let action = proxy
//!         .receive_action_invoked()
//!         .await?
//!         .next()
//!         .await
//!         .expect("Stream exhausted");
//!     match action.name() {
//!         "copy" => (),   // Copy something to clipboard
//!         "delete" => (), // Delete the file
//!         _ => (),
//!     };
//!     println!("{:#?}", action.id());
//!     println!(
//!         "{:#?}",
//!         action.parameter().get(0).unwrap().downcast_ref::<u32>()
//!     );
//!
//!     proxy.remove_notification(notification_id).await?;
//!     Ok(())
//! }
//! ```

use std::{fmt, os::fd::AsFd, str::FromStr};

use futures_util::Stream;
use serde::{self, Deserialize, Serialize};
use zbus::zvariant::{DeserializeDict, OwnedValue, SerializeDict, Type, Value};

use super::Icon;
use crate::{proxy::Proxy, Error};

#[derive(Debug, Clone, PartialEq, Eq, Type)]
#[zvariant(signature = "s")]
/// The content of a notification.
pub enum Category {
    /// Instant messaging apps message.
    #[doc(alias = "im.message")]
    ImMessage,
    /// Ringing alarm.
    #[doc(alias = "alarm.ringing")]
    AlarmRinging,
    /// Incoming call.
    #[doc(alias = "call.incoming")]
    IncomingCall,
    /// Ongoing call.
    #[doc(alias = "call.ongoing")]
    OngoingCall,
    /// Missed call.
    #[doc(alias = "call.missed")]
    MissedCall,
    /// Extreme weather warning.
    #[doc(alias = "weather.warning.extreme")]
    ExtremeWeather,
    /// Extreme danger broadcast.
    #[doc(alias = "cellbroadcast.danger.extreme")]
    CellNetworkExtremeDanger,
    /// Severe danger broadcast.
    #[doc(alias = "cellbroadcast.danger.severe")]
    CellNetworkSevereDanger,
    /// Amber alert broadcast.
    #[doc(alias = "cellbroadcast.amber-alert")]
    CellNetworkAmberAlert,
    /// Test broadcast.
    #[doc(alias = "cellbroadcast.test")]
    CellNetworkBroadcastTest,
    /// Low battery.
    #[doc(alias = "os.battery.low")]
    LowBattery,
    /// Browser websites notifications.
    #[doc(alias = "browser.web-notification")]
    WebNotification,
    /// Vendor specific.
    Other(String),
}

impl Serialize for Category {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        let category_str = match self {
            Self::ImMessage => "im.message",
            Self::AlarmRinging => "alarm.ringing",
            Self::IncomingCall => "call.incoming",
            Self::OngoingCall => "call.ongoing",
            Self::MissedCall => "call.missed",
            Self::ExtremeWeather => "weather.warning.extreme",
            Self::CellNetworkExtremeDanger => "cellbroadcast.danger.extreme",
            Self::CellNetworkSevereDanger => "cellbroadcast.danger.severe",
            Self::CellNetworkAmberAlert => "cellbroadcast.amber-alert",
            Self::CellNetworkBroadcastTest => "cellbroadcast.test",
            Self::LowBattery => "os.battery.low",
            Self::WebNotification => "browser.web-notification",
            Self::Other(other) => other.as_str(),
        };
        serializer.serialize_str(category_str)
    }
}

impl FromStr for Category {
    type Err = crate::Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "im.message" => Ok(Self::ImMessage),
            "alarm.ringing" => Ok(Self::AlarmRinging),
            "call.incoming" => Ok(Self::IncomingCall),
            "call.ongoing" => Ok(Self::OngoingCall),
            "call.missed" => Ok(Self::MissedCall),
            "weather.warning.extreme" => Ok(Self::ExtremeWeather),
            "cellbroadcast.danger.extreme" => Ok(Self::CellNetworkExtremeDanger),
            "cellbroadcast.danger.severe" => Ok(Self::CellNetworkSevereDanger),
            "cellbroadcast.amber-alert" => Ok(Self::CellNetworkAmberAlert),
            "cellbroadcast.test" => Ok(Self::CellNetworkBroadcastTest),
            "os.battery.low" => Ok(Self::LowBattery),
            "browser.web-notification" => Ok(Self::WebNotification),
            _ => Ok(Self::Other(s.to_owned())),
        }
    }
}

impl<'de> Deserialize<'de> for Category {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let category = String::deserialize(deserializer)?;
        category
            .parse::<Self>()
            .map_err(|_e| serde::de::Error::custom("Failed to parse category"))
    }
}

#[cfg_attr(feature = "glib", derive(glib::Enum))]
#[cfg_attr(feature = "glib", enum_type(name = "AshpdPriority"))]
#[derive(Debug, Copy, Clone, Serialize, PartialEq, Eq, Type)]
#[zvariant(signature = "s")]
#[serde(rename_all = "lowercase")]
/// The notification priority
pub enum Priority {
    /// Low.
    Low,
    /// Normal.
    Normal,
    /// High.
    High,
    /// Urgent.
    Urgent,
}

impl fmt::Display for Priority {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Low => write!(f, "Low"),
            Self::Normal => write!(f, "Normal"),
            Self::High => write!(f, "High"),
            Self::Urgent => write!(f, "Urgent"),
        }
    }
}

impl AsRef<str> for Priority {
    fn as_ref(&self) -> &str {
        match self {
            Self::Low => "Low",
            Self::Normal => "Normal",
            Self::High => "High",
            Self::Urgent => "Urgent",
        }
    }
}

impl From<Priority> for &'static str {
    fn from(d: Priority) -> Self {
        match d {
            Priority::Low => "Low",
            Priority::Normal => "Normal",
            Priority::High => "High",
            Priority::Urgent => "Urgent",
        }
    }
}

impl FromStr for Priority {
    type Err = Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "Low" | "low" => Ok(Priority::Low),
            "Normal" | "normal" => Ok(Priority::Normal),
            "High" | "high" => Ok(Priority::High),
            "Urgent" | "urgent" => Ok(Priority::Urgent),
            _ => Err(Error::ParseError("Failed to parse priority, invalid value")),
        }
    }
}

#[cfg_attr(feature = "glib", derive(glib::Enum))]
#[cfg_attr(feature = "glib", enum_type(name = "AshpdNotificationDisplayHint"))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Type)]
#[zvariant(signature = "s")]
/// Ways to display a notification.
pub enum DisplayHint {
    /// Transient.
    #[doc(alias = "transient")]
    Transient,
    /// Tray.
    #[doc(alias = "tray")]
    Tray,
    /// Persistent.
    #[doc(alias = "persistent")]
    Persistent,
    /// Hide on lockscreen.
    #[doc(alias = "hide-on-lockscreen")]
    HideOnLockScreen,
    /// Enable speakerphone.
    #[doc(alias = "hide-content-on-lockscreen")]
    HideContentOnLockScreen,
    /// Show as new.
    #[doc(alias = "show-as-new")]
    ShowAsNew,
}

impl Serialize for DisplayHint {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        let purpose = match self {
            Self::Transient => "transient",
            Self::Tray => "tray",
            Self::Persistent => "persistent",
            Self::HideOnLockScreen => "hide-on-lockscreen",
            Self::HideContentOnLockScreen => "hide-content-on-lockscreen",
            Self::ShowAsNew => "show-as-new",
        };
        serializer.serialize_str(purpose)
    }
}

#[derive(SerializeDict, Type, Debug)]
/// A notification
#[zvariant(signature = "dict")]
pub struct Notification {
    /// User-visible string to display as the title.
    title: String,
    /// User-visible string to display as the body.
    body: Option<String>,
    #[zvariant(rename = "markup-body")]
    markup_body: Option<String>,
    /// Serialized icon (e.g using gio::Icon::serialize).
    icon: Option<Icon>,
    /// The priority for the notification.
    priority: Option<Priority>,
    /// Name of an action that is exported by the application.
    /// This action will be activated when the user clicks on the notification.
    #[zvariant(rename = "default-action")]
    default_action: Option<String>,
    /// Target parameter to send along when activating the default action.
    #[zvariant(rename = "default-action-target")]
    default_action_target: Option<OwnedValue>,
    /// Array of buttons to add to the notification.
    buttons: Option<Vec<Button>>,
    category: Option<Category>,
    #[zvariant(rename = "display-hint")]
    display_hints: Option<Vec<DisplayHint>>,
    sound: Option<OwnedValue>,
}

impl Notification {
    /// Create a new notification.
    ///
    /// # Arguments
    ///
    /// * `title` - the notification title.
    pub fn new(title: &str) -> Self {
        Self {
            title: title.to_owned(),
            body: None,
            markup_body: None,
            priority: None,
            icon: None,
            default_action: None,
            default_action_target: None,
            buttons: None,
            category: None,
            display_hints: None,
            sound: None,
        }
    }

    /// Sets the notification body.
    #[must_use]
    pub fn body<'a>(mut self, body: impl Into<Option<&'a str>>) -> Self {
        self.body = body.into().map(ToOwned::to_owned);
        self
    }

    /// Same as [`Notification::body`] but supports markup formatting.
    #[must_use]
    pub fn markup_body<'a>(mut self, markup_body: impl Into<Option<&'a str>>) -> Self {
        self.markup_body = markup_body.into().map(ToOwned::to_owned);
        self
    }

    /// Sets an icon to the notification.
    #[must_use]
    pub fn icon(mut self, icon: impl Into<Option<Icon>>) -> Self {
        self.icon = icon.into();
        self
    }

    /// Sets the notification sound.
    #[must_use]
    pub fn sound<S>(mut self, sound: impl Into<Option<S>>) -> Self
    where
        S: AsFd,
    {
        self.sound = sound.into().map(|s| {
            zbus::zvariant::Value::from(zbus::zvariant::Fd::from(s.as_fd()))
                .try_to_owned()
                .unwrap()
        });
        self
    }

    /// Sets the notification category.
    #[must_use]
    pub fn category(mut self, category: impl Into<Option<Category>>) -> Self {
        self.category = category.into();
        self
    }

    #[must_use]
    /// Sets the notification display hints.
    pub fn display_hint(mut self, hints: impl IntoIterator<Item = DisplayHint>) -> Self {
        self.display_hints = Some(hints.into_iter().collect());
        self
    }

    /// Sets the notification priority.
    #[must_use]
    pub fn priority(mut self, priority: impl Into<Option<Priority>>) -> Self {
        self.priority = priority.into();
        self
    }

    /// Sets the default action when the user clicks on the notification.
    #[must_use]
    pub fn default_action<'a>(mut self, default_action: impl Into<Option<&'a str>>) -> Self {
        self.default_action = default_action.into().map(ToOwned::to_owned);
        self
    }

    /// Sets a value to be sent in the `action_invoked` signal.
    #[must_use]
    pub fn default_action_target<'a, T: Into<Value<'a>>>(
        mut self,
        default_action_target: impl Into<Option<T>>,
    ) -> Self {
        self.default_action_target = default_action_target
            .into()
            .map(|t| t.into().try_to_owned().unwrap());
        self
    }

    /// Adds a new button to the notification.
    #[must_use]
    pub fn button(mut self, button: Button) -> Self {
        match self.buttons {
            Some(ref mut buttons) => buttons.push(button),
            None => {
                self.buttons.replace(vec![button]);
            }
        };
        self
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Type)]
#[zvariant(signature = "s")]
/// The purpose of a button.
pub enum ButtonPurpose {
    /// Instant messaging reply with text.
    #[doc(alias = "im.reply-with-text")]
    ImReplyWithText,
    /// Accept call.
    #[doc(alias = "call.accept")]
    CallAccept,
    /// Decline call.
    #[doc(alias = "call.decline")]
    CallDecline,
    /// Hangup call.
    #[doc(alias = "call.hang-up")]
    CallHangup,
    /// Enable speakerphone.
    #[doc(alias = "call.enable-speakerphone")]
    CallEnableSpeakerphone,
    /// Disable speakerphone.
    #[doc(alias = "call.disable-speakerphone")]
    CallDisableSpeakerphone,
    /// System custom alert.
    #[doc(alias = "system.custom-alert")]
    SystemCustomAlert,
    /// Vendor specific.
    Other(String),
}

impl Serialize for ButtonPurpose {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        let purpose = match self {
            Self::ImReplyWithText => "im.reply-with-text",
            Self::CallAccept => "call.accept",
            Self::CallDecline => "call.decline",
            Self::CallHangup => "call.hang-up",
            Self::CallEnableSpeakerphone => "call.enable-speakerphone",
            Self::CallDisableSpeakerphone => "call.disable-speakerphone",
            Self::SystemCustomAlert => "system.custom-alert",
            Self::Other(other) => other.as_str(),
        };
        serializer.serialize_str(purpose)
    }
}

impl FromStr for ButtonPurpose {
    type Err = crate::Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "im.reply-with-text" => Ok(Self::ImReplyWithText),
            "call.accept" => Ok(Self::CallAccept),
            "call.decline" => Ok(Self::CallDecline),
            "call.hang-up" => Ok(Self::CallHangup),
            "call.enable-speakerphone" => Ok(Self::CallEnableSpeakerphone),
            "call.disable-speakerphone" => Ok(Self::CallDisableSpeakerphone),
            "system.custom-alert" => Ok(Self::SystemCustomAlert),
            _ => Ok(Self::Other(s.to_owned())),
        }
    }
}

impl<'de> Deserialize<'de> for ButtonPurpose {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let purpose = String::deserialize(deserializer)?;
        purpose
            .parse::<Self>()
            .map_err(|_e| serde::de::Error::custom("Failed to parse purpose"))
    }
}

#[derive(SerializeDict, Type, Debug)]
/// A notification button
#[zvariant(signature = "dict")]
pub struct Button {
    /// User-visible label for the button. Mandatory.
    label: String,
    /// Name of an action that is exported by the application. The action will
    /// be activated when the user clicks on the button.
    action: String,
    /// Target parameter to send along when activating the action.
    target: Option<OwnedValue>,
    purpose: Option<ButtonPurpose>,
}

impl Button {
    /// Create a new notification button.
    ///
    /// # Arguments
    ///
    /// * `label` - the user visible label of the button.
    /// * `action` - the action name to be invoked when the user clicks on the
    ///   button.
    pub fn new(label: &str, action: &str) -> Self {
        Self {
            label: label.to_owned(),
            action: action.to_owned(),
            target: None,
            purpose: None,
        }
    }

    /// The value to send with the action name when the button is clicked.
    #[must_use]
    pub fn target<'a, T: Into<Value<'a>>>(mut self, target: impl Into<Option<T>>) -> Self {
        self.target = target.into().map(|t| t.into().try_to_owned().unwrap());
        self
    }

    /// Sets the button purpose.
    #[must_use]
    pub fn purpose(mut self, purpose: impl Into<Option<ButtonPurpose>>) -> Self {
        self.purpose = purpose.into();
        self
    }
}

#[derive(Debug, Deserialize, Type)]
/// An invoked action.
pub struct Action(String, String, Vec<OwnedValue>);

impl Action {
    /// Notification ID.
    pub fn id(&self) -> &str {
        &self.0
    }

    /// Action name.
    pub fn name(&self) -> &str {
        &self.1
    }

    /// The parameters passed to the action.
    pub fn parameter(&self) -> &Vec<OwnedValue> {
        &self.2
    }
}

#[derive(DeserializeDict, Type, Debug, OwnedValue)]
#[zvariant(signature = "dict")]
// TODO: figure out why this can't use the enums
struct SupportedOptions {
    category: Vec<String>,
    #[zvariant(rename = "button-purpose")]
    button_purpose: Vec<String>,
}

/// The interface lets sandboxed applications send and withdraw notifications.
///
/// It is not possible for the application to learn if the notification was
/// actually presented to the user. Not a portal in the strict sense, since
/// there is no user interaction.
///
/// **Note** in contrast to most other portal requests, notifications are
/// expected to outlast the running application. If a user clicks on a
/// notification after the application has exited, it will get activated again.
///
/// Notifications can specify actions that can be activated by the user.
/// Actions whose name starts with 'app.' are assumed to be exported and will be
/// activated via the ActivateAction() method in the org.freedesktop.Application
/// interface. Other actions are activated by sending the
///  `#org.freedeskop.portal.Notification::ActionInvoked` signal to the
/// application.
///
/// Wrapper of the DBus interface: [`org.freedesktop.portal.Notification`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Notification.html).
#[derive(Debug)]
#[doc(alias = "org.freedesktop.portal.Notification")]
pub struct NotificationProxy<'a>(Proxy<'a>);

impl<'a> NotificationProxy<'a> {
    /// Create a new instance of [`NotificationProxy`].
    pub async fn new() -> Result<NotificationProxy<'a>, Error> {
        let proxy = Proxy::new_desktop("org.freedesktop.portal.Notification").await?;
        Ok(Self(proxy))
    }

    /// Signal emitted when a particular action is invoked.
    ///
    /// # Specifications
    ///
    /// See also [`ActionInvoked`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Notification.html#org-freedesktop-portal-notification-actioninvoked).
    #[doc(alias = "ActionInvoked")]
    #[doc(alias = "XdpPortal::notification-action-invoked")]
    pub async fn receive_action_invoked(&self) -> Result<impl Stream<Item = Action>, Error> {
        self.0.signal("ActionInvoked").await
    }

    /// Sends a notification.
    ///
    /// The ID can be used to later withdraw the notification.
    /// If the application reuses the same ID without withdrawing, the
    /// notification is replaced by the new one.
    ///
    /// # Arguments
    ///
    /// * `id` - Application-provided ID for this notification.
    /// * `notification` - The notification.
    ///
    /// # Specifications
    ///
    /// See also [`AddNotification`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Notification.html#org-freedesktop-portal-notification-addnotification).
    #[doc(alias = "AddNotification")]
    #[doc(alias = "xdp_portal_add_notification")]
    pub async fn add_notification(
        &self,
        id: &str,
        notification: Notification,
    ) -> Result<(), Error> {
        self.0.call("AddNotification", &(id, notification)).await
    }

    /// Withdraws a notification.
    ///
    /// # Arguments
    ///
    /// * `id` - Application-provided ID for this notification.
    ///
    /// # Specifications
    ///
    /// See also [`RemoveNotification`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Notification.html#org-freedesktop-portal-notification-removenotification).
    #[doc(alias = "RemoveNotification")]
    #[doc(alias = "xdp_portal_remove_notification")]
    pub async fn remove_notification(&self, id: &str) -> Result<(), Error> {
        self.0.call("RemoveNotification", &(id)).await
    }

    /// Supported options by the notifications server.
    ///
    /// # Required version
    ///
    /// The method requires the 2nd version implementation of the portal and
    /// would fail with [`Error::RequiresVersion`] otherwise.
    ///
    /// # Specifications
    ///
    /// See also [`SupportedOptions`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Notification.html#org-freedesktop-portal-notification-supportedoptions).
    pub async fn supported_options(&self) -> Result<(Vec<Category>, Vec<ButtonPurpose>), Error> {
        let options = self
            .0
            .property_versioned::<SupportedOptions>("SupportedOptions", 2)
            .await?;
        let categories = options
            .category
            .into_iter()
            .map(|c| Category::from_str(&c).unwrap())
            .collect();
        let purposes = options
            .button_purpose
            .into_iter()
            .map(|c| ButtonPurpose::from_str(&c).unwrap())
            .collect();
        Ok((categories, purposes))
    }
}

impl<'a> std::ops::Deref for NotificationProxy<'a> {
    type Target = zbus::Proxy<'a>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}