From 7df3b8eb2c2ce5a5491147ba3d497287092e5b2d Mon Sep 17 00:00:00 2001 From: Blendman974 Date: Mon, 19 Aug 2024 10:13:27 +0400 Subject: [PATCH] Fix Bluetooth block not working when device has no icon (#2078) --- src/blocks/bluetooth.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/blocks/bluetooth.rs b/src/blocks/bluetooth.rs index 89540af28..8bfb064d0 100644 --- a/src/blocks/bluetooth.rs +++ b/src/blocks/bluetooth.rs @@ -300,25 +300,26 @@ impl DeviceMonitor { async fn get_device_info(&mut self) -> Option { let device = self.device.as_ref()?; - let Ok((connected, icon, name)) = tokio::try_join!( - device.device.connected(), - device.device.icon(), - device.device.name(), - ) else { + let Ok((connected, name)) = + tokio::try_join!(device.device.connected(), device.device.name(),) + else { debug!("failed to fetch device info, assuming device or bluez disappeared"); self.device = None; return None; }; + //icon can be null, so ignore errors when fetching it + let icon: &str = match device.device.icon().await.ok().as_deref() { + Some("audio-card" | "audio-headset" | "audio-headphones") => "headphones", + Some("input-gaming") => "joystick", + Some("input-keyboard") => "keyboard", + Some("input-mouse") => "mouse", + _ => "bluetooth", + }; + Some(DeviceInfo { connected, - icon: match icon.as_str() { - "audio-card" | "audio-headset" | "audio-headphones" => "headphones", - "input-gaming" => "joystick", - "input-keyboard" => "keyboard", - "input-mouse" => "mouse", - _ => "bluetooth", - }, + icon, name, battery_percentage: device.battery.percentage().await.ok(), })