diff --git a/Cargo.toml b/Cargo.toml index 93c35d3..bd54f69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scriptkeys" -version = "0.2.0" +version = "0.2.1" edition = "2021" description = "ScriptKeys allows you to easily build macros (in Lua) on every key press for the supported devices." documentation = "https://github.com/bigmstone/scriptkeys/blob/main/README.md" diff --git a/src/config/mod.rs b/src/config/mod.rs index 4d52a8d..5294181 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -30,13 +30,13 @@ pub enum ConfigEvent { Script, } -#[derive(Deserialize, PartialEq)] +#[derive(Deserialize, PartialEq, Debug)] pub struct Mapping { pub key: u32, pub script: String, } -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] pub struct Config { pub device: Devices, pub mappings: Vec, @@ -157,3 +157,4 @@ async fn config_watcher( } } } + diff --git a/src/device/mod.rs b/src/device/mod.rs index 505c55d..c9c68d3 100644 --- a/src/device/mod.rs +++ b/src/device/mod.rs @@ -16,7 +16,7 @@ pub struct Event { pub action: Action, } -#[derive(Deserialize, PartialEq)] +#[derive(Deserialize, PartialEq, Debug)] pub enum Devices { XK68JS, Dummy, @@ -55,3 +55,4 @@ impl Device for Dummy { } } } + diff --git a/src/device/xkeys/xk68js.rs b/src/device/xkeys/xk68js.rs index 63e2640..5d5a57b 100644 --- a/src/device/xkeys/xk68js.rs +++ b/src/device/xkeys/xk68js.rs @@ -30,6 +30,7 @@ use std::collections::HashMap; use { anyhow::{Error, Result}, hidapi::{HidApi, HidDevice}, + log::trace, serde::Deserialize, tokio::sync::mpsc::Sender, }; @@ -153,6 +154,7 @@ impl Device for XK68JS { let txc = tx.clone(); tokio::spawn(async move { for event in events { + trace!("Sending event: {:?}", event); txc.send(event).await.unwrap(); } }); @@ -189,3 +191,4 @@ mod test { } } } + diff --git a/src/script/mod.rs b/src/script/mod.rs index 68b28b2..3cd7fff 100644 --- a/src/script/mod.rs +++ b/src/script/mod.rs @@ -76,18 +76,21 @@ impl Script { pub fn load_mapping(&mut self, conf: &Config) -> Result<()> { for mapping in &conf.mappings { + trace!("Loading mapping: {:?}", mapping); if let Some(full_path) = find_script(&mapping.script) { match self.load_script_mapping(&full_path, mapping) { - Ok(()) => break, + Ok(()) => continue, Err(err) => { if err.downcast_ref::().is_some() { continue; } else { + error!("Error loading mapping: {:?}, {}", mapping, err); return Err(err); } } }; } else { + error!("Script not found: {:?}", mapping); return Err(Error::new(ScriptNotFound)); } } @@ -98,6 +101,7 @@ impl Script { pub fn load_script_mapping(&mut self, path: &Path, mapping: &Mapping) -> Result<()> { if path.exists() { if let Ok(script) = fs::read_to_string(path) { + trace!("Loading script: {}", path.display()); self.lua.load(&script).exec()?; let name = Path::new(&mapping.script).file_stem().unwrap(); self.script_map @@ -138,6 +142,8 @@ pub async fn script_loop(script: Arc>, mut rx: Receiver) { Action::Release => format!("{}.Release", table_name), }; + trace!("Executing script: {}", method); + script.lua.load(&format!("{}()", method)).exec().unwrap(); } } @@ -272,3 +278,4 @@ async fn script_watcher( } } } +