From b529f8003486f24a88f16a8819a55bd47a835528 Mon Sep 17 00:00:00 2001 From: Lucy Date: Thu, 10 Feb 2022 12:33:18 -0500 Subject: [PATCH] VPN connection support --- .../src/ui/current_networks.rs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/applets/cosmic-applet-network/src/ui/current_networks.rs b/applets/cosmic-applet-network/src/ui/current_networks.rs index 77e3440c..5969b3ca 100644 --- a/applets/cosmic-applet-network/src/ui/current_networks.rs +++ b/applets/cosmic-applet-network/src/ui/current_networks.rs @@ -53,6 +53,7 @@ fn display_active_connections( rsn_flags, wpa_flags, } => todo!(), + ActiveConnectionInfo::Vpn { name, ip_addresses } => render_vpn(name, ip_addresses), }; let entry = ListBoxRow::builder().child(&entry).build(); target.append(&entry); @@ -94,6 +95,36 @@ fn render_wired_connection(name: String, speed: u32, ip_addresses: Vec) entry } +fn render_vpn(name: String, ip_addresses: Vec) -> gtk4::Box { + view! { + entry = gtk4::Box { + set_orientation: Orientation::Horizontal, + set_spacing: 8, + append: wired_icon = &Image { + set_icon_name: Some("network-vpn-symbolic"), + set_icon_size: IconSize::Large + }, + append: wired_label_box = >k4::Box { + set_orientation: Orientation::Vertical, + append: wired_label = >k4::Label { + set_label: &name, + set_halign: gtk4::Align::Start, + } + } + } + } + for address in ip_addresses { + view! { + wired_ip = gtk4::Label { + set_label: &format!("IP Address: {}", address), + set_halign: gtk4::Align::Start, + } + } + wired_label_box.append(&wired_ip); + } + entry +} + async fn handle_devices(tx: Sender>) -> zbus::Result<()> { let conn = Connection::system().await?; let network_manager = NetworkManager::new(&conn).await?; @@ -101,6 +132,20 @@ async fn handle_devices(tx: Sender>) -> zbus::Result<( let active_connections = network_manager.active_connections().await?; let mut info = Vec::::with_capacity(active_connections.len()); for connection in active_connections { + if connection.vpn().await? { + let mut ip_addresses = Vec::new(); + for address_data in connection.ip4_config().await?.address_data().await? { + ip_addresses.push(IpAddr::V4(address_data.address)); + } + for address_data in connection.ip6_config().await?.address_data().await? { + ip_addresses.push(IpAddr::V6(address_data.address)); + } + info.push(ActiveConnectionInfo::Vpn { + name: connection.id().await?, + ip_addresses, + }); + continue; + } for device in connection.devices().await? { match device.downcast_to_device().await? { Some(SpecificDevice::Wired(wired_device)) => { @@ -152,4 +197,8 @@ enum ActiveConnectionInfo { rsn_flags: ApSecurityFlags, wpa_flags: ApSecurityFlags, }, + Vpn { + name: String, + ip_addresses: Vec, + }, }