Fix: compile for windows and handle errors

This commit is contained in:
Dorian Zedler 2023-02-16 10:59:26 +01:00
parent 8a907ed401
commit d77c7351aa
3 changed files with 16 additions and 10 deletions

View file

@ -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,

View file

@ -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(|_| ())
}

View file

@ -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() {