Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions cosmic-applet-network/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,26 @@ struct CosmicNetworkApplet {
hw_device_to_show: Option<HwAddress>,
}

fn wifi_icon(strength: u8) -> &'static str {
fn wifi_icon(strength: u8, network_type: NetworkType) -> &'static str {
match network_type {
NetworkType::Open => wifi_icon_open(strength),
_ => wifi_icon_secure(strength),
}
}

fn wifi_icon_secure(strength: u8) -> &'static str {
if strength < 25 {
"network-wireless-secure-signal-weak-symbolic"
} else if strength < 50 {
"network-wireless-secure-signal-ok-symbolic"
} else if strength < 75 {
"network-wireless-secure-signal-good-symbolic"
} else {
"network-wireless-secure-signal-excellent-symbolic"
}
}

fn wifi_icon_open(strength: u8) -> &'static str {
if strength < 25 {
"network-wireless-signal-weak-symbolic"
} else if strength < 50 {
Expand Down Expand Up @@ -171,7 +190,7 @@ impl CosmicNetworkApplet {
(
"network-wired-disconnected-symbolic",
ActiveConnectionInfo::WiFi { strength, .. },
) => wifi_icon(*strength),
) => wifi_icon(*strength, NetworkType::Open), // Use Open icon for clarity
(_, ActiveConnectionInfo::Wired { .. })
if icon_name != "network-vpn-symbolic" =>
{
Expand Down Expand Up @@ -710,6 +729,7 @@ impl cosmic::Application for CosmicNetworkApplet {
state,
strength,
hw_address,
network_type,
} => {
if self.hw_device_to_show.is_some()
&& hw_address != self.hw_device_to_show.as_ref().unwrap()
Expand All @@ -721,10 +741,13 @@ impl cosmic::Application for CosmicNetworkApplet {
ipv4.push(text(format!("{}: {}", fl!("ipv4"), addr)).size(12).into());
}
let mut btn_content = vec![
icon::from_name(wifi_icon(*strength))
.size(24)
.symbolic(true)
.into(),
icon::from_name(wifi_icon(
*strength,
network_type.unwrap_or(NetworkType::Open),
))
.size(24)
.symbolic(true)
.into(),
column![text::body(name), Column::with_children(ipv4)]
.width(Length::Fill)
.into(),
Expand Down Expand Up @@ -935,7 +958,7 @@ impl cosmic::Application for CosmicNetworkApplet {
btn_content.push(ssid.into());
} else {
btn_content.push(
icon::from_name(wifi_icon(known.strength))
icon::from_name(wifi_icon(known.strength, known.network_type))
.size(24)
.symbolic(true)
.into(),
Expand Down Expand Up @@ -1129,7 +1152,7 @@ impl cosmic::Application for CosmicNetworkApplet {
}
let button = menu_button(
row![
icon::from_name(wifi_icon(ap.strength))
icon::from_name(wifi_icon(ap.strength, ap.network_type))
.size(16)
.symbolic(true),
text::body(&ap.ssid).align_y(Alignment::Center)
Expand Down
33 changes: 21 additions & 12 deletions cosmic-applet-network/src/network_manager/available_wifi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,9 @@ pub async fn handle_wireless_device(
}
};
let proxy: &AccessPointProxy = &ap;
let Ok(flags) = ap.rsn_flags().await else {
continue;
};

let network_type = if flags.intersects(ApSecurityFlags::KEY_MGMT_802_1X) {
NetworkType::EAP
} else if flags.intersects(ApSecurityFlags::KEY_MGMTPSK) {
NetworkType::PSK
} else if flags.is_empty() {
NetworkType::Open
} else {
continue;
let network_type = match get_network_type(&ap).await {
Some(value) => value,
None => continue,
};

aps.insert(
Expand All @@ -85,6 +76,24 @@ pub async fn handle_wireless_device(
Ok(aps)
}

pub async fn get_network_type(
access_point: &cosmic_dbus_networkmanager::access_point::AccessPoint<'_>,
) -> Option<NetworkType> {
let Ok(flags) = access_point.rsn_flags().await else {
return None;
};
let network_type = if flags.intersects(ApSecurityFlags::KEY_MGMT_802_1X) {
NetworkType::EAP
} else if flags.intersects(ApSecurityFlags::KEY_MGMTPSK) {
NetworkType::PSK
} else if flags.is_empty() {
NetworkType::Open
} else {
return None;
};
Some(network_type)
}

#[derive(Debug, Clone)]
pub struct AccessPoint {
pub ssid: String,
Expand Down
3 changes: 3 additions & 0 deletions cosmic-applet-network/src/network_manager/current_networks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use cosmic_dbus_networkmanager::{
};
use std::net::Ipv4Addr;

use super::available_wifi::{get_network_type, NetworkType};
use super::hw_address::HwAddress;

pub async fn active_connections(
Expand Down Expand Up @@ -59,6 +60,7 @@ pub async fn active_connections(
.unwrap_or_default(),
state,
strength: access_point.strength().await.unwrap_or_default(),
network_type: get_network_type(&access_point).await,
});
}
}
Expand Down Expand Up @@ -99,6 +101,7 @@ pub enum ActiveConnectionInfo {
hw_address: HwAddress,
state: ActiveConnectionState,
strength: u8,
network_type: Option<NetworkType>,
},
Vpn {
name: String,
Expand Down
Loading