Entire otaManager tested and working!

This commit is contained in:
Nicolas Mailloux 2021-08-25 13:16:41 -04:00
parent 1f539e6bf3
commit 191efea6a8
8 changed files with 172 additions and 53 deletions

View file

@ -201,10 +201,16 @@ void generalDialog::on_okBtn_clicked()
} }
if(updateDialog == true) { if(updateDialog == true) {
if(global::otaUpdate::isUpdateOta == true) { if(global::otaUpdate::isUpdateOta == true) {
this->hide();
global::otaUpdate::downloadOta = true; global::otaUpdate::downloadOta = true;
otaManagerWindow = new otaManager(this); otaManagerWindow = new otaManager(this);
connect(otaManagerWindow, SIGNAL(downloadedOtaUpdate(bool)), SLOT(startOtaUpdate(bool))); connect(otaManagerWindow, SIGNAL(downloadedOtaUpdate(bool)), SLOT(startOtaUpdate(bool)));
otaManagerWindow->setAttribute(Qt::WA_DeleteOnClose); otaManagerWindow->setAttribute(Qt::WA_DeleteOnClose);
global::toast::indefiniteToast = true;
global::toast::modalToast = true;
emit showToast("Downloading update");
} }
else { else {
installUpdate(); installUpdate();
@ -401,12 +407,14 @@ void generalDialog::connectToNetworkSlot() {
} }
void generalDialog::startOtaUpdate(bool wasDownloadSuccessful) { void generalDialog::startOtaUpdate(bool wasDownloadSuccessful) {
emit closeIndefiniteToast();
if(wasDownloadSuccessful == true) { if(wasDownloadSuccessful == true) {
global::otaUpdate::isUpdateOta = false; global::otaUpdate::isUpdateOta = false;
installUpdate(); installUpdate();
} }
else { else {
showToast("Download failed"); emit showToast("Download failed");
global::otaUpdate::isUpdateOta = false; global::otaUpdate::isUpdateOta = false;
} }
generalDialog::close();
} }

View file

@ -547,7 +547,7 @@ MainWindow::~MainWindow()
void MainWindow::openUpdateDialog() { void MainWindow::openUpdateDialog() {
global::mainwindow::updateDialog = true; global::mainwindow::updateDialog = true;
// Write to a temporary file to show a "Reset" prompt // Write to a temporary file to show an "Update" prompt
string_writeconfig("/inkbox/updateDialog", "true"); string_writeconfig("/inkbox/updateDialog", "true");
// Show the dialog // Show the dialog
@ -609,8 +609,6 @@ void MainWindow::on_settingsBtn_clicked()
else { else {
; ;
} }
// Testing
// showToast("Connection successful");
} }
void MainWindow::on_appsBtn_clicked() void MainWindow::on_appsBtn_clicked()
@ -962,7 +960,7 @@ void MainWindow::showToast(QString messageToDisplay) {
toastWindow->show(); toastWindow->show();
if(messageToDisplay == "Connection successful") { if(messageToDisplay == "Connection successful") {
// Give the toast some time to vanish away // Give the toast some time to vanish away, then launch OTA updater
QTimer::singleShot(5000, this, SLOT(launchOtaUpdater())); QTimer::singleShot(5000, this, SLOT(launchOtaUpdater()));
} }
} }

View file

@ -10,50 +10,47 @@ otaManager::otaManager(QWidget *parent) :
ui(new Ui::otaManager) ui(new Ui::otaManager)
{ {
ui->setupUi(this); ui->setupUi(this);
if(QFile::exists("/mnt/onboard/onboard/.inkbox/SKIP_OTACHECK") == false) { QThread::msleep(500);
if(global::otaUpdate::downloadOta == false) {
qDebug() << "Checking for available OTA update ..."; qDebug() << "Checking for available OTA update ...";
if(global::otaUpdate::downloadOta != true) { string_writeconfig("/opt/ibxd", "ota_update_check\n");
string_writeconfig("/opt/ibxd", "ota_update_check\n"); QTimer * otaCheckTimer = new QTimer(this);
QTimer * otaCheckTimer = new QTimer(this); otaCheckTimer->setInterval(100);
otaCheckTimer->setInterval(100); connect(otaCheckTimer, &QTimer::timeout, [&]() {
connect(otaCheckTimer, &QTimer::timeout, [&]() { if(QFile::exists("/run/can_ota_update") == true) {
if(QFile::exists("/run/can_ota_update") == true) { if(checkconfig("/run/can_ota_update") == true) {
if(checkconfig("/run/can_ota_update") == true) { qDebug() << "OTA update is available!";
qDebug() << "OTA update is available!"; emit canOtaUpdate(true);
emit canOtaUpdate(true);
}
else {
qDebug() << "No OTA update available.";
emit canOtaUpdate(false);
}
otaManager::close();
} }
} ); else {
otaCheckTimer->start(); qDebug() << "No OTA update available.";
} emit canOtaUpdate(false);
else {
string_writeconfig("/opt/ibxd", "ota_update_download\n");
QTimer * otaDownloadTimer = new QTimer(this);
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;
}
else {
emit downloadedOta(false);
global::otaUpdate::downloadOta = false;
}
otaManager::close();
} }
} ); otaManager::close();
otaDownloadTimer->start(); }
} } );
otaCheckTimer->start();
} }
else { else {
qDebug() << "Skip OTA update check!"; qDebug() << "Downloading OTA update ...";
otaManager::close(); QFile::remove("/run/can_install_ota_update");
string_writeconfig("/opt/ibxd", "ota_update_download\n");
QTimer * otaDownloadTimer = new QTimer(this);
otaDownloadTimer->setInterval(100);
connect(otaDownloadTimer, &QTimer::timeout, [&]() {
if(QFile::exists("/run/can_install_ota_update") == true) {
if(checkconfig("/run/can_install_ota_update") == true) {
emit downloadedOtaUpdate(true);
global::otaUpdate::downloadOta = false;
}
else {
emit downloadedOtaUpdate(false);
global::otaUpdate::downloadOta = false;
}
otaManager::close();
}
} );
otaDownloadTimer->start();
} }
} }

