From 7f3c70c8df33995412e8094acda85fe13a180ca7 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 31 Jul 2021 22:28:18 +0200 Subject: [PATCH] feat(core): improve config dump when patched --- espanso/src/patch/config_store.rs | 2 +- espanso/src/patch/mod.rs | 2 +- espanso/src/patch/patches/macros.rs | 7 +++++-- espanso/src/patch/patches/win/onenote_for_windows_10.rs | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/espanso/src/patch/config_store.rs b/espanso/src/patch/config_store.rs index 65c29c8..169c4aa 100644 --- a/espanso/src/patch/config_store.rs +++ b/espanso/src/patch/config_store.rs @@ -75,7 +75,7 @@ impl ConfigStore for PatchedConfigStore { // Check if a patch should be applied if let Some(patch) = self.patches.iter().find(|patch| (patch.should_patch)(app)) { - (patch.apply)(active_config) + (patch.apply)(active_config, patch.name) } else { active_config } diff --git a/espanso/src/patch/mod.rs b/espanso/src/patch/mod.rs index bc782dc..c0a711f 100644 --- a/espanso/src/patch/mod.rs +++ b/espanso/src/patch/mod.rs @@ -48,5 +48,5 @@ pub struct PatchDefinition { pub name: &'static str, pub is_enabled: fn() -> bool, pub should_patch: fn(app: &AppProperties) -> bool, - pub apply: fn(config: Arc) -> Arc, + pub apply: fn(config: Arc, name: &str) -> Arc, } \ No newline at end of file diff --git a/espanso/src/patch/patches/macros.rs b/espanso/src/patch/patches/macros.rs index e365186..a818057 100644 --- a/espanso/src/patch/patches/macros.rs +++ b/espanso/src/patch/patches/macros.rs @@ -26,14 +26,17 @@ macro_rules! generate_patchable_config { pub struct $struct_name { base: Arc, patch: Patches, + patched_label: String, } impl $struct_name { #[allow(dead_code)] - pub fn patch(base: Arc, patch: Patches) -> Self { + pub fn patch(base: Arc, name: &str, patch: Patches) -> Self { + let patched_label = format!("{} (PATCHED: {})", base.label(), name); Self { base, patch, + patched_label, } } } @@ -61,7 +64,7 @@ macro_rules! generate_patchable_config { } fn label(&self) -> &str { - self.base.label() + &self.patched_label } fn match_paths(&self) -> &[String] { diff --git a/espanso/src/patch/patches/win/onenote_for_windows_10.rs b/espanso/src/patch/patches/win/onenote_for_windows_10.rs index aefb459..b437d67 100644 --- a/espanso/src/patch/patches/win/onenote_for_windows_10.rs +++ b/espanso/src/patch/patches/win/onenote_for_windows_10.rs @@ -27,9 +27,10 @@ pub fn patch() -> PatchDefinition { name: module_path!().split(":").last().unwrap_or("unknown"), is_enabled: || cfg!(target_os = "windows"), should_patch: |app| app.title.unwrap_or_default().contains("OneNote"), - apply: |base| { + apply: |base, name| { Arc::new(PatchedConfig::patch( base, + name, Patches { key_delay: Some(Some(10)), ..Default::default()