From eb1d5457d4a5e207445043ddbff246ea44988485 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Fri, 20 Sep 2024 22:32:20 +0200 Subject: [PATCH] fix(wired): display known connections when unplugged --- Cargo.lock | 2 +- cosmic-settings/src/pages/networking/wired.rs | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a58349..b16e2e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1646,7 +1646,7 @@ dependencies = [ [[package]] name = "cosmic-settings-subscriptions" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-settings-subscriptions#90df5c4b22c47f0e0213dcf2025519b0312437df" +source = "git+https://github.com/pop-os/cosmic-settings-subscriptions#ece1b2475c9eb90e0f2042b743577670e799a010" dependencies = [ "cosmic-dbus-networkmanager", "futures", diff --git a/cosmic-settings/src/pages/networking/wired.rs b/cosmic-settings/src/pages/networking/wired.rs index 56a56ae..bf76e83 100644 --- a/cosmic-settings/src/pages/networking/wired.rs +++ b/cosmic-settings/src/pages/networking/wired.rs @@ -11,9 +11,10 @@ use cosmic::{ widget::{self, icon}, Apply, Command, Element, }; +use cosmic_dbus_networkmanager::interface::enums::DeviceState; use cosmic_settings_page::{self as page, section, Section}; use cosmic_settings_subscriptions::network_manager::{ - self, current_networks::ActiveConnectionInfo, devices::DeviceState, NetworkManagerState, + self, current_networks::ActiveConnectionInfo, NetworkManagerState, }; pub type ConnectionId = Arc; @@ -446,13 +447,14 @@ impl Page { remove_txt: &'a str, settings_txt: &'a str, wired_conns_txt: &'a str, + unplugged_txt: &'a str, device: &'a network_manager::devices::DeviceInfo, ) -> Element<'a, Message> { - let has_multiple_connection_profiles = device.available_connections.len() > 1; + let has_multiple_connection_profiles = device.known_connections.len() > 1; let header_txt = format!("{}", wired_conns_txt); device - .available_connections + .known_connections .iter() .fold( widget::settings::section().title(header_txt), @@ -467,6 +469,8 @@ impl Page { let (connect_txt, connect_msg) = if is_connected { (connected_txt, None) + } else if device.state == DeviceState::Unavailable { + (unplugged_txt, None) } else { ( connect_txt, @@ -552,6 +556,7 @@ fn devices_view() -> Section { connected_txt = fl!("connected"); settings_txt = fl!("settings"); disconnect_txt = fl!("disconnect"); + unplugged_txt = fl!("network-device-state", "unplugged"); }); Section::default() @@ -570,8 +575,7 @@ fn devices_view() -> Section { let active_device = page .active_device .as_ref() - .or_else(|| (nm_state.devices.len() == 1).then(|| nm_state.devices.get(0))?) - .filter(|device| !matches!(device.state, DeviceState::Unavailable)); + .or_else(|| (nm_state.devices.len() == 1).then(|| nm_state.devices.get(0))?); view = match active_device { Some(device) => view.push(page.device_view( @@ -583,6 +587,7 @@ fn devices_view() -> Section { §ion.descriptions[remove_txt], §ion.descriptions[settings_txt], §ion.descriptions[wired_conns_txt], + §ion.descriptions[unplugged_txt], device, )),