fix for wifi not working + cpu usage

This commit is contained in:
Szybet 2023-05-22 20:11:12 +02:00
parent 6a4f8835d4
commit af75ba1969
3 changed files with 18 additions and 30 deletions

View file

@ -1,4 +1,4 @@
QT += core gui network
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

View file

@ -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 = "<font face='u001'>This app needs a Wi-Fi connection, continue anyway</font><font face='Inter'>?</font>";
launchDialog = true;
}

View file

@ -20,6 +20,7 @@
#include <QJsonValue>
#include <QJsonArray>
#include <QCryptographicHash>
#include <QNetworkInterface>
#include <stdio.h>
#include <fcntl.h>
@ -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.