Przeglądaj źródła

Userland: Make representation of 'null' IPv4-address friendlier

Show an empty column rather than 'null' in SystemMonitor and show
'no IP' in the network applet if the adapter has no IPv4-address
configured.
Thomas Wagenveld 4 lat temu
rodzic
commit
df6db8b8cc

+ 1 - 1
Userland/Applets/Network/main.cpp

@@ -122,7 +122,7 @@ private:
         int connected_adapters = 0;
         json.value().as_array().for_each([&adapter_info, include_loopback, &connected_adapters](auto& value) {
             auto& if_object = value.as_object();
-            auto ip_address = if_object.get("ipv4_address").to_string();
+            auto ip_address = if_object.get("ipv4_address").as_string_or("no IP");
             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();

+ 4 - 1
Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp

@@ -56,7 +56,10 @@ NetworkStatisticsWidget::NetworkStatisticsWidget()
                 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("IPv4", Gfx::TextAlignment::CenterLeft,
+            [this](JsonObject const& object) -> String {
+                return object.get("ipv4_address").as_string_or("");
+            });
         net_adapters_fields.empend("packets_in", "Pkt In", Gfx::TextAlignment::CenterRight);
         net_adapters_fields.empend("packets_out", "Pkt Out", Gfx::TextAlignment::CenterRight);
         net_adapters_fields.empend("bytes_in", "Bytes In", Gfx::TextAlignment::CenterRight);