feat(config): create options to delay injection after form/search gui

This commit is contained in:
Federico Terzi 2022-03-05 20:27:49 +01:00
parent 9760776904
commit 3abe84f8b0
6 changed files with 58 additions and 2 deletions

View File

@ -21,3 +21,5 @@ pub(crate) const DEFAULT_CLIPBOARD_THRESHOLD: usize = 100;
pub(crate) const DEFAULT_PRE_PASTE_DELAY: usize = 100;
pub(crate) const DEFAULT_SHORTCUT_EVENT_DELAY: usize = 10;
pub(crate) const DEFAULT_RESTORE_CLIPBOARD_DELAY: usize = 300;
pub(crate) const DEFAULT_POST_FORM_DELAY: usize = 200;
pub(crate) const DEFAULT_POST_SEARCH_DELAY: usize = 200;

View File

@ -150,6 +150,18 @@ pub trait Config: Send + Sync {
// If false, avoid showing the SecureInput notification on macOS
fn secure_input_notification(&self) -> bool;
// The number of milliseconds to wait after a form has been closed.
// This is useful to let the target application regain focus
// after a form has been closed, otherwise the injection might
// not be targeted to the right application.
fn post_form_delay(&self) -> usize;
// The number of milliseconds to wait after the search bar has been closed.
// This is useful to let the target application regain focus
// after the search bar has been closed, otherwise the injection might
// not be targeted to the right application.
fn post_search_delay(&self) -> usize;
// If true, use the `xclip` command to implement the clipboard instead of
// the built-in native module on X11.
fn x11_use_xclip_backend(&self) -> bool;
@ -188,6 +200,8 @@ pub trait Config: Send + Sync {
toggle_key: {:?}
auto_restart: {:?}
restore_clipboard_delay: {:?}
post_form_delay: {:?}
post_search_delay: {:?}
backspace_limit: {}
search_trigger: {:?}
search_shortcut: {:?}
@ -220,6 +234,8 @@ pub trait Config: Send + Sync {
self.toggle_key(),
self.auto_restart(),
self.restore_clipboard_delay(),
self.post_form_delay(),
self.post_search_delay(),
self.backspace_limit(),
self.search_trigger(),
self.search_shortcut(),

View File

@ -44,6 +44,8 @@ pub(crate) struct ParsedConfig {
pub show_notifications: Option<bool>,
pub show_icon: Option<bool>,
pub secure_input_notification: Option<bool>,
pub post_form_delay: Option<usize>,
pub post_search_delay: Option<usize>,
pub win32_exclude_orphan_events: Option<bool>,
pub win32_keyboard_layout_cache_interval: Option<i64>,
pub x11_use_xclip_backend: Option<bool>,

View File

@ -103,6 +103,12 @@ pub(crate) struct YAMLConfig {
#[serde(default)]
pub show_icon: Option<bool>,
#[serde(default)]
pub post_form_delay: Option<usize>,
#[serde(default)]
pub post_search_delay: Option<usize>,
#[serde(default)]
pub secure_input_notification: Option<bool>,
@ -201,6 +207,8 @@ impl TryFrom<YAMLConfig> for ParsedConfig {
pre_paste_delay: yaml_config.pre_paste_delay,
restore_clipboard_delay: yaml_config.restore_clipboard_delay,
paste_shortcut_event_delay: yaml_config.paste_shortcut_event_delay,
post_form_delay: yaml_config.post_form_delay,
post_search_delay: yaml_config.post_search_delay,
win32_exclude_orphan_events: yaml_config.win32_exclude_orphan_events,
win32_keyboard_layout_cache_interval: yaml_config.win32_keyboard_layout_cache_interval,
@ -260,6 +268,8 @@ mod tests {
show_icon: false
show_notifications: false
secure_input_notification: false
post_form_delay: 300
post_search_delay: 400
win32_exclude_orphan_events: false
win32_keyboard_layout_cache_interval: 300
x11_use_xclip_backend: true
@ -314,6 +324,8 @@ mod tests {
show_icon: Some(false),
show_notifications: Some(false),
secure_input_notification: Some(false),
post_form_delay: Some(300),
post_search_delay: Some(400),
win32_exclude_orphan_events: Some(false),
win32_keyboard_layout_cache_interval: Some(300),
x11_use_xclip_backend: Some(true),

View File

@ -19,8 +19,8 @@
use super::{
default::{
DEFAULT_CLIPBOARD_THRESHOLD, DEFAULT_PRE_PASTE_DELAY, DEFAULT_RESTORE_CLIPBOARD_DELAY,
DEFAULT_SHORTCUT_EVENT_DELAY,
DEFAULT_CLIPBOARD_THRESHOLD, DEFAULT_POST_FORM_DELAY, DEFAULT_POST_SEARCH_DELAY,
DEFAULT_PRE_PASTE_DELAY, DEFAULT_RESTORE_CLIPBOARD_DELAY, DEFAULT_SHORTCUT_EVENT_DELAY,
},
parse::ParsedConfig,
path::calculate_paths,
@ -299,6 +299,20 @@ impl Config for ResolvedConfig {
self.parsed.secure_input_notification.unwrap_or(true)
}
fn post_form_delay(&self) -> usize {
self
.parsed
.post_form_delay
.unwrap_or(DEFAULT_POST_FORM_DELAY)
}
fn post_search_delay(&self) -> usize {
self
.parsed
.post_search_delay
.unwrap_or(DEFAULT_POST_SEARCH_DELAY)
}
fn win32_exclude_orphan_events(&self) -> bool {
self.parsed.win32_exclude_orphan_events.unwrap_or(true)
}
@ -398,6 +412,8 @@ impl ResolvedConfig {
show_icon,
show_notifications,
secure_input_notification,
post_form_delay,
post_search_delay,
win32_exclude_orphan_events,
win32_keyboard_layout_cache_interval,
x11_use_xclip_backend,

View File

@ -387,6 +387,14 @@ impl Config for LegacyInteropConfig {
self.config.enable_active
}
fn post_form_delay(&self) -> usize {
crate::config::default::DEFAULT_POST_FORM_DELAY
}
fn post_search_delay(&self) -> usize {
crate::config::default::DEFAULT_POST_SEARCH_DELAY
}
fn win32_exclude_orphan_events(&self) -> bool {
true
}