|
4 | 4 | /// It registers observers for various application events (hiding, launching, activating, and deactivating)
|
5 | 5 | /// and prints information about these events when they occur.
|
6 | 6 | ///
|
7 |
| -use cidre::{blocks, ns, objc::Obj}; |
| 7 | +use cidre::{blocks, ns, ns::workspace::notification as wsn, objc::Obj}; |
8 | 8 |
|
9 | 9 | fn main() {
|
10 | 10 | let block = |n: &ns::Notification| {
|
11 | 11 | // let workspace = n.id().try_cast(ns::Workspace::cls()).unwrap();
|
12 | 12 | println!("{:?}", n.name());
|
13 | 13 | let user_info = n.user_info().unwrap();
|
14 | 14 |
|
15 |
| - if let Some(app) = user_info.get(ns::workspace::notification::app_key()) { |
| 15 | + if let Some(app) = user_info.get(wsn::app_key()) { |
16 | 16 | if let Some(app) = app.try_cast(ns::RunningApp::cls()) {
|
17 | 17 | println!("{app:?}");
|
18 | 18 | }
|
19 | 19 | }
|
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 |
| - } |
34 | 20 | };
|
35 | 21 |
|
36 | 22 | // One block for all notifications
|
37 | 23 | let mut block = blocks::SyncBlock::new1(block);
|
38 | 24 |
|
39 | 25 | 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(), |
44 | 30 | ];
|
45 | 31 | let mut observers = Vec::with_capacity(notifications.len());
|
46 | 32 |
|
|
0 commit comments