diff --git a/receiver/src/comm.rs b/receiver/src/comm.rs index c16f654..32b3347 100644 --- a/receiver/src/comm.rs +++ b/receiver/src/comm.rs @@ -4,7 +4,7 @@ extern crate rumqttc as mqtt; use serde::{Deserialize, Serialize}; -pub type TimeCallback = fn(u32) -> (); +pub type TimeCallback = fn(u32) -> Result<(),()>; #[derive(Serialize, Deserialize, PartialEq)] enum MqttMessageKind { @@ -95,7 +95,10 @@ impl Comm { return; } - (self.handler)(msg.time); + if (self.handler)(msg.time).is_err() { + println!("[WARN] error in time handler -> not sending confirmation"); + return; + } let reply = MqttMessage { id: msg.id, diff --git a/receiver/src/keyboard.rs b/receiver/src/keyboard.rs index eb4dcc3..d6d7e01 100644 --- a/receiver/src/keyboard.rs +++ b/receiver/src/keyboard.rs @@ -1,20 +1,22 @@ #[cfg(target_family = "unix")] use enigo::{KeyboardControllable}; +#[cfg(target_family = "unix")] pub fn type_text(text: &str) { enigo::Enigo::default().key_sequence(text); } +#[cfg(target_family = "unix")] pub fn click_tab() { enigo::Enigo::default().key_click(enigo::Key::Tab); } #[cfg(target_family = "windows")] -pub fn type_text(&self, text: &str) { - simulate::type_str(text); +pub fn type_text(text: &str) -> Result<(),()>{ + simulate::type_str(text).map_err(|_| ()) } #[cfg(target_family = "windows")] -pub fn click_tab(&self) { - simulate::send(simulate::Key::Tab); +pub fn click_tab() -> Result<(),()> { + simulate::send(simulate::Key::Tab).map_err(|_| ()) } \ No newline at end of file diff --git a/receiver/src/main.rs b/receiver/src/main.rs index 6a05b8e..4516dff 100644 --- a/receiver/src/main.rs +++ b/receiver/src/main.rs @@ -66,14 +66,15 @@ fn millis_to_string(millis: u32) -> String { formatted.replace(".", ",") } -fn handle_time(time: u32) { +fn handle_time(time: u32) -> Result<(),()> { println!("Got time: {}", time); let time_with_comma = millis_to_string(time); println!("Trying to type {time_with_comma}"); - keyboard::type_text(&time_with_comma); - keyboard::click_tab(); - keyboard::click_tab(); + keyboard::type_text(&time_with_comma)?; + keyboard::click_tab()?; + keyboard::click_tab()?; + Ok(()) } fn main() {