diff --git a/functions.h b/functions.h index 1bf5fc5..5b19677 100644 --- a/functions.h +++ b/functions.h @@ -78,6 +78,13 @@ namespace global { namespace device { inline bool isWifiAble; } + namespace network { + inline bool isConnected; + } + namespace otaUpdate { + inline bool isUpdateOta; + inline bool downloadOta; + } inline QString systemInfoText; inline bool forbidOpenSearchDialog; inline bool isN705; @@ -492,11 +499,13 @@ namespace { if(checkconfig("/run/wifi_connected_successfully") == true) { QFile::remove("/run/wifi_connected_successfully"); connectionSuccessful = 1; + global::network::isConnected = true; return true; } else { QFile::remove("/run/wifi_connected_successfully"); connectionSuccessful = 0; + global::network::isConnected = false; return false; } } @@ -527,6 +536,12 @@ namespace { } string_writeconfig(sysfsWarmthPath, warmthValueStr); } + void installUpdate() { + string_writeconfig("/mnt/onboard/onboard/.inkbox/can_really_update", "true"); + string_writeconfig("/external_root/opt/update/will_update", "true"); + string_writeconfig("/external_root/boot/flags/WILL_UPDATE", "true"); + reboot(true); + } } #endif // FUNCTIONS_H diff --git a/generaldialog.cpp b/generaldialog.cpp index 28e8894..d62e075 100644 --- a/generaldialog.cpp +++ b/generaldialog.cpp @@ -196,10 +196,15 @@ void generalDialog::on_okBtn_clicked() } } if(updateDialog == true) { - string_writeconfig("/mnt/onboard/onboard/.inkbox/can_really_update", "true"); - string_writeconfig("/external_root/opt/update/will_update", "true"); - string_writeconfig("/external_root/boot/flags/WILL_UPDATE", "true"); - reboot(true); + if(global::otaUpdate::isUpdateOta == true) { + global::otaUpdate::downloadOta = true; + otaManagerWindow = new otaManager(this); + connect(otaManagerWindow, SIGNAL(downloadedOtaUpdate(bool)), SLOT(startOtaUpdate(bool))); + otaManagerWindow->setAttribute(Qt::WA_DeleteOnClose); + } + else { + installUpdate(); + } } if(usbmsDialog == true) { global::usbms::usbmsDialog = false; @@ -390,3 +395,14 @@ void generalDialog::connectToNetworkSlot() { } generalDialog::close(); } + +void generalDialog::startOtaUpdate(bool wasDownloadSuccessful) { + if(wasDownloadSuccessful == true) { + global::otaUpdate::isUpdateOta = false; + installUpdate(); + } + else { + showToast("Download failed"); + global::otaUpdate::isUpdateOta = false; + } +} diff --git a/generaldialog.h b/generaldialog.h index 7e4b3e5..b79b08c 100644 --- a/generaldialog.h +++ b/generaldialog.h @@ -8,6 +8,7 @@ #include "virtualkeyboard.h" #include "virtualkeypad.h" #include "dictionarywidget.h" +#include "otamanager.h" using namespace std; @@ -51,6 +52,7 @@ private slots: void restartSearchDialog(); void refreshScreenNative(); void connectToNetworkSlot(); + void startOtaUpdate(bool wasDownloadSuccessful); private: Ui::generalDialog *ui; @@ -59,6 +61,7 @@ private: virtualkeyboard *keyboardWidget; virtualkeypad *keypadWidget; dictionaryWidget *dictionaryWidgetWindow; + otaManager *otaManagerWindow; signals: void gotoPageSelected(int value); diff --git a/mainwindow.cpp b/mainwindow.cpp index a1215fd..3448090 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -953,12 +953,11 @@ void MainWindow::showToast(QString messageToDisplay) { connect(toastWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToast())); toastWindow->show(); - // Testing - /* if(messageToDisplay == "Connection successful") { + if(messageToDisplay == "Connection successful") { otaManagerWindow = new otaManager(this); - connect(otaManagerWindow, SIGNAL(canInstallOtaUpdate(bool)), SLOT(openUpdateDialogOTA(bool))); + connect(otaManagerWindow, SIGNAL(canOtaUpdate(bool)), SLOT(openUpdateDialogOTA(bool))); otaManagerWindow->setAttribute(Qt::WA_DeleteOnClose); - } */ + } } void MainWindow::hello(int testNumber) { @@ -972,6 +971,7 @@ void MainWindow::closeIndefiniteToast() { void MainWindow::openUpdateDialogOTA(bool open) { if(open == true) { + global::otaUpdate::isUpdateOta = true; openUpdateDialog(); } else { diff --git a/otamanager.cpp b/otamanager.cpp index fe39986..8bbca94 100644 --- a/otamanager.cpp +++ b/otamanager.cpp @@ -9,21 +9,42 @@ otaManager::otaManager(QWidget *parent) : ui(new Ui::otaManager) { ui->setupUi(this); - string_writeconfig("/opt/ibxd", "ota_update_check\n"); - QTimer *otaCheckTimer = new QTimer(); - otaCheckTimer->setInterval(100); - connect(otaCheckTimer, &QTimer::timeout, [&]() { - if(QFile::exists("/run/can_install_ota_update") == true) { - if(checkconfig("/run/can_install_ota_update") == true) { - emit canInstallOtaUpdate(true); - otaManager::close(); + if(global::otaUpdate::downloadOta != true) { + string_writeconfig("/opt/ibxd", "ota_update_check\n"); + QTimer *otaCheckTimer = new QTimer(); + otaCheckTimer->setInterval(100); + connect(otaCheckTimer, &QTimer::timeout, [&]() { + if(QFile::exists("/run/can_ota_update") == true) { + if(checkconfig("/run/can_ota_update") == true) { + emit canOtaUpdate(true); + otaManager::close(); + } + else { + emit canOtaUpdate(false); + otaManager::close(); + } } - else { - emit canInstallOtaUpdate(false); - otaManager::close(); + } ); + } + else { + string_writeconfig("/opt/ibxd", "ota_update_download\n"); + QTimer *otaDownloadTimer = new QTimer(); + otaDownloadTimer->setInterval(500); + connect(otaDownloadTimer, &QTimer::timeout, [&]() { + if(QFile::exists("/run/can_install_ota_update") == true) { + if(checkconfig("/run/can_install_ota_update") == true) { + emit downloadedOta(true); + global::otaUpdate::downloadOta = false; + otaManager::close(); + } + else { + emit downloadedOta(false); + global::otaUpdate::downloadOta = false; + otaManager::close(); + } } - } - } ); + } ); + } } otaManager::~otaManager() diff --git a/otamanager.h b/otamanager.h index bff50c3..fa22017 100644 --- a/otamanager.h +++ b/otamanager.h @@ -19,7 +19,8 @@ private: Ui::otaManager *ui; signals: - void canInstallOtaUpdate(bool yesno); + void canOtaUpdate(bool yesno); + void downloadedOta(bool wasDownloadSuccessful); };