feat(config): add inject_delay and key_delay options
This commit is contained in:
parent
0829816bac
commit
9efc7cfa0a
|
@ -83,6 +83,14 @@ pub trait Config: Send {
|
|||
// the expansion content.
|
||||
fn restore_clipboard_delay(&self) -> usize;
|
||||
|
||||
// Number of milliseconds between text injection events. Increase if the target
|
||||
// application is missing some characters.
|
||||
fn inject_delay(&self) -> Option<usize>;
|
||||
|
||||
// Number of milliseconds between key injection events. Increase if the target
|
||||
// application is missing some key events.
|
||||
fn key_delay(&self) -> Option<usize>;
|
||||
|
||||
fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@ pub(crate) struct ParsedConfig {
|
|||
pub pre_paste_delay: Option<usize>,
|
||||
pub restore_clipboard_delay: Option<usize>,
|
||||
pub paste_shortcut_event_delay: Option<usize>,
|
||||
pub inject_delay: Option<usize>,
|
||||
pub key_delay: Option<usize>,
|
||||
|
||||
|
||||
// Includes
|
||||
|
|
|
@ -60,6 +60,15 @@ pub(crate) struct YAMLConfig {
|
|||
#[serde(default)]
|
||||
pub disable_x11_fast_inject: Option<bool>,
|
||||
|
||||
#[serde(default)]
|
||||
pub inject_delay: Option<usize>,
|
||||
|
||||
#[serde(default)]
|
||||
pub key_delay: Option<usize>,
|
||||
|
||||
#[serde(default)]
|
||||
pub backspace_delay: Option<usize>,
|
||||
|
||||
// Include/Exclude
|
||||
#[serde(default)]
|
||||
pub includes: Option<Vec<String>>,
|
||||
|
@ -116,6 +125,8 @@ impl TryFrom<YAMLConfig> for ParsedConfig {
|
|||
preserve_clipboard: yaml_config.preserve_clipboard,
|
||||
paste_shortcut: yaml_config.paste_shortcut,
|
||||
disable_x11_fast_inject: yaml_config.disable_x11_fast_inject,
|
||||
inject_delay: yaml_config.inject_delay,
|
||||
key_delay: yaml_config.key_delay.or(yaml_config.backspace_delay),
|
||||
|
||||
pre_paste_delay: yaml_config.pre_paste_delay,
|
||||
restore_clipboard_delay: yaml_config.restore_clipboard_delay,
|
||||
|
@ -155,6 +166,9 @@ mod tests {
|
|||
paste_shortcut: CTRL+ALT+V
|
||||
paste_shortcut_event_delay: 10
|
||||
disable_x11_fast_inject: true
|
||||
inject_delay: 10
|
||||
key_delay: 20
|
||||
backspace_delay: 30
|
||||
|
||||
use_standard_includes: true
|
||||
includes: ["test1"]
|
||||
|
@ -184,6 +198,8 @@ mod tests {
|
|||
paste_shortcut: Some("CTRL+ALT+V".to_string()),
|
||||
paste_shortcut_event_delay: Some(10),
|
||||
disable_x11_fast_inject: Some(true),
|
||||
inject_delay: Some(10),
|
||||
key_delay: Some(20),
|
||||
|
||||
pre_paste_delay: Some(300),
|
||||
|
||||
|
|
|
@ -207,6 +207,14 @@ impl Config for ResolvedConfig {
|
|||
fn disable_x11_fast_inject(&self) -> bool {
|
||||
self.parsed.disable_x11_fast_inject.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn inject_delay(&self) -> Option<usize> {
|
||||
self.parsed.inject_delay
|
||||
}
|
||||
|
||||
fn key_delay(&self) -> Option<usize> {
|
||||
self.parsed.key_delay
|
||||
}
|
||||
}
|
||||
|
||||
impl ResolvedConfig {
|
||||
|
@ -273,6 +281,8 @@ impl ResolvedConfig {
|
|||
paste_shortcut_event_delay,
|
||||
disable_x11_fast_inject,
|
||||
toggle_key,
|
||||
inject_delay,
|
||||
key_delay,
|
||||
includes,
|
||||
excludes,
|
||||
extra_includes,
|
||||
|
|
|
@ -311,6 +311,22 @@ impl Config for LegacyInteropConfig {
|
|||
fn disable_x11_fast_inject(&self) -> bool {
|
||||
self.config.fast_inject
|
||||
}
|
||||
|
||||
fn inject_delay(&self) -> Option<usize> {
|
||||
if self.config.inject_delay == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(self.config.inject_delay.try_into().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
fn key_delay(&self) -> Option<usize> {
|
||||
if self.config.backspace_delay == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(self.config.backspace_delay.try_into().unwrap())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct LegacyMatchGroup {
|
||||
|
|
Loading…
Reference in New Issue
Block a user