Solve some TODOs

This commit is contained in:
Federico Terzi 2019-09-15 15:46:24 +02:00
parent fbee38d5b8
commit 29629afa52
6 changed files with 17 additions and 12 deletions

View File

@ -121,6 +121,8 @@ int32_t initialize(void * _context_instance) {
} }
xdo_context = xdo_new(NULL); xdo_context = xdo_new(NULL);
return 1;
} }
int32_t eventloop() { int32_t eventloop() {

View File

@ -3,7 +3,7 @@ use std::os::raw::{c_void, c_char};
#[allow(improper_ctypes)] #[allow(improper_ctypes)]
#[link(name="linuxbridge", kind="static")] #[link(name="linuxbridge", kind="static")]
extern { extern {
pub fn initialize(s: *const c_void); pub fn initialize(s: *const c_void) -> i32;
pub fn eventloop(); pub fn eventloop();
pub fn cleanup(); pub fn cleanup();

View File

@ -3,6 +3,8 @@ use std::os::raw::c_void;
use crate::event::*; use crate::event::*;
use crate::event::KeyModifier::*; use crate::event::KeyModifier::*;
use crate::bridge::linux::*; use crate::bridge::linux::*;
use std::process::exit;
use log::error;
#[repr(C)] #[repr(C)]
pub struct LinuxContext { pub struct LinuxContext {
@ -20,7 +22,11 @@ impl LinuxContext {
register_keypress_callback(keypress_callback); 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 context

View File

@ -10,7 +10,6 @@ use crate::extension::Extension;
use std::cell::RefCell; use std::cell::RefCell;
use std::process::exit; use std::process::exit;
use std::collections::HashMap; use std::collections::HashMap;
use serde_yaml::Mapping;
use regex::{Regex, Captures}; use regex::{Regex, Captures};
pub struct Engine<'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, 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! { lazy_static! {
static ref VarRegex: Regex = Regex::new("\\{\\{\\s*(?P<name>\\w+)\\s*\\}\\}").unwrap(); static ref VAR_REGEX: Regex = Regex::new("\\{\\{\\s*(?P<name>\\w+)\\s*\\}\\}").unwrap();
} }
impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIManager> 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); self.keyboard_manager.delete_string(m.trigger.len() as i32);
let target_string = if m._has_vars { let target_string = if m._has_vars {
//self.extension_map.get("date").unwrap().calculate(Mapping::new()).unwrap()
let mut output_map = HashMap::new(); let mut output_map = HashMap::new();
for variable in m.vars.iter() { for variable in m.vars.iter() {
@ -114,7 +112,7 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa
} }
// Replace the variables // 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 var_name = caps.name("name").unwrap().as_str();
let output = output_map.get(var_name); let output = output_map.get(var_name);
output.unwrap() output.unwrap()

View File

@ -28,11 +28,11 @@ impl <'de> serde::Deserialize<'de> for Match {
impl<'a> From<&'a AutoMatch> for Match{ impl<'a> From<&'a AutoMatch> for Match{
fn from(other: &'a AutoMatch) -> Self { fn from(other: &'a AutoMatch) -> Self {
lazy_static! { 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 // Check if the match contains variables
let has_vars = VarRegex.is_match(&other.replace); let has_vars = VAR_REGEX.is_match(&other.replace);
Self { Self {
trigger: other.trigger.clone(), trigger: other.trigger.clone(),

View File

@ -1,5 +1,6 @@
use std::process::Command; use std::process::Command;
use super::MenuItem; use super::MenuItem;
use log::error;
pub struct LinuxUIManager {} pub struct LinuxUIManager {}
@ -9,8 +10,8 @@ impl super::UIManager for LinuxUIManager {
.args(&["-t", "2000", "espanso", message]) .args(&["-t", "2000", "espanso", message])
.output(); .output();
if let Err(_) = res { if let Err(e) = res {
// TODO: print error log error!("Could not send a notification, error: {}", e);
} }
} }
@ -21,8 +22,6 @@ impl super::UIManager for LinuxUIManager {
impl LinuxUIManager { impl LinuxUIManager {
pub fn new() -> LinuxUIManager { pub fn new() -> LinuxUIManager {
// TODO: check if notify-send is present and log an error otherwise.
LinuxUIManager{} LinuxUIManager{}
} }
} }