From da19664f5bfd1a8265286c608f1394d43e514438 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Thu, 3 Jun 2021 21:00:38 +0200 Subject: [PATCH] feat(config): add auto_restart option --- espanso-config/src/config/mod.rs | 2 ++ espanso-config/src/config/parse/mod.rs | 2 ++ espanso-config/src/config/parse/yaml.rs | 6 ++++++ espanso-config/src/config/resolve.rs | 5 +++++ espanso-config/src/legacy/mod.rs | 4 ++++ 5 files changed, 19 insertions(+) diff --git a/espanso-config/src/config/mod.rs b/espanso-config/src/config/mod.rs index b4e120c..a564663 100644 --- a/espanso-config/src/config/mod.rs +++ b/espanso-config/src/config/mod.rs @@ -54,6 +54,8 @@ pub trait Config: Send { // Defines the key that disables/enables espanso when double pressed fn toggle_key(&self) -> Option; + fn auto_restart(&self) -> bool; + fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool; } diff --git a/espanso-config/src/config/parse/mod.rs b/espanso-config/src/config/parse/mod.rs index d7dc03d..4280ec8 100644 --- a/espanso-config/src/config/parse/mod.rs +++ b/espanso-config/src/config/parse/mod.rs @@ -29,11 +29,13 @@ pub(crate) struct ParsedConfig { pub backend: Option, pub clipboard_threshold: Option, + pub auto_restart: Option, pub pre_paste_delay: Option, pub toggle_key: Option, + // Includes pub includes: Option>, pub excludes: Option>, diff --git a/espanso-config/src/config/parse/yaml.rs b/espanso-config/src/config/parse/yaml.rs index 6637b2e..00dc3d5 100644 --- a/espanso-config/src/config/parse/yaml.rs +++ b/espanso-config/src/config/parse/yaml.rs @@ -42,6 +42,9 @@ pub(crate) struct YAMLConfig { #[serde(default)] pub toggle_key: Option, + #[serde(default)] + pub auto_restart: Option, + #[serde(default)] pub includes: Option>, @@ -92,6 +95,7 @@ impl TryFrom for ParsedConfig { label: yaml_config.label, backend: yaml_config.backend, clipboard_threshold: yaml_config.clipboard_threshold, + auto_restart: yaml_config.auto_restart, pre_paste_delay: yaml_config.pre_paste_delay, @@ -125,6 +129,7 @@ mod tests { clipboard_threshold: 200 pre_paste_delay: 300 toggle_key: CTRL + auto_restart: false use_standard_includes: true includes: ["test1"] @@ -148,6 +153,7 @@ mod tests { backend: Some("clipboard".to_string()), clipboard_threshold: Some(200), + auto_restart: Some(false), pre_paste_delay: Some(300), diff --git a/espanso-config/src/config/resolve.rs b/espanso-config/src/config/resolve.rs index eb880e8..ea8ed82 100644 --- a/espanso-config/src/config/resolve.rs +++ b/espanso-config/src/config/resolve.rs @@ -150,6 +150,10 @@ impl Config for ResolvedConfig { .unwrap_or(DEFAULT_CLIPBOARD_THRESHOLD) } + fn auto_restart(&self) -> bool { + self.parsed.auto_restart.unwrap_or(true) + } + fn pre_paste_delay(&self) -> usize { self .parsed @@ -244,6 +248,7 @@ impl ResolvedConfig { label, backend, clipboard_threshold, + auto_restart, pre_paste_delay, toggle_key, includes, diff --git a/espanso-config/src/legacy/mod.rs b/espanso-config/src/legacy/mod.rs index c7036c0..c564009 100644 --- a/espanso-config/src/legacy/mod.rs +++ b/espanso-config/src/legacy/mod.rs @@ -210,6 +210,10 @@ impl Config for LegacyInteropConfig { } } + fn auto_restart(&self) -> bool { + self.config.auto_restart + } + fn match_paths(&self) -> &[String] { &self.match_paths }