Skip to content

Commit 81f4c39

Browse files
committed
cleanup ns-workspace-notifications example
1 parent d5a4275 commit 81f4c39

File tree

1 file changed

+6
-20
lines changed
  • cidre/examples/ns-workspace-notifications

1 file changed

+6
-20
lines changed

cidre/examples/ns-workspace-notifications/main.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,29 @@
44
/// It registers observers for various application events (hiding, launching, activating, and deactivating)
55
/// and prints information about these events when they occur.
66
///
7-
use cidre::{blocks, ns, objc::Obj};
7+
use cidre::{blocks, ns, ns::workspace::notification as wsn, objc::Obj};
88

99
fn main() {
1010
let block = |n: &ns::Notification| {
1111
// let workspace = n.id().try_cast(ns::Workspace::cls()).unwrap();
1212
println!("{:?}", n.name());
1313
let user_info = n.user_info().unwrap();
1414

15-
if let Some(app) = user_info.get(ns::workspace::notification::app_key()) {
15+
if let Some(app) = user_info.get(wsn::app_key()) {
1616
if let Some(app) = app.try_cast(ns::RunningApp::cls()) {
1717
println!("{app:?}");
1818
}
1919
}
20-
21-
let name = n.name().as_ref() as *const _;
22-
use ns::workspace::notification as names;
23-
match () {
24-
_ if name == names::did_activate_app() as *const _ => {
25-
println!("activating!");
26-
}
27-
_ if name == names::did_deactivate_app() as *const _ => {
28-
println!("deactivating!");
29-
}
30-
_ => {
31-
panic!("unknwon event");
32-
}
33-
}
3420
};
3521

3622
// One block for all notifications
3723
let mut block = blocks::SyncBlock::new1(block);
3824

3925
let notifications = [
40-
ns::workspace::notification::did_hide_app(),
41-
ns::workspace::notification::did_launch_app(),
42-
ns::workspace::notification::did_activate_app(),
43-
ns::workspace::notification::did_deactivate_app(),
26+
wsn::did_hide_app(),
27+
wsn::did_launch_app(),
28+
wsn::did_activate_app(),
29+
wsn::did_deactivate_app(),
4430
];
4531
let mut observers = Vec::with_capacity(notifications.len());
4632

0 commit comments

Comments
 (0)