-
Notifications
You must be signed in to change notification settings - Fork 0
/
delegate.rs
48 lines (41 loc) · 1.43 KB
/
delegate.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
use objc2::msg_send_id;
use objc2::mutability::InteriorMutable;
use objc2::rc::Id;
use objc2::runtime::{NSObject, NSObjectProtocol};
use objc2::{declare_class, ClassType, DeclaredClass};
use objc2_foundation::{
MainThreadMarker, NSUserNotification, NSUserNotificationCenter,
NSUserNotificationCenterDelegate,
};
#[derive(Debug, Default)]
pub(super) struct State {}
declare_class! {
pub(super) struct RustNotificationDelegate;
unsafe impl ClassType for RustNotificationDelegate {
type Super = NSObject;
type Mutability = InteriorMutable;
const NAME: &'static str = "RustNotificationDelegate";
}
impl DeclaredClass for RustNotificationDelegate {
type Ivars = State;
}
unsafe impl NSObjectProtocol for RustNotificationDelegate {}
unsafe impl NSUserNotificationCenterDelegate for RustNotificationDelegate {
#[method(userNotificationCenter:didActivateNotification:)]
fn user_notification_center_did_activate_notification(
&self,
_center: &NSUserNotificationCenter,
notification: &NSUserNotification,
) {
println!("Notification activated: {:?}", notification);
}
}
}
impl RustNotificationDelegate {
pub fn new() -> Id<Self> {
let this = MainThreadMarker::new().unwrap().alloc().set_ivars(State {
..Default::default()
});
unsafe { msg_send_id![super(this), init] }
}
}