Userland: Add network adapter link status to SystemMonitor and applet

Add a column named 'Link status' to the Network tab in SystemMonitor
showing the speed and duplex if the link is up.
Add the link speed behind the existing text in the applet or show
'down' if the link is down.
This commit is contained in:
Thomas Wagenveld 2021-07-28 14:23:39 +02:00 committed by Gunnar Beutner
commit 3a40287776
Notes: sideshowbarker 2024-07-18 07:33:17 +09:00
2 changed files with 15 additions and 1 deletions

View file

@ -124,6 +124,8 @@ private:
auto& if_object = value.as_object();
auto ip_address = if_object.get("ipv4_address").to_string();
auto ifname = if_object.get("name").to_string();
auto link_up = if_object.get("link_up").as_bool();
auto link_speed = if_object.get("link_speed").to_i32();
if (!include_loopback)
if (ifname == "loop")
@ -134,7 +136,11 @@ private:
if (!adapter_info.is_empty())
adapter_info.append('\n');
adapter_info.appendff("{}: {}", ifname, ip_address);
adapter_info.appendff("{}: {} ", ifname, ip_address);
if (!link_up)
adapter_info.appendff("(down)");
else
adapter_info.appendff("({} Mb/s)", link_speed);
});
// show connected icon so long as at least one adapter is connected

View file

@ -48,6 +48,14 @@ NetworkStatisticsWidget::NetworkStatisticsWidget()
net_adapters_fields.empend("name", "Name", Gfx::TextAlignment::CenterLeft);
net_adapters_fields.empend("class_name", "Class", Gfx::TextAlignment::CenterLeft);
net_adapters_fields.empend("mac_address", "MAC", Gfx::TextAlignment::CenterLeft);
net_adapters_fields.empend("Link status", Gfx::TextAlignment::CenterLeft,
[this](JsonObject const& object) -> String {
if (!object.get("link_up").as_bool())
return "Down";
return String::formatted("{} Mb/s {}-duplex", object.get("link_speed").to_i32(),
object.get("link_full_duplex").as_bool() ? "full" : "half");
});
net_adapters_fields.empend("ipv4_address", "IPv4", Gfx::TextAlignment::CenterLeft);
net_adapters_fields.empend("packets_in", "Pkt In", Gfx::TextAlignment::CenterRight);
net_adapters_fields.empend("packets_out", "Pkt Out", Gfx::TextAlignment::CenterRight);