feat: error handling for macos hook
parent
8aa4bea93a
commit
564f1eca4b
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ pub struct Event {
|
|||
pub data: EventData,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Error {
|
||||
pub message: String,
|
||||
}
|
||||
|
|
Reference in New Issue