View file

@ -20,8 +20,7 @@ private:
signals: signals:
void canOtaUpdate(bool yesno); void canOtaUpdate(bool yesno);
void downloadedOta(bool wasDownloadSuccessful); void downloadedOtaUpdate(bool wasDownloadSuccessful);
}; };
#endif // OTAMANAGER_H #endif // OTAMANAGER_H

View file

@ -1,9 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>otaManager</class> <class>otaManager</class>
<widget name="otaManager" class="QWidget"> <widget class="QWidget" name="otaManager">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
@ -15,7 +13,23 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>OTA updates manager</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget> </widget>
<pixmapfunction/> <resources/>
<connections/> <connections/>
</ui> </ui>

View file

@ -31,6 +31,7 @@ settings::settings(QWidget *parent) :
ui->updateBtn->setProperty("type", "borderless"); ui->updateBtn->setProperty("type", "borderless");
ui->resetBtn->setProperty("type", "borderless"); ui->resetBtn->setProperty("type", "borderless");
ui->showSystemInfoBtn->setProperty("type", "borderless"); ui->showSystemInfoBtn->setProperty("type", "borderless");
ui->checkOtaUpdateBtn->setProperty("type", "borderless");
ui->previousBtn->setProperty("type", "borderless"); ui->previousBtn->setProperty("type", "borderless");
ui->nextBtn->setProperty("type", "borderless"); ui->nextBtn->setProperty("type", "borderless");
ui->aboutBtn->setStyleSheet("font-size: 9pt"); ui->aboutBtn->setStyleSheet("font-size: 9pt");
@ -39,6 +40,7 @@ settings::settings(QWidget *parent) :
ui->updateBtn->setStyleSheet("font-size: 9pt"); ui->updateBtn->setStyleSheet("font-size: 9pt");
ui->resetBtn->setStyleSheet("font-size: 9pt"); ui->resetBtn->setStyleSheet("font-size: 9pt");
ui->showSystemInfoBtn->setStyleSheet("font-size: 9pt"); ui->showSystemInfoBtn->setStyleSheet("font-size: 9pt");
ui->checkOtaUpdateBtn->setStyleSheet("font-size: 9pt");
ui->comboBox->setStyleSheet("font-size: 9pt"); ui->comboBox->setStyleSheet("font-size: 9pt");
ui->sleepTimeoutComboBox->setStyleSheet("font-size: 9pt"); ui->sleepTimeoutComboBox->setStyleSheet("font-size: 9pt");
ui->setPasscodeBtn->setStyleSheet("font-size: 9pt"); ui->setPasscodeBtn->setStyleSheet("font-size: 9pt");
@ -324,6 +326,9 @@ settings::settings(QWidget *parent) :
ui->label_8->setText("Reset InkBox"); ui->label_8->setText("Reset InkBox");
} }
if(global::device::isWifiAble == false) {
ui->checkOtaUpdateGridLayout->deleteLater();
}
QFile stylesheetFile(":/resources/eink.qss"); QFile stylesheetFile(":/resources/eink.qss");
stylesheetFile.open(QFile::ReadOnly); stylesheetFile.open(QFile::ReadOnly);
@ -853,3 +858,51 @@ void settings::on_globalReadingSettingsCheckBox_toggled(bool checked)
} }
} }
void settings::on_checkOtaUpdateBtn_clicked()
{
launchOtaUpdater();
}
void settings::openUpdateDialog() {
global::mainwindow::updateDialog = true;
// Write to a temporary file to show an "Update" prompt
string_writeconfig("/inkbox/updateDialog", "true");
// Show the dialog
generalDialogWindow = new generalDialog(this);
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
connect(generalDialogWindow, SIGNAL(showToast(QString)), SLOT(showToast(QString)));
connect(generalDialogWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToast()));
generalDialogWindow->show();
QApplication::processEvents();
}
void settings::launchOtaUpdater() {
otaManagerWindow = new otaManager(this);
connect(otaManagerWindow, SIGNAL(canOtaUpdate(bool)), SLOT(openUpdateDialogOTA(bool)));
otaManagerWindow->setAttribute(Qt::WA_DeleteOnClose);
}
void settings::openUpdateDialogOTA(bool open) {
if(open == true) {
global::otaUpdate::isUpdateOta = true;
openUpdateDialog();
}
else {
;
}
}
void settings::showToast(QString messageToDisplay) {
global::toast::message = messageToDisplay;
toastWindow = new toast(this);
toastWindow->setAttribute(Qt::WA_DeleteOnClose);
connect(toastWindow, SIGNAL(showToast(QString)), SLOT(showToast(QString)));
connect(toastWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToast()));
toastWindow->show();
}
void settings::closeIndefiniteToast() {
// Warning: use with caution
toastWindow->close();
}

