Added update prompt at startup if update is detected

This commit is contained in:
Nicolas Mailloux 2021-04-01 08:58:37 -04:00
parent 55978a75fa
commit 22a3cb25ae
6 changed files with 69 additions and 9 deletions

View file

@ -3,6 +3,7 @@
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
#include <QProcess>
generalDialog::generalDialog(QWidget *parent) : generalDialog::generalDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
@ -35,6 +36,15 @@ generalDialog::generalDialog(QWidget *parent) :
this->adjustSize(); this->adjustSize();
string_writeconfig("/inkbox/resetDialog", "false"); string_writeconfig("/inkbox/resetDialog", "false");
} }
if(checkconfig("/inkbox/updateDialog") == true) {
updateDialog = true;
ui->okBtn->setText("Update");
ui->cancelBtn->setText("Not now");
ui->bodyLabel->setText("Do you want to update InkBox now?");
ui->headerLabel->setText("Update available");
this->adjustSize();
string_writeconfig("/inkbox/updateDialog", "false");
}
else { else {
// We shouldn't be there ;) // We shouldn't be there ;)
; ;
@ -51,6 +61,10 @@ void generalDialog::on_cancelBtn_clicked()
if(resetDialog == true) { if(resetDialog == true) {
generalDialog::close(); generalDialog::close();
} }
if(updateDialog == true) {
string_writeconfig("/tmp/cancelUpdateDialog", "true");
generalDialog::close();
}
} }
void generalDialog::on_okBtn_clicked() void generalDialog::on_okBtn_clicked()
@ -59,4 +73,14 @@ void generalDialog::on_okBtn_clicked()
// Reset the device ... some code to come // Reset the device ... some code to come
; ;
} }
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");
QString prog ("reboot");
QStringList args;
QProcess *proc = new QProcess();
proc->start(prog, args);
proc->waitForFinished();
}
} }

View file

@ -20,6 +20,7 @@ public:
explicit generalDialog(QWidget *parent = nullptr); explicit generalDialog(QWidget *parent = nullptr);
~generalDialog(); ~generalDialog();
bool resetDialog = false; bool resetDialog = false;
bool updateDialog = false;
bool checkconfig(QString file) { bool checkconfig(QString file) {
QFile config(file); QFile config(file);
config.open(QIODevice::ReadWrite); config.open(QIODevice::ReadWrite);

View file

@ -15,6 +15,7 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "alert.h" #include "alert.h"
#include "generaldialog.h"
#include <QApplication> #include <QApplication>
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>

View file

@ -418,6 +418,17 @@ MainWindow::MainWindow(QWidget *parent)
} }
} }
// Check for an update and ask if the user wants to install it
if(checkconfig("/mnt/onboard/onboard/.inkbox/can_update") == true) {
if(checkconfig("/tmp/cancelUpdateDialog") == false) {
// I'm sorry.
QTimer::singleShot(2000, this, SLOT(openUpdateDialog()));
}
else {
qDebug() << "Not showing update dialog, user dismissed it...";
}
}
// Check if it's the first boot since an update and confirm that it installed successfully // Check if it's the first boot since an update and confirm that it installed successfully
if(checkconfig("/opt/inkbox_genuine") == true) { if(checkconfig("/opt/inkbox_genuine") == true) {
if(checkconfig("/external_root/opt/update/inkbox_updated") == true) { if(checkconfig("/external_root/opt/update/inkbox_updated") == true) {
@ -439,6 +450,18 @@ MainWindow::~MainWindow()
delete ui; delete ui;
} }
void MainWindow::openUpdateDialog() {
updateDialog = true;
// We write to a temporary file to show a "Reset" prompt
string_writeconfig("/inkbox/updateDialog", "true");
// We show the dialog
generalDialogWindow = new generalDialog(this);
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
generalDialogWindow->show();
QApplication::processEvents();
}
void MainWindow::on_settingsBtn_clicked() void MainWindow::on_settingsBtn_clicked()
{ {
settingsWindow = new settings(); settingsWindow = new settings();

View file

@ -30,6 +30,8 @@ public:
bool existing_recent_books = false; bool existing_recent_books = false;
bool reboot_after_update = false; bool reboot_after_update = false;
int batt_level_int; int batt_level_int;
bool updateDialog = false;
int timerTime = 0;
QString checkconfig_str_val; QString checkconfig_str_val;
QString relative_path; QString relative_path;
QString batt_level; QString batt_level;
@ -47,6 +49,20 @@ public:
} }
config.close(); config.close();
}; };
bool checkconfig_rw(QString file) {
QFile config(file);
config.open(QIODevice::ReadWrite);
QTextStream in (&config);
const QString content = in.readAll();
string contentstr = content.toStdString();
if(contentstr.find("true") != std::string::npos) {
return true;
}
else {
return false;
}
config.close();
};
void writeconfig(string file, string config) { void writeconfig(string file, string config) {
ofstream fhandler; ofstream fhandler;
fhandler.open(file); fhandler.open(file);
@ -137,22 +153,15 @@ public slots:
private slots: private slots:
void on_settingsBtn_clicked(); void on_settingsBtn_clicked();
void on_appsBtn_clicked(); void on_appsBtn_clicked();
void on_pushButton_clicked(); void on_pushButton_clicked();
void on_searchBtn_clicked(); void on_searchBtn_clicked();
void on_quitBtn_clicked(); void on_quitBtn_clicked();
void on_book1Btn_clicked(); void on_book1Btn_clicked();
void on_book2Btn_clicked(); void on_book2Btn_clicked();
void on_book3Btn_clicked(); void on_book3Btn_clicked();
void on_book4Btn_clicked(); void on_book4Btn_clicked();
void on_brightnessBtn_clicked(); void on_brightnessBtn_clicked();
void openUpdateDialog();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;

View file

@ -366,7 +366,9 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="page_2"/> <widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout_3"/>
</widget>
</widget> </widget>
</item> </item>
<item> <item>