Fix warnings on Linux

This commit is contained in:
Federico Terzi 2020-04-03 20:10:06 +02:00
parent 4d91085321
commit dab98a7a67
16 changed files with 147 additions and 172 deletions

View File

@ -19,7 +19,7 @@
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use std::io::{Write}; use std::io::{Write};
use log::{error, warn}; use log::{error};
use std::path::Path; use std::path::Path;
pub struct LinuxClipboardManager {} pub struct LinuxClipboardManager {}
@ -86,6 +86,10 @@ impl super::ClipboardManager for LinuxClipboardManager {
let res = Command::new("xclip") let res = Command::new("xclip")
.args(&["-selection", "clipboard", "-t", mime, "-i", &image_path]) .args(&["-selection", "clipboard", "-t", mime, "-i", &image_path])
.spawn(); .spawn();
if let Err(e) = res {
error!("Could not set image clipboard: {}", e);
}
} }
} }

View File

@ -427,12 +427,10 @@ impl ConfigSet {
// Check if some triggers are conflicting with each other // Check if some triggers are conflicting with each other
// For more information, see: https://github.com/federico-terzi/espanso/issues/135 // For more information, see: https://github.com/federico-terzi/espanso/issues/135
if default.conflict_check { if default.conflict_check {
for s in specific.iter() { let has_conflicts = Self::has_conflicts(&default, &specific);
let has_conflicts = Self::has_conflicts(&default, &specific); if has_conflicts {
if has_conflicts { eprintln!("Warning: some triggers had conflicts and may not behave as intended");
eprintln!("Warning: some triggers had conflicts and may not behave as intended"); eprintln!("To turn off this check, add \"conflict_check: false\" in the configuration");
eprintln!("To turn off this check, add \"conflict_check: false\" in the configuration");
}
} }
} }
@ -583,8 +581,7 @@ mod tests {
use super::*; use super::*;
use std::io::Write; use std::io::Write;
use tempfile::{NamedTempFile, TempDir}; use tempfile::{NamedTempFile, TempDir};
use std::any::Any; use crate::matcher::{MatchContentType};
use crate::matcher::{TextContent, MatchContentType};
const TEST_WORKING_CONFIG_FILE : &str = include_str!("../res/test/working_config.yml"); const TEST_WORKING_CONFIG_FILE : &str = include_str!("../res/test/working_config.yml");
const TEST_CONFIG_FILE_WITH_BAD_YAML : &str = include_str!("../res/test/config_with_bad_yaml.yml"); const TEST_CONFIG_FILE_WITH_BAD_YAML : &str = include_str!("../res/test/config_with_bad_yaml.yml");
@ -593,7 +590,7 @@ mod tests {
fn create_tmp_file(string: &str) -> NamedTempFile { fn create_tmp_file(string: &str) -> NamedTempFile {
let file = NamedTempFile::new().unwrap(); let file = NamedTempFile::new().unwrap();
file.as_file().write_all(string.as_bytes()); file.as_file().write_all(string.as_bytes()).unwrap();
file file
} }
@ -716,7 +713,7 @@ mod tests {
let package_dir = TempDir::new().expect("unable to create package directory"); let package_dir = TempDir::new().expect("unable to create package directory");
let default_path = data_dir.path().join(DEFAULT_CONFIG_FILE_NAME); let default_path = data_dir.path().join(DEFAULT_CONFIG_FILE_NAME);
fs::write(default_path, default_content); fs::write(default_path, default_content).unwrap();
(data_dir, package_dir) (data_dir, package_dir)
} }
@ -724,7 +721,7 @@ mod tests {
pub fn create_temp_file_in_dir(tmp_dir: &PathBuf, name: &str, content: &str) -> PathBuf { pub fn create_temp_file_in_dir(tmp_dir: &PathBuf, name: &str, content: &str) -> PathBuf {
let user_defined_path = tmp_dir.join(name); let user_defined_path = tmp_dir.join(name);
let user_defined_path_copy = user_defined_path.clone(); let user_defined_path_copy = user_defined_path.clone();
fs::write(user_defined_path, content); fs::write(user_defined_path, content).unwrap();
user_defined_path_copy user_defined_path_copy
} }
@ -732,7 +729,7 @@ mod tests {
pub fn create_user_config_file(tmp_dir: &Path, name: &str, content: &str) -> PathBuf { pub fn create_user_config_file(tmp_dir: &Path, name: &str, content: &str) -> PathBuf {
let user_config_dir = tmp_dir.join(USER_CONFIGS_FOLDER_NAME); let user_config_dir = tmp_dir.join(USER_CONFIGS_FOLDER_NAME);
if !user_config_dir.exists() { if !user_config_dir.exists() {
create_dir_all(&user_config_dir); create_dir_all(&user_config_dir).unwrap();
} }
create_temp_file_in_dir(&user_config_dir, name, content) create_temp_file_in_dir(&user_config_dir, name, content)
@ -741,7 +738,7 @@ mod tests {
pub fn create_package_file(package_data_dir: &Path, package_name: &str, filename: &str, content: &str) -> PathBuf { pub fn create_package_file(package_data_dir: &Path, package_name: &str, filename: &str, content: &str) -> PathBuf {
let package_dir = package_data_dir.join(package_name); let package_dir = package_data_dir.join(package_name);
if !package_dir.exists() { if !package_dir.exists() {
create_dir_all(&package_dir); create_dir_all(&package_dir).unwrap();
} }
create_temp_file_in_dir(&package_dir, filename, content) create_temp_file_in_dir(&package_dir, filename, content)
@ -824,11 +821,11 @@ mod tests {
fn test_config_set_specific_file_duplicate_name() { fn test_config_set_specific_file_duplicate_name() {
let (data_dir, package_dir) = create_temp_espanso_directories(); let (data_dir, package_dir) = create_temp_espanso_directories();
let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" create_user_config_file(data_dir.path(), "specific.yml", r###"
name: specific1 name: specific1
"###); "###);
let user_defined_path2 = create_user_config_file(data_dir.path(), "specific2.yml", r###" create_user_config_file(data_dir.path(), "specific2.yml", r###"
name: specific1 name: specific1
"###); "###);
@ -847,7 +844,7 @@ mod tests {
replace: "Bob" replace: "Bob"
"###); "###);
let user_defined_path = create_user_config_file(data_dir.path(), "specific1.yml", r###" create_user_config_file(data_dir.path(), "specific1.yml", r###"
name: specific1 name: specific1
matches: matches:
@ -874,7 +871,7 @@ mod tests {
replace: "Bob" replace: "Bob"
"###); "###);
let user_defined_path2 = create_user_config_file(data_dir.path(), "specific2.yml", r###" create_user_config_file(data_dir.path(), "specific2.yml", r###"
name: specific1 name: specific1
matches: matches:
@ -906,7 +903,7 @@ mod tests {
replace: "Bob" replace: "Bob"
"###); "###);
let user_defined_path2 = create_user_config_file(data_dir.path(), "specific2.yml", r###" create_user_config_file(data_dir.path(), "specific2.yml", r###"
name: specific1 name: specific1
exclude_default_entries: true exclude_default_entries: true
@ -941,7 +938,7 @@ mod tests {
"### "###
); );
let user_defined_path2 = create_user_config_file(data_dir.path(), "specific.zzz", r###" create_user_config_file(data_dir.path(), "specific.zzz", r###"
name: specific1 name: specific1
exclude_default_entries: true exclude_default_entries: true
@ -959,11 +956,11 @@ mod tests {
fn test_config_set_no_parent_configs_works_correctly() { fn test_config_set_no_parent_configs_works_correctly() {
let (data_dir, package_dir) = create_temp_espanso_directories(); let (data_dir, package_dir) = create_temp_espanso_directories();
let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" create_user_config_file(data_dir.path(), "specific.yml", r###"
name: specific1 name: specific1
"###); "###);
let user_defined_path2 = create_user_config_file(data_dir.path(), "specific2.yml", r###" create_user_config_file(data_dir.path(), "specific2.yml", r###"
name: specific2 name: specific2
"###); "###);
@ -979,7 +976,7 @@ mod tests {
replace: Hasta la vista replace: Hasta la vista
"###); "###);
let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" create_user_config_file(data_dir.path(), "specific.yml", r###"
parent: default parent: default
matches: matches:
@ -1002,7 +999,7 @@ mod tests {
replace: Hasta la vista replace: Hasta la vista
"###); "###);
let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" create_user_config_file(data_dir.path(), "specific.yml", r###"
matches: matches:
- trigger: "hello" - trigger: "hello"
replace: "world" replace: "world"
@ -1024,7 +1021,7 @@ mod tests {
replace: Hasta la vista replace: Hasta la vista
"###); "###);
let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" create_user_config_file(data_dir.path(), "specific.yml", r###"
name: custom1 name: custom1
parent: default parent: default
@ -1033,7 +1030,7 @@ mod tests {
replace: "world" replace: "world"
"###); "###);
let user_defined_path2 = create_user_config_file(data_dir.path(), "specific2.yml", r###" create_user_config_file(data_dir.path(), "specific2.yml", r###"
parent: custom1 parent: custom1
matches: matches:
@ -1057,7 +1054,7 @@ mod tests {
replace: Hasta la vista replace: Hasta la vista
"###); "###);
let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" create_user_config_file(data_dir.path(), "specific.yml", r###"
parent: default parent: default
matches: matches:
@ -1085,7 +1082,7 @@ mod tests {
replace: Hasta la vista replace: Hasta la vista
"###); "###);
let package_path = create_package_file(package_dir.path(), "package1", "package.yml", r###" create_package_file(package_dir.path(), "package1", "package.yml", r###"
parent: default parent: default
matches: matches:
@ -1108,7 +1105,7 @@ mod tests {
replace: Hasta la vista replace: Hasta la vista
"###); "###);
let package_path = create_package_file(package_dir.path(), "package1", "package.yml", r###" create_package_file(package_dir.path(), "package1", "package.yml", r###"
matches: matches:
- trigger: "harry" - trigger: "harry"
replace: "potter" replace: "potter"
@ -1129,7 +1126,7 @@ mod tests {
replace: Hasta la vista replace: Hasta la vista
"###); "###);
let package_path = create_package_file(package_dir.path(), "package1", "package.yml", r###" create_package_file(package_dir.path(), "package1", "package.yml", r###"
name: package1 name: package1
matches: matches:
@ -1137,7 +1134,7 @@ mod tests {
replace: "potter" replace: "potter"
"###); "###);
let package_path2 = create_package_file(package_dir.path(), "package1", "addon.yml", r###" create_package_file(package_dir.path(), "package1", "addon.yml", r###"
parent: package1 parent: package1
matches: matches:
@ -1175,7 +1172,7 @@ mod tests {
replace: Jon replace: Jon
"###); "###);
let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" create_user_config_file(data_dir.path(), "specific.yml", r###"
name: specific1 name: specific1
matches: matches:
@ -1199,7 +1196,7 @@ mod tests {
replace: Error replace: Error
"###); "###);
let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" create_user_config_file(data_dir.path(), "specific.yml", r###"
name: specific1 name: specific1
matches: matches:
@ -1221,7 +1218,7 @@ mod tests {
replace: Jon replace: Jon
"###); "###);
let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" create_user_config_file(data_dir.path(), "specific.yml", r###"
name: specific1 name: specific1
matches: matches:
@ -1243,14 +1240,14 @@ mod tests {
replace: Jon replace: Jon
"###); "###);
let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" create_user_config_file(data_dir.path(), "specific.yml", r###"
name: specific1 name: specific1
matches: matches:
- trigger: "bad" - trigger: "bad"
replace: "Conflict" replace: "Conflict"
"###); "###);
let user_defined_path2 = create_user_config_file(data_dir.path(), "specific2.yml", r###" create_user_config_file(data_dir.path(), "specific2.yml", r###"
name: specific2 name: specific2
matches: matches:
@ -1272,7 +1269,7 @@ mod tests {
format: "%m" format: "%m"
"###); "###);
let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" create_user_config_file(data_dir.path(), "specific.yml", r###"
global_vars: global_vars:
- name: specificvar - name: specificvar
type: date type: date
@ -1298,7 +1295,7 @@ mod tests {
format: "%m" format: "%m"
"###); "###);
let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" create_user_config_file(data_dir.path(), "specific.yml", r###"
parent: default parent: default
global_vars: global_vars:
- name: specificvar - name: specificvar
@ -1324,7 +1321,7 @@ mod tests {
format: "%m" format: "%m"
"###); "###);
let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" create_user_config_file(data_dir.path(), "specific.yml", r###"
exclude_default_entries: true exclude_default_entries: true
global_vars: global_vars:

View File

@ -204,12 +204,8 @@ impl <'a, S: SystemManager> super::ConfigManager<'a> for RuntimeConfigManager<'a
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use tempfile::{NamedTempFile, TempDir};
use crate::config::{DEFAULT_CONFIG_FILE_NAME, DEFAULT_CONFIG_FILE_CONTENT};
use std::fs;
use std::path::PathBuf;
use crate::config::ConfigManager; use crate::config::ConfigManager;
use crate::config::tests::{create_temp_espanso_directories, create_temp_file_in_dir, create_user_config_file}; use crate::config::tests::{create_temp_espanso_directories, create_user_config_file};
struct DummySystemManager { struct DummySystemManager {
title: RefCell<String>, title: RefCell<String>,
@ -251,18 +247,18 @@ mod tests {
fn test_runtime_constructor_regex_load_correctly() { fn test_runtime_constructor_regex_load_correctly() {
let (data_dir, package_dir) = create_temp_espanso_directories(); let (data_dir, package_dir) = create_temp_espanso_directories();
let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" create_user_config_file(&data_dir.path(), "specific.yml", r###"
name: myname1 name: myname1
filter_exec: "Title" filter_exec: "Title"
"###); "###);
let specific_path2 = create_user_config_file(&data_dir.path(), "specific2.yml", r###" create_user_config_file(&data_dir.path(), "specific2.yml", r###"
name: myname2 name: myname2
filter_title: "Yeah" filter_title: "Yeah"
filter_class: "Car" filter_class: "Car"
"###); "###);
let specific_path3 = create_user_config_file(&data_dir.path(), "specific3.yml", r###" create_user_config_file(&data_dir.path(), "specific3.yml", r###"
name: myname3 name: myname3
filter_title: "Nice" filter_title: "Nice"
"###); "###);
@ -302,18 +298,18 @@ mod tests {
fn test_runtime_constructor_malformed_regexes_are_ignored() { fn test_runtime_constructor_malformed_regexes_are_ignored() {
let (data_dir, package_dir) = create_temp_espanso_directories(); let (data_dir, package_dir) = create_temp_espanso_directories();
let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" create_user_config_file(&data_dir.path(), "specific.yml", r###"
name: myname1 name: myname1
filter_exec: "[`-_]" filter_exec: "[`-_]"
"###); "###);
let specific_path2 = create_user_config_file(&data_dir.path(), "specific2.yml", r###" create_user_config_file(&data_dir.path(), "specific2.yml", r###"
name: myname2 name: myname2
filter_title: "[`-_]" filter_title: "[`-_]"
filter_class: "Car" filter_class: "Car"
"###); "###);
let specific_path3 = create_user_config_file(&data_dir.path(), "specific3.yml", r###" create_user_config_file(&data_dir.path(), "specific3.yml", r###"
name: myname3 name: myname3
filter_title: "Nice" filter_title: "Nice"
"###); "###);
@ -353,7 +349,7 @@ mod tests {
fn test_runtime_calculate_active_config_specific_title_match() { fn test_runtime_calculate_active_config_specific_title_match() {
let (data_dir, package_dir) = create_temp_espanso_directories(); let (data_dir, package_dir) = create_temp_espanso_directories();
let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" create_user_config_file(&data_dir.path(), "specific.yml", r###"
name: chrome name: chrome
filter_title: "Chrome" filter_title: "Chrome"
"###); "###);
@ -368,10 +364,11 @@ mod tests {
assert_eq!(config_manager.calculate_active_config().name, "chrome"); assert_eq!(config_manager.calculate_active_config().name, "chrome");
} }
#[test]
fn test_runtime_calculate_active_config_specific_class_match() { fn test_runtime_calculate_active_config_specific_class_match() {
let (data_dir, package_dir) = create_temp_espanso_directories(); let (data_dir, package_dir) = create_temp_espanso_directories();
let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" create_user_config_file(&data_dir.path(), "specific.yml", r###"
name: chrome name: chrome
filter_class: "Chrome" filter_class: "Chrome"
"###); "###);
@ -386,10 +383,11 @@ mod tests {
assert_eq!(config_manager.calculate_active_config().name, "chrome"); assert_eq!(config_manager.calculate_active_config().name, "chrome");
} }
#[test]
fn test_runtime_calculate_active_config_specific_exec_match() { fn test_runtime_calculate_active_config_specific_exec_match() {
let (data_dir, package_dir) = create_temp_espanso_directories(); let (data_dir, package_dir) = create_temp_espanso_directories();
let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" create_user_config_file(&data_dir.path(), "specific.yml", r###"
name: chrome name: chrome
filter_exec: "chrome.exe" filter_exec: "chrome.exe"
"###); "###);
@ -404,10 +402,11 @@ mod tests {
assert_eq!(config_manager.calculate_active_config().name, "chrome"); assert_eq!(config_manager.calculate_active_config().name, "chrome");
} }
#[test]
fn test_runtime_calculate_active_config_specific_multi_filter_match() { fn test_runtime_calculate_active_config_specific_multi_filter_match() {
let (data_dir, package_dir) = create_temp_espanso_directories(); let (data_dir, package_dir) = create_temp_espanso_directories();
let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" create_user_config_file(&data_dir.path(), "specific.yml", r###"
name: chrome name: chrome
filter_class: Browser filter_class: Browser
filter_exec: "firefox.exe" filter_exec: "firefox.exe"
@ -427,7 +426,7 @@ mod tests {
fn test_runtime_calculate_active_config_no_match() { fn test_runtime_calculate_active_config_no_match() {
let (data_dir, package_dir) = create_temp_espanso_directories(); let (data_dir, package_dir) = create_temp_espanso_directories();
let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" create_user_config_file(&data_dir.path(), "specific.yml", r###"
name: firefox name: firefox
filter_title: "Firefox" filter_title: "Firefox"
"###); "###);
@ -446,7 +445,7 @@ mod tests {
fn test_runtime_active_config_cache() { fn test_runtime_active_config_cache() {
let (data_dir, package_dir) = create_temp_espanso_directories(); let (data_dir, package_dir) = create_temp_espanso_directories();
let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" create_user_config_file(&data_dir.path(), "specific.yml", r###"
name: firefox name: firefox
filter_title: "Firefox" filter_title: "Firefox"
"###); "###);

View File

@ -23,9 +23,8 @@ use crate::event::*;
use crate::event::KeyModifier::*; use crate::event::KeyModifier::*;
use crate::bridge::linux::*; use crate::bridge::linux::*;
use std::process::exit; use std::process::exit;
use log::{debug, error, info}; use log::{debug, error};
use std::ffi::CStr; use std::ffi::CStr;
use std::{thread, time};
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::Ordering::Acquire; use std::sync::atomic::Ordering::Acquire;
@ -38,7 +37,7 @@ pub struct LinuxContext {
} }
impl LinuxContext { impl LinuxContext {
pub fn new(config: Configs, send_channel: Sender<Event>, is_injecting: Arc<AtomicBool>) -> Box<LinuxContext> { pub fn new(_: Configs, send_channel: Sender<Event>, is_injecting: Arc<AtomicBool>) -> Box<LinuxContext> {
// Check if the X11 context is available // Check if the X11 context is available
let x11_available = unsafe { let x11_available = unsafe {
check_x11() check_x11()
@ -86,7 +85,7 @@ impl Drop for LinuxContext {
// Native bridge code // Native bridge code
extern fn keypress_callback(_self: *mut c_void, raw_buffer: *const u8, len: i32, extern fn keypress_callback(_self: *mut c_void, raw_buffer: *const u8, _len: i32,
event_type: i32, key_code: i32) { event_type: i32, key_code: i32) {
unsafe { unsafe {
let _self = _self as *mut LinuxContext; let _self = _self as *mut LinuxContext;
@ -101,7 +100,7 @@ extern fn keypress_callback(_self: *mut c_void, raw_buffer: *const u8, len: i32,
if event_type == 0 { // Char event if event_type == 0 { // Char event
// Convert the received buffer to a string // Convert the received buffer to a string
let c_str = CStr::from_ptr(raw_buffer as (*const c_char)); let c_str = CStr::from_ptr(raw_buffer as *const c_char);
let char_str = c_str.to_str(); let char_str = c_str.to_str();
// Send the char through the channel // Send the char through the channel

View File

@ -17,7 +17,7 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
use crate::matcher::{Match, MatchReceiver, MatchContentType}; use crate::matcher::{Match, MatchReceiver};
use crate::keyboard::KeyboardManager; use crate::keyboard::KeyboardManager;
use crate::config::ConfigManager; use crate::config::ConfigManager;
use crate::config::BackendType; use crate::config::BackendType;
@ -25,17 +25,13 @@ use crate::clipboard::ClipboardManager;
use log::{info, warn, debug, error}; use log::{info, warn, debug, error};
use crate::ui::{UIManager, MenuItem, MenuItemType}; use crate::ui::{UIManager, MenuItem, MenuItemType};
use crate::event::{ActionEventReceiver, ActionType, SystemEventReceiver, SystemEvent}; use crate::event::{ActionEventReceiver, ActionType, SystemEventReceiver, SystemEvent};
use crate::extension::Extension;
use crate::render::{Renderer, RenderResult}; use crate::render::{Renderer, RenderResult};
use std::cell::RefCell; use std::cell::RefCell;
use std::process::exit; use std::process::exit;
use std::collections::HashMap; use regex::{Regex};
use std::path::PathBuf;
use regex::{Regex, Captures};
use std::time::SystemTime;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::{Relaxed, Release, Acquire, AcqRel, SeqCst}; use std::sync::atomic::Ordering::Release;
pub struct Engine<'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, pub struct Engine<'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>,
U: UIManager, R: Renderer> { U: UIManager, R: Renderer> {
@ -47,7 +43,6 @@ pub struct Engine<'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<
is_injecting: Arc<AtomicBool>, is_injecting: Arc<AtomicBool>,
enabled: RefCell<bool>, enabled: RefCell<bool>,
last_action_time: RefCell<SystemTime>, // Used to block espanso from re-interpreting it's own inputs
} }
impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIManager, R: Renderer> impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIManager, R: Renderer>
@ -56,7 +51,6 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa
config_manager: &'a M, ui_manager: &'a U, config_manager: &'a M, ui_manager: &'a U,
renderer: &'a R, is_injecting: Arc<AtomicBool>) -> Engine<'a, S, C, M, U, R> { renderer: &'a R, is_injecting: Arc<AtomicBool>) -> Engine<'a, S, C, M, U, R> {
let enabled = RefCell::new(true); let enabled = RefCell::new(true);
let last_action_time = RefCell::new(SystemTime::now());
Engine{keyboard_manager, Engine{keyboard_manager,
clipboard_manager, clipboard_manager,
@ -65,7 +59,6 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa
renderer, renderer,
is_injecting, is_injecting,
enabled, enabled,
last_action_time,
} }
} }
@ -111,20 +104,6 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa
None None
} }
} }
/// Used to check if the last action has been executed within a specified interval.
/// If so, return true (blocking the action), otherwise false.
fn check_last_action_and_set(&self, interval: u128) -> bool {
let mut last_action_time = self.last_action_time.borrow_mut();
if let Ok(elapsed) = last_action_time.elapsed() {
if elapsed.as_millis() < interval {
return true;
}
}
(*last_action_time) = SystemTime::now();
return false;
}
} }
lazy_static! { lazy_static! {

View File

@ -21,6 +21,7 @@ pub(crate) mod manager;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
#[allow(dead_code)]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Event { pub enum Event {
Action(ActionType), Action(ActionType),
@ -58,7 +59,7 @@ pub enum KeyEvent {
Other Other
} }
#[warn(non_camel_case_types)] #[allow(non_camel_case_types)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum KeyModifier { pub enum KeyModifier {
CTRL, CTRL,
@ -133,6 +134,7 @@ impl KeyModifier {
} }
} }
#[allow(dead_code)]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum SystemEvent { pub enum SystemEvent {
// MacOS specific // MacOS specific

View File

@ -17,7 +17,7 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
use serde_yaml::{Mapping, Value}; use serde_yaml::{Mapping};
use crate::clipboard::ClipboardManager; use crate::clipboard::ClipboardManager;
pub struct ClipboardExtension { pub struct ClipboardExtension {
@ -37,7 +37,7 @@ impl super::Extension for ClipboardExtension {
String::from("clipboard") String::from("clipboard")
} }
fn calculate(&self, params: &Mapping, _: &Vec<String>) -> Option<String> { fn calculate(&self, _: &Mapping, _: &Vec<String>) -> Option<String> {
self.clipboard_manager.get_clipboard() self.clipboard_manager.get_clipboard()
} }
} }

View File

@ -17,7 +17,7 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
use serde::{Serialize, Deserialize, Deserializer}; use serde::{Serialize, Deserialize};
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
mod windows; mod windows;

View File

@ -20,32 +20,32 @@
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
use std::thread;
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};
use std::io::{BufRead, BufReader};
use std::process::exit; use std::process::exit;
use std::sync::{mpsc, Arc}; use std::sync::{Arc, mpsc};
use std::sync::atomic::AtomicBool;
use std::sync::mpsc::Receiver; use std::sync::mpsc::Receiver;
use std::thread;
use std::time::Duration; use std::time::Duration;
use clap::{App, Arg, SubCommand, ArgMatches}; use clap::{App, Arg, ArgMatches, SubCommand};
use fs2::FileExt; use fs2::FileExt;
use log::{info, warn, LevelFilter}; use log::{info, LevelFilter, warn};
use simplelog::{CombinedLogger, SharedLogger, TerminalMode, TermLogger, WriteLogger}; use simplelog::{CombinedLogger, SharedLogger, TerminalMode, TermLogger, WriteLogger};
use crate::config::{ConfigSet, ConfigManager}; use crate::config::{ConfigManager, ConfigSet};
use crate::config::runtime::RuntimeConfigManager; use crate::config::runtime::RuntimeConfigManager;
use crate::engine::Engine; use crate::engine::Engine;
use crate::event::*; use crate::event::*;
use crate::event::manager::{DefaultEventManager, EventManager}; use crate::event::manager::{DefaultEventManager, EventManager};
use crate::matcher::scrolling::ScrollingMatcher; use crate::matcher::scrolling::ScrollingMatcher;
use crate::package::{InstallResult, PackageManager, RemoveResult, UpdateResult};
use crate::package::default::DefaultPackageManager;
use crate::package::zip::ZipPackageResolver;
use crate::protocol::*;
use crate::system::SystemManager; use crate::system::SystemManager;
use crate::ui::UIManager; use crate::ui::UIManager;
use crate::protocol::*;
use std::io::{BufReader, BufRead};
use crate::package::default::DefaultPackageManager;
use crate::package::{PackageManager, InstallResult, UpdateResult, RemoveResult, PackageResolver};
use std::sync::atomic::AtomicBool;
use crate::package::zip::ZipPackageResolver;
mod ui; mod ui;
mod edit; mod edit;
@ -445,7 +445,7 @@ fn start_daemon(config_set: ConfigSet) {
// If Systemd is not available in the system, espanso should default to unmanaged mode // If Systemd is not available in the system, espanso should default to unmanaged mode
// See issue https://github.com/federico-terzi/espanso/issues/139 // See issue https://github.com/federico-terzi/espanso/issues/139
let force_unmanaged = if let Err(status) = status { let force_unmanaged = if let Err(_) = status {
true true
} else { } else {
false false
@ -993,7 +993,7 @@ fn edit_main(matches: &ArgMatches) {
if should_reload { if should_reload {
// Load the configuration // Load the configuration
let mut config_set = ConfigSet::load_default().unwrap_or_else(|e| { let config_set = ConfigSet::load_default().unwrap_or_else(|e| {
eprintln!("{}", e); eprintln!("{}", e);
eprintln!("Unable to reload espanso due to previous configuration error."); eprintln!("Unable to reload espanso due to previous configuration error.");
exit(1); exit(1);

View File

@ -90,7 +90,7 @@ impl<'a> From<&'a AutoMatch> for Match{
if other.propagate_case { if other.propagate_case {
// List with first letter capitalized // List with first letter capitalized
let first_capitalized : Vec<String> = triggers.iter().map(|trigger| { let first_capitalized : Vec<String> = triggers.iter().map(|trigger| {
let mut capitalized = trigger.clone(); let capitalized = trigger.clone();
let mut v: Vec<char> = capitalized.chars().collect(); let mut v: Vec<char> = capitalized.chars().collect();
v[0] = v[0].to_uppercase().nth(0).unwrap(); v[0] = v[0].to_uppercase().nth(0).unwrap();
v.into_iter().collect() v.into_iter().collect()

View File

@ -18,7 +18,7 @@
*/ */
use crate::matcher::{Match, MatchReceiver, TriggerEntry}; use crate::matcher::{Match, MatchReceiver, TriggerEntry};
use std::cell::{RefCell, Ref}; use std::cell::{RefCell};
use crate::event::{KeyModifier, ActionEventReceiver, ActionType}; use crate::event::{KeyModifier, ActionEventReceiver, ActionType};
use crate::config::ConfigManager; use crate::config::ConfigManager;
use crate::event::KeyModifier::BACKSPACE; use crate::event::KeyModifier::BACKSPACE;

View File

@ -26,7 +26,6 @@ use std::time::{SystemTime, UNIX_EPOCH};
use crate::package::UpdateResult::{NotOutdated, Updated}; use crate::package::UpdateResult::{NotOutdated, Updated};
use crate::package::InstallResult::{NotFoundInIndex, AlreadyInstalled, BlockedExternalPackage}; use crate::package::InstallResult::{NotFoundInIndex, AlreadyInstalled, BlockedExternalPackage};
use std::fs; use std::fs;
use tempfile::TempDir;
use regex::Regex; use regex::Regex;
use crate::package::RemoveResult::Removed; use crate::package::RemoveResult::Removed;
use std::collections::HashMap; use std::collections::HashMap;
@ -335,7 +334,6 @@ mod tests {
use crate::package::PackageManager; use crate::package::PackageManager;
use std::fs::{create_dir, create_dir_all}; use std::fs::{create_dir, create_dir_all};
use crate::package::InstallResult::*; use crate::package::InstallResult::*;
use std::io::Write;
use crate::package::zip::ZipPackageResolver; use crate::package::zip::ZipPackageResolver;
const OUTDATED_INDEX_CONTENT : &str = include_str!("../res/test/outdated_index.json"); const OUTDATED_INDEX_CONTENT : &str = include_str!("../res/test/outdated_index.json");
@ -370,7 +368,7 @@ mod tests {
#[test] #[test]
fn test_download_index() { fn test_download_index() {
let temp = create_temp_package_manager(|_, _| {}); create_temp_package_manager(|_, _| {});
let index = DefaultPackageManager::request_index(); let index = DefaultPackageManager::request_index();
assert!(index.is_ok()); assert!(index.is_ok());
@ -381,7 +379,7 @@ mod tests {
fn test_outdated_index() { fn test_outdated_index() {
let temp = create_temp_package_manager(|_, data_dir| { let temp = create_temp_package_manager(|_, data_dir| {
let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE);
std::fs::write(index_file, OUTDATED_INDEX_CONTENT); std::fs::write(index_file, OUTDATED_INDEX_CONTENT).unwrap();
}); });
assert!(temp.package_manager.is_index_outdated()); assert!(temp.package_manager.is_index_outdated());
@ -394,7 +392,7 @@ mod tests {
let current_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time went backwards"); let current_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time went backwards");
let current_timestamp = current_time.as_secs(); let current_timestamp = current_time.as_secs();
let new_contents = INDEX_CONTENT_WITHOUT_UPDATE.replace("XXXX", &format!("{}", current_timestamp)); let new_contents = INDEX_CONTENT_WITHOUT_UPDATE.replace("XXXX", &format!("{}", current_timestamp));
std::fs::write(index_file, new_contents); std::fs::write(index_file, new_contents).unwrap();
}); });
assert_eq!(temp.package_manager.update_index(false).unwrap(), UpdateResult::NotOutdated); assert_eq!(temp.package_manager.update_index(false).unwrap(), UpdateResult::NotOutdated);
@ -407,7 +405,7 @@ mod tests {
let current_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time went backwards"); let current_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time went backwards");
let current_timestamp = current_time.as_secs(); let current_timestamp = current_time.as_secs();
let new_contents = INDEX_CONTENT_WITHOUT_UPDATE.replace("XXXX", &format!("{}", current_timestamp)); let new_contents = INDEX_CONTENT_WITHOUT_UPDATE.replace("XXXX", &format!("{}", current_timestamp));
std::fs::write(index_file, new_contents); std::fs::write(index_file, new_contents).unwrap();
}); });
assert_eq!(temp.package_manager.update_index(true).unwrap(), UpdateResult::Updated); assert_eq!(temp.package_manager.update_index(true).unwrap(), UpdateResult::Updated);
@ -417,7 +415,7 @@ mod tests {
fn test_outdated_index_should_be_updated() { fn test_outdated_index_should_be_updated() {
let mut temp = create_temp_package_manager(|_, data_dir| { let mut temp = create_temp_package_manager(|_, data_dir| {
let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE);
std::fs::write(index_file, OUTDATED_INDEX_CONTENT); std::fs::write(index_file, OUTDATED_INDEX_CONTENT).unwrap();
}); });
assert_eq!(temp.package_manager.update_index(false).unwrap(), UpdateResult::Updated); assert_eq!(temp.package_manager.update_index(false).unwrap(), UpdateResult::Updated);
@ -433,9 +431,9 @@ mod tests {
#[test] #[test]
fn test_get_package_should_be_found() { fn test_get_package_should_be_found() {
let mut temp = create_temp_package_manager(|_, data_dir| { let temp = create_temp_package_manager(|_, data_dir| {
let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE);
std::fs::write(index_file, GET_PACKAGE_INDEX); std::fs::write(index_file, GET_PACKAGE_INDEX).unwrap();
}); });
assert_eq!(temp.package_manager.get_package("italian-accents").unwrap().title, "Italian Accents"); assert_eq!(temp.package_manager.get_package("italian-accents").unwrap().title, "Italian Accents");
@ -443,9 +441,9 @@ mod tests {
#[test] #[test]
fn test_get_package_should_not_be_found() { fn test_get_package_should_not_be_found() {
let mut temp = create_temp_package_manager(|_, data_dir| { let temp = create_temp_package_manager(|_, data_dir| {
let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE);
std::fs::write(index_file, GET_PACKAGE_INDEX); std::fs::write(index_file, GET_PACKAGE_INDEX).unwrap();
}); });
assert!(temp.package_manager.get_package("not-existing").is_none()); assert!(temp.package_manager.get_package("not-existing").is_none());
@ -453,10 +451,10 @@ mod tests {
#[test] #[test]
fn test_list_local_packages_names() { fn test_list_local_packages_names() {
let mut temp = create_temp_package_manager(|package_dir, _| { let temp = create_temp_package_manager(|package_dir, _| {
create_dir(package_dir.join("package-1")); create_dir(package_dir.join("package-1")).unwrap();
create_dir(package_dir.join("package2")); create_dir(package_dir.join("package2")).unwrap();
std::fs::write(package_dir.join("dummyfile.txt"), "test"); std::fs::write(package_dir.join("dummyfile.txt"), "test").unwrap();
}); });
let packages = temp.package_manager.list_local_packages_names(); let packages = temp.package_manager.list_local_packages_names();
@ -467,9 +465,9 @@ mod tests {
#[test] #[test]
fn test_install_package_not_found() { fn test_install_package_not_found() {
let mut temp = create_temp_package_manager(|package_dir, data_dir| { let temp = create_temp_package_manager(|_, data_dir| {
let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE);
std::fs::write(index_file, INSTALL_PACKAGE_INDEX); std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap();
}); });
assert_eq!(temp.package_manager.install_package("doesnotexist", false).unwrap(), NotFoundInIndex); assert_eq!(temp.package_manager.install_package("doesnotexist", false).unwrap(), NotFoundInIndex);
@ -477,10 +475,10 @@ mod tests {
#[test] #[test]
fn test_install_package_already_installed() { fn test_install_package_already_installed() {
let mut temp = create_temp_package_manager(|package_dir, data_dir| { let temp = create_temp_package_manager(|package_dir, data_dir| {
create_dir(package_dir.join("italian-accents")); create_dir(package_dir.join("italian-accents")).unwrap();
let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE);
std::fs::write(index_file, INSTALL_PACKAGE_INDEX); std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap();
}); });
assert_eq!(temp.package_manager.install_package("italian-accents", false).unwrap(), AlreadyInstalled); assert_eq!(temp.package_manager.install_package("italian-accents", false).unwrap(), AlreadyInstalled);
@ -488,9 +486,9 @@ mod tests {
#[test] #[test]
fn test_install_package() { fn test_install_package() {
let mut temp = create_temp_package_manager(|_, data_dir| { let temp = create_temp_package_manager(|_, data_dir| {
let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE);
std::fs::write(index_file, INSTALL_PACKAGE_INDEX); std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap();
}); });
assert_eq!(temp.package_manager.install_package("dummy-package", false).unwrap(), Installed); assert_eq!(temp.package_manager.install_package("dummy-package", false).unwrap(), Installed);
@ -501,9 +499,9 @@ mod tests {
#[test] #[test]
fn test_install_package_does_not_exist_in_repo() { fn test_install_package_does_not_exist_in_repo() {
let mut temp = create_temp_package_manager(|_, data_dir| { let temp = create_temp_package_manager(|_, data_dir| {
let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE);
std::fs::write(index_file, INSTALL_PACKAGE_INDEX); std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap();
}); });
assert_eq!(temp.package_manager.install_package("not-existing", false).unwrap(), NotFoundInRepo); assert_eq!(temp.package_manager.install_package("not-existing", false).unwrap(), NotFoundInRepo);
@ -511,9 +509,9 @@ mod tests {
#[test] #[test]
fn test_install_package_missing_version() { fn test_install_package_missing_version() {
let mut temp = create_temp_package_manager(|_, data_dir| { let temp = create_temp_package_manager(|_, data_dir| {
let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE);
std::fs::write(index_file, INSTALL_PACKAGE_INDEX); std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap();
}); });
assert_eq!(temp.package_manager.install_package("dummy-package2", false).unwrap(), MissingPackageVersion); assert_eq!(temp.package_manager.install_package("dummy-package2", false).unwrap(), MissingPackageVersion);
@ -521,9 +519,9 @@ mod tests {
#[test] #[test]
fn test_install_package_missing_readme_unable_to_parse_package_info() { fn test_install_package_missing_readme_unable_to_parse_package_info() {
let mut temp = create_temp_package_manager(|_, data_dir| { let temp = create_temp_package_manager(|_, data_dir| {
let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE);
std::fs::write(index_file, INSTALL_PACKAGE_INDEX); std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap();
}); });
assert_eq!(temp.package_manager.install_package("dummy-package3", false).unwrap(), UnableToParsePackageInfo); assert_eq!(temp.package_manager.install_package("dummy-package3", false).unwrap(), UnableToParsePackageInfo);
@ -531,9 +529,9 @@ mod tests {
#[test] #[test]
fn test_install_package_bad_readme_unable_to_parse_package_info() { fn test_install_package_bad_readme_unable_to_parse_package_info() {
let mut temp = create_temp_package_manager(|_, data_dir| { let temp = create_temp_package_manager(|_, data_dir| {
let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE);
std::fs::write(index_file, INSTALL_PACKAGE_INDEX); std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap();
}); });
assert_eq!(temp.package_manager.install_package("dummy-package4", false).unwrap(), UnableToParsePackageInfo); assert_eq!(temp.package_manager.install_package("dummy-package4", false).unwrap(), UnableToParsePackageInfo);
@ -541,9 +539,9 @@ mod tests {
#[test] #[test]
fn test_list_local_packages() { fn test_list_local_packages() {
let mut temp = create_temp_package_manager(|_, data_dir| { let temp = create_temp_package_manager(|_, data_dir| {
let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE);
std::fs::write(index_file, INSTALL_PACKAGE_INDEX); std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap();
}); });
assert_eq!(temp.package_manager.install_package("dummy-package", false).unwrap(), Installed); assert_eq!(temp.package_manager.install_package("dummy-package", false).unwrap(), Installed);
@ -558,11 +556,11 @@ mod tests {
#[test] #[test]
fn test_remove_package() { fn test_remove_package() {
let mut temp = create_temp_package_manager(|package_dir, _| { let temp = create_temp_package_manager(|package_dir, _| {
let dummy_package_dir = package_dir.join("dummy-package"); let dummy_package_dir = package_dir.join("dummy-package");
create_dir_all(&dummy_package_dir); create_dir_all(&dummy_package_dir).unwrap();
std::fs::write(dummy_package_dir.join("README.md"), "readme"); std::fs::write(dummy_package_dir.join("README.md"), "readme").unwrap();
std::fs::write(dummy_package_dir.join("package.yml"), "name: package"); std::fs::write(dummy_package_dir.join("package.yml"), "name: package").unwrap();
}); });
assert!(temp.package_dir.path().join("dummy-package").exists()); assert!(temp.package_dir.path().join("dummy-package").exists());
@ -576,7 +574,7 @@ mod tests {
#[test] #[test]
fn test_remove_package_not_found() { fn test_remove_package_not_found() {
let mut temp = create_temp_package_manager(|_, _| {}); let temp = create_temp_package_manager(|_, _| {});
assert_eq!(temp.package_manager.remove_package("not-existing").unwrap(), RemoveResult::NotFound); assert_eq!(temp.package_manager.remove_package("not-existing").unwrap(), RemoveResult::NotFound);
} }
@ -594,7 +592,7 @@ mod tests {
package_repo: "https://github.com/federico-terzi/espanso-hub-core" package_repo: "https://github.com/federico-terzi/espanso-hub-core"
is_core: true is_core: true
--- ---
"###); "###).unwrap();
let package = DefaultPackageManager::parse_package_from_readme(file.path()).unwrap(); let package = DefaultPackageManager::parse_package_from_readme(file.path()).unwrap();
@ -626,7 +624,7 @@ mod tests {
is_core: true is_core: true
--- ---
Readme text Readme text
"###); "###).unwrap();
let package = DefaultPackageManager::parse_package_from_readme(file.path()).unwrap(); let package = DefaultPackageManager::parse_package_from_readme(file.path()).unwrap();

View File

@ -1,9 +1,7 @@
use tempfile::TempDir; use tempfile::TempDir;
use std::error::Error; use std::error::Error;
use super::PackageResolver; use std::io::{Cursor, copy};
use std::io::{Cursor, copy, Read};
use std::{fs, io}; use std::{fs, io};
use std::fs::File;
use log::debug; use log::debug;
pub struct ZipPackageResolver; pub struct ZipPackageResolver;
@ -33,7 +31,7 @@ impl super::PackageResolver for ZipPackageResolver {
// Find the root folder name // Find the root folder name
let mut root_folder = { let mut root_folder = {
let mut root_folder = archive.by_index(0).unwrap(); let root_folder = archive.by_index(0).unwrap();
let root_folder = root_folder.sanitized_name(); let root_folder = root_folder.sanitized_name();
root_folder.to_str().unwrap().to_owned() root_folder.to_str().unwrap().to_owned()
}; };
@ -77,7 +75,7 @@ impl super::PackageResolver for ZipPackageResolver {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use tempfile::{TempDir, NamedTempFile}; use super::super::PackageResolver;
#[test] #[test]
fn test_clone_temp_repository() { fn test_clone_temp_repository() {

View File

@ -17,8 +17,7 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
use serde_yaml::{Mapping, Value}; use serde_yaml::{Value};
use std::path::PathBuf;
use std::collections::HashMap; use std::collections::HashMap;
use regex::{Regex, Captures}; use regex::{Regex, Captures};
use log::{warn, error}; use log::{warn, error};
@ -50,7 +49,7 @@ impl DefaultRenderer {
// Compile the regexes // Compile the regexes
let passive_match_regex = Regex::new(&config.passive_match_regex) let passive_match_regex = Regex::new(&config.passive_match_regex)
.unwrap_or_else(|e| { .unwrap_or_else(|e| {
panic!("Invalid passive match regex"); panic!("Invalid passive match regex: {:?}", e);
}); });
DefaultRenderer{ DefaultRenderer{

View File

@ -108,9 +108,9 @@ const LINUX_SERVICE_CONTENT : &str = include_str!("res/linux/systemd.service");
const LINUX_SERVICE_FILENAME : &str = "espanso.service"; const LINUX_SERVICE_FILENAME : &str = "espanso.service";
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
pub fn register(config_set: ConfigSet) { pub fn register(_: ConfigSet) {
use std::fs::create_dir_all; use std::fs::create_dir_all;
use std::process::{Command, ExitStatus}; use std::process::{Command};
// Check if espanso service is already registered // Check if espanso service is already registered
let res = Command::new("systemctl") let res = Command::new("systemctl")
@ -191,7 +191,7 @@ pub enum VerifyResult {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
pub fn verify() -> VerifyResult { pub fn verify() -> VerifyResult {
use regex::Regex; use regex::Regex;
use std::process::{Command, ExitStatus}; use std::process::{Command};
// Check if espanso service is already registered // Check if espanso service is already registered
let res = Command::new("systemctl") let res = Command::new("systemctl")
@ -206,7 +206,7 @@ pub fn verify() -> VerifyResult {
} }
lazy_static! { lazy_static! {
static ref ExecPathRegex: Regex = Regex::new("ExecStart=(?P<path>.*?)\\s").unwrap(); static ref EXEC_PATH_REGEX: Regex = Regex::new("ExecStart=(?P<path>.*?)\\s").unwrap();
} }
// Check if the currently registered path is valid // Check if the currently registered path is valid
@ -217,7 +217,7 @@ pub fn verify() -> VerifyResult {
let output = String::from_utf8_lossy(res.stdout.as_slice()); let output = String::from_utf8_lossy(res.stdout.as_slice());
let output = output.trim(); let output = output.trim();
if res.status.success() { if res.status.success() {
let caps = ExecPathRegex.captures(output).unwrap(); let caps = EXEC_PATH_REGEX.captures(output).unwrap();
let path = caps.get(1).map_or("", |m| m.as_str()); let path = caps.get(1).map_or("", |m| m.as_str());
let espanso_path = std::env::current_exe().expect("Could not get espanso executable path"); let espanso_path = std::env::current_exe().expect("Could not get espanso executable path");
@ -231,13 +231,13 @@ pub fn verify() -> VerifyResult {
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
pub fn unregister(config_set: ConfigSet) { pub fn unregister(_: ConfigSet) {
use std::process::{Command, ExitStatus}; use std::process::{Command};
// Disable the service first // Disable the service first
let res = Command::new("systemctl") Command::new("systemctl")
.args(&["--user", "disable", "espanso"]) .args(&["--user", "disable", "espanso"])
.status(); .status().expect("Unable to invoke systemctl");
// Then delete the espanso.service entry // Then delete the espanso.service entry
let config_dir = dirs::config_dir().expect("Could not get configuration directory"); let config_dir = dirs::config_dir().expect("Could not get configuration directory");

View File

@ -51,14 +51,14 @@ mod tests {
let dest_tmp_dir = TempDir::new().expect("Error creating temp directory"); let dest_tmp_dir = TempDir::new().expect("Error creating temp directory");
let source_dir = source_tmp_dir.path().join("source"); let source_dir = source_tmp_dir.path().join("source");
create_dir(&source_dir); create_dir(&source_dir).unwrap();
std::fs::write(source_dir.join("file1.txt"), "file1"); std::fs::write(source_dir.join("file1.txt"), "file1").unwrap();
std::fs::write(source_dir.join("file2.txt"), "file2"); std::fs::write(source_dir.join("file2.txt"), "file2").unwrap();
let target_dir = dest_tmp_dir.path().join("source"); let target_dir = dest_tmp_dir.path().join("source");
create_dir(&target_dir); create_dir(&target_dir).unwrap();
copy_dir(&source_dir, &target_dir); copy_dir(&source_dir, &target_dir).unwrap();
assert!(dest_tmp_dir.path().join("source").exists()); assert!(dest_tmp_dir.path().join("source").exists());
assert!(dest_tmp_dir.path().join("source/file1.txt").exists()); assert!(dest_tmp_dir.path().join("source/file1.txt").exists());
@ -71,17 +71,17 @@ mod tests {
let dest_tmp_dir = TempDir::new().expect("Error creating temp directory"); let dest_tmp_dir = TempDir::new().expect("Error creating temp directory");
let source_dir = source_tmp_dir.path().join("source"); let source_dir = source_tmp_dir.path().join("source");
create_dir(&source_dir); create_dir(&source_dir).unwrap();
std::fs::write(source_dir.join("file1.txt"), "file1"); std::fs::write(source_dir.join("file1.txt"), "file1").unwrap();
std::fs::write(source_dir.join("file2.txt"), "file2"); std::fs::write(source_dir.join("file2.txt"), "file2").unwrap();
let nested_dir = source_dir.join("nested"); let nested_dir = source_dir.join("nested");
create_dir(&nested_dir); create_dir(&nested_dir).unwrap();
std::fs::write(nested_dir.join("nestedfile.txt"), "nestedfile1"); std::fs::write(nested_dir.join("nestedfile.txt"), "nestedfile1").unwrap();
let target_dir = dest_tmp_dir.path().join("source"); let target_dir = dest_tmp_dir.path().join("source");
create_dir(&target_dir); create_dir(&target_dir).unwrap();
copy_dir(&source_dir, &target_dir); copy_dir(&source_dir, &target_dir).unwrap();
assert!(dest_tmp_dir.path().join("source").exists()); assert!(dest_tmp_dir.path().join("source").exists());
assert!(dest_tmp_dir.path().join("source/file1.txt").exists()); assert!(dest_tmp_dir.path().join("source/file1.txt").exists());