From 3a402877763009c325acce9ee9a545898143c2dc Mon Sep 17 00:00:00 2001 From: Thomas Wagenveld Date: Wed, 28 Jul 2021 14:23:39 +0200 Subject: [PATCH] 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. --- Userland/Applets/Network/main.cpp | 8 +++++++- .../SystemMonitor/NetworkStatisticsWidget.cpp | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Userland/Applets/Network/main.cpp b/Userland/Applets/Network/main.cpp index 196fafc3c2..7c5952b42b 100644 --- a/Userland/Applets/Network/main.cpp +++ b/Userland/Applets/Network/main.cpp @@ -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 diff --git a/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp b/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp index 8178689532..89181f5a25 100644 --- a/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp +++ b/Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp @@ -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);