diff --git a/src-tauri/src/display/manager.rs b/src-tauri/src/display/manager.rs index 0ff24d5..78a4916 100644 --- a/src-tauri/src/display/manager.rs +++ b/src-tauri/src/display/manager.rs @@ -5,7 +5,10 @@ use std::{ use ddc_hi::Display; use paris::{error, info, warn}; -use tokio::{sync::{watch, OnceCell, RwLock}, task::yield_now}; +use tokio::{ + sync::{broadcast, watch, OnceCell, RwLock}, + task::yield_now, +}; use crate::rpc::{BoardMessageChannels, DisplaySetting}; @@ -75,7 +78,22 @@ impl DisplayManager { let channels = BoardMessageChannels::global().await; let mut request_rx = channels.display_setting_request_sender.subscribe(); - while let Ok(message) = request_rx.recv().await { + loop { + if let Err(err) = request_rx.recv().await { + match err { + broadcast::error::RecvError::Closed => { + info!("display setting request channel closed"); + break; + } + broadcast::error::RecvError::Lagged(_) => { + warn!("display setting request channel lagged"); + continue; + } + } + } + + let message = request_rx.recv().await.unwrap(); + let displays = displays.write().await; let display = displays.get(message.display_index); @@ -84,7 +102,6 @@ impl DisplayManager { continue; } - let display = display.unwrap().write().await; let result = match message.setting { DisplaySetting::Brightness(value) => display.set_brightness(value as u16).await, @@ -122,8 +139,8 @@ impl DisplayManager { impl Drop for DisplayManager { fn drop(&mut self) { + log::info!("dropping display manager============="); if let Some(handler) = self.setting_request_handler.take() { - info!("abort display setting request handler"); handler.abort(); } }