From fa149471f2ed99d294aeb3d8a0fa3df4fffe12ca Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Fri, 20 Aug 2021 18:45:22 +0200 Subject: [PATCH] feat(config): add gui-related fields --- espanso-config/src/config/mod.rs | 10 ++++++++++ espanso-config/src/config/parse/mod.rs | 3 +++ espanso-config/src/config/parse/yaml.rs | 19 +++++++++++++++++++ espanso-config/src/config/resolve.rs | 15 +++++++++++++++ espanso-config/src/legacy/mod.rs | 12 ++++++++++++ 5 files changed, 59 insertions(+) diff --git a/espanso-config/src/config/mod.rs b/espanso-config/src/config/mod.rs index e544f95..c1cd266 100644 --- a/espanso-config/src/config/mod.rs +++ b/espanso-config/src/config/mod.rs @@ -121,6 +121,16 @@ pub trait Config: Send + Sync { // presses the Backspace key afterwards. fn undo_backspace(&self) -> bool; + // If false, disable all notifications + fn show_notifications(&self) -> bool; + + // If false, avoid showing the espanso icon on the system's tray bar + // Note: currently not working on Linux + fn show_icon(&self) -> bool; + + // If false, avoid showing the SecureInput notification on macOS + fn secure_input_notification(&self) -> bool; + fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool; fn pretty_dump(&self) -> String { diff --git a/espanso-config/src/config/parse/mod.rs b/espanso-config/src/config/parse/mod.rs index 9558b1d..25dbbc9 100644 --- a/espanso-config/src/config/parse/mod.rs +++ b/espanso-config/src/config/parse/mod.rs @@ -40,6 +40,9 @@ pub(crate) struct ParsedConfig { pub search_trigger: Option, pub search_shortcut: Option, pub undo_backspace: Option, + pub show_notifications: Option, + pub show_icon: Option, + pub secure_input_notification: Option, pub pre_paste_delay: Option, pub restore_clipboard_delay: Option, diff --git a/espanso-config/src/config/parse/yaml.rs b/espanso-config/src/config/parse/yaml.rs index 6f6e34d..6e19955 100644 --- a/espanso-config/src/config/parse/yaml.rs +++ b/espanso-config/src/config/parse/yaml.rs @@ -91,6 +91,15 @@ pub(crate) struct YAMLConfig { #[serde(default)] pub undo_backspace: Option, + #[serde(default)] + pub show_notifications: Option, + + #[serde(default)] + pub show_icon: Option, + + #[serde(default)] + pub secure_input_notification: Option, + // Include/Exclude #[serde(default)] pub includes: Option>, @@ -168,6 +177,10 @@ impl TryFrom for ParsedConfig { search_shortcut: yaml_config.search_shortcut, undo_backspace: yaml_config.undo_backspace, + show_icon: yaml_config.show_icon, + show_notifications: yaml_config.show_notifications, + secure_input_notification: yaml_config.secure_input_notification, + 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, @@ -221,6 +234,9 @@ mod tests { search_trigger: "search" search_shortcut: "CTRL+SPACE" undo_backspace: false + show_icon: false + show_notifications: false + secure_input_notification: false use_standard_includes: true includes: ["test1"] @@ -267,6 +283,9 @@ mod tests { search_trigger: Some("search".to_owned()), search_shortcut: Some("CTRL+SPACE".to_owned()), undo_backspace: Some(false), + show_icon: Some(false), + show_notifications: Some(false), + secure_input_notification: Some(false), pre_paste_delay: Some(300), diff --git a/espanso-config/src/config/resolve.rs b/espanso-config/src/config/resolve.rs index a18fb0b..d49a5aa 100644 --- a/espanso-config/src/config/resolve.rs +++ b/espanso-config/src/config/resolve.rs @@ -294,6 +294,18 @@ impl Config for ResolvedConfig { fn undo_backspace(&self) -> bool { self.parsed.undo_backspace.unwrap_or(true) } + + fn show_icon(&self) -> bool { + self.parsed.show_icon.unwrap_or(true) + } + + fn show_notifications(&self) -> bool { + self.parsed.show_notifications.unwrap_or(true) + } + + fn secure_input_notification(&self) -> bool { + self.parsed.secure_input_notification.unwrap_or(true) + } } impl ResolvedConfig { @@ -370,6 +382,9 @@ impl ResolvedConfig { search_trigger, search_shortcut, undo_backspace, + show_icon, + show_notifications, + secure_input_notification, includes, excludes, extra_includes, diff --git a/espanso-config/src/legacy/mod.rs b/espanso-config/src/legacy/mod.rs index 02f920a..e81a3f8 100644 --- a/espanso-config/src/legacy/mod.rs +++ b/espanso-config/src/legacy/mod.rs @@ -370,6 +370,18 @@ impl Config for LegacyInteropConfig { fn undo_backspace(&self) -> bool { self.config.undo_backspace } + + fn show_icon(&self) -> bool { + self.config.show_icon + } + + fn show_notifications(&self) -> bool { + self.config.show_notifications + } + + fn secure_input_notification(&self) -> bool { + self.config.secure_input_notification + } } struct LegacyMatchGroup {