feat(config): add auto_restart option

This commit is contained in:
Federico Terzi 2021-06-03 21:00:38 +02:00
parent 8fb95ccf22
commit da19664f5b
5 changed files with 19 additions and 0 deletions

View File

@ -54,6 +54,8 @@ pub trait Config: Send {
// Defines the key that disables/enables espanso when double pressed // Defines the key that disables/enables espanso when double pressed
fn toggle_key(&self) -> Option<ToggleKey>; fn toggle_key(&self) -> Option<ToggleKey>;
fn auto_restart(&self) -> bool;
fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool; fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool;
} }

View File

@ -29,11 +29,13 @@ pub(crate) struct ParsedConfig {
pub backend: Option<String>, pub backend: Option<String>,
pub clipboard_threshold: Option<usize>, pub clipboard_threshold: Option<usize>,
pub auto_restart: Option<bool>,
pub pre_paste_delay: Option<usize>, pub pre_paste_delay: Option<usize>,
pub toggle_key: Option<String>, pub toggle_key: Option<String>,
// Includes // Includes
pub includes: Option<Vec<String>>, pub includes: Option<Vec<String>>,
pub excludes: Option<Vec<String>>, pub excludes: Option<Vec<String>>,

View File

@ -42,6 +42,9 @@ pub(crate) struct YAMLConfig {
#[serde(default)] #[serde(default)]
pub toggle_key: Option<String>, pub toggle_key: Option<String>,
#[serde(default)]
pub auto_restart: Option<bool>,
#[serde(default)] #[serde(default)]
pub includes: Option<Vec<String>>, pub includes: Option<Vec<String>>,
@ -92,6 +95,7 @@ impl TryFrom<YAMLConfig> for ParsedConfig {
label: yaml_config.label, label: yaml_config.label,
backend: yaml_config.backend, backend: yaml_config.backend,
clipboard_threshold: yaml_config.clipboard_threshold, clipboard_threshold: yaml_config.clipboard_threshold,
auto_restart: yaml_config.auto_restart,
pre_paste_delay: yaml_config.pre_paste_delay, pre_paste_delay: yaml_config.pre_paste_delay,
@ -125,6 +129,7 @@ mod tests {
clipboard_threshold: 200 clipboard_threshold: 200
pre_paste_delay: 300 pre_paste_delay: 300
toggle_key: CTRL toggle_key: CTRL
auto_restart: false
use_standard_includes: true use_standard_includes: true
includes: ["test1"] includes: ["test1"]
@ -148,6 +153,7 @@ mod tests {
backend: Some("clipboard".to_string()), backend: Some("clipboard".to_string()),
clipboard_threshold: Some(200), clipboard_threshold: Some(200),
auto_restart: Some(false),
pre_paste_delay: Some(300), pre_paste_delay: Some(300),

View File

@ -150,6 +150,10 @@ impl Config for ResolvedConfig {
.unwrap_or(DEFAULT_CLIPBOARD_THRESHOLD) .unwrap_or(DEFAULT_CLIPBOARD_THRESHOLD)
} }
fn auto_restart(&self) -> bool {
self.parsed.auto_restart.unwrap_or(true)
}
fn pre_paste_delay(&self) -> usize { fn pre_paste_delay(&self) -> usize {
self self
.parsed .parsed
@ -244,6 +248,7 @@ impl ResolvedConfig {
label, label,
backend, backend,
clipboard_threshold, clipboard_threshold,
auto_restart,
pre_paste_delay, pre_paste_delay,
toggle_key, toggle_key,
includes, includes,

View File

@ -210,6 +210,10 @@ impl Config for LegacyInteropConfig {
} }
} }
fn auto_restart(&self) -> bool {
self.config.auto_restart
}
fn match_paths(&self) -> &[String] { fn match_paths(&self) -> &[String] {
&self.match_paths &self.match_paths
} }