network: Don't show SSID multiple times, and make sure it's sorted
This commit is contained in:
parent
14101dc7db
commit
3782df1e96
3 changed files with 22 additions and 14 deletions
|
|
@ -7,10 +7,10 @@ pub mod task;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
pub mod widgets;
|
pub mod widgets;
|
||||||
|
|
||||||
use gtk4::{glib, gio::ApplicationFlags, prelude::*, Orientation, Separator};
|
use cosmic_panel_config::config::{CosmicPanelConfig, XdgWrapperConfig};
|
||||||
|
use gtk4::{gio::ApplicationFlags, glib, prelude::*, Orientation, Separator};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
use cosmic_panel_config::config::{CosmicPanelConfig, XdgWrapperConfig};
|
|
||||||
|
|
||||||
static RT: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("failed to build tokio runtime"));
|
static RT: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("failed to build tokio runtime"));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,11 @@ use gtk4::{
|
||||||
Image, ListBox, ListBoxRow, Separator,
|
Image, ListBox, ListBoxRow, Separator,
|
||||||
};
|
};
|
||||||
use libcosmic_widgets::{relm4::RelmContainerExt, LabeledItem};
|
use libcosmic_widgets::{relm4::RelmContainerExt, LabeledItem};
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{
|
||||||
|
cell::RefCell,
|
||||||
|
collections::{BTreeMap, HashMap},
|
||||||
|
rc::Rc,
|
||||||
|
};
|
||||||
use zbus::Connection;
|
use zbus::Connection;
|
||||||
|
|
||||||
pub fn add_available_wifi(target: >k4::Box, separator: Separator) {
|
pub fn add_available_wifi(target: >k4::Box, separator: Separator) {
|
||||||
|
|
@ -90,9 +94,7 @@ async fn handle_wireless_device(
|
||||||
device: WirelessDevice<'_>,
|
device: WirelessDevice<'_>,
|
||||||
tx: Sender<Vec<AccessPoint>>,
|
tx: Sender<Vec<AccessPoint>>,
|
||||||
) -> zbus::Result<()> {
|
) -> zbus::Result<()> {
|
||||||
device
|
device.request_scan(HashMap::new()).await?;
|
||||||
.request_scan(std::collections::HashMap::new())
|
|
||||||
.await?;
|
|
||||||
let mut scan_changed = device.receive_last_scan_changed().await;
|
let mut scan_changed = device.receive_last_scan_changed().await;
|
||||||
if let Some(t) = scan_changed.next().await {
|
if let Some(t) = scan_changed.next().await {
|
||||||
if let Ok(-1) = t.get().await {
|
if let Ok(-1) = t.get().await {
|
||||||
|
|
@ -101,13 +103,19 @@ async fn handle_wireless_device(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let access_points = device.get_access_points().await?;
|
let access_points = device.get_access_points().await?;
|
||||||
let mut aps = Vec::with_capacity(access_points.len());
|
// Sort by SSID and remove duplicates
|
||||||
|
let mut aps = BTreeMap::<String, AccessPoint>::new();
|
||||||
for ap in access_points {
|
for ap in access_points {
|
||||||
aps.push(AccessPoint {
|
let ssid = String::from_utf8_lossy(&ap.ssid().await?.clone()).into_owned();
|
||||||
ssid: String::from_utf8_lossy(&ap.ssid().await?.clone()).into_owned(),
|
let strength = ap.strength().await?;
|
||||||
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 });
|
||||||
}
|
}
|
||||||
|
let aps = aps.into_iter().map(|(_, x)| x).collect();
|
||||||
tx.send(aps).expect("failed to send back to main thread");
|
tx.send(aps).expect("failed to send back to main thread");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ fn display_active_connections(
|
||||||
} => {
|
} => {
|
||||||
icon_image.set_icon_name(Some("network-wired-symbolic"));
|
icon_image.set_icon_name(Some("network-wired-symbolic"));
|
||||||
render_wired_connection(name, speed, ip_addresses)
|
render_wired_connection(name, speed, ip_addresses)
|
||||||
},
|
}
|
||||||
ActiveConnectionInfo::WiFi {
|
ActiveConnectionInfo::WiFi {
|
||||||
name,
|
name,
|
||||||
hw_address,
|
hw_address,
|
||||||
|
|
@ -64,7 +64,7 @@ fn display_active_connections(
|
||||||
ActiveConnectionInfo::Vpn { name, ip_addresses } => {
|
ActiveConnectionInfo::Vpn { name, ip_addresses } => {
|
||||||
icon_image.set_icon_name(Some("network-vpn-symbolic"));
|
icon_image.set_icon_name(Some("network-vpn-symbolic"));
|
||||||
render_vpn(name, ip_addresses)
|
render_vpn(name, ip_addresses)
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
let entry = ListBoxRow::builder().child(&entry).build();
|
let entry = ListBoxRow::builder().child(&entry).build();
|
||||||
target.append(&entry);
|
target.append(&entry);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue