From f342ec8cfa743df02c3a40f845d460a672ee4e0e Mon Sep 17 00:00:00 2001 From: Bob Date: Fri, 27 Feb 2026 09:00:24 +0000 Subject: [PATCH 1/2] fix(transform): use scheme as domain for file:// and other non-web URLs When splitting URLs, file://, about:, and other URLs without a host produced an empty string for $domain. This caused all such events to cluster together as a single empty entry in "Top Browser Domains". Now falls back to using the URL scheme (e.g. "file", "about") as the domain when host is None. Matches the corresponding fix in aw-core (ActivityWatch/aw-core#129). Fixes ActivityWatch/aw-core#67 --- aw-transform/src/split_url.rs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/aw-transform/src/split_url.rs b/aw-transform/src/split_url.rs index 4bdaf58f..d6750867 100644 --- a/aw-transform/src/split_url.rs +++ b/aw-transform/src/split_url.rs @@ -41,9 +41,11 @@ pub fn split_url_event(event: &mut Event) { .data .insert("$protocol".to_string(), Value::String(protocol)); // Domain + // For URLs without a host (e.g. file://, about:), fall back to the scheme + // so they don't all cluster as an empty string in "Top Browser Domains". let domain = match uri.host_str() { Some(domain) => domain.trim_start_matches("www.").to_string(), - None => "".to_string(), + None => uri.scheme().to_string(), }; event .data @@ -97,4 +99,34 @@ mod tests { } ); } + + #[test] + fn test_split_url_file_scheme() { + let mut e = Event { + id: None, + timestamp: DateTime::from_str("2000-01-01T00:00:01Z").unwrap(), + duration: Duration::seconds(1), + data: json_map! {"url": "file:///home/user/document.pdf"}, + }; + split_url_event(&mut e); + assert_eq!(e.data.get("$protocol"), Some(&json!("file"))); + assert_eq!(e.data.get("$domain"), Some(&json!("file"))); + assert_eq!( + e.data.get("$path"), + Some(&json!("/home/user/document.pdf")) + ); + } + + #[test] + fn test_split_url_about_scheme() { + let mut e = Event { + id: None, + timestamp: DateTime::from_str("2000-01-01T00:00:01Z").unwrap(), + duration: Duration::seconds(1), + data: json_map! {"url": "about:blank"}, + }; + split_url_event(&mut e); + assert_eq!(e.data.get("$protocol"), Some(&json!("about"))); + assert_eq!(e.data.get("$domain"), Some(&json!("about"))); + } } From be99690901eb2ff01363bd6bffd39125148c29a5 Mon Sep 17 00:00:00 2001 From: Bob Date: Fri, 27 Feb 2026 11:45:17 +0000 Subject: [PATCH 2/2] style: fix rustfmt formatting in test assertion --- aw-transform/src/split_url.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/aw-transform/src/split_url.rs b/aw-transform/src/split_url.rs index d6750867..48e99c45 100644 --- a/aw-transform/src/split_url.rs +++ b/aw-transform/src/split_url.rs @@ -111,10 +111,7 @@ mod tests { split_url_event(&mut e); assert_eq!(e.data.get("$protocol"), Some(&json!("file"))); assert_eq!(e.data.get("$domain"), Some(&json!("file"))); - assert_eq!( - e.data.get("$path"), - Some(&json!("/home/user/document.pdf")) - ); + assert_eq!(e.data.get("$path"), Some(&json!("/home/user/document.pdf"))); } #[test]