Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit aeadd21

Browse files
committed
improved version check
1 parent c5fb7af commit aeadd21

File tree

10 files changed

+79
-62
lines changed

10 files changed

+79
-62
lines changed

src/duqf-app/app-utils.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ bool DuApplication::processArgs(QStringList examples, QStringList helpStrings)
132132
return help;
133133
}
134134

135-
void DuApplication::checkUpdate()
135+
void DuApplication::checkUpdate(bool wait)
136136
{
137137
if (QString(URL_UPDATE) == "") return;
138138

@@ -175,8 +175,31 @@ void DuApplication::checkUpdate()
175175
qInfo().noquote() << "App Version: " % QString(STR_VERSION);
176176
qInfo().noquote() << "Language code: en";
177177

178-
connect(am, SIGNAL(finished(QNetworkReply*)), this, SLOT(gotUpdateInfo(QNetworkReply*)));
179-
am->get(request);
178+
if (wait) {
179+
// Create a loop to wait for the data
180+
QTimer timer;
181+
timer.setSingleShot(true);
182+
183+
QNetworkReply *reply = am->get( request );
184+
185+
timer.start( 5000 ); // no more than 5 seconds
186+
187+
while ( reply->isRunning() )
188+
{
189+
if (!timer.isActive()) {
190+
reply->abort();
191+
reply->deleteLater();
192+
return;
193+
}
194+
qApp->processEvents();
195+
}
196+
gotUpdateInfo(reply);
197+
reply->deleteLater();
198+
}
199+
else {
200+
connect(am, SIGNAL(finished(QNetworkReply*)), this, SLOT(gotUpdateInfo(QNetworkReply*)));
201+
am->get(request);
202+
}
180203
}
181204

182205
bool DuApplication::notify(QObject *receiver, QEvent *ev)

src/duqf-app/app-utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class DuApplication : public QApplication
118118

119119
public slots:
120120
// Check for updates
121-
void checkUpdate();
121+
void checkUpdate(bool wait = false);
122122

123123
signals:
124124
void idle();

src/duqf-app/app-version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#define VERSION_MAJOR 0
55
#define VERSION_MINOR 8
6-
#define VERSION_BUILD 6
6+
#define VERSION_BUILD 5
77
#define VERSION_SUFFIX "Beta"
88

99
#define STRINGIFY_VERSION(A, B, C) CONCAT(A, B, C )

src/duqf-widgets/duqfupdatedialog.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "duqfupdatedialog.h"
22

