diff --git a/src/Bar.cpp b/src/Bar.cpp index c6aaf1b..d4982fa 100644 --- a/src/Bar.cpp +++ b/src/Bar.cpp @@ -555,7 +555,7 @@ namespace Bar if (RuntimeConfig::Get().hasBlueZ) WidgetBluetooth(*right); #endif - if (Config::Get().networkWidget) + if (Config::Get().networkWidget && RuntimeConfig::Get().hasNet) WidgetNetwork(*right); WidgetSensors(*right); diff --git a/src/Config.h b/src/Config.h index fe3c03b..ab11249 100644 --- a/src/Config.h +++ b/src/Config.h @@ -57,5 +57,7 @@ public: bool hasBlueZ = false; #endif + bool hasNet = true; + static RuntimeConfig& Get(); }; diff --git a/src/System.cpp b/src/System.cpp index fd427d7..61e42cd 100644 --- a/src/System.cpp +++ b/src/System.cpp @@ -467,10 +467,23 @@ namespace System } #endif + void CheckNetwork() + { + std::ifstream bytes("/sys/class/net/" + Config::Get().networkAdapter + "/statistics/tx_bytes"); + if (!bytes.is_open()) + { + LOG("Cannot open network device! Disabling Network widget."); + RuntimeConfig::Get().hasNet = false; + } + } + double GetNetworkBpsCommon(double dt, uint64_t& prevBytes, const std::string& deviceFile) { + if (!RuntimeConfig::Get().hasNet) + { + return 0.f; + } std::ifstream bytes(deviceFile); - ASSERT(bytes.is_open(), "Couldn't open " << deviceFile); std::string bytesStr; std::getline(bytes, bytesStr); @@ -563,6 +576,8 @@ namespace System #endif PulseAudio::Init(); + + CheckNetwork(); } void FreeResources() {