Wi-Fi fix again

This commit is contained in:
Nicolas Mailloux 2023-06-10 10:03:12 -04:00
parent fe0e62d672
commit 72322a7fe5

View file

@ -1102,32 +1102,35 @@ namespace {
} }
} }
global::wifi::wifiState checkWifiState() { global::wifi::wifiState checkWifiState() {
QString interfaceStateFileHead = "/sys/class/net/";
QString interfaceStateFileTail = "/operstate";
QString interfaceName; QString interfaceName;
QString interfaceStateFile;
if(global::deviceID == "n437\n" or global::deviceID == "kt\n") { if(global::deviceID == "n437\n" or global::deviceID == "kt\n") {
interfaceName = "wlan0"; interfaceName = "wlan0";
} }
else { else {
interfaceName = "eth0"; interfaceName = "eth0";
} }
interfaceStateFile = interfaceStateFileHead + interfaceName + interfaceStateFileTail;
QString state = readFile(interfaceStateFile); // Check if network interface has an IP address
if(state == "up\n") { QNetworkInterface iface = QNetworkInterface::interfaceFromName(interfaceName);
QList<QNetworkAddressEntry> entries = iface.addressEntries();
if(!entries.isEmpty()) {
// Interface is up and has an IP address
global::wifi::isConnected = true; global::wifi::isConnected = true;
return global::wifi::wifiState::configured; return global::wifi::wifiState::configured;
} }
else if(state == "unknown\n") { else {
if(QFile::exists("/sys/class/net/" + interfaceName + "/operstate")) {
// Interface is up but doesn't have an IP address
global::wifi::isConnected = false; global::wifi::isConnected = false;
return global::wifi::wifiState::enabled; return global::wifi::wifiState::enabled;
} }
else { else {
// Interface is not up
global::wifi::isConnected = false; global::wifi::isConnected = false;
return global::wifi::wifiState::disabled; return global::wifi::wifiState::disabled;
} }
} }
}
int testPing() { int testPing() {
// For some reason, implementing a non-blocking version of this functions triggers a "terminate called without an active exception" error with a platform plugin compiled with a newer GCC 11 toolchain. The problem has been solved by transplanting this function into the related area which uses it. // For some reason, implementing a non-blocking version of this functions triggers a "terminate called without an active exception" error with a platform plugin compiled with a newer GCC 11 toolchain. The problem has been solved by transplanting this function into the related area which uses it.
QProcess *pingProcess = new QProcess(); QProcess *pingProcess = new QProcess();