feat: more improvements to network applet

This commit is contained in:
Ashley Wulber 2023-01-07 00:21:16 -05:00
parent 13ccc03676
commit c10087a55d
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
6 changed files with 363 additions and 128 deletions

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
use cosmic_dbus_networkmanager::device::wireless::WirelessDevice;
use cosmic_dbus_networkmanager::{device::wireless::WirelessDevice, interface::enums::DeviceState};
use futures_util::StreamExt;
use itertools::Itertools;
@ -16,17 +16,32 @@ pub async fn handle_wireless_device(device: WirelessDevice<'_>) -> zbus::Result<
}
}
let access_points = device.get_access_points().await?;
let state: DeviceState = device
.upcast()
.await
.and_then(|dev| dev.cached_state())
.unwrap_or_default()
.map(|s| s.into())
.unwrap_or_else(|| DeviceState::Unknown);
// Sort by strength and remove duplicates
let mut aps = HashMap::<String, AccessPoint>::new();
for ap in access_points {
let ssid = String::from_utf8_lossy(&ap.ssid().await?.clone()).into_owned();
let strength = ap.strength().await?;
if let Some(access_point) = aps.get(&ssid) {
if access_point.strength > strength {
continue;
}
}
aps.insert(ssid.clone(), AccessPoint { ssid, strength });
aps.insert(
ssid.clone(),
AccessPoint {
ssid,
strength,
state: state,
},
);
}
let aps = aps
.into_iter()
@ -40,4 +55,5 @@ pub async fn handle_wireless_device(device: WirelessDevice<'_>) -> zbus::Result<
pub struct AccessPoint {
pub ssid: String,
pub strength: u8,
pub state: DeviceState,
}