diff --git a/espanso/src/cli/worker/config.rs b/espanso/src/cli/worker/config.rs index dd69176..7371ffc 100644 --- a/espanso/src/cli/worker/config.rs +++ b/espanso/src/cli/worker/config.rs @@ -197,3 +197,15 @@ impl<'a> espanso_engine::process::EnabledStatusProvider for ConfigManager<'a> { self.active().enable() } } + +impl<'a> crate::gui::modulo::form::ModuloFormUIOptionProvider for ConfigManager<'a> { + fn get_post_form_delay(&self) -> usize { + self.active().post_form_delay() + } +} + +impl<'a> crate::gui::modulo::search::ModuloSearchUIOptionProvider for ConfigManager<'a> { + fn get_post_search_delay(&self) -> usize { + self.active().post_search_delay() + } +} diff --git a/espanso/src/cli/worker/engine/mod.rs b/espanso/src/cli/worker/engine/mod.rs index 6e4ad71..d48269d 100644 --- a/espanso/src/cli/worker/engine/mod.rs +++ b/espanso/src/cli/worker/engine/mod.rs @@ -107,8 +107,10 @@ pub fn initialize_and_spawn( let default_config = &*config_manager.default(); let modulo_manager = crate::gui::modulo::manager::ModuloManager::new(); - let modulo_form_ui = crate::gui::modulo::form::ModuloFormUI::new(&modulo_manager); - let modulo_search_ui = crate::gui::modulo::search::ModuloSearchUI::new(&modulo_manager); + let modulo_form_ui = + crate::gui::modulo::form::ModuloFormUI::new(&modulo_manager, &config_manager); + let modulo_search_ui = + crate::gui::modulo::search::ModuloSearchUI::new(&modulo_manager, &config_manager); let modulo_text_ui = crate::gui::modulo::textview::ModuloTextUI::new(&modulo_manager); let context: Box = Box::new(super::context::DefaultContext::new( diff --git a/espanso/src/gui/modulo/form.rs b/espanso/src/gui/modulo/form.rs index 6c0f778..c483a13 100644 --- a/espanso/src/gui/modulo/form.rs +++ b/espanso/src/gui/modulo/form.rs @@ -20,18 +20,30 @@ use serde::Serialize; use serde_json::{json, Map, Value}; use std::collections::HashMap; +use std::convert::TryInto; use crate::gui::{FormField, FormUI}; use super::manager::ModuloManager; +pub trait ModuloFormUIOptionProvider { + fn get_post_form_delay(&self) -> usize; +} + pub struct ModuloFormUI<'a> { manager: &'a ModuloManager, + option_provider: &'a dyn ModuloFormUIOptionProvider, } impl<'a> ModuloFormUI<'a> { - pub fn new(manager: &'a ModuloManager) -> Self { - Self { manager } + pub fn new( + manager: &'a ModuloManager, + option_provider: &'a dyn ModuloFormUIOptionProvider, + ) -> Self { + Self { + manager, + option_provider, + } } } @@ -52,7 +64,7 @@ impl<'a> FormUI for ModuloFormUI<'a> { .manager .invoke(&["form", "-j", "-i", "-"], &json_config)?; let json: Result, _> = serde_json::from_str(&output); - match json { + let result = match json { Ok(json) => { if json.is_empty() { Ok(None) @@ -61,7 +73,16 @@ impl<'a> FormUI for ModuloFormUI<'a> { } } Err(error) => Err(error.into()), + }; + + let post_form_delay = self.option_provider.get_post_form_delay(); + if post_form_delay > 0 { + std::thread::sleep(std::time::Duration::from_millis( + post_form_delay.try_into().unwrap(), + )); } + + result } } diff --git a/espanso/src/gui/modulo/search.rs b/espanso/src/gui/modulo/search.rs index a55d525..d8d0bac 100644 --- a/espanso/src/gui/modulo/search.rs +++ b/espanso/src/gui/modulo/search.rs @@ -19,19 +19,30 @@ use serde::Serialize; use serde_json::Value; -use std::collections::HashMap; +use std::{collections::HashMap, convert::TryInto}; use crate::gui::{SearchItem, SearchUI}; use super::manager::ModuloManager; +pub trait ModuloSearchUIOptionProvider { + fn get_post_search_delay(&self) -> usize; +} + pub struct ModuloSearchUI<'a> { manager: &'a ModuloManager, + option_provider: &'a dyn ModuloSearchUIOptionProvider, } impl<'a> ModuloSearchUI<'a> { - pub fn new(manager: &'a ModuloManager) -> Self { - Self { manager } + pub fn new( + manager: &'a ModuloManager, + option_provider: &'a dyn ModuloSearchUIOptionProvider, + ) -> Self { + Self { + manager, + option_provider, + } } } @@ -48,7 +59,7 @@ impl<'a> SearchUI for ModuloSearchUI<'a> { .manager .invoke(&["search", "-j", "-i", "-"], &json_config)?; let json: Result, _> = serde_json::from_str(&output); - match json { + let result = match json { Ok(json) => { if let Some(Value::String(selected_id)) = json.get("selected") { Ok(Some(selected_id.clone())) @@ -57,7 +68,16 @@ impl<'a> SearchUI for ModuloSearchUI<'a> { } } Err(error) => Err(error.into()), + }; + + let post_search_delay = self.option_provider.get_post_search_delay(); + if post_search_delay > 0 { + std::thread::sleep(std::time::Duration::from_millis( + post_search_delay.try_into().unwrap(), + )); } + + result } } diff --git a/espanso/src/patch/patches/mod.rs b/espanso/src/patch/patches/mod.rs index e45567d..cd0a492 100644 --- a/espanso/src/patch/patches/mod.rs +++ b/espanso/src/patch/patches/mod.rs @@ -48,6 +48,8 @@ generate_patchable_config!( backspace_limit -> usize, apply_patch -> bool, undo_backspace -> bool, + post_form_delay -> usize, + post_search_delay -> usize, win32_exclude_orphan_events -> bool, win32_keyboard_layout_cache_interval -> i64, x11_use_xclip_backend -> bool,