From cda123096f274b28eb27c26af990ef0af56a623e Mon Sep 17 00:00:00 2001 From: Alexander Bachmann Date: Sat, 8 Feb 2025 02:13:45 +0100 Subject: [PATCH] improve(bluetooth): ignore devices with unknown type and without alias --- cosmic-applet-bluetooth/src/app.rs | 1 + cosmic-applet-bluetooth/src/bluetooth.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cosmic-applet-bluetooth/src/app.rs b/cosmic-applet-bluetooth/src/app.rs index 715a1e96..4b89a9cd 100644 --- a/cosmic-applet-bluetooth/src/app.rs +++ b/cosmic-applet-bluetooth/src/app.rs @@ -528,6 +528,7 @@ impl cosmic::Application for CosmicBluetoothApplet { .request_confirmation .as_ref() .map_or(false, |(dev, _, _)| d.address == dev.address) + && (d.has_name() || d.is_known_device_type()) }) { let row = row![ icon::from_name(dev.icon.as_str()).size(16).symbolic(true), diff --git a/cosmic-applet-bluetooth/src/bluetooth.rs b/cosmic-applet-bluetooth/src/bluetooth.rs index 98bfb94a..337b2441 100644 --- a/cosmic-applet-bluetooth/src/bluetooth.rs +++ b/cosmic-applet-bluetooth/src/bluetooth.rs @@ -222,6 +222,8 @@ impl PartialEq for BluerDevice { } } +const default_device_icon: &str = "bluetooth-symbolic"; + impl BluerDevice { pub async fn from_device(device: &bluer::Device) -> Self { let mut name = device @@ -251,7 +253,7 @@ impl BluerDevice { None } }) - .unwrap_or_else(|| "bluetooth-symbolic".into()); + .unwrap_or_else(|| default_device_icon.into()); Self { name, @@ -274,6 +276,16 @@ impl BluerDevice { .count() == 2 } + + #[must_use] + pub fn is_known_device_type(&self) -> bool { + self.icon != default_device_icon + } + + #[must_use] + pub fn has_name(&self) -> bool { + self.name != self.address.to_string() + } } #[derive(Debug, Clone)]