diff --git a/Cargo.lock b/Cargo.lock index 128e67ad..632d1e82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -668,7 +668,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel#9502913468dc7bf1cc17da6c1fcf1e274f43a769" +source = "git+https://github.com/pop-os/cosmic-panel#bab60b3883bd90b71b1be8bdf771fa11be0cf1dc" dependencies = [ "anyhow", "ron", @@ -1996,7 +1996,7 @@ dependencies = [ [[package]] name = "iced" version = "0.6.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" dependencies = [ "iced_core", "iced_futures", @@ -2013,7 +2013,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.6.2" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" dependencies = [ "bitflags", "palette", @@ -2023,7 +2023,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.5.1" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" dependencies = [ "futures", "log", @@ -2035,7 +2035,7 @@ dependencies = [ [[package]] name = "iced_glow" version = "0.5.1" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" dependencies = [ "bytemuck", "euclid", @@ -2050,7 +2050,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.5.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" dependencies = [ "bitflags", "bytemuck", @@ -2070,7 +2070,7 @@ dependencies = [ [[package]] name = "iced_lazy" version = "0.3.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" dependencies = [ "iced_native", "ouroboros 0.13.0", @@ -2079,7 +2079,7 @@ dependencies = [ [[package]] name = "iced_native" version = "0.7.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" dependencies = [ "iced_core", "iced_futures", @@ -2093,7 +2093,7 @@ dependencies = [ [[package]] name = "iced_sctk" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" dependencies = [ "enum-repr", "futures", @@ -2112,7 +2112,7 @@ dependencies = [ [[package]] name = "iced_style" version = "0.5.1" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" dependencies = [ "iced_core", "once_cell", @@ -2122,7 +2122,7 @@ dependencies = [ [[package]] name = "iced_swbuf" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" dependencies = [ "cosmic-text", "iced_graphics", @@ -2137,7 +2137,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.7.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" dependencies = [ "bitflags", "bytemuck", @@ -2327,7 +2327,7 @@ checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" dependencies = [ "apply", "cosmic-panel-config", @@ -2336,7 +2336,6 @@ dependencies = [ "freedesktop-icons", "iced", "iced_core", - "iced_glow", "iced_lazy", "iced_native", "iced_style", @@ -3953,9 +3952,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.23.0" +version = "1.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" +checksum = "38a54aca0c15d014013256222ba0ebed095673f89345dd79119d912eb561b7a8" dependencies = [ "autocfg", "bytes", diff --git a/cosmic-applet-network/Cargo.toml b/cosmic-applet-network/Cargo.toml index 18e681db..a1b75f8e 100644 --- a/cosmic-applet-network/Cargo.toml +++ b/cosmic-applet-network/Cargo.toml @@ -8,7 +8,7 @@ license = "GPL-3.0-or-later" once_cell = "1.16.0" cosmic-dbus-networkmanager = { git = "https://github.com/pop-os/dbus-settings-bindings", branch = "deps" } futures-util = "0.3.21" -libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet"] } +libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet", "tokio"] } sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", rev = "3776d4a" } futures = "0.3" zbus = { version = "3.6.2", no-default-features = true } diff --git a/cosmic-applet-network/i18n/en/cosmic_applet_network.ftl b/cosmic-applet-network/i18n/en/cosmic_applet_network.ftl index e19faeed..1a107ca3 100644 --- a/cosmic-applet-network/i18n/en/cosmic_applet_network.ftl +++ b/cosmic-applet-network/i18n/en/cosmic_applet_network.ftl @@ -5,3 +5,12 @@ ipv4 = IPv4 Address ipv6 = IPv6 Address mac = MAC megabits-per-second = Mbps +connected = Connected +connecting = Connecting +connect = Connect +cancel = Cancel +visible-wireless-networks = Visible Wireless Networks +enter-password = Enter the password or encryption key +router-wps-button = You can also connect by pressing the "WIPS" button on the router +unable-to-connect = Unable to connect to network +check-wifi-connection = Make sure Wi-Fi is connected to the internet and the password is correct \ No newline at end of file diff --git a/cosmic-applet-network/src/app.rs b/cosmic-applet-network/src/app.rs index 92949f8b..b81506d7 100644 --- a/cosmic-applet-network/src/app.rs +++ b/cosmic-applet-network/src/app.rs @@ -6,15 +6,31 @@ use cosmic::{ popup::{destroy_popup, get_popup}, SurfaceIdWrapper, }, - widget::{column, container, row, scrollable, text}, + widget::{column, container, row, scrollable, text, text_input}, Alignment, Application, Color, Command, Length, Subscription, }, - iced_native::window, - iced_style::{application, svg}, + iced_native::{ + alignment::{Horizontal, Vertical}, + layout::Limits, + renderer::BorderRadius, + subscription, window, + }, + iced_style::{application, button::StyleSheet, svg}, theme::{Button, Svg}, widget::{button, horizontal_rule, icon, list_column, toggler}, Element, Theme, }; +use cosmic::{ + iced_style, + widget::segmented_button::{ + self, + cosmic::{ + horizontal_segmented_selection, horizontal_view_switcher, vertical_segmented_selection, + vertical_view_switcher, + }, + }, +}; +use cosmic_dbus_networkmanager::access_point; use futures::channel::mpsc::UnboundedSender; use crate::{ @@ -30,7 +46,29 @@ pub fn run() -> cosmic::iced::Result { CosmicNetworkApplet::run(helper.window_settings()) } -#[derive(Clone, Default)] +enum NewConnectionState { + EnterPassword { + access_point: AccessPoint, + password: String, + }, + Waiting(AccessPoint), + Failure(AccessPoint), +} + +impl Into for NewConnectionState { + fn into(self) -> AccessPoint { + match self { + NewConnectionState::EnterPassword { + access_point, + password, + } => access_point, + NewConnectionState::Waiting(access_point) => access_point, + NewConnectionState::Failure(access_point) => access_point, + } + } +} + +#[derive(Default)] struct CosmicNetworkApplet { icon_name: String, theme: Theme, @@ -43,6 +81,8 @@ struct CosmicNetworkApplet { wireless_access_points: Vec, active_conns: Vec, nm_sender: Option>, + show_visible_networks: bool, + new_connection: Option, } impl CosmicNetworkApplet { @@ -72,10 +112,14 @@ enum Message { TogglePopup, ToggleAirplaneMode(bool), ToggleWiFi(bool), + ToggleVisibleNetworks, Errored(String), Ignore, NetworkManagerEvent(NetworkManagerEvent), - SelectWirelessAccessPoint(String), + SelectWirelessAccessPoint(AccessPoint), + CancelNewConnection, + Password(String), + SubmitPassword, } impl Application for CosmicNetworkApplet { @@ -109,13 +153,18 @@ impl Application for CosmicNetworkApplet { let new_id = window::Id::new(self.id_ctr); self.popup.replace(new_id); - let popup_settings = self.applet_helper.get_popup_settings( + let mut popup_settings = self.applet_helper.get_popup_settings( window::Id::new(0), new_id, None, None, None, ); + popup_settings.positioner.size_limits = Limits::NONE + .min_height(1) + .min_width(1) + .max_height(600) + .max_width(600); return get_popup(popup_settings); } } @@ -166,20 +215,65 @@ impl Application for CosmicNetworkApplet { if success { self.wireless_access_points = wireless_access_points; self.active_conns = active_conns; + self.wifi = wifi_enabled; self.update_icon_name(); } } }, - Message::SelectWirelessAccessPoint(ssid) => { - if let Some(tx) = self.nm_sender.as_ref() { - let _ = tx.unbounded_send(NetworkManagerRequest::SelectAccessPoint(ssid)); + Message::SelectWirelessAccessPoint(access_point) => { + // if let Some(tx) = self.nm_sender.as_ref() { + // let _ = tx.unbounded_send(NetworkManagerRequest::SelectAccessPoint( + // access_point.ssid.clone(), + // )); + // } + self.new_connection + .replace(NewConnectionState::EnterPassword { + access_point, + password: String::new(), + }); + } + Message::ToggleVisibleNetworks => { + self.new_connection.take(); + self.show_visible_networks = !self.show_visible_networks; + } + Message::Password(entered_pw) => { + dbg!(&entered_pw); + + match &mut self.new_connection { + Some(NewConnectionState::EnterPassword { password, .. }) => { + *password = entered_pw; + } + _ => {} } } + Message::SubmitPassword => { + // TODO setup connection + match self.new_connection.take() { + Some(new_connection) => { + self.new_connection + .replace(NewConnectionState::Failure(new_connection.into())); + } + None => {} + } + } + Message::CancelNewConnection => { + self.new_connection.take(); + } } Command::none() } fn view(&self, id: SurfaceIdWrapper) -> Element { + let button_style = Button::Custom { + active: |t| iced_style::button::Appearance { + border_radius: BorderRadius::from(0.0), + ..t.active(&Button::Text) + }, + hover: |t| iced_style::button::Appearance { + border_radius: BorderRadius::from(0.0), + ..t.hovered(&Button::Text) + }, + }; match id { SurfaceIdWrapper::LayerSurface(_) => unimplemented!(), SurfaceIdWrapper::Window(_) => self @@ -188,39 +282,23 @@ impl Application for CosmicNetworkApplet { .on_press(Message::TogglePopup) .into(), SurfaceIdWrapper::Popup(_) => { - let name = text(fl!("network")).size(18); - let icon = icon(&*self.icon_name, 24) - .style(Svg::Custom(|theme| svg::Appearance { - color: Some(theme.palette().text), - })) - .width(Length::Units(24)) - .height(Length::Units(24)); - let mut list_col = list_column(); - + let mut list_col = column![]; for conn in &self.active_conns { let el = match conn { ActiveConnectionInfo::Vpn { name, ip_addresses } => { let mut ipv4 = column![]; - let mut ipv6 = column![]; for addr in ip_addresses { match addr { std::net::IpAddr::V4(a) => { - ipv4 = ipv4.push(text(format!( - "{}: {}", - fl!("ipv4"), - a.to_string() - ))); - } - std::net::IpAddr::V6(a) => { - ipv6 = ipv6.push(text(format!( - "{}: {}", - fl!("ipv6"), - a.to_string() - ))); + ipv4 = ipv4.push( + text(format!("{}: {}", fl!("ipv4"), a.to_string())) + .size(12), + ); } + std::net::IpAddr::V6(a) => {} } } - column![text(name), ipv4, ipv6].spacing(4) + column![text(name), ipv4].spacing(4) } ActiveConnectionInfo::Wired { name, @@ -229,23 +307,15 @@ impl Application for CosmicNetworkApplet { ip_addresses, } => { let mut ipv4 = column![]; - let mut ipv6 = column![]; for addr in ip_addresses { match addr { std::net::IpAddr::V4(a) => { - ipv4 = ipv4.push(text(format!( - "{}: {}", - fl!("ipv4"), - a.to_string() - ))); - } - std::net::IpAddr::V6(a) => { - ipv6 = ipv6.push(text(format!( - "{}: {}", - fl!("ipv6"), - a.to_string() - ))); + ipv4 = ipv4.push( + text(format!("{}: {}", fl!("ipv4"), a.to_string())) + .size(12), + ); } + std::net::IpAddr::V6(a) => {} } } column![ @@ -255,27 +325,51 @@ impl Application for CosmicNetworkApplet { ] .spacing(16), ipv4, - ipv6, - text(format!("{}: {hw_address}", fl!("mac"))), ] .spacing(4) } ActiveConnectionInfo::WiFi { - name, hw_address, .. - } => column![row![ - text(name), - text(format!("{}: {hw_address}", fl!("mac"))) - ] - .spacing(12)] - .spacing(4), + name, ip_addresses, .. + } => { + let mut ipv4 = column![]; + for addr in ip_addresses { + match addr { + std::net::IpAddr::V4(a) => { + ipv4 = ipv4.push( + text(format!("{}: {}", fl!("ipv4"), a.to_string())) + .size(12), + ); + } + std::net::IpAddr::V6(a) => {} + } + } + column![button(Button::Secondary) + .custom(vec![ + icon("network-wireless-symbolic", 24) + .style(Svg::Custom(|theme| svg::Appearance { + color: Some(theme.palette().text), + })) + .width(Length::Units(24)) + .height(Length::Units(24)) + .into(), + column![text(name).size(14), ipv4,].into(), + text(format!("{}", fl!("connected"))) + .size(14) + .width(Length::Fill) + .height(Length::Units(24)) + .horizontal_alignment(Horizontal::Right) + .vertical_alignment(Vertical::Center) + .into() + ]) + .padding([8, 24]) + .style(button_style.clone()) + .on_press(Message::Ignore)] + } }; - list_col = list_col.add(el); + list_col = list_col.push(el); } let mut content = column![ - row![icon, name].spacing(8).width(Length::Fill), - list_col, - horizontal_rule(1), container( toggler(fl!("airplane-mode"), self.airplane_mode, |m| { Message::ToggleAirplaneMode(m) @@ -289,36 +383,178 @@ impl Application for CosmicNetworkApplet { .width(Length::Fill) ) .padding([0, 12]), + horizontal_rule(1), + list_col, ] .align_items(Alignment::Center) .spacing(8) - .padding(8); - if self.wifi { - let mut list_col = list_column(); - for ap in &self.wireless_access_points { - let button = self - .active_conns - .iter() - .find_map(|conn| match conn { - ActiveConnectionInfo::WiFi { name, .. } if name == &ap.ssid => { - Some( - button(Button::Primary) - .text(&ap.ssid) - .on_press(Message::Ignore) - .width(Length::Fill), - ) - } - _ => None, - }) - .unwrap_or_else(|| { - button(Button::Text) - .text(&ap.ssid) - .on_press(Message::SelectWirelessAccessPoint(ap.ssid.clone())) - .width(Length::Fill) - }); - list_col = list_col.add(button); + .padding([8, 0]); + let dropdown_icon = if self.show_visible_networks { + "go-down-symbolic" + } else { + "go-next-symbolic" + }; + let available_connections_btn = button(Button::Secondary) + .custom( + vec![ + text(fl!("visible-wireless-networks")) + .size(14) + .width(Length::Fill) + .height(Length::Units(24)) + .vertical_alignment(Vertical::Center) + .into(), + container( + icon(dropdown_icon, 14) + .style(Svg::Custom(|theme| svg::Appearance { + color: Some(theme.palette().text), + })) + .width(Length::Units(14)) + .height(Length::Units(14)), + ) + .align_x(Horizontal::Center) + .align_y(Vertical::Center) + .width(Length::Units(24)) + .height(Length::Units(24)) + .into(), + ] + .into(), + ) + .padding([8, 24]) + .style(button_style.clone()) + .on_press(Message::ToggleVisibleNetworks); + content = content.push(available_connections_btn); + if self.show_visible_networks { + if let Some(new_conn_state) = self.new_connection.as_ref() { + match new_conn_state { + NewConnectionState::EnterPassword { + access_point, + password, + } => { + let id = row![ + icon("network-wireless-symbolic", 24) + .style(Svg::Custom(|theme| svg::Appearance { + color: Some(theme.palette().text), + })) + .width(Length::Units(24)) + .height(Length::Units(24)), + text(&access_point.ssid).size(14), + ] + .align_items(Alignment::Center) + .width(Length::Fill) + .padding([0, 24]) + .spacing(12); + content = content.push(id); + let col = column![ + text(fl!("enter-password")), + text_input("", password, Message::Password) + .on_submit(Message::SubmitPassword) + .password(), + container(text(fl!("router-wps-button"))).padding(8), + row![ + button(Button::Secondary) + .custom(vec![container(text(fl!("cancel"))) + .padding([0, 24]) + .into()]) + .on_press(Message::CancelNewConnection), + button(Button::Secondary).custom(vec![container(text( + fl!("connect") + )) + .padding([0, 24]) + .into()]) + ] + .spacing(24) + ] + .spacing(8) + .padding([0, 48]) + .align_items(Alignment::Center); + content = content.push(col); + } + NewConnectionState::Waiting(access_point) => { + let connecting = row![ + icon("network-wireless-symbolic", 24) + .style(Svg::Custom(|theme| svg::Appearance { + color: Some(theme.palette().text), + })) + .width(Length::Units(24)) + .height(Length::Units(24)), + text(format!("{}", fl!("connecting"))) + .size(14) + .width(Length::Fill) + .height(Length::Units(24)) + .horizontal_alignment(Horizontal::Right) + .vertical_alignment(Vertical::Center) + ]; + content = content.push(connecting); + } + NewConnectionState::Failure(access_point) => { + let id = row![ + icon("network-wireless-symbolic", 24) + .style(Svg::Custom(|theme| svg::Appearance { + color: Some(theme.palette().text), + })) + .width(Length::Units(24)) + .height(Length::Units(24)), + text(&access_point.ssid).size(14), + ] + .align_items(Alignment::Center) + .width(Length::Fill) + .padding([0, 24]) + .spacing(8); + content = content.push(id); + let col = column![ + text(fl!("unable-to-connect")), + text(fl!("check-wifi-connection")), + row![ + button(Button::Secondary) + .custom(vec![container(text("Cancel")) + .padding([0, 24]) + .into()]) + .on_press(Message::CancelNewConnection), + button(Button::Secondary) + .custom(vec![container(text("Connect")) + .padding([0, 24]) + .into()]) + .on_press(Message::SelectWirelessAccessPoint( + access_point.clone() + )) + ] + .spacing(24) + ] + .spacing(16) + .padding([0, 48]) + .align_items(Alignment::Center); + content = content.push(col); + } + } + } else if self.wifi { + let mut list_col = column![]; + for ap in &self.wireless_access_points { + if self.active_conns.iter().any(|a| ap.ssid == a.name()) { + continue; + } + let button = button(button_style) + .custom(vec![row![ + icon("network-wireless-symbolic", 16) + .style(Svg::Custom(|theme| svg::Appearance { + color: Some(theme.palette().text), + })) + .width(Length::Units(16)) + .height(Length::Units(16)), + text(&ap.ssid) + .size(14) + .height(Length::Units(24)) + .vertical_alignment(Vertical::Center) + ] + .align_items(Alignment::Center) + .spacing(12) + .into()]) + .on_press(Message::SelectWirelessAccessPoint(ap.clone())) + .width(Length::Fill) + .padding([8, 24]); + list_col = list_col.push(button); + } + content = content.push(scrollable(list_col).height(Length::Units(300))); } - content = content.push(scrollable(list_col).height(Length::Units(300))); } self.applet_helper.popup_container(content).into() } diff --git a/cosmic-applet-network/src/network_manager/current_networks.rs b/cosmic-applet-network/src/network_manager/current_networks.rs index de714af6..a32bf354 100644 --- a/cosmic-applet-network/src/network_manager/current_networks.rs +++ b/cosmic-applet-network/src/network_manager/current_networks.rs @@ -39,6 +39,25 @@ pub async fn active_connections( continue; } for device in connection.devices().await.unwrap_or_default() { + let mut ip_addresses = Vec::new(); + for address_data in connection + .ip4_config() + .await? + .address_data() + .await + .unwrap_or_default() + { + ip_addresses.push(IpAddr::V4(address_data.address)); + } + for address_data in connection + .ip6_config() + .await? + .address_data() + .await + .unwrap_or_default() + { + ip_addresses.push(IpAddr::V6(address_data.address)); + } match device .downcast_to_device() .await @@ -46,25 +65,6 @@ pub async fn active_connections( .and_then(|inner| inner) { Some(SpecificDevice::Wired(wired_device)) => { - let mut ip_addresses = Vec::new(); - for address_data in device - .ip4_config() - .await? - .address_data() - .await - .unwrap_or_default() - { - ip_addresses.push(IpAddr::V4(address_data.address)); - } - for address_data in device - .ip6_config() - .await? - .address_data() - .await - .unwrap_or_default() - { - ip_addresses.push(IpAddr::V6(address_data.address)); - } info.push(ActiveConnectionInfo::Wired { name: connection.id().await?, hw_address: wired_device.hw_address().await?, @@ -76,6 +76,7 @@ pub async fn active_connections( if let Ok(access_point) = wireless_device.active_access_point().await { info.push(ActiveConnectionInfo::WiFi { name: String::from_utf8_lossy(&access_point.ssid().await?).into_owned(), + ip_addresses, hw_address: wireless_device.hw_address().await?, flags: access_point.flags().await?, rsn_flags: access_point.rsn_flags().await?, @@ -84,25 +85,6 @@ pub async fn active_connections( } } Some(SpecificDevice::WireGuard(_)) => { - let mut ip_addresses = Vec::new(); - for address_data in connection - .ip4_config() - .await? - .address_data() - .await - .unwrap_or_default() - { - ip_addresses.push(IpAddr::V4(address_data.address)); - } - for address_data in connection - .ip6_config() - .await? - .address_data() - .await - .unwrap_or_default() - { - ip_addresses.push(IpAddr::V6(address_data.address)); - } info.push(ActiveConnectionInfo::Vpn { name: connection.id().await?, ip_addresses, @@ -135,6 +117,7 @@ pub enum ActiveConnectionInfo { }, WiFi { name: String, + ip_addresses: Vec, hw_address: String, flags: ApFlags, rsn_flags: ApSecurityFlags, @@ -145,3 +128,13 @@ pub enum ActiveConnectionInfo { ip_addresses: Vec, }, } + +impl ActiveConnectionInfo { + pub fn name(&self) -> String { + match &self { + ActiveConnectionInfo::Wired { name, .. } => name.clone(), + ActiveConnectionInfo::WiFi { name, .. } => name.clone(), + ActiveConnectionInfo::Vpn { name, .. } => name.clone(), + } + } +}