diff --git a/watchers/src/report_client.rs b/watchers/src/report_client.rs index 7249f47..aa5fb44 100644 --- a/watchers/src/report_client.rs +++ b/watchers/src/report_client.rs @@ -4,9 +4,9 @@ use anyhow::Context; use aw_client_rust::{AwClient, Event as AwEvent}; use chrono::{DateTime, TimeDelta, Utc}; use serde_json::{Map, Value}; +use std::collections::HashMap; use std::error::Error; use std::future::Future; -use std::collections::HashMap; pub struct ReportClient { pub client: AwClient, @@ -94,7 +94,8 @@ impl ReportClient { } pub async fn send_active_window(&self, app_id: &str, title: &str) -> anyhow::Result<()> { - self.send_active_window_with_extra(app_id, title, None).await + self.send_active_window_with_extra(app_id, title, None) + .await } pub async fn send_active_window_with_extra( diff --git a/watchers/src/watchers/x11_window.rs b/watchers/src/watchers/x11_window.rs index 8bff0d7..1534a6e 100644 --- a/watchers/src/watchers/x11_window.rs +++ b/watchers/src/watchers/x11_window.rs @@ -2,8 +2,8 @@ use super::{x11_connection::X11Client, Watcher}; use crate::report_client::ReportClient; use anyhow::Context; use async_trait::async_trait; -use std::sync::Arc; use std::collections::HashMap; +use std::sync::Arc; pub struct WindowWatcher { client: X11Client, @@ -22,13 +22,18 @@ impl WindowWatcher { ) -> 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 + 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()?; - if data.app_id != self.last_app_id || data.title != self.last_title || data.wm_instance != self.last_wm_instance { + if data.app_id != self.last_app_id + || data.title != self.last_title + || data.wm_instance != self.last_wm_instance + { debug!( r#"Changed window app_id="{}", title="{}", wm_instance="{}""#, data.app_id, data.title, data.wm_instance @@ -38,10 +43,14 @@ impl WindowWatcher { self.last_wm_instance = data.wm_instance.clone(); } - 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") + 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") } }