From 1aca2ba6156035b540c529dea0cd8930f2c68c2a Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Fri, 11 Mar 2022 20:44:26 -0500 Subject: [PATCH] Wi-Fi: Auto-connect on wake-up things --- mainwindow.cpp | 27 ++++++++++++++++++++++++--- mainwindow.h | 2 ++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 24eefe1..845ad37 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -65,6 +65,7 @@ MainWindow::MainWindow(QWidget *parent) global::usbms::koboxExportExtensions = false; global::mainwindow::tabSwitcher::repaint = true; resetFullWindowException = false; + wifiIconClickedWhileReconnecting = false; // Getting the screen's size sW = QGuiApplication::screens()[0]->size().width(); @@ -924,7 +925,7 @@ void MainWindow::updateWifiIcon(int mode) { */ if(mode == 0) { QTimer *wifiIconTimer = new QTimer(this); - wifiIconTimer->setInterval(60000); + wifiIconTimer->setInterval(10000); connect(wifiIconTimer, SIGNAL(timeout()), this, SLOT(setWifiIcon())); wifiIconTimer->start(); } @@ -988,8 +989,24 @@ void MainWindow::setWifiIcon() { } void MainWindow::openWifiDialog() { - global::toast::wifiToast = true; - showToast("Searching for networks"); + if(checkconfig("/external_root/run/was_connected_to_wifi") == true and wifiIconClickedWhileReconnecting == false) { + showToast("Reconnection in progress\nTap again to cancel"); + wifiIconClickedWhileReconnecting = true; + QTimer::singleShot(10000, this, SLOT(resetWifiIconClickedWhileReconnecting())); + } + else { + if(wifiIconClickedWhileReconnecting == true) { + string_writeconfig("/opt/ibxd", "stop_wifi_reconnection\n"); + while(true) { + if(QFile::exists("/run/stop_wifi_reconnection_done")) { + QFile::remove("/run/stop_wifi_reconnection_done"); + break; + } + } + } + global::toast::wifiToast = true; + showToast("Searching for networks"); + } } void MainWindow::on_wifiBtn_clicked() @@ -1145,3 +1162,7 @@ void MainWindow::checkForOtaUpdate() { } } } + +void MainWindow::resetWifiIconClickedWhileReconnecting() { + wifiIconClickedWhileReconnecting = false; +} diff --git a/mainwindow.h b/mainwindow.h index 106846b..d4eb3f5 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -48,6 +48,7 @@ public: bool existing_recent_books = false; bool reboot_after_update = false; bool resetFullWindowException; + bool wifiIconClickedWhileReconnecting; int timerTime = 0; QString relative_path; QString usbmsStatus; @@ -96,6 +97,7 @@ private slots: void resetWindow(bool resetStackedWidget); void resetFullWindow(); void setRecentBooksLabelsTruncateTreshold(); + void resetWifiIconClickedWhileReconnecting(); private: Ui::MainWindow * ui;