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