mirror of
https://github.com/2e3s/awatcher.git
synced 2025-06-06 11:35:46 +00:00
cargo fmt
This commit is contained in:
parent
dd974db422
commit
d719c54fdd
@ -4,9 +4,9 @@ use anyhow::Context;
|
|||||||
use aw_client_rust::{AwClient, Event as AwEvent};
|
use aw_client_rust::{AwClient, Event as AwEvent};
|
||||||
use chrono::{DateTime, TimeDelta, Utc};
|
use chrono::{DateTime, TimeDelta, Utc};
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
pub struct ReportClient {
|
pub struct ReportClient {
|
||||||
pub client: AwClient,
|
pub client: AwClient,
|
||||||
@ -94,7 +94,8 @@ impl ReportClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_active_window(&self, app_id: &str, title: &str) -> anyhow::Result<()> {
|
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(
|
pub async fn send_active_window_with_extra(
|
||||||
|
@ -2,8 +2,8 @@ use super::{x11_connection::X11Client, Watcher};
|
|||||||
use crate::report_client::ReportClient;
|
use crate::report_client::ReportClient;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct WindowWatcher {
|
pub struct WindowWatcher {
|
||||||
client: X11Client,
|
client: X11Client,
|
||||||
@ -22,13 +22,18 @@ impl WindowWatcher {
|
|||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let mut extra_data = HashMap::new();
|
let mut extra_data = HashMap::new();
|
||||||
extra_data.insert("wm_instance".to_string(), wm_instance.to_string());
|
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<()> {
|
async fn send_active_window(&mut self, client: &ReportClient) -> anyhow::Result<()> {
|
||||||
let data = self.client.active_window_data()?;
|
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!(
|
debug!(
|
||||||
r#"Changed window app_id="{}", title="{}", wm_instance="{}""#,
|
r#"Changed window app_id="{}", title="{}", wm_instance="{}""#,
|
||||||
data.app_id, data.title, data.wm_instance
|
data.app_id, data.title, data.wm_instance
|
||||||
@ -38,8 +43,12 @@ impl WindowWatcher {
|
|||||||
self.last_wm_instance = data.wm_instance.clone();
|
self.last_wm_instance = data.wm_instance.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self.send_active_window_with_instance(
|
||||||
.send_active_window_with_instance(client, &self.last_app_id, &self.last_title, &self.last_wm_instance)
|
client,
|
||||||
|
&self.last_app_id,
|
||||||
|
&self.last_title,
|
||||||
|
&self.last_wm_instance,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.with_context(|| "Failed to send heartbeat for active window")
|
.with_context(|| "Failed to send heartbeat for active window")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user