Fix bug mainwindow show abnormal reconnect a wifi after disconned another wifi

This commit is contained in:
chenlelin 2021-03-20 10:30:04 +08:00
parent fdc48b06cc
commit fd17607484
2 changed files with 37 additions and 0 deletions

View File

@ -2907,6 +2907,34 @@ void MainWindow::on_btnHotspotState()
//处理外界对网络的连接与断开
void MainWindow::onExternalConnectionChange(QString type, bool isConnUp)
{
if ( (type == "802-11-wireless" || type == "wifi") && !isConnUp ){
QTimer::singleShot(2*1000, this, SLOT(onToResetValue() ));
}
if (type == "802-11-wireless" || type == "wifi") {
addNumberForWifi += 1;
}
if (addNumberForWifi == 2) {
//断开一个wifi的时候如果存在回连可能接连发出两个信号
//当连续发出wifi断开与连接的信号时短时间内addNumberForWifi值为2
is_stop_check_net_state = 1;
if (is_connect_net_failed) {
qDebug()<<"debug: connect wifi failed just now, no need to refresh wifi interface";
is_connect_net_failed = 0;
is_stop_check_net_state = 0;
} else if (is_wifi_reconnected) {
qDebug()<<"debug: wifi reconnected just now, no need to refresh wifi interface";
is_wifi_reconnected = 0;
is_stop_check_net_state = 0;
}else {
QTimer::singleShot(1*1000, this, SLOT(onExternalWifiChange() ));
}
addNumberForWifi = 0;
return;
}
if ( (type == "802-11-wireless" || type == "wifi") && isConnUp ){
addNumberForWifi = 0;
}
QTimer::singleShot(4*1000, this, SLOT(onToSetTrayIcon() ));
if (type == "") {
@ -2943,6 +2971,7 @@ void MainWindow::onExternalConnectionChange(QString type, bool isConnUp)
}
if (type == "802-11-wireless" || type == "wifi") {
addNumberForWifi = 0;
if (is_connect_net_failed) {
qDebug()<<"debug: connect wifi failed just now, no need to refresh wifi interface";
is_connect_net_failed = 0;
@ -2950,6 +2979,7 @@ void MainWindow::onExternalConnectionChange(QString type, bool isConnUp)
} else if (is_wifi_reconnected) {
qDebug()<<"debug: wifi reconnected just now, no need to refresh wifi interface";
is_wifi_reconnected = 0;
is_stop_check_net_state = 0;
}else {
isToSetWifiValue = false;
QTimer::singleShot(2*1000, this, SLOT(onExternalWifiChange() ));
@ -2994,6 +3024,11 @@ void MainWindow::onToSetTrayIcon()
getActiveInfoAndSetTrayIcon();
}
void MainWindow::onToResetValue()
{
addNumberForWifi = 0;
}
void MainWindow::onWifiSwitchChange()
{
if (is_btnWifiList_clicked) {

View File

@ -179,6 +179,7 @@ public:
bool isWifiBeConnUp = false; //wifi是否是连接上
bool isToSetLanValue = true; //本次执行是否进行赋值
bool isToSetWifiValue = true; //本次执行是否进行赋值
int addNumberForWifi = 0;
int m_priX;
int m_priY;
@ -199,6 +200,7 @@ public slots:
void onExternalLanChange();
void onExternalWifiChange();
void onToSetTrayIcon();
void onToResetValue();
void onWifiSwitchChange();
void onExternalWifiSwitchChange(bool wifiEnabled);