From 878180ed5bdd5a66668b2735cb70b42d941972a2 Mon Sep 17 00:00:00 2001 From: Ivan Li Date: Wed, 10 May 2023 21:18:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BA=AE=E5=BA=A6=E8=B0=83=E8=8A=82?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E9=A2=91=E7=B9=81=E6=97=B6=E9=80=9A=E9=81=93?= =?UTF-8?q?=E8=A2=AB=E5=85=B3=E9=97=AD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/display/manager.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) 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(); } }