diff --git a/cosmic-applet-bluetooth/src/bluetooth.rs b/cosmic-applet-bluetooth/src/bluetooth.rs index 0b813a46..37fe74f8 100644 --- a/cosmic-applet-bluetooth/src/bluetooth.rs +++ b/cosmic-applet-bluetooth/src/bluetooth.rs @@ -132,16 +132,16 @@ pub struct BluerState { pub pairable: bool, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub enum BluerDeviceStatus { Connected, - Disconnected, - Paired, Connecting, - Disconnecting, + Paired, /// Pairing is in progress, maybe with a passkey or pincode /// passkey or pincode will be 000000 - 999999 Pairing, + Disconnected, + Disconnecting, } #[derive(Debug, Clone)] @@ -152,6 +152,34 @@ pub struct BluerDevice { pub properties: Vec, } +impl Eq for BluerDevice {} + +impl Ord for BluerDevice { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + match self.status.cmp(&other.status) { + std::cmp::Ordering::Equal => self.name.to_lowercase().cmp(&other.name.to_lowercase()), + o => o, + } + } +} + +impl PartialOrd for BluerDevice { + fn partial_cmp(&self, other: &Self) -> Option { + match self.status.cmp(&other.status) { + std::cmp::Ordering::Equal => { + Some(self.name.to_lowercase().cmp(&other.name.to_lowercase())) + } + o => Some(o), + } + } +} + +impl PartialEq for BluerDevice { + fn eq(&self, other: &Self) -> bool { + self.name == other.name && self.address == other.address + } +} + impl BluerDevice { pub async fn from_device(device: &bluer::Device) -> Self { let name = device @@ -606,5 +634,6 @@ async fn build_device_list(adapter: &Adapter) -> Vec { properties, }); } + devices.sort(); devices }