Show IP address for current wired

This commit is contained in:
Lucy 2022-02-08 14:11:15 -05:00
parent d53171519a
commit 4c4f1300e4
No known key found for this signature in database
GPG key ID: EBC517FAD666BBF1
2 changed files with 18 additions and 5 deletions

2
Cargo.lock generated
View file

@ -236,7 +236,7 @@ dependencies = [
[[package]]
name = "cosmic-dbus-networkmanager"
version = "0.1.0"
source = "git+https://github.com/pop-os/dbus-settings-bindings#8bdccc1f18fb80543318c7748cf0b78ced268add"
source = "git+https://github.com/pop-os/dbus-settings-bindings#a81830cd20bd97922c7ead697ac6ef87635bf374"
dependencies = [
"bitflags",
"derive_builder",

View file

@ -11,7 +11,7 @@ use gtk4::{
prelude::*,
Image, Orientation,
};
use std::{cell::RefCell, rc::Rc};
use std::{cell::RefCell, net::Ipv4Addr, rc::Rc};
use zbus::Connection;
pub fn add_current_networks(target: &gtk4::Box) {
@ -44,7 +44,8 @@ fn display_active_connections(
name,
hw_address,
speed,
} => render_wired_connection(name, speed),
ip_address,
} => render_wired_connection(name, speed, ip_address),
ActiveConnectionInfo::WiFi {
name,
hw_address,
@ -58,7 +59,7 @@ fn display_active_connections(
}
}
fn render_wired_connection(name: String, speed: u32) -> gtk4::Box {
fn render_wired_connection(name: String, speed: u32, ip_address: Ipv4Addr) -> gtk4::Box {
view! {
entry = gtk4::Box {
set_orientation: Orientation::Horizontal,
@ -72,7 +73,7 @@ fn render_wired_connection(name: String, speed: u32) -> gtk4::Box {
set_label: &name,
},
append: wired_ip = &gtk4::Label {
set_label: "IP Address: N/A",
set_label: &format!("IP Address: {}", ip_address),
}
},
append: wired_speed = &gtk4::Label {
@ -94,10 +95,21 @@ async fn handle_devices(tx: Sender<Vec<ActiveConnectionInfo>>) -> zbus::Result<(
for device in connection.devices().await? {
match device.downcast_to_device().await? {
Some(SpecificDevice::Wired(wired_device)) => {
let ip4_config = device.ip4_config().await?;
let ip_address = ip4_config
.addresses()
.await?
.into_iter()
.next()
.unwrap()
.into_iter()
.next()
.unwrap();
info.push(ActiveConnectionInfo::Wired {
name: connection.id().await?,
hw_address: wired_device.hw_address().await?,
speed: wired_device.speed().await?,
ip_address,
});
}
Some(SpecificDevice::Wireless(wireless_device)) => {
@ -125,6 +137,7 @@ enum ActiveConnectionInfo {
name: String,
hw_address: String,
speed: u32,
ip_address: Ipv4Addr,
},
WiFi {
name: String,