feat(config): add gui-related fields

This commit is contained in:
Federico Terzi 2021-08-20 18:45:22 +02:00
parent 19aab8987e
commit fa149471f2
5 changed files with 59 additions and 0 deletions

View File

@ -121,6 +121,16 @@ pub trait Config: Send + Sync {
// presses the Backspace key afterwards. // presses the Backspace key afterwards.
fn undo_backspace(&self) -> bool; 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 is_match<'a>(&self, app: &AppProperties<'a>) -> bool;
fn pretty_dump(&self) -> String { fn pretty_dump(&self) -> String {

View File

@ -40,6 +40,9 @@ pub(crate) struct ParsedConfig {
pub search_trigger: Option<String>, pub search_trigger: Option<String>,
pub search_shortcut: Option<String>, pub search_shortcut: Option<String>,
pub undo_backspace: Option<bool>, pub undo_backspace: Option<bool>,
pub show_notifications: Option<bool>,
pub show_icon: Option<bool>,
pub secure_input_notification: Option<bool>,
pub pre_paste_delay: Option<usize>, pub pre_paste_delay: Option<usize>,
pub restore_clipboard_delay: Option<usize>, pub restore_clipboard_delay: Option<usize>,

View File

@ -91,6 +91,15 @@ pub(crate) struct YAMLConfig {
#[serde(default)] #[serde(default)]
pub undo_backspace: Option<bool>, pub undo_backspace: Option<bool>,
#[serde(default)]
pub show_notifications: Option<bool>,
#[serde(default)]
pub show_icon: Option<bool>,
#[serde(default)]
pub secure_input_notification: Option<bool>,
// Include/Exclude // Include/Exclude
#[serde(default)] #[serde(default)]
pub includes: Option<Vec<String>>, pub includes: Option<Vec<String>>,
@ -168,6 +177,10 @@ impl TryFrom<YAMLConfig> for ParsedConfig {
search_shortcut: yaml_config.search_shortcut, search_shortcut: yaml_config.search_shortcut,
undo_backspace: yaml_config.undo_backspace, 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, pre_paste_delay: yaml_config.pre_paste_delay,
restore_clipboard_delay: yaml_config.restore_clipboard_delay, restore_clipboard_delay: yaml_config.restore_clipboard_delay,
paste_shortcut_event_delay: yaml_config.paste_shortcut_event_delay, paste_shortcut_event_delay: yaml_config.paste_shortcut_event_delay,
@ -221,6 +234,9 @@ mod tests {
search_trigger: "search" search_trigger: "search"
search_shortcut: "CTRL+SPACE" search_shortcut: "CTRL+SPACE"
undo_backspace: false undo_backspace: false
show_icon: false
show_notifications: false
secure_input_notification: false
use_standard_includes: true use_standard_includes: true
includes: ["test1"] includes: ["test1"]
@ -267,6 +283,9 @@ mod tests {
search_trigger: Some("search".to_owned()), search_trigger: Some("search".to_owned()),
search_shortcut: Some("CTRL+SPACE".to_owned()), search_shortcut: Some("CTRL+SPACE".to_owned()),
undo_backspace: Some(false), undo_backspace: Some(false),
show_icon: Some(false),
show_notifications: Some(false),
secure_input_notification: Some(false),
pre_paste_delay: Some(300), pre_paste_delay: Some(300),

View File

@ -294,6 +294,18 @@ impl Config for ResolvedConfig {
fn undo_backspace(&self) -> bool { fn undo_backspace(&self) -> bool {
self.parsed.undo_backspace.unwrap_or(true) 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 { impl ResolvedConfig {
@ -370,6 +382,9 @@ impl ResolvedConfig {
search_trigger, search_trigger,
search_shortcut, search_shortcut,
undo_backspace, undo_backspace,
show_icon,
show_notifications,
secure_input_notification,
includes, includes,
excludes, excludes,
extra_includes, extra_includes,

View File

@ -370,6 +370,18 @@ impl Config for LegacyInteropConfig {
fn undo_backspace(&self) -> bool { fn undo_backspace(&self) -> bool {
self.config.undo_backspace 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 { struct LegacyMatchGroup {