3+
#include "duqf-app/app-version.h"
4+
35
DuQFUpdateDialog::DuQFUpdateDialog(QJsonObject updateInfo, QWidget *parent) : QDialog(parent)
46
{
57
setupUi(updateInfo);
@@ -8,19 +10,19 @@ DuQFUpdateDialog::DuQFUpdateDialog(QJsonObject updateInfo, QWidget *parent) : QD
810
void DuQFUpdateDialog::download()
911
{
1012
QDesktopServices::openUrl ( QUrl( m_downloadURL ) );
11-
this->close();
13+
this->accept();
1214
}
1315

1416
void DuQFUpdateDialog::changelog()
1517
{
1618
QDesktopServices::openUrl ( QUrl( m_changelogURL ) );
17-
this->close();
19+
this->reject();
1820
}
1921

2022
void DuQFUpdateDialog::donate()
2123
{
2224
QDesktopServices::openUrl ( QUrl( m_donateURL ) );
23-
this->close();
25+
this->reject();
2426
}
2527

2628
void DuQFUpdateDialog::setupUi(QJsonObject updateInfo)
@@ -38,8 +40,13 @@ void DuQFUpdateDialog::setupUi(QJsonObject updateInfo)
3840
QLabel *latestVersionLabel = new QLabel("New version: " % updateInfo.value("version").toString(), this );
3941
mainLayout->addWidget(latestVersionLabel);
4042

41-
QTextEdit *descriptionEdit = new QTextEdit(updateInfo.value("description").toString(), this);
43+
QTextEdit *descriptionEdit = new QTextEdit(this);
4244
descriptionEdit->setReadOnly(true);
45+
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
46+
descriptionEdit->setPlainText( updateInfo.value("description").toString() );
47+
#else
48+
descriptionEdit->setMarkdown( updateInfo.value("description").toString() );
49+
#endif
4350
mainLayout->addWidget(descriptionEdit);
4451

4552
QLabel *currentVersionLabel = new QLabel("Current version: " % QString(STR_VERSION), this );

src/duqf-widgets/duqfupdatedialog.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include <QStringBuilder>
1111
#include <QDesktopServices>
1212

13-
#include "duqf-app/app-version.h"
14-
1513
class DuQFUpdateDialog : public QDialog
1614
{
1715
Q_OBJECT

src/duqf-widgets/duqfupdatesettingswidget.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "duqfupdatesettingswidget.h"
22

33
#include "duqf-app/app-utils.h"
4+
#include "duqf-widgets/duqfupdatedialog.h"
45

56
DuQFUpdateSettingsWidget::DuQFUpdateSettingsWidget(QWidget *parent) :
67
QWidget(parent)
@@ -19,6 +20,14 @@ void DuQFUpdateSettingsWidget::checkAtStartup(bool c)
1920
m_settings.setValue("checkUpdateAtStartup", c);
2021
}
2122

23+
void DuQFUpdateSettingsWidget::checkUpdate()
24+
{
25+
DuApplication *app = qobject_cast<DuApplication*>(qApp);
26+
app->checkUpdate(true);
27+
DuQFUpdateDialog dialog( app->updateInfo() );
28+
dialog.exec();
29+
}
30+
2231
void DuQFUpdateSettingsWidget::setupUi()
2332
{
2433
QHBoxLayout *mainLayout = new QHBoxLayout(this);
@@ -51,8 +60,6 @@ void DuQFUpdateSettingsWidget::setupUi()
5160

5261
void DuQFUpdateSettingsWidget::connectEvents()
5362
{
54-
DuApplication *app = qobject_cast<DuApplication*>(qApp);
55-
5663
connect( ui_checkAtStartupBox, SIGNAL(clicked(bool)), this, SLOT(checkAtStartup(bool)));
57-
connect( ui_checkNowButton, SIGNAL(clicked()), app, SLOT(checkUpdate()));
64+
connect( ui_checkNowButton, SIGNAL(clicked()), this, SLOT(checkUpdate()));
5865
}

src/duqf-widgets/duqfupdatesettingswidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class DuQFUpdateSettingsWidget : public QWidget
1616

1717
private slots:
1818
void checkAtStartup(bool c);
19+
void checkUpdate();
1920

2021
private:
2122
void setupUi();

src/main.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#endif
1212

1313
#include "duqf-app/app-utils.h"
14+
#include "duqf-widgets/duqfupdatedialog.h"
1415

1516
int main(int argc, char *argv[])
1617
{
@@ -54,6 +55,29 @@ int main(int argc, char *argv[])
5455
qDebug() << tcpSocket->error();
5556
}
5657

58+
// Check for updates, right during startup
59+
s->newMessage("Looking for udpates...");
60+
QSettings settings;
61+
qDebug() << "Update check...";
62+
QDateTime lastCheck = settings.value("updates/latestUpdateCheck").toDateTime();
63+
qDebug().noquote() << "Last check was on: " + lastCheck.toString("yyyy-MM-dd hh:mm:ss");
64+
int days = lastCheck.daysTo(QDateTime::currentDateTime());
65+
qDebug().noquote() << days << " days since last check.";
66+
if (days > 0 || !lastCheck.isValid() || lastCheck.isNull()) {
67+
a.checkUpdate(true);
68+
QJsonObject updateInfo = a.updateInfo();
69+
if (updateInfo.value("update").toBool()) {
70+
s->newMessage("A new version is available!");
71+
DuQFUpdateDialog dialog(updateInfo);
72+
if (dialog.exec()) return 0;
73+
}
74+
settings.setValue("updates/latestUpdateCheck", QDateTime::currentDateTime());
75+
}
76+
else
77+
{
78+
qDebug() << "We'll check again tomorrow.";
79+
}
80+
5781
// build and show UI
5882
s->newMessage("Building UI");
5983
MainWindow *w = new MainWindow( a.arguments() );

src/mainwindow.cpp

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "dbmanagerwidget.h"
3131
#include "duqf-widgets/duqftoolbarspacer.h"
3232
#include "duqf-widgets/duqflogtoolbutton.h"
33-
#include "duqf-widgets/duqfupdatedialog.h"
3433
#include "duqf-widgets/duqfupdatesettingswidget.h"
3534
#include "duqf-widgets/appearancesettingswidget.h"
3635
#include "duqf-app/app-version.h"
@@ -601,35 +600,6 @@ void MainWindow::hidePropertiesDock()
601600
ui_propertiesDockWidget->hide();
602601
}
603602

604-
void MainWindow::duqf_checkUpdate()
605-
{
606-
DuApplication *app = qobject_cast<DuApplication*>(qApp);
607-
connect(app, SIGNAL(newUpdateInfo(QJsonObject)), this, SLOT(duqf_updateAvailable(QJsonObject)));
608-
// Check for update
609-
QSettings settings;
610-
bool doCheckUpdate = settings.value("updates/checkUpdateAtStartup", true).toBool();
611-
// Just once a day
612-
if (doCheckUpdate)
613-
{
614-
qDebug() << "Update check...";
615-
QDateTime lastCheck = settings.value("updates/latestUpdateCheck").toDateTime();
616-
qDebug().noquote() << "Last check was on: " + lastCheck.toString("yyyy-MM-dd hh:mm:ss");
617-
int days = lastCheck.daysTo(QDateTime::currentDateTime());
618-
qDebug().noquote() << days << " days since last check.";
619-
if (days > 0 || !lastCheck.isValid())
620-
{
621-
app->checkUpdate();
622-
return;
623-
}
624-
else
625-
{
626-
qDebug() << "We'll check again tomorrow.";
627-
duqf_updateAvailable(app->updateInfo());
628-
}
629-
}
630-
m_showUpdateAlerts = true;
631-
}
632-
633603
void MainWindow::duqf_initUi()
634604
{
635605
// ===== SYSTRAY ======
@@ -759,7 +729,8 @@ void MainWindow::duqf_initUi()
759729
helpMenu->addAction(aboutQtAction);
760730

761731
// Check for update
762-
duqf_checkUpdate();
732+
// moved in main()
733+
//duqf_checkUpdate();
763734

764735
// ========= SETTINGS ========
765736

@@ -783,6 +754,9 @@ void MainWindow::duqf_initUi()
783754
connect(duqf_settingsButton, SIGNAL(clicked(bool)), this, SLOT(duqf_settings(bool)));
784755
connect(settingsWidget, SIGNAL(closeRequested()), this, SLOT(duqf_closeSettings()));
785756
connect(settingsWidget, SIGNAL(reinitRequested()), this, SLOT(duqf_reinitSettings()));
757+
758+
DuApplication *app = qobject_cast<DuApplication*>(qApp);
759+
duqf_updateAvailable(app->updateInfo());
786760
}
787761

788762
void MainWindow::duqf_setStyle()
@@ -932,19 +906,6 @@ void MainWindow::duqf_updateAvailable(QJsonObject updateInfo)
932906
));
933907
}
934908
}
935-
936-
if (!updateInfo.value("update").toBool() && !m_showUpdateAlerts)
937-
{
938-
m_showUpdateAlerts = true;
939-
return;
940-
}
941-
942-
QSettings settings;
943-
QDate latestUpdateCheck = settings.value("updates/latestUpdateCheck", QDate(1970,1,1)).toDate();
944-
if (latestUpdateCheck == QDate::currentDate()) return;
945-
946-
DuQFUpdateDialog *dialog = new DuQFUpdateDialog(updateInfo, this);
947-
dialog->show();
948909
}
949910

950911
void MainWindow::log(DuQFLog m)

src/mainwindow.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ public slots:
5454
void connectShortCuts();
5555

5656
// ========= RxOT UI ==============
57-
/**
58-
* @brief duqf_checkUpdate Called once to check if an update is available
59-
*/
60-
void duqf_checkUpdate();
6157
/**
6258
* @brief initUi Called once to build the default RxOT UI
6359
*/

0 commit comments

Comments
 (0)