feat(config): introduce clipboard threshold option

This commit is contained in:
Federico Terzi 2021-05-05 21:19:32 +02:00
parent 47587681bd
commit fddb2711e4
7 changed files with 21 additions and 25 deletions

View File

@ -32,6 +32,7 @@ pub trait Config: Send {
fn label(&self) -> &str;
fn match_paths(&self) -> &[String];
fn backend(&self) -> Backend;
fn clipboard_threshold(&self) -> usize;
fn is_match(&self, app: &AppProperties) -> bool;
}

View File

@ -28,6 +28,7 @@ pub(crate) struct ParsedConfig {
pub label: Option<String>,
pub backend: Option<String>,
pub clipboard_threshold: Option<usize>,
// Includes
pub includes: Option<Vec<String>>,

View File

@ -33,6 +33,9 @@ pub(crate) struct YAMLConfig {
#[serde(default)]
pub backend: Option<String>,
#[serde(default)]
pub clipboard_threshold: Option<usize>,
#[serde(default)]
pub includes: Option<Vec<String>>,
@ -82,6 +85,7 @@ impl TryFrom<YAMLConfig> for ParsedConfig {
Ok(Self {
label: yaml_config.label,
backend: yaml_config.backend,
clipboard_threshold: yaml_config.clipboard_threshold,
use_standard_includes: yaml_config.use_standard_includes,
includes: yaml_config.includes,
extra_includes: yaml_config.extra_includes,
@ -107,6 +111,7 @@ mod tests {
r#"
label: "test"
backend: clipboard
clipboard_threshold: 200
use_standard_includes: true
includes: ["test1"]
@ -129,6 +134,7 @@ mod tests {
label: Some("test".to_string()),
backend: Some("clipboard".to_string()),
clipboard_threshold: Some(200),
use_standard_includes: Some(true),
includes: Some(vec!["test1".to_string()]),

View File

@ -128,6 +128,10 @@ impl Config for ResolvedConfig {
}
}
}
fn clipboard_threshold(&self) -> usize {
self.parsed.clipboard_threshold.unwrap_or(100)
}
}
impl ResolvedConfig {
@ -185,6 +189,7 @@ impl ResolvedConfig {
// Fields
label,
backend,
clipboard_threshold,
includes,
excludes,
extra_includes,

View File

@ -161,6 +161,10 @@ mod tests {
fn backend(&self) -> crate::config::Backend {
unimplemented!()
}
fn clipboard_threshold(&self) -> usize {
unimplemented!()
}
}
#[test]

View File

@ -378,34 +378,9 @@ impl LegacyConfig {
pub enum BackendType {
Inject,
Clipboard,
// On Linux systems there is a long standing issue with text injection (which
// in general is better than Clipboard copy/pasting) that prevents certain
// apps from correctly handling special characters (such as emojis or accented letters)
// when injected. For this reason, espanso initially defaulted on the Clipboard
// backend on Linux, as it was the most reliable (working in 99% of cases),
// even though it was less efficient and with a few inconveniences (for example, the
// previous clipboard content being overwritten).
// The Auto backend tries to take it a step further, by automatically determining
// when an injection is possible (only ascii characters in the replacement), and falling
// back to the Clipboard backend otherwise.
// Should only be used on Linux systems.
Auto,
}
impl Default for BackendType {
// The default backend varies based on the operating system.
// On Windows and macOS, the Inject backend is working great and should
// be preferred as it doesn't override the clipboard.
// On the other hand, on linux it has many problems due to the bugs
// of the libxdo used. For this reason, Clipboard will be the default
// backend on Linux from version v0.3.0
#[cfg(not(target_os = "linux"))]
fn default() -> Self {
BackendType::Inject
}
#[cfg(target_os = "linux")]
fn default() -> Self {
BackendType::Auto
}

View File

@ -252,6 +252,10 @@ impl Config for LegacyInteropConfig {
// All the filters that have been specified must be true to define a match
is_exec_match && is_title_match && is_class_match
}
fn clipboard_threshold(&self) -> usize {
100
}
}
struct LegacyMatchGroup {