in native/desktop-macos/src/macos/robot.rs [110:137]
fn new() -> anyhow::Result<Self> {
let (mark_is_ready, check_is_ready) = std::sync::mpsc::sync_channel::<anyhow::Result<RunLoopWrapper>>(1);
let (events_data_snd, events_data_rcv) = std::sync::mpsc::sync_channel::<i64>(1);
let handle = thread::spawn(move || {
// Safety: the Arc is alive until the event loop is running
let events_data_snd = Arc::new(events_data_snd);
match Self::create_tap_subscription(Arc::as_ptr(&events_data_snd)) {
Ok(subscription) => {
mark_is_ready
.send(Ok(RunLoopWrapper(subscription.run_loop.clone())))
.expect("Can't fail here");
CFRunLoop::run();
Self::remove_tap_subscription(subscription);
}
Err(err) => {
mark_is_ready.send(Err(err)).expect("Can't fail here");
}
}
});
let run_loop_wrapper = check_is_ready.recv().expect("Can't fail here")?;
Ok(Self {
handle: Some(handle),
events_data_rcv,
run_loop_wrapper,
})
}