feat(bluetooth): define ordering of device lists
This commit is contained in:
parent
b1a5468547
commit
7a9ab9de72
1 changed files with 33 additions and 4 deletions
|
|
@ -132,16 +132,16 @@ pub struct BluerState {
|
||||||
pub pairable: bool,
|
pub pairable: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum BluerDeviceStatus {
|
pub enum BluerDeviceStatus {
|
||||||
Connected,
|
Connected,
|
||||||
Disconnected,
|
|
||||||
Paired,
|
|
||||||
Connecting,
|
Connecting,
|
||||||
Disconnecting,
|
Paired,
|
||||||
/// Pairing is in progress, maybe with a passkey or pincode
|
/// Pairing is in progress, maybe with a passkey or pincode
|
||||||
/// passkey or pincode will be 000000 - 999999
|
/// passkey or pincode will be 000000 - 999999
|
||||||
Pairing,
|
Pairing,
|
||||||
|
Disconnected,
|
||||||
|
Disconnecting,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
@ -152,6 +152,34 @@ pub struct BluerDevice {
|
||||||
pub properties: Vec<DeviceProperty>,
|
pub properties: Vec<DeviceProperty>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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<std::cmp::Ordering> {
|
||||||
|
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 {
|
impl BluerDevice {
|
||||||
pub async fn from_device(device: &bluer::Device) -> Self {
|
pub async fn from_device(device: &bluer::Device) -> Self {
|
||||||
let name = device
|
let name = device
|
||||||
|
|
@ -606,5 +634,6 @@ async fn build_device_list(adapter: &Adapter) -> Vec<BluerDevice> {
|
||||||
properties,
|
properties,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
devices.sort();
|
||||||
devices
|
devices
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue