mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-24 20:22:10 +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)
|
if (RuntimeConfig::Get().hasBlueZ)
|
||||||
WidgetBluetooth(*right);
|
WidgetBluetooth(*right);
|
||||||
#endif
|
#endif
|
||||||
if (Config::Get().networkWidget)
|
if (Config::Get().networkWidget && RuntimeConfig::Get().hasNet)
|
||||||
WidgetNetwork(*right);
|
WidgetNetwork(*right);
|
||||||
|
|
||||||
WidgetSensors(*right);
|
WidgetSensors(*right);
|
||||||
|
|
|
@ -57,5 +57,7 @@ public:
|
||||||
bool hasBlueZ = false;
|
bool hasBlueZ = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool hasNet = true;
|
||||||
|
|
||||||
static RuntimeConfig& Get();
|
static RuntimeConfig& Get();
|
||||||
};
|
};
|
||||||
|
|
|
@ -467,10 +467,23 @@ namespace System
|
||||||
}
|
}
|
||||||
#endif
|
#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)
|
double GetNetworkBpsCommon(double dt, uint64_t& prevBytes, const std::string& deviceFile)
|
||||||
{
|
{
|
||||||
|
if (!RuntimeConfig::Get().hasNet)
|
||||||
|
{
|
||||||
|
return 0.f;
|
||||||
|
}
|
||||||
std::ifstream bytes(deviceFile);
|
std::ifstream bytes(deviceFile);
|
||||||
ASSERT(bytes.is_open(), "Couldn't open " << deviceFile);
|
|
||||||
std::string bytesStr;
|
std::string bytesStr;
|
||||||
std::getline(bytes, bytesStr);
|
std::getline(bytes, bytesStr);
|
||||||
|
|
||||||
|
@ -563,6 +576,8 @@ namespace System
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PulseAudio::Init();
|
PulseAudio::Init();
|
||||||
|
|
||||||
|
CheckNetwork();
|
||||||
}
|
}
|
||||||
void FreeResources()
|
void FreeResources()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue