Skip to content

Commit

Permalink
Fix Bluetooth block not working when device has no icon (#2078)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blendman974 committed Aug 19, 2024
1 parent 9e43517 commit 7df3b8e
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/blocks/bluetooth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,25 +300,26 @@ impl DeviceMonitor {
async fn get_device_info(&mut self) -> Option<DeviceInfo> {
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(),
})
Expand Down

0 comments on commit 7df3b8e

Please sign in to comment.