diff --git a/native/liblinuxbridge/bridge.cpp b/native/liblinuxbridge/bridge.cpp index ab2caed..51bd1db 100644 --- a/native/liblinuxbridge/bridge.cpp +++ b/native/liblinuxbridge/bridge.cpp @@ -121,6 +121,8 @@ int32_t initialize(void * _context_instance) { } xdo_context = xdo_new(NULL); + + return 1; } int32_t eventloop() { diff --git a/src/bridge/linux.rs b/src/bridge/linux.rs index 3ca74b3..6e9e731 100644 --- a/src/bridge/linux.rs +++ b/src/bridge/linux.rs @@ -3,7 +3,7 @@ use std::os::raw::{c_void, c_char}; #[allow(improper_ctypes)] #[link(name="linuxbridge", kind="static")] extern { - pub fn initialize(s: *const c_void); + pub fn initialize(s: *const c_void) -> i32; pub fn eventloop(); pub fn cleanup(); diff --git a/src/context/linux.rs b/src/context/linux.rs index d7810c0..c7bec33 100644 --- a/src/context/linux.rs +++ b/src/context/linux.rs @@ -3,6 +3,8 @@ use std::os::raw::c_void; use crate::event::*; use crate::event::KeyModifier::*; use crate::bridge::linux::*; +use std::process::exit; +use log::error; #[repr(C)] pub struct LinuxContext { @@ -20,7 +22,11 @@ impl LinuxContext { register_keypress_callback(keypress_callback); - initialize(context_ptr); // TODO: check initialization return codes + let res = initialize(context_ptr); + if res <= 0 { + error!("Could not initialize linux context, error: {}", res); + exit(10); + } } context diff --git a/src/engine.rs b/src/engine.rs index 0cf624f..94da325 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -10,7 +10,6 @@ use crate::extension::Extension; use std::cell::RefCell; use std::process::exit; use std::collections::HashMap; -use serde_yaml::Mapping; use regex::{Regex, Captures}; pub struct Engine<'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, @@ -79,7 +78,7 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa } lazy_static! { - static ref VarRegex: Regex = Regex::new("\\{\\{\\s*(?P\\w+)\\s*\\}\\}").unwrap(); + static ref VAR_REGEX: Regex = Regex::new("\\{\\{\\s*(?P\\w+)\\s*\\}\\}").unwrap(); } impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIManager> @@ -95,7 +94,6 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa self.keyboard_manager.delete_string(m.trigger.len() as i32); let target_string = if m._has_vars { - //self.extension_map.get("date").unwrap().calculate(Mapping::new()).unwrap() let mut output_map = HashMap::new(); for variable in m.vars.iter() { @@ -114,7 +112,7 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa } // Replace the variables - let result = VarRegex.replace_all(&m.replace, |caps: &Captures| { + let result = VAR_REGEX.replace_all(&m.replace, |caps: &Captures| { let var_name = caps.name("name").unwrap().as_str(); let output = output_map.get(var_name); output.unwrap() diff --git a/src/matcher/mod.rs b/src/matcher/mod.rs index 8790ec4..eaf505e 100644 --- a/src/matcher/mod.rs +++ b/src/matcher/mod.rs @@ -28,11 +28,11 @@ impl <'de> serde::Deserialize<'de> for Match { impl<'a> From<&'a AutoMatch> for Match{ fn from(other: &'a AutoMatch) -> Self { lazy_static! { - static ref VarRegex: Regex = Regex::new("\\{\\{\\s*(\\w+)\\s*\\}\\}").unwrap(); + static ref VAR_REGEX: Regex = Regex::new("\\{\\{\\s*(\\w+)\\s*\\}\\}").unwrap(); } // Check if the match contains variables - let has_vars = VarRegex.is_match(&other.replace); + let has_vars = VAR_REGEX.is_match(&other.replace); Self { trigger: other.trigger.clone(), diff --git a/src/ui/linux.rs b/src/ui/linux.rs index ca1ac40..f1b7bf0 100644 --- a/src/ui/linux.rs +++ b/src/ui/linux.rs @@ -1,5 +1,6 @@ use std::process::Command; use super::MenuItem; +use log::error; pub struct LinuxUIManager {} @@ -9,8 +10,8 @@ impl super::UIManager for LinuxUIManager { .args(&["-t", "2000", "espanso", message]) .output(); - if let Err(_) = res { - // TODO: print error log + if let Err(e) = res { + error!("Could not send a notification, error: {}", e); } } @@ -21,8 +22,6 @@ impl super::UIManager for LinuxUIManager { impl LinuxUIManager { pub fn new() -> LinuxUIManager { - // TODO: check if notify-send is present and log an error otherwise. - LinuxUIManager{} } } \ No newline at end of file