🐞 fix(网络监听): 修改监听逻辑,防止死循环

177008 【多端协同】偶现多端协同应用无法打开(2/15)
This commit is contained in:
huheng@kylinos.cn 2023-06-16 14:24:22 +08:00
parent bf76835779
commit e86da602a5
2 changed files with 22 additions and 6 deletions

View File

@ -11,12 +11,16 @@
#include <QVariant>
#include <QVariantMap>
WifiManager::~WifiManager() {}
WifiManager::~WifiManager()
{
}
void WifiManager::onPropertiesChanged(QString str, QVariantMap map)
{
Q_UNUSED(str);
Q_UNUSED(map);
if (!map.keys().contains("ActiveConnections")) {
return;
}
QString wifiIP = checkWifiConnectivity();
if (!m_wifiIP.isEmpty()) {
if (wifiIP.isEmpty()) {
@ -25,7 +29,12 @@ void WifiManager::onPropertiesChanged(QString str, QVariantMap map)
Q_EMIT sigWifiDisconnected();
}
} else {
while (checkWifiConnectivity().isEmpty()) {}
while (checkWifiConnectivity().isEmpty() && m_isWifi) {
m_count++;
if (m_count > 10) {
continue;
}
}
m_wifiIP = wifiIP;
qInfo() << m_wifiIP << "connect";
Q_EMIT sigWifiConnected(m_wifiIP);
@ -75,9 +84,10 @@ QDBusObjectPath WifiManager::getConnectedWiFiIPPath(QDBusObjectPath objPath)
QDBusReply<QVariant> replyType =
interfaceType->call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Type");
if (replyType.value().toString() == "wifi" || replyType.value().toString() == "802-11-wireless") {
m_isWifi = true;
QDBusReply<QVariant> replyState =
interfaceType->call("Get", "org.freedesktop.NetworkManager.Connection.Active", "State");
int wifiState = replyState.value().toUInt(); //正在连接的状态是1连接上的状态是2
int wifiState = replyState.value().toUInt(); // 正在连接的状态是1连接上的状态是2
if (wifiState == 2) {
QDBusMessage replyIp4 =
interfaceType->call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Ip4Config");
@ -91,6 +101,8 @@ QDBusObjectPath WifiManager::getConnectedWiFiIPPath(QDBusObjectPath objPath)
return dbusPathIp4;
}
}
} else {
m_isWifi = false;
}
interfaceType->deleteLater();

View File

@ -9,7 +9,9 @@ class WifiManager : public QObject
{
Q_OBJECT
public:
WifiManager() {}
WifiManager()
{
}
~WifiManager();
private:
@ -33,6 +35,8 @@ public Q_SLOTS:
private:
QString m_wifiIP = "";
int m_count = 0;
bool m_isWifi = true;
};
#endif // WIFIMANAGER_H
#endif // WIFIMANAGER_H