mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-26 23:57:22 -08:00
Added update prompt at startup if update is detected
This commit is contained in:
parent
55978a75fa
commit
22a3cb25ae
6 changed files with 69 additions and 9 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
#include <QProcess>
|
||||
|
||||
generalDialog::generalDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
|
@ -35,6 +36,15 @@ generalDialog::generalDialog(QWidget *parent) :
|
|||
this->adjustSize();
|
||||
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 {
|
||||
// We shouldn't be there ;)
|
||||
;
|
||||
|
@ -51,6 +61,10 @@ void generalDialog::on_cancelBtn_clicked()
|
|||
if(resetDialog == true) {
|
||||
generalDialog::close();
|
||||
}
|
||||
if(updateDialog == true) {
|
||||
string_writeconfig("/tmp/cancelUpdateDialog", "true");
|
||||
generalDialog::close();
|
||||
}
|
||||
}
|
||||
|
||||
void generalDialog::on_okBtn_clicked()
|
||||
|
@ -59,4 +73,14 @@ void generalDialog::on_okBtn_clicked()
|
|||
// 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public:
|
|||
explicit generalDialog(QWidget *parent = nullptr);
|
||||
~generalDialog();
|
||||
bool resetDialog = false;
|
||||
bool updateDialog = false;
|
||||
bool checkconfig(QString file) {
|
||||
QFile config(file);
|
||||
config.open(QIODevice::ReadWrite);
|
||||
|
|
1
main.cpp
1
main.cpp
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "mainwindow.h"
|
||||
#include "alert.h"
|
||||
#include "generaldialog.h"
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
|
|
@ -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
|
||||
if(checkconfig("/opt/inkbox_genuine") == true) {
|
||||
if(checkconfig("/external_root/opt/update/inkbox_updated") == true) {
|
||||
|
@ -439,6 +450,18 @@ MainWindow::~MainWindow()
|
|||
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()
|
||||
{
|
||||
settingsWindow = new settings();
|
||||
|
|
25
mainwindow.h
25
mainwindow.h
|
@ -30,6 +30,8 @@ public:
|
|||
bool existing_recent_books = false;
|
||||
bool reboot_after_update = false;
|
||||
int batt_level_int;
|
||||
bool updateDialog = false;
|
||||
int timerTime = 0;
|
||||
QString checkconfig_str_val;
|
||||
QString relative_path;
|
||||
QString batt_level;
|
||||
|
@ -47,6 +49,20 @@ public:
|
|||
}
|
||||
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) {
|
||||
ofstream fhandler;
|
||||
fhandler.open(file);
|
||||
|
@ -137,22 +153,15 @@ public slots:
|
|||
private slots:
|
||||
void on_settingsBtn_clicked();
|
||||
void on_appsBtn_clicked();
|
||||
|
||||
void on_pushButton_clicked();
|
||||
|
||||
void on_searchBtn_clicked();
|
||||
|
||||
void on_quitBtn_clicked();
|
||||
|
||||
void on_book1Btn_clicked();
|
||||
|
||||
void on_book2Btn_clicked();
|
||||
|
||||
void on_book3Btn_clicked();
|
||||
|
||||
void on_book4Btn_clicked();
|
||||
|
||||
void on_brightnessBtn_clicked();
|
||||
void openUpdateDialog();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
|
|
@ -366,7 +366,9 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_2"/>
|
||||
<widget class="QWidget" name="page_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3"/>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
|
Loading…
Reference in a new issue