mirror of
https://github.com/2e3s/awatcher.git
synced 2025-06-07 12:05:49 +00:00
Simplify iteration errors
This commit is contained in:
parent
79f8e53850
commit
59b2c88c65
@ -64,12 +64,14 @@ pub trait Watcher: Send {
|
|||||||
warn!("Received an exit signal, shutting down {watcher_type}");
|
warn!("Received an exit signal, shutting down {watcher_type}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
self.run_iteration(client);
|
if let Err(e) = self.run_iteration(client) {
|
||||||
|
error!("Error on {watcher_type} iteration: {e}");
|
||||||
|
}
|
||||||
thread::sleep(watcher_type.sleep_time(&client.config));
|
thread::sleep(watcher_type.sleep_time(&client.config));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_iteration(&mut self, client: &Arc<ReportClient>);
|
fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
type BoxedWatcher = Box<dyn Watcher>;
|
type BoxedWatcher = Box<dyn Watcher>;
|
||||||
|
@ -36,12 +36,9 @@ impl Watcher for IdleWatcher {
|
|||||||
Ok(watcher)
|
Ok(watcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_iteration(&mut self, client: &Arc<ReportClient>) {
|
fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||||
match idle::ping_since_last_input(self, self.is_idle, client) {
|
self.is_idle = idle::ping_since_last_input(self, self.is_idle, client)?;
|
||||||
Ok(is_idle_again) => {
|
|
||||||
self.is_idle = is_idle_again;
|
Ok(())
|
||||||
}
|
|
||||||
Err(e) => error!("Error on idle iteration: {e}"),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,9 +85,7 @@ impl Watcher for WindowWatcher {
|
|||||||
Ok(watcher)
|
Ok(watcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_iteration(&mut self, client: &Arc<ReportClient>) {
|
fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||||
if let Err(error) = self.send_active_window(client) {
|
self.send_active_window(client)
|
||||||
error!("Error on active window: {error}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,9 +201,7 @@ impl Watcher for WindowWatcher {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_iteration(&mut self, client: &Arc<ReportClient>) {
|
fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||||
if let Err(error) = send_active_window(client, &self.active_window) {
|
send_active_window(client, &self.active_window)
|
||||||
error!("Error on sending active window: {error}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,15 +155,12 @@ impl Watcher for WindowWatcher {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_iteration(&mut self, client: &Arc<ReportClient>) {
|
fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||||
if let Err(e) = self
|
self.connection
|
||||||
.connection
|
|
||||||
.event_queue
|
.event_queue
|
||||||
.roundtrip(&mut self.toplevel_state)
|
.roundtrip(&mut self.toplevel_state)
|
||||||
{
|
.map_err(|e| anyhow!("Event queue is not processed: {e}"))?;
|
||||||
error!("Event queue is not processed: {e}");
|
|
||||||
} else if let Err(e) = self.send_active_window(client) {
|
self.send_active_window(client)
|
||||||
error!("Error on iteration: {e}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ use super::wl_bindings;
|
|||||||
use super::wl_connection::{subscribe_state, WlEventConnection};
|
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 chrono::{DateTime, Duration, Utc};
|
use chrono::{DateTime, Duration, Utc};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wayland_client::{
|
use wayland_client::{
|
||||||
@ -131,11 +132,12 @@ impl Watcher for IdleWatcher {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_iteration(&mut self, client: &Arc<ReportClient>) {
|
fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||||
if let Err(e) = self.connection.event_queue.roundtrip(&mut self.idle_state) {
|
self.connection
|
||||||
error!("Event queue is not processed: {e}");
|
.event_queue
|
||||||
} else if let Err(e) = self.idle_state.send_ping(client) {
|
.roundtrip(&mut self.idle_state)
|
||||||
error!("Error on idle iteration: {e}");
|
.map_err(|e| anyhow!("Event queue is not processed: {e}"))?;
|
||||||
}
|
|
||||||
|
self.idle_state.send_ping(client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,12 +26,9 @@ impl Watcher for IdleWatcher {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_iteration(&mut self, client: &Arc<ReportClient>) {
|
fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||||
match idle::ping_since_last_input(self, self.is_idle, client) {
|
self.is_idle = idle::ping_since_last_input(self, self.is_idle, client)?;
|
||||||
Ok(is_idle_again) => {
|
|
||||||
self.is_idle = is_idle_again;
|
Ok(())
|
||||||
}
|
|
||||||
Err(e) => error!("Error on idle iteration: {e}"),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,9 +40,7 @@ impl Watcher for WindowWatcher {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_iteration(&mut self, client: &Arc<ReportClient>) {
|
fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||||
if let Err(error) = self.send_active_window(client) {
|
self.send_active_window(client)
|
||||||
error!("Error on sending active window: {error}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user