fix wired speed detection and layout (#1156)

* fix wired speed detection and layout

* show 2.5 Gbps and 2.5 Tbps interface with decimal values
This commit is contained in:
Fred 2025-11-14 00:34:42 +01:00 committed by GitHub
parent 1e27c3f2f4
commit 8320b54074
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 51 additions and 8 deletions

View file

@ -754,6 +754,30 @@ impl cosmic::Application for CosmicNetworkApplet {
ipv4.push(text(format!("{}: {}", fl!("ipv4"), addr)).size(12).into());
}
let mut right_column = vec![text::body(fl!("connected")).into()];
// Only show speed if it's greater than 0
if *speed > 0 {
let speed_text = if *speed >= 1_000_000 {
let tbps = *speed as f64 / 1_000_000.0;
if tbps.fract() == 0.0 {
format!("{} {}", tbps as u32, fl!("terabits-per-second"))
} else {
format!("{:.1} {}", tbps, fl!("terabits-per-second"))
}
} else if *speed >= 1_000 {
let gbps = *speed as f64 / 1_000.0;
if gbps.fract() == 0.0 {
format!("{} {}", gbps as u32, fl!("gigabits-per-second"))
} else {
format!("{:.1} {}", gbps, fl!("gigabits-per-second"))
}
} else {
format!("{speed} {}", fl!("megabits-per-second"))
};
right_column.push(text(speed_text).size(12).into());
}
vpn_ethernet_col = vpn_ethernet_col.push(column![
row![
icon::icon(
@ -763,13 +787,9 @@ impl cosmic::Application for CosmicNetworkApplet {
)
.size(40),
Column::with_children(ipv4),
text::body(format!(
"{} - {speed} {}",
fl!("connected"),
fl!("megabits-per-second")
))
.width(Length::Fill)
.align_x(Alignment::End),
Column::with_children(right_column)
.width(Length::Fill)
.align_x(Alignment::End),
]
.align_y(Alignment::Center)
.spacing(8)