rust_macios/user_notifications/
un_notification_action.rs1use objc::{msg_send, sel, sel_impl};
2use rust_macios_objective_c_runtime_proc_macros::interface_impl;
3
4use crate::{
5 foundation::NSString,
6 object,
7 objective_c_runtime::traits::{FromId, PNSObject},
8 utils::to_optional,
9};
10
11use super::UNNotificationActionIcon;
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
14#[repr(u64)]
15pub enum UNNotificationActionOptions {
16 None = 0,
17 AuthenticationRequired = (1 << 0),
18 Destructive = (1 << 1),
19 Foreground = (1 << 2),
20}
21
22object! {
23 unsafe pub struct UNNotificationAction;
24}
25
26#[interface_impl(NSObject)]
27impl UNNotificationAction {
28 #[method]
33 pub fn action_with_identifier_title_options(
34 identifier: NSString,
35 title: NSString,
36 options: &[UNNotificationActionOptions],
37 ) -> Self
38 where
39 Self: Sized + FromId,
40 {
41 let options = options.iter().fold(0, |init, option| init | *option as u64);
42
43 unsafe {
44 Self::from_id(
45 msg_send![Self::m_class(), actionWithIdentifier: identifier title: title options: options],
46 )
47 }
48 }
49
50 #[method]
51 pub fn action_with_identifier_title_options_icon(
52 identifier: NSString,
53 title: NSString,
54 options: &[UNNotificationActionOptions],
55 icon: UNNotificationActionIcon,
56 ) -> Self
57 where
58 Self: Sized + FromId,
59 {
60 let options = options.iter().fold(0, |init, option| init | *option as u64);
61
62 unsafe {
63 Self::from_id(
64 msg_send![Self::m_class(), actionWithIdentifier: identifier title: title options: options icon: icon],
65 )
66 }
67 }
68
69 #[property]
74 pub fn identifier(&self) -> NSString {
75 unsafe { NSString::from_id(msg_send![self.m_self(), identifier]) }
76 }
77
78 #[property]
80 pub fn title(&self) -> NSString {
81 unsafe { NSString::from_id(msg_send![self.m_self(), title]) }
82 }
83
84 #[property]
86 pub fn icon(&self) -> Option<UNNotificationActionIcon> {
87 unsafe { to_optional(msg_send![self.m_self(), icon]) }
88 }
89
90 #[property]
95 pub fn options(&self) -> UNNotificationActionOptions {
96 unsafe { msg_send![self.m_self(), options] }
97 }
98}