feat(core): wire up options to delay injection after form/search gui
This commit is contained in:
parent
3abe84f8b0
commit
cbca79ab0f
|
@ -197,3 +197,15 @@ impl<'a> espanso_engine::process::EnabledStatusProvider for ConfigManager<'a> {
|
||||||
self.active().enable()
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -107,8 +107,10 @@ pub fn initialize_and_spawn(
|
||||||
let default_config = &*config_manager.default();
|
let default_config = &*config_manager.default();
|
||||||
|
|
||||||
let modulo_manager = crate::gui::modulo::manager::ModuloManager::new();
|
let modulo_manager = crate::gui::modulo::manager::ModuloManager::new();
|
||||||
let modulo_form_ui = crate::gui::modulo::form::ModuloFormUI::new(&modulo_manager);
|
let modulo_form_ui =
|
||||||
let modulo_search_ui = crate::gui::modulo::search::ModuloSearchUI::new(&modulo_manager);
|
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 modulo_text_ui = crate::gui::modulo::textview::ModuloTextUI::new(&modulo_manager);
|
||||||
|
|
||||||
let context: Box<dyn Context> = Box::new(super::context::DefaultContext::new(
|
let context: Box<dyn Context> = Box::new(super::context::DefaultContext::new(
|
||||||
|
|
|
@ -20,18 +20,30 @@
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::{json, Map, Value};
|
use serde_json::{json, Map, Value};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::convert::TryInto;
|
||||||
|
|
||||||
use crate::gui::{FormField, FormUI};
|
use crate::gui::{FormField, FormUI};
|
||||||
|
|
||||||
use super::manager::ModuloManager;
|
use super::manager::ModuloManager;
|
||||||
|
|
||||||
|
pub trait ModuloFormUIOptionProvider {
|
||||||
|
fn get_post_form_delay(&self) -> usize;
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ModuloFormUI<'a> {
|
pub struct ModuloFormUI<'a> {
|
||||||
manager: &'a ModuloManager,
|
manager: &'a ModuloManager,
|
||||||
|
option_provider: &'a dyn ModuloFormUIOptionProvider,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ModuloFormUI<'a> {
|
impl<'a> ModuloFormUI<'a> {
|
||||||
pub fn new(manager: &'a ModuloManager) -> Self {
|
pub fn new(
|
||||||
Self { manager }
|
manager: &'a ModuloManager,
|
||||||
|
option_provider: &'a dyn ModuloFormUIOptionProvider,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
manager,
|
||||||
|
option_provider,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +64,7 @@ impl<'a> FormUI for ModuloFormUI<'a> {
|
||||||
.manager
|
.manager
|
||||||
.invoke(&["form", "-j", "-i", "-"], &json_config)?;
|
.invoke(&["form", "-j", "-i", "-"], &json_config)?;
|
||||||
let json: Result<HashMap<String, String>, _> = serde_json::from_str(&output);
|
let json: Result<HashMap<String, String>, _> = serde_json::from_str(&output);
|
||||||
match json {
|
let result = match json {
|
||||||
Ok(json) => {
|
Ok(json) => {
|
||||||
if json.is_empty() {
|
if json.is_empty() {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
@ -61,7 +73,16 @@ impl<'a> FormUI for ModuloFormUI<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(error) => Err(error.into()),
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,19 +19,30 @@
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::collections::HashMap;
|
use std::{collections::HashMap, convert::TryInto};
|
||||||
|
|
||||||
use crate::gui::{SearchItem, SearchUI};
|
use crate::gui::{SearchItem, SearchUI};
|
||||||
|
|
||||||
use super::manager::ModuloManager;
|
use super::manager::ModuloManager;
|
||||||
|
|
||||||
|
pub trait ModuloSearchUIOptionProvider {
|
||||||
|
fn get_post_search_delay(&self) -> usize;
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ModuloSearchUI<'a> {
|
pub struct ModuloSearchUI<'a> {
|
||||||
manager: &'a ModuloManager,
|
manager: &'a ModuloManager,
|
||||||
|
option_provider: &'a dyn ModuloSearchUIOptionProvider,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ModuloSearchUI<'a> {
|
impl<'a> ModuloSearchUI<'a> {
|
||||||
pub fn new(manager: &'a ModuloManager) -> Self {
|
pub fn new(
|
||||||
Self { manager }
|
manager: &'a ModuloManager,
|
||||||
|
option_provider: &'a dyn ModuloSearchUIOptionProvider,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
manager,
|
||||||
|
option_provider,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +59,7 @@ impl<'a> SearchUI for ModuloSearchUI<'a> {
|
||||||
.manager
|
.manager
|
||||||
.invoke(&["search", "-j", "-i", "-"], &json_config)?;
|
.invoke(&["search", "-j", "-i", "-"], &json_config)?;
|
||||||
let json: Result<HashMap<String, Value>, _> = serde_json::from_str(&output);
|
let json: Result<HashMap<String, Value>, _> = serde_json::from_str(&output);
|
||||||
match json {
|
let result = match json {
|
||||||
Ok(json) => {
|
Ok(json) => {
|
||||||
if let Some(Value::String(selected_id)) = json.get("selected") {
|
if let Some(Value::String(selected_id)) = json.get("selected") {
|
||||||
Ok(Some(selected_id.clone()))
|
Ok(Some(selected_id.clone()))
|
||||||
|
@ -57,7 +68,16 @@ impl<'a> SearchUI for ModuloSearchUI<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(error) => Err(error.into()),
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,8 @@ generate_patchable_config!(
|
||||||
backspace_limit -> usize,
|
backspace_limit -> usize,
|
||||||
apply_patch -> bool,
|
apply_patch -> bool,
|
||||||
undo_backspace -> bool,
|
undo_backspace -> bool,
|
||||||
|
post_form_delay -> usize,
|
||||||
|
post_search_delay -> usize,
|
||||||
win32_exclude_orphan_events -> bool,
|
win32_exclude_orphan_events -> bool,
|
||||||
win32_keyboard_layout_cache_interval -> i64,
|
win32_keyboard_layout_cache_interval -> i64,
|
||||||
x11_use_xclip_backend -> bool,
|
x11_use_xclip_backend -> bool,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user