View file

@ -5,6 +5,8 @@
#include <usbms_splash.h> #include <usbms_splash.h>
#include "generaldialog.h" #include "generaldialog.h"
#include "otamanager.h"
#include "toast.h"
using namespace std; using namespace std;
@ -53,11 +55,19 @@ private slots:
void on_sleepTimeoutComboBox_currentIndexChanged(const QString &arg1); void on_sleepTimeoutComboBox_currentIndexChanged(const QString &arg1);
void brightnessDown(); void brightnessDown();
void on_globalReadingSettingsCheckBox_toggled(bool checked); void on_globalReadingSettingsCheckBox_toggled(bool checked);
void on_checkOtaUpdateBtn_clicked();
void openUpdateDialog();
void launchOtaUpdater();
void openUpdateDialogOTA(bool open);
void showToast(QString messageToDisplay);
void closeIndefiniteToast();
private: private:
Ui::settings *ui; Ui::settings *ui;
usbms_splash *usbmsWindow; usbms_splash *usbmsWindow;
generalDialog *generalDialogWindow; generalDialog *generalDialogWindow;
otaManager *otaManagerWindow;
toast *toastWindow;
}; };
#endif // SETTINGS_H #endif // SETTINGS_H

View file

@ -48,8 +48,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>560</width> <width>463</width>
<height>818</height> <height>556</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
@ -893,6 +893,46 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="14" column="0">
<layout class="QGridLayout" name="checkOtaUpdateGridLayout">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="checkOtaUpdateLabel">
<property name="text">
<string>Check for updates</string>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer_13">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="checkOtaUpdateBtn">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Check</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>