mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-24 12:12:09 +00:00
Add Net sanity checking
This disables network if the tx_bytes file is not found on Init()
This commit is contained in:
parent
35b7065879
commit
906a1259c3
3 changed files with 19 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -57,5 +57,7 @@ public:
|
|||
bool hasBlueZ = false;
|
||||
#endif
|
||||
|
||||
bool hasNet = true;
|
||||
|
||||
static RuntimeConfig& Get();
|
||||
};
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue