diff --git a/watchers/src/watchers.rs b/watchers/src/watchers.rs index 9a52ea5..21f88bd 100644 --- a/watchers/src/watchers.rs +++ b/watchers/src/watchers.rs @@ -64,12 +64,14 @@ pub trait Watcher: Send { warn!("Received an exit signal, shutting down {watcher_type}"); 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)); } } - fn run_iteration(&mut self, client: &Arc); + fn run_iteration(&mut self, client: &Arc) -> anyhow::Result<()>; } type BoxedWatcher = Box; diff --git a/watchers/src/watchers/gnome_idle.rs b/watchers/src/watchers/gnome_idle.rs index 48ec538..9c8cb5e 100644 --- a/watchers/src/watchers/gnome_idle.rs +++ b/watchers/src/watchers/gnome_idle.rs @@ -36,12 +36,9 @@ impl Watcher for IdleWatcher { Ok(watcher) } - fn run_iteration(&mut self, client: &Arc) { - match idle::ping_since_last_input(self, self.is_idle, client) { - Ok(is_idle_again) => { - self.is_idle = is_idle_again; - } - Err(e) => error!("Error on idle iteration: {e}"), - }; + fn run_iteration(&mut self, client: &Arc) -> anyhow::Result<()> { + self.is_idle = idle::ping_since_last_input(self, self.is_idle, client)?; + + Ok(()) } } diff --git a/watchers/src/watchers/gnome_window.rs b/watchers/src/watchers/gnome_window.rs index 8208795..50d5de9 100644 --- a/watchers/src/watchers/gnome_window.rs +++ b/watchers/src/watchers/gnome_window.rs @@ -85,9 +85,7 @@ impl Watcher for WindowWatcher { Ok(watcher) } - fn run_iteration(&mut self, client: &Arc) { - if let Err(error) = self.send_active_window(client) { - error!("Error on active window: {error}"); - } + fn run_iteration(&mut self, client: &Arc) -> anyhow::Result<()> { + self.send_active_window(client) } } diff --git a/watchers/src/watchers/kwin_window.rs b/watchers/src/watchers/kwin_window.rs index b34f9e2..4b6e2cc 100644 --- a/watchers/src/watchers/kwin_window.rs +++ b/watchers/src/watchers/kwin_window.rs @@ -201,9 +201,7 @@ impl Watcher for WindowWatcher { }) } - fn run_iteration(&mut self, client: &Arc) { - if let Err(error) = send_active_window(client, &self.active_window) { - error!("Error on sending active window: {error}"); - } + fn run_iteration(&mut self, client: &Arc) -> anyhow::Result<()> { + send_active_window(client, &self.active_window) } } diff --git a/watchers/src/watchers/wl_foreign_toplevel.rs b/watchers/src/watchers/wl_foreign_toplevel.rs index ce0abdd..4de86fc 100644 --- a/watchers/src/watchers/wl_foreign_toplevel.rs +++ b/watchers/src/watchers/wl_foreign_toplevel.rs @@ -155,15 +155,12 @@ impl Watcher for WindowWatcher { }) } - fn run_iteration(&mut self, client: &Arc) { - if let Err(e) = self - .connection + fn run_iteration(&mut self, client: &Arc) -> anyhow::Result<()> { + self.connection .event_queue .roundtrip(&mut self.toplevel_state) - { - error!("Event queue is not processed: {e}"); - } else if let Err(e) = self.send_active_window(client) { - error!("Error on iteration: {e}"); - } + .map_err(|e| anyhow!("Event queue is not processed: {e}"))?; + + self.send_active_window(client) } } diff --git a/watchers/src/watchers/wl_kwin_idle.rs b/watchers/src/watchers/wl_kwin_idle.rs index 7dbcb9c..3b8350e 100644 --- a/watchers/src/watchers/wl_kwin_idle.rs +++ b/watchers/src/watchers/wl_kwin_idle.rs @@ -2,6 +2,7 @@ use super::wl_bindings; use super::wl_connection::{subscribe_state, WlEventConnection}; use super::Watcher; use crate::report_client::ReportClient; +use anyhow::anyhow; use chrono::{DateTime, Duration, Utc}; use std::sync::Arc; use wayland_client::{ @@ -131,11 +132,12 @@ impl Watcher for IdleWatcher { }) } - fn run_iteration(&mut self, client: &Arc) { - if let Err(e) = self.connection.event_queue.roundtrip(&mut self.idle_state) { - error!("Event queue is not processed: {e}"); - } else if let Err(e) = self.idle_state.send_ping(client) { - error!("Error on idle iteration: {e}"); - } + fn run_iteration(&mut self, client: &Arc) -> anyhow::Result<()> { + self.connection + .event_queue + .roundtrip(&mut self.idle_state) + .map_err(|e| anyhow!("Event queue is not processed: {e}"))?; + + self.idle_state.send_ping(client) } } diff --git a/watchers/src/watchers/x11_screensaver_idle.rs b/watchers/src/watchers/x11_screensaver_idle.rs index 7a79688..4964f29 100644 --- a/watchers/src/watchers/x11_screensaver_idle.rs +++ b/watchers/src/watchers/x11_screensaver_idle.rs @@ -26,12 +26,9 @@ impl Watcher for IdleWatcher { }) } - fn run_iteration(&mut self, client: &Arc) { - match idle::ping_since_last_input(self, self.is_idle, client) { - Ok(is_idle_again) => { - self.is_idle = is_idle_again; - } - Err(e) => error!("Error on idle iteration: {e}"), - }; + fn run_iteration(&mut self, client: &Arc) -> anyhow::Result<()> { + self.is_idle = idle::ping_since_last_input(self, self.is_idle, client)?; + + Ok(()) } } diff --git a/watchers/src/watchers/x11_window.rs b/watchers/src/watchers/x11_window.rs index b75ed84..231d233 100644 --- a/watchers/src/watchers/x11_window.rs +++ b/watchers/src/watchers/x11_window.rs @@ -40,9 +40,7 @@ impl Watcher for WindowWatcher { }) } - fn run_iteration(&mut self, client: &Arc) { - if let Err(error) = self.send_active_window(client) { - error!("Error on sending active window: {error}"); - } + fn run_iteration(&mut self, client: &Arc) -> anyhow::Result<()> { + self.send_active_window(client) } }