feat: error handling for macos hook

pull/11/head
paring 2022-11-03 16:29:41 +09:00
parent 8aa4bea93a
commit 564f1eca4b
2 changed files with 15 additions and 3 deletions

View File

@ -9,17 +9,29 @@ use self::listen::RUN_LOOP;
mod common;
mod listen;
static mut ERROR: Option<Error> = None;
pub fn start(callback: fn(Event)) -> Result<(), Error> {
if let Err(e) = thread::Builder::new()
.name("SkyHook Listener Thread".into())
.spawn(move || listen::listen(callback))
.spawn(move || {
if let Err(e) = listen::listen(callback) {
unsafe {
ERROR = Some(e);
}
}
})
{
return Err(Error {
message: format!("Failed to start listener thread: {:?}", e),
});
}
while let None = unsafe { &RUN_LOOP } {}
while let None = unsafe { &RUN_LOOP } {
if let Some(err) = unsafe { &ERROR } {
return Err(err.clone());
}
}
Ok(())
}

View File

@ -12,7 +12,7 @@ pub struct Event {
pub data: EventData,
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Error {
pub message: String,
}