feat(config): add enable option
This commit is contained in:
parent
ce802bc72e
commit
eb727abeec
|
@ -39,8 +39,21 @@ pub trait Config: Send + Sync {
|
|||
fn id(&self) -> i32;
|
||||
fn label(&self) -> &str;
|
||||
fn match_paths(&self) -> &[String];
|
||||
|
||||
// The mechanism used to perform the injection. Espanso can either
|
||||
// inject text by simulating keypresses (Inject backend) or
|
||||
// by using the clipboard (Clipboard backend). Both of them have pros
|
||||
// and cons, so the "Auto" backend is used by default to automatically
|
||||
// choose the most appropriate one based on the situation.
|
||||
// If for whatever reason the Auto backend is not appropriate, you
|
||||
// can change this option to override it.
|
||||
fn backend(&self) -> Backend;
|
||||
|
||||
// If false, espanso will be disabled for the current configuration.
|
||||
// This option can be used to selectively disable espanso when
|
||||
// using a specific application (by creating an app-specific config).
|
||||
fn enable(&self) -> bool;
|
||||
|
||||
// Number of chars after which a match is injected with the clipboard
|
||||
// backend instead of the default one. This is done for efficiency
|
||||
// reasons, as injecting a long match through separate events becomes
|
||||
|
|
|
@ -28,6 +28,7 @@ pub(crate) struct ParsedConfig {
|
|||
pub label: Option<String>,
|
||||
|
||||
pub backend: Option<String>,
|
||||
pub enable: Option<bool>,
|
||||
pub clipboard_threshold: Option<usize>,
|
||||
pub auto_restart: Option<bool>,
|
||||
pub preserve_clipboard: Option<bool>,
|
||||
|
|
|
@ -34,6 +34,9 @@ pub(crate) struct YAMLConfig {
|
|||
#[serde(default)]
|
||||
pub backend: Option<String>,
|
||||
|
||||
#[serde(default)]
|
||||
pub enable: Option<bool>,
|
||||
|
||||
#[serde(default)]
|
||||
pub clipboard_threshold: Option<usize>,
|
||||
|
||||
|
@ -150,6 +153,7 @@ impl TryFrom<YAMLConfig> for ParsedConfig {
|
|||
Ok(Self {
|
||||
label: yaml_config.label,
|
||||
backend: yaml_config.backend,
|
||||
enable: yaml_config.enable,
|
||||
clipboard_threshold: yaml_config.clipboard_threshold,
|
||||
auto_restart: yaml_config.auto_restart,
|
||||
toggle_key: yaml_config.toggle_key,
|
||||
|
@ -210,6 +214,7 @@ mod tests {
|
|||
r#"
|
||||
label: "test"
|
||||
backend: clipboard
|
||||
enable: false
|
||||
clipboard_threshold: 200
|
||||
pre_paste_delay: 300
|
||||
toggle_key: CTRL
|
||||
|
@ -268,6 +273,7 @@ mod tests {
|
|||
label: Some("test".to_string()),
|
||||
|
||||
backend: Some("clipboard".to_string()),
|
||||
enable: Some(false),
|
||||
clipboard_threshold: Some(200),
|
||||
auto_restart: Some(false),
|
||||
preserve_clipboard: Some(false),
|
||||
|
|
|
@ -158,6 +158,10 @@ impl Config for ResolvedConfig {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn enable(&self) -> bool {
|
||||
self.parsed.enable.unwrap_or(true)
|
||||
}
|
||||
|
||||
fn clipboard_threshold(&self) -> usize {
|
||||
self
|
||||
|
@ -364,6 +368,7 @@ impl ResolvedConfig {
|
|||
// Fields
|
||||
label,
|
||||
backend,
|
||||
enable,
|
||||
clipboard_threshold,
|
||||
auto_restart,
|
||||
pre_paste_delay,
|
||||
|
|
|
@ -382,6 +382,10 @@ impl Config for LegacyInteropConfig {
|
|||
fn secure_input_notification(&self) -> bool {
|
||||
self.config.secure_input_notification
|
||||
}
|
||||
|
||||
fn enable(&self) -> bool {
|
||||
self.config.enable_active
|
||||
}
|
||||
}
|
||||
|
||||
struct LegacyMatchGroup {
|
||||
|
|
Loading…
Reference in New Issue
Block a user