summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/app_map.rs38
-rw-r--r--tests/integration.rs37
4 files changed, 76 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b35a84c..d5bab30 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -146,7 +146,7 @@ checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
name = "plasma-task-manager-notifications"
-version = "0.1.0"
+version = "0.1.1"
dependencies = [
"env_logger",
"libc",
diff --git a/Cargo.toml b/Cargo.toml
index e63e172..b9ee741 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "plasma-task-manager-notifications"
-version = "0.1.0"
+version = "0.1.1"
edition = "2021"
description = "Taskbar badge notifications for KDE Plasma 6"
license = "MIT"
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<u64, String>,
}
+/// 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<String> {
+ 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())
}
@@ -273,6 +282,33 @@ mod tests {
}
#[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();
assert!(am.patterns().is_empty());
diff --git a/tests/integration.rs b/tests/integration.rs
index e4bd9f8..b009b1f 100644
--- a/tests/integration.rs
+++ b/tests/integration.rs
@@ -273,3 +273,40 @@ signal time=1700000000.400 sender=:1.1 -> destination=(null destination) serial=
("application://org.mozilla.firefox.desktop".into(), 1)
);
}
+
+/// Google Chrome: app_name "Google Chrome" must match pattern "google-chrome" (space vs hyphen).
+#[test]
+fn test_google_chrome_space_vs_hyphen() {
+ let mut map = AppMap::new();
+ let mut patterns = HashMap::new();
+ patterns.insert(
+ "google-chrome".into(),
+ "application://google-chrome.desktop".into(),
+ );
+ map.update_patterns(patterns);
+
+ let stream = r#"method call time=1700000000.000 sender=:1.100 -> destination=:1.5 serial=500 path=/org/freedesktop/Notifications; interface=org.freedesktop.Notifications; member=Notify
+ string "Google Chrome"
+ uint32 0
+ string ""
+ string "New message"
+ string ""
+method return time=1700000000.100 sender=:1.5 -> destination=:1.100 serial=600 reply_serial=500
+ uint32 55
+signal time=1700000001.000 sender=:1.5 -> destination=(null destination) serial=700 path=/org/freedesktop/Notifications; interface=org.freedesktop.Notifications; member=NotificationClosed
+ uint32 55
+ uint32 2
+"#;
+
+ let updates = process_stream(stream, &mut map);
+
+ assert_eq!(updates.len(), 2);
+ assert_eq!(
+ updates[0],
+ ("application://google-chrome.desktop".into(), 1)
+ );
+ assert_eq!(
+ updates[1],
+ ("application://google-chrome.desktop".into(), 0)
+ );
+}