quill/otamanager.cpp

61 lines
1.9 KiB
C++
Raw Normal View History

#include "otamanager.h"
#include "ui_otamanager.h"
#include "functions.h"
#include <QTimer>
2021-08-20 14:12:51 -07:00
#include <QDebug>
otaManager::otaManager(QWidget *parent) :
QWidget(parent),
ui(new Ui::otaManager)
{
ui->setupUi(this);
2021-08-25 10:16:41 -07:00
QThread::msleep(500);
if(global::otaUpdate::downloadOta == false) {
2021-08-20 14:12:51 -07:00
qDebug() << "Checking for available OTA update ...";
2021-08-25 10:16:41 -07:00
string_writeconfig("/opt/ibxd", "ota_update_check\n");
QTimer * otaCheckTimer = new QTimer(this);
otaCheckTimer->setInterval(100);
connect(otaCheckTimer, &QTimer::timeout, [&]() {
if(QFile::exists("/run/can_ota_update") == true) {
if(checkconfig("/run/can_ota_update") == true) {
qDebug() << "OTA update is available!";
emit canOtaUpdate(true);
}
2021-08-25 10:16:41 -07:00
else {
qDebug() << "No OTA update available.";
emit canOtaUpdate(false);
}
2021-08-25 10:16:41 -07:00
otaManager::close();
}
} );
otaCheckTimer->start();
}
else {
2021-08-25 10:16:41 -07:00
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(100);
2021-08-29 12:05:07 -07:00
connect(otaDownloadTimer, &QTimer::timeout, [&]() {
2021-08-25 10:16:41 -07:00
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();
}
}
otaManager::~otaManager()
{
delete ui;
}