From a5024b35f61cf58c01a0731b9d1ca8adf872b0a8 Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Sat, 2 May 2026 20:23:21 +0300 Subject: Fix Chrome notifications not matching due to space vs hyphen in app name Normalize separators (hyphens, spaces, underscores) during pattern matching so that Chrome's app_name "Google Chrome" matches KWin's desktopFile "google-chrome". --- src/app_map.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/app_map.rs') diff --git a/src/app_map.rs b/src/app_map.rs index 07a4cf3..15b061a 100644 --- a/src/app_map.rs +++ b/src/app_map.rs @@ -14,6 +14,14 @@ pub struct AppMap { pending: HashMap, } +/// Normalize separators (hyphens, underscores, spaces) to a single form +/// so that "google-chrome", "google chrome", and "google_chrome" all match. +fn normalize_separators(s: &str) -> String { + s.chars() + .map(|c| if matches!(c, '-' | '_' | ' ') { '-' } else { c }) + .collect() +} + impl AppMap { pub fn new() -> Self { Self::default() @@ -38,9 +46,10 @@ impl AppMap { } fn find_pattern(&self, lower: &str) -> Option { + let normalized = normalize_separators(lower); self.patterns .iter() - .find(|(pattern, _)| lower.contains(pattern.as_str())) + .find(|(pattern, _)| normalized.contains(&normalize_separators(pattern))) .map(|(_, desktop_id)| desktop_id.clone()) } @@ -272,6 +281,33 @@ mod tests { assert!(ids.contains(&"application://com.slack.Slack.desktop".to_string())); } + #[test] + fn test_match_app_normalizes_separators() { + let mut am = AppMap::new(); + let mut m = HashMap::new(); + // KWin reports "google-chrome" as the desktopFile + m.insert( + "google-chrome".into(), + "application://google-chrome.desktop".into(), + ); + am.update_patterns(m); + + // Chrome sends app_name "Google Chrome" (space, not hyphen) + assert_eq!( + am.match_app(&["Google Chrome"]), + Some("application://google-chrome.desktop".into()) + ); + // Also match with underscore or exact hyphen + assert_eq!( + am.match_app(&["google_chrome"]), + Some("application://google-chrome.desktop".into()) + ); + assert_eq!( + am.match_app(&["google-chrome"]), + Some("application://google-chrome.desktop".into()) + ); + } + #[test] fn test_patterns_accessor() { let mut am = AppMap::new(); -- cgit v1.2.3