improve(bluetooth): ignore devices with unknown type and without alias

This commit is contained in:
Alexander Bachmann 2025-02-07 21:50:41 +01:00 committed by Michael Murphy
parent 91dadaec90
commit 6fea8dc624
2 changed files with 11 additions and 1 deletions

View file

@ -158,6 +158,8 @@ impl PartialEq for Adapter {
impl Eq for Adapter {}
const default_device_icon: &str = "bluetooth-symbolic";
fn device_type_to_icon(device_type: &str) -> &'static str {
match device_type {
"computer" => "laptop-symbolic",
@ -173,7 +175,7 @@ fn device_type_to_icon(device_type: &str) -> &'static str {
"input-mouse" => "input-mouse-symbolic",
"printer" => "printer-network-symbolic",
"camera-photo" => "camera-photo-symbolic",
_ => "bluetooth-symbolic",
_ => default_device_icon,
}
}
@ -266,6 +268,10 @@ impl Device {
self.alias.is_some()
}
#[must_use]
pub fn is_known_device_type(&self) -> bool {
self.icon != default_device_icon
}
#[must_use]
pub fn alias_or_addr(&self) -> &str {
self.alias.as_ref().unwrap_or(&self.address)
}

View file

@ -746,6 +746,10 @@ fn available_devices() -> Section<crate::pages::Message> {
return None::<Element<'_, Message>>;
}
if !device.is_known_device_type() && !device.has_alias() {
return None::<Element<'_, Message>>;
}
let mut items = vec![
widget::icon::from_name(device.icon).size(16).into(),
text(device.alias_or_addr()).wrapping(Wrapping::Word).into(),