Simplify iteration errors

This commit is contained in:
Demmie 2023-05-11 19:00:32 -04:00
parent 79f8e53850
commit 59b2c88c65
No known key found for this signature in database
GPG Key ID: B06DAA3D432C6E9A
8 changed files with 31 additions and 42 deletions

View File

@ -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<ReportClient>);
fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()>;
}
type BoxedWatcher = Box<dyn Watcher>;

View File

@ -36,12 +36,9 @@ impl Watcher for IdleWatcher {
Ok(watcher)
}
fn run_iteration(&mut self, client: &Arc<ReportClient>) {
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<ReportClient>) -> anyhow::Result<()> {
self.is_idle = idle::ping_since_last_input(self, self.is_idle, client)?;
Ok(())
}
}

View File

@ -85,9 +85,7 @@ impl Watcher for WindowWatcher {
Ok(watcher)
}
fn run_iteration(&mut self, client: &Arc<ReportClient>) {
if let Err(error) = self.send_active_window(client) {
error!("Error on active window: {error}");
}
fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
self.send_active_window(client)
}
}

View File

@ -201,9 +201,7 @@ impl Watcher for WindowWatcher {
})
}
fn run_iteration(&mut self, client: &Arc<ReportClient>) {
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<ReportClient>) -> anyhow::Result<()> {
send_active_window(client, &self.active_window)
}
}

View File

@ -155,15 +155,12 @@ impl Watcher for WindowWatcher {
})
}
fn run_iteration(&mut self, client: &Arc<ReportClient>) {
if let Err(e) = self
.connection
fn run_iteration(&mut self, client: &Arc<ReportClient>) -> 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)
}
}

View File

@ -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<ReportClient>) {
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<ReportClient>) -> 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)
}
}

View File

@ -26,12 +26,9 @@ impl Watcher for IdleWatcher {
})
}
fn run_iteration(&mut self, client: &Arc<ReportClient>) {
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<ReportClient>) -> anyhow::Result<()> {
self.is_idle = idle::ping_since_last_input(self, self.is_idle, client)?;
Ok(())
}
}

View File

@ -40,9 +40,7 @@ impl Watcher for WindowWatcher {
})
}
fn run_iteration(&mut self, client: &Arc<ReportClient>) {
if let Err(error) = self.send_active_window(client) {
error!("Error on sending active window: {error}");
}
fn run_iteration(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
self.send_active_window(client)
}
}