diff --git a/inkbox.pro b/inkbox.pro index 03a5e3f..9d7fbe4 100644 --- a/inkbox.pro +++ b/inkbox.pro @@ -1,4 +1,4 @@ -QT += core gui network +QT += core gui network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets diff --git a/src/apps/userapps.cpp b/src/apps/userapps.cpp index 29c156b..c25133d 100644 --- a/src/apps/userapps.cpp +++ b/src/apps/userapps.cpp @@ -185,7 +185,7 @@ bool userapps::manageRequiredFeatures() if(featureId == 0) { // Double 'if' conditions to avoid launching unnecesery testPing() in emu if(global::deviceID != "emu\n") { - if(testPing() != 0) { + if(checkWifiState() != global::wifi::wifiState::configured) { global::userApps::appCompatibilityText = "This app needs a Wi-Fi connection, continue anyway?"; launchDialog = true; } diff --git a/src/functions.h b/src/functions.h index 64ecd68..1d1bf11 100644 --- a/src/functions.h +++ b/src/functions.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -1101,35 +1102,22 @@ namespace { } } global::wifi::wifiState checkWifiState() { - QProcess *wifiStateProcess = new QProcess(); - QString path = "/external_root/usr/local/bin/wifi/wifi_status.sh"; - QStringList args; - wifiStateProcess->start(path, args); - wifiStateProcess->waitForFinished(); - wifiStateProcess->deleteLater(); - - QString currentWifiState; - if(QFile("/run/wifi_status").exists() == true) { - currentWifiState = readFile("/run/wifi_status"); - } else { - log("/run/wifi_status doesn't exist", "functions"); - } - if (currentWifiState.contains("configured") == true) { - global::wifi::isConnected = true; - return global::wifi::wifiState::configured; - } - else if (currentWifiState.contains("enabled") == true) { - global::wifi::isConnected = false; - return global::wifi::wifiState::enabled; - } - else if (currentWifiState.contains("disabled") == true) { - global::wifi::isConnected = false; - return global::wifi::wifiState::disabled; - } else { - global::wifi::isConnected = false; - QString function = __func__; log(function + ": Critical error", "functions"); - return global::wifi::wifiState::unknown; + foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces()) { + // If something is wrong, debug with this: + // qDebug() << interface; + if(interface.flags().testFlag(QNetworkInterface::IsLoopBack) == false) { + if(interface.flags().testFlag(QNetworkInterface::IsUp) == true) { + if(interface.flags().testFlag(QNetworkInterface::IsRunning) == true) { + global::wifi::isConnected = true; + return global::wifi::wifiState::configured; + } + global::wifi::isConnected = false; + return global::wifi::wifiState::enabled; + } + } } + global::wifi::isConnected = false; + return global::wifi::wifiState::disabled; } 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.