Fix: compile for windows and handle errors
This commit is contained in:
parent
8a907ed401
commit
d77c7351aa
3 changed files with 16 additions and 10 deletions
|
@ -4,7 +4,7 @@ extern crate rumqttc as mqtt;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub type TimeCallback = fn(u32) -> ();
|
pub type TimeCallback = fn(u32) -> Result<(),()>;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, PartialEq)]
|
#[derive(Serialize, Deserialize, PartialEq)]
|
||||||
enum MqttMessageKind {
|
enum MqttMessageKind {
|
||||||
|
@ -95,7 +95,10 @@ impl Comm {
|
||||||
return;
|
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 {
|
let reply = MqttMessage {
|
||||||
id: msg.id,
|
id: msg.id,
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
use enigo::{KeyboardControllable};
|
use enigo::{KeyboardControllable};
|
||||||
|
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
pub fn type_text(text: &str) {
|
pub fn type_text(text: &str) {
|
||||||
enigo::Enigo::default().key_sequence(text);
|
enigo::Enigo::default().key_sequence(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
pub fn click_tab() {
|
pub fn click_tab() {
|
||||||
enigo::Enigo::default().key_click(enigo::Key::Tab);
|
enigo::Enigo::default().key_click(enigo::Key::Tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_family = "windows")]
|
#[cfg(target_family = "windows")]
|
||||||
pub fn type_text(&self, text: &str) {
|
pub fn type_text(text: &str) -> Result<(),()>{
|
||||||
simulate::type_str(text);
|
simulate::type_str(text).map_err(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_family = "windows")]
|
#[cfg(target_family = "windows")]
|
||||||
pub fn click_tab(&self) {
|
pub fn click_tab() -> Result<(),()> {
|
||||||
simulate::send(simulate::Key::Tab);
|
simulate::send(simulate::Key::Tab).map_err(|_| ())
|
||||||
}
|
}
|
|
@ -66,14 +66,15 @@ fn millis_to_string(millis: u32) -> String {
|
||||||
formatted.replace(".", ",")
|
formatted.replace(".", ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_time(time: u32) {
|
fn handle_time(time: u32) -> Result<(),()> {
|
||||||
println!("Got time: {}", time);
|
println!("Got time: {}", time);
|
||||||
let time_with_comma = millis_to_string(time);
|
let time_with_comma = millis_to_string(time);
|
||||||
|
|
||||||
println!("Trying to type {time_with_comma}");
|
println!("Trying to type {time_with_comma}");
|
||||||
keyboard::type_text(&time_with_comma);
|
keyboard::type_text(&time_with_comma)?;
|
||||||
keyboard::click_tab();
|
keyboard::click_tab()?;
|
||||||
keyboard::click_tab();
|
keyboard::click_tab()?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
Loading…
Reference in a new issue