Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
powellnorma committed Oct 15, 2024
1 parent dd974db commit d719c54
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
5 changes: 3 additions & 2 deletions watchers/src/report_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
23 changes: 16 additions & 7 deletions watchers/src/watchers/x11_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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")
}
}

Expand Down

0 comments on commit d719c54

Please sign in to comment.