diff --git a/watchers/src/report_client.rs b/watchers/src/report_client.rs index 24d8eb6..02ccfd8 100644 --- a/watchers/src/report_client.rs +++ b/watchers/src/report_client.rs @@ -7,6 +7,7 @@ use chrono::{DateTime, TimeDelta, Utc}; use serde_json::{Map, Value}; use std::error::Error; use std::future::Future; +use std::collections::HashMap; pub struct ReportClient { pub client: AwClient, @@ -94,14 +95,14 @@ impl ReportClient { } pub async fn send_active_window(&self, app_id: &str, title: &str) -> anyhow::Result<()> { - self.send_active_window_with_instance(app_id, title, None).await + self.send_active_window_with_extra(app_id, title, None).await } - pub async fn send_active_window_with_instance( + pub async fn send_active_window_with_extra( &self, app_id: &str, title: &str, - wm_instance: Option<&str>, + extra_data: Option>, ) -> anyhow::Result<()> { let mut data = Map::new(); @@ -126,8 +127,10 @@ impl ReportClient { data.insert("app".to_string(), Value::String(inserted_app_id)); data.insert("title".to_string(), Value::String(inserted_title)); - if let Some(instance) = wm_instance { - data.insert("wm_instance".to_string(), Value::String(instance.to_string())); + if let Some(extra) = extra_data { + for (key, value) in extra { + data.insert(key, Value::String(value)); + } } let event = AwEvent { diff --git a/watchers/src/watchers/x11_window.rs b/watchers/src/watchers/x11_window.rs index a6f91ad..8bff0d7 100644 --- a/watchers/src/watchers/x11_window.rs +++ b/watchers/src/watchers/x11_window.rs @@ -3,6 +3,7 @@ use crate::report_client::ReportClient; use anyhow::Context; use async_trait::async_trait; use std::sync::Arc; +use std::collections::HashMap; pub struct WindowWatcher { client: X11Client, @@ -12,6 +13,18 @@ pub struct WindowWatcher { } impl WindowWatcher { + pub async fn send_active_window_with_instance( + &self, + client: &ReportClient, + app_id: &str, + title: &str, + wm_instance: &str, + ) -> anyhow::Result<()> { + let mut extra_data = HashMap::new(); + extra_data.insert("wm_instance".to_string(), wm_instance.to_string()); + client.send_active_window_with_extra(app_id, title, Some(extra_data)).await + } + async fn send_active_window(&mut self, client: &ReportClient) -> anyhow::Result<()> { let data = self.client.active_window_data()?; @@ -25,8 +38,8 @@ impl WindowWatcher { self.last_wm_instance = data.wm_instance.clone(); } - client - .send_active_window_with_instance(&self.last_app_id, &self.last_title, Some(&self.last_wm_instance)) + self + .send_active_window_with_instance(client, &self.last_app_id, &self.last_title, &self.last_wm_instance) .await .with_context(|| "Failed to send heartbeat for active window") }