mirror of
https://github.com/2e3s/awatcher.git
synced 2025-06-04 02:20:15 +00:00
Remove async_trait crate
This commit is contained in:
parent
e39e720f5e
commit
ddc36b75b6
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -3814,7 +3814,6 @@ name = "watchers"
|
||||
version = "0.2.4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"aw-client-rust",
|
||||
"chrono",
|
||||
"dirs 5.0.1",
|
||||
|
@ -31,7 +31,6 @@ regex = "1.10.2"
|
||||
gethostname = "0.4.3"
|
||||
log = { workspace = true }
|
||||
anyhow = { workspace = true }
|
||||
async-trait = "0.1.75"
|
||||
tokio = { workspace = true, features = ["time", "sync"] }
|
||||
|
||||
[features]
|
||||
|
@ -16,8 +16,7 @@ mod x11_screensaver_idle;
|
||||
mod x11_window;
|
||||
|
||||
use crate::{config::Config, report_client::ReportClient};
|
||||
use async_trait::async_trait;
|
||||
use std::{fmt::Display, sync::Arc};
|
||||
use std::{fmt::Display, sync::Arc, pin::Pin, future::Future};
|
||||
use tokio::time;
|
||||
|
||||
pub enum WatcherType {
|
||||
@ -43,13 +42,11 @@ impl Display for WatcherType {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait Watcher: Send {
|
||||
async fn new(client: &Arc<ReportClient>) -> anyhow::Result<Self>
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
async fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()>;
|
||||
fn run_iteration<'a>(
|
||||
&'a mut self,
|
||||
client: &'a Arc<ReportClient>,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<()>> + Send + 'a>>;
|
||||
}
|
||||
|
||||
macro_rules! watch {
|
||||
|
@ -1,8 +1,7 @@
|
||||
use super::{gnome_wayland::load_watcher, gnome_wayland::GnomeWatcher, idle, Watcher};
|
||||
use crate::report_client::ReportClient;
|
||||
use anyhow::Context;
|
||||
use async_trait::async_trait;
|
||||
use std::sync::Arc;
|
||||
use std::{sync::Arc, pin::Pin, future::Future};
|
||||
use zbus::Connection;
|
||||
|
||||
pub struct IdleWatcher {
|
||||
@ -10,7 +9,6 @@ pub struct IdleWatcher {
|
||||
is_idle: bool,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl idle::SinceLastInput for IdleWatcher {
|
||||
async fn seconds_since_input(&mut self) -> anyhow::Result<u32> {
|
||||
let ms = self
|
||||
@ -40,15 +38,21 @@ impl GnomeWatcher for IdleWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Watcher for IdleWatcher {
|
||||
async fn new(_: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
impl IdleWatcher {
|
||||
pub async fn new(_: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
load_watcher().await
|
||||
}
|
||||
}
|
||||
|
||||
async fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||
self.is_idle = idle::ping_since_last_input(self, self.is_idle, client).await?;
|
||||
|
||||
Ok(())
|
||||
impl Watcher for IdleWatcher {
|
||||
fn run_iteration<'a>(
|
||||
&'a mut self,
|
||||
client: &'a Arc<ReportClient>,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<()>> + Send + 'a>> {
|
||||
Box::pin(async move {
|
||||
self.is_idle = idle::ping_since_last_input(self, self.is_idle, client).await?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::report_client::ReportClient;
|
||||
use anyhow::Context;
|
||||
use async_trait::async_trait;
|
||||
use serde::Deserialize;
|
||||
use std::sync::Arc;
|
||||
use zbus::Connection;
|
||||
@ -20,6 +19,10 @@ struct WindowData {
|
||||
}
|
||||
|
||||
impl WindowWatcher {
|
||||
pub async fn new(_: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
load_watcher().await
|
||||
}
|
||||
|
||||
async fn get_window_data(&self) -> anyhow::Result<WindowData> {
|
||||
let call_response = self
|
||||
.dbus_connection
|
||||
@ -92,12 +95,7 @@ impl GnomeWatcher for WindowWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Watcher for WindowWatcher {
|
||||
async fn new(_: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
load_watcher().await
|
||||
}
|
||||
|
||||
async fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||
self.send_active_window(client).await
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
use crate::report_client::ReportClient;
|
||||
use async_trait::async_trait;
|
||||
use chrono::{Duration, Utc};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[async_trait]
|
||||
pub trait SinceLastInput {
|
||||
async fn seconds_since_input(&mut self) -> anyhow::Result<u32>;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
use super::Watcher;
|
||||
use crate::report_client::ReportClient;
|
||||
use anyhow::{anyhow, Context};
|
||||
use async_trait::async_trait;
|
||||
use std::env::{self, temp_dir};
|
||||
use std::path::Path;
|
||||
use std::sync::{mpsc::channel, Arc};
|
||||
@ -167,9 +166,8 @@ pub struct WindowWatcher {
|
||||
_kwin_script: KWinScript,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Watcher for WindowWatcher {
|
||||
async fn new(_: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
impl WindowWatcher {
|
||||
pub async fn new(_: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
let mut kwin_script = KWinScript::new(Connection::session().await?);
|
||||
if kwin_script.is_loaded().await? {
|
||||
debug!("KWin script is already loaded, unloading");
|
||||
@ -230,7 +228,9 @@ impl Watcher for WindowWatcher {
|
||||
_kwin_script: kwin_script,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Watcher for WindowWatcher {
|
||||
async fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||
send_active_window(client, &self.active_window).await
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ use super::wl_connection::{subscribe_state, WlEventConnection};
|
||||
use super::Watcher;
|
||||
use crate::report_client::ReportClient;
|
||||
use anyhow::anyhow;
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Duration, Utc};
|
||||
use std::sync::Arc;
|
||||
use wayland_client::{
|
||||
@ -127,9 +126,8 @@ pub struct IdleWatcher {
|
||||
idle_state: IdleState,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Watcher for IdleWatcher {
|
||||
async fn new(client: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
impl IdleWatcher {
|
||||
pub async fn new(client: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
let mut connection: WlEventConnection<IdleState> = WlEventConnection::connect()?;
|
||||
connection.get_ext_idle()?;
|
||||
|
||||
@ -146,7 +144,9 @@ impl Watcher for IdleWatcher {
|
||||
idle_state,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Watcher for IdleWatcher {
|
||||
async fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||
self.connection
|
||||
.event_queue
|
||||
|
@ -2,7 +2,6 @@ use super::wl_connection::WlEventConnection;
|
||||
use super::{wl_connection::subscribe_state, Watcher};
|
||||
use crate::report_client::ReportClient;
|
||||
use anyhow::{anyhow, Context};
|
||||
use async_trait::async_trait;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use wayland_client::{
|
||||
@ -138,11 +137,8 @@ impl WindowWatcher {
|
||||
.await
|
||||
.with_context(|| "Failed to send heartbeat for active window")
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Watcher for WindowWatcher {
|
||||
async fn new(_: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
pub async fn new(_: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
let mut connection: WlEventConnection<ToplevelState> = WlEventConnection::connect()?;
|
||||
connection.get_foreign_toplevel_manager()?;
|
||||
|
||||
@ -159,6 +155,9 @@ impl Watcher for WindowWatcher {
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Watcher for WindowWatcher {
|
||||
async fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||
self.connection
|
||||
.event_queue
|
||||
|
@ -2,7 +2,6 @@ use super::wl_connection::{subscribe_state, WlEventConnection};
|
||||
use super::Watcher;
|
||||
use crate::report_client::ReportClient;
|
||||
use anyhow::anyhow;
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Duration, Utc};
|
||||
use std::sync::Arc;
|
||||
use wayland_client::{
|
||||
@ -128,9 +127,8 @@ pub struct IdleWatcher {
|
||||
idle_state: IdleState,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Watcher for IdleWatcher {
|
||||
async fn new(client: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
impl IdleWatcher {
|
||||
pub async fn new(client: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
let mut connection: WlEventConnection<IdleState> = WlEventConnection::connect()?;
|
||||
connection.get_kwin_idle()?;
|
||||
|
||||
@ -145,6 +143,9 @@ impl Watcher for IdleWatcher {
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Watcher for IdleWatcher {
|
||||
async fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||
self.connection
|
||||
.event_queue
|
||||
|
@ -1,5 +1,3 @@
|
||||
use async_trait::async_trait;
|
||||
|
||||
use super::{idle, x11_connection::X11Client, Watcher};
|
||||
use crate::report_client::ReportClient;
|
||||
use std::sync::Arc;
|
||||
@ -9,16 +7,14 @@ pub struct IdleWatcher {
|
||||
is_idle: bool,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl idle::SinceLastInput for IdleWatcher {
|
||||
async fn seconds_since_input(&mut self) -> anyhow::Result<u32> {
|
||||
self.client.seconds_since_last_input()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Watcher for IdleWatcher {
|
||||
async fn new(_: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
impl IdleWatcher {
|
||||
pub async fn new(_: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
let mut client = X11Client::new()?;
|
||||
|
||||
// Check if screensaver extension is supported
|
||||
@ -29,7 +25,9 @@ impl Watcher for IdleWatcher {
|
||||
is_idle: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Watcher for IdleWatcher {
|
||||
async fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||
self.is_idle = idle::ping_since_last_input(self, self.is_idle, client).await?;
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
use super::{x11_connection::X11Client, Watcher};
|
||||
use crate::report_client::ReportClient;
|
||||
use anyhow::Context;
|
||||
use async_trait::async_trait;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct WindowWatcher {
|
||||
@ -30,9 +29,8 @@ impl WindowWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Watcher for WindowWatcher {
|
||||
async fn new(_: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
impl WindowWatcher {
|
||||
pub async fn new(_: &Arc<ReportClient>) -> anyhow::Result<Self> {
|
||||
let mut client = X11Client::new()?;
|
||||
client.active_window_data()?;
|
||||
|
||||
@ -43,6 +41,9 @@ impl Watcher for WindowWatcher {
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Watcher for WindowWatcher {
|
||||
async fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||
self.send_active_window(client).await
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user