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

View file

@ -547,7 +547,7 @@ MainWindow::~MainWindow()
void MainWindow::openUpdateDialog() {
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");
// Show the dialog
@ -609,8 +609,6 @@ void MainWindow::on_settingsBtn_clicked()
else {
;
}
// Testing
// showToast("Connection successful");
}
void MainWindow::on_appsBtn_clicked()
@ -962,7 +960,7 @@ void MainWindow::showToast(QString messageToDisplay) {
toastWindow->show();
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()));
}
}

View file

@ -10,9 +10,9 @@ otaManager::otaManager(QWidget *parent) :
ui(new Ui::otaManager)
{
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 ...";
if(global::otaUpdate::downloadOta != true) {
string_writeconfig("/opt/ibxd", "ota_update_check\n");
QTimer * otaCheckTimer = new QTimer(this);
otaCheckTimer->setInterval(100);
@ -32,17 +32,19 @@ otaManager::otaManager(QWidget *parent) :
otaCheckTimer->start();
}
else {
qDebug() << "Downloading OTA update ...";
QFile::remove("/run/can_install_ota_update");
string_writeconfig("/opt/ibxd", "ota_update_download\n");
QTimer * otaDownloadTimer = new QTimer(this);
otaDownloadTimer->setInterval(500);
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 downloadedOta(true);
emit downloadedOtaUpdate(true);
global::otaUpdate::downloadOta = false;
}
else {
emit downloadedOta(false);
emit downloadedOtaUpdate(false);
global::otaUpdate::downloadOta = false;
}
otaManager::close();
@ -50,11 +52,6 @@ otaManager::otaManager(QWidget *parent) :
} );
otaDownloadTimer->start();
}
}
else {
qDebug() << "Skip OTA update check!";
otaManager::close();
}
}
otaManager::~otaManager()

View file

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

View file

@ -1,9 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>otaManager</class>
<widget name="otaManager" class="QWidget">
<widget class="QWidget" name="otaManager">
<property name="geometry">
<rect>
<x>0</x>
@ -15,7 +13,23 @@
<property name="windowTitle">
<string>Form</string>
</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>
<pixmapfunction/>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -31,6 +31,7 @@ settings::settings(QWidget *parent) :
ui->updateBtn->setProperty("type", "borderless");
ui->resetBtn->setProperty("type", "borderless");
ui->showSystemInfoBtn->setProperty("type", "borderless");
ui->checkOtaUpdateBtn->setProperty("type", "borderless");
ui->previousBtn->setProperty("type", "borderless");
ui->nextBtn->setProperty("type", "borderless");
ui->aboutBtn->setStyleSheet("font-size: 9pt");
@ -39,6 +40,7 @@ settings::settings(QWidget *parent) :
ui->updateBtn->setStyleSheet("font-size: 9pt");
ui->resetBtn->setStyleSheet("font-size: 9pt");
ui->showSystemInfoBtn->setStyleSheet("font-size: 9pt");
ui->checkOtaUpdateBtn->setStyleSheet("font-size: 9pt");
ui->comboBox->setStyleSheet("font-size: 9pt");
ui->sleepTimeoutComboBox->setStyleSheet("font-size: 9pt");
ui->setPasscodeBtn->setStyleSheet("font-size: 9pt");
@ -324,6 +326,9 @@ settings::settings(QWidget *parent) :
ui->label_8->setText("Reset InkBox");
}
if(global::device::isWifiAble == false) {
ui->checkOtaUpdateGridLayout->deleteLater();
}
QFile stylesheetFile(":/resources/eink.qss");
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 "generaldialog.h"
#include "otamanager.h"
#include "toast.h"
using namespace std;
@ -53,11 +55,19 @@ private slots:
void on_sleepTimeoutComboBox_currentIndexChanged(const QString &arg1);
void brightnessDown();
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:
Ui::settings *ui;
usbms_splash *usbmsWindow;
generalDialog *generalDialogWindow;
otaManager *otaManagerWindow;
toast *toastWindow;
};
#endif // SETTINGS_H

View file

@ -48,8 +48,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>560</width>
<height>818</height>
<width>463</width>
<height>556</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
@ -893,6 +893,46 @@
</item>
</layout>
</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>
</item>
</layout>