Show all IPs
This commit is contained in:
parent
4c4f1300e4
commit
8ef033f39e
2 changed files with 24 additions and 20 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
|
@ -236,13 +236,14 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-dbus-networkmanager"
|
name = "cosmic-dbus-networkmanager"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/dbus-settings-bindings#a81830cd20bd97922c7ead697ac6ef87635bf374"
|
source = "git+https://github.com/pop-os/dbus-settings-bindings#4f28c3c02be771a542df4a10a00f51a409010fe4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"derive_builder",
|
"derive_builder",
|
||||||
"procfs",
|
"procfs",
|
||||||
"time 0.3.7",
|
"time 0.3.7",
|
||||||
"zbus",
|
"zbus",
|
||||||
|
"zvariant",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use gtk4::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
Image, Orientation,
|
Image, Orientation,
|
||||||
};
|
};
|
||||||
use std::{cell::RefCell, net::Ipv4Addr, rc::Rc};
|
use std::{cell::RefCell, net::IpAddr, rc::Rc};
|
||||||
use zbus::Connection;
|
use zbus::Connection;
|
||||||
|
|
||||||
pub fn add_current_networks(target: >k4::Box) {
|
pub fn add_current_networks(target: >k4::Box) {
|
||||||
|
|
@ -44,8 +44,8 @@ fn display_active_connections(
|
||||||
name,
|
name,
|
||||||
hw_address,
|
hw_address,
|
||||||
speed,
|
speed,
|
||||||
ip_address,
|
ip_addresses,
|
||||||
} => render_wired_connection(name, speed, ip_address),
|
} => render_wired_connection(name, speed, ip_addresses),
|
||||||
ActiveConnectionInfo::WiFi {
|
ActiveConnectionInfo::WiFi {
|
||||||
name,
|
name,
|
||||||
hw_address,
|
hw_address,
|
||||||
|
|
@ -59,7 +59,7 @@ fn display_active_connections(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_wired_connection(name: String, speed: u32, ip_address: Ipv4Addr) -> gtk4::Box {
|
fn render_wired_connection(name: String, speed: u32, ip_addresses: Vec<IpAddr>) -> gtk4::Box {
|
||||||
view! {
|
view! {
|
||||||
entry = gtk4::Box {
|
entry = gtk4::Box {
|
||||||
set_orientation: Orientation::Horizontal,
|
set_orientation: Orientation::Horizontal,
|
||||||
|
|
@ -71,9 +71,6 @@ fn render_wired_connection(name: String, speed: u32, ip_address: Ipv4Addr) -> gt
|
||||||
set_orientation: Orientation::Vertical,
|
set_orientation: Orientation::Vertical,
|
||||||
append: wired_label = >k4::Label {
|
append: wired_label = >k4::Label {
|
||||||
set_label: &name,
|
set_label: &name,
|
||||||
},
|
|
||||||
append: wired_ip = >k4::Label {
|
|
||||||
set_label: &format!("IP Address: {}", ip_address),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
append: wired_speed = >k4::Label {
|
append: wired_speed = >k4::Label {
|
||||||
|
|
@ -82,6 +79,15 @@ fn render_wired_connection(name: String, speed: u32, ip_address: Ipv4Addr) -> gt
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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
|
entry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,21 +101,18 @@ async fn handle_devices(tx: Sender<Vec<ActiveConnectionInfo>>) -> zbus::Result<(
|
||||||
for device in connection.devices().await? {
|
for device in connection.devices().await? {
|
||||||
match device.downcast_to_device().await? {
|
match device.downcast_to_device().await? {
|
||||||
Some(SpecificDevice::Wired(wired_device)) => {
|
Some(SpecificDevice::Wired(wired_device)) => {
|
||||||
let ip4_config = device.ip4_config().await?;
|
let mut ip_addresses = Vec::new();
|
||||||
let ip_address = ip4_config
|
for address_data in device.ip4_config().await?.address_data().await? {
|
||||||
.addresses()
|
ip_addresses.push(IpAddr::V4(address_data.address));
|
||||||
.await?
|
}
|
||||||
.into_iter()
|
for address_data in device.ip6_config().await?.address_data().await? {
|
||||||
.next()
|
ip_addresses.push(IpAddr::V6(address_data.address));
|
||||||
.unwrap()
|
}
|
||||||
.into_iter()
|
|
||||||
.next()
|
|
||||||
.unwrap();
|
|
||||||
info.push(ActiveConnectionInfo::Wired {
|
info.push(ActiveConnectionInfo::Wired {
|
||||||
name: connection.id().await?,
|
name: connection.id().await?,
|
||||||
hw_address: wired_device.hw_address().await?,
|
hw_address: wired_device.hw_address().await?,
|
||||||
speed: wired_device.speed().await?,
|
speed: wired_device.speed().await?,
|
||||||
ip_address,
|
ip_addresses,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Some(SpecificDevice::Wireless(wireless_device)) => {
|
Some(SpecificDevice::Wireless(wireless_device)) => {
|
||||||
|
|
@ -137,7 +140,7 @@ enum ActiveConnectionInfo {
|
||||||
name: String,
|
name: String,
|
||||||
hw_address: String,
|
hw_address: String,
|
||||||
speed: u32,
|
speed: u32,
|
||||||
ip_address: Ipv4Addr,
|
ip_addresses: Vec<IpAddr>,
|
||||||
},
|
},
|
||||||
WiFi {
|
WiFi {
|
||||||
name: String,
|
name: String,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue