Skip to content

Commit

Permalink
improve(bluetooth): ignore devices with unknown type and without alias
Browse files Browse the repository at this point in the history
  • Loading branch information
abachmann authored and mmstick committed Feb 7, 2025
1 parent 91dadae commit 6fea8dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cosmic-settings/src/pages/bluetooth/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions cosmic-settings/src/pages/bluetooth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 6fea8dc

Please sign in to comment.