Skip to content

Commit d6193d0

Browse files
committed
[update] 基本支持软件更新功能
1 parent deb18e7 commit d6193d0

File tree

7 files changed

+45
-11
lines changed

7 files changed

+45
-11
lines changed

project/main/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ int main(int argc, char *argv[])
2020
QApplication a(argc, argv);
2121

2222
MainWindow w;
23+
QString version = "RTduino Pinout Generator V" + get_version_string();
2324

2425
if(argc == 1) { //设置条件不用每次都设置
2526
QString appPath = qApp->applicationFilePath();
@@ -40,8 +41,8 @@ int main(int argc, char *argv[])
4041
}
4142

4243
w.show();
43-
QString version = "RTduino Pinout Generator V" + get_version_string();
4444
w.setWindowTitle(version);
45+
a.setApplicationVersion(get_version_string());
4546

4647
return a.exec();
4748
}

project/main/version.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#define PG_VERSION_MINOR 0 /**< Minor version number (x.X.x) */
88
#define PG_VERSION_PATCH 3 /**< Patch version number (x.x.X) */
99

10+
#define DEFS_URL "https://raw.githubusercontent.com/RTduino/pinout-generator/master/tools/updates.json"
11+
1012
QString get_version_string(void);
1113

1214
#endif // VERSION_H

project/third-party/QSimpleUpdater/src/Updater.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Updater::Updater()
3737
m_changelog = "";
3838
m_downloadUrl = "";
3939
m_latestVersion = "";
40+
m_typeVersion = "Release";
4041
m_customAppcast = false;
4142
m_notifyOnUpdate = true;
4243
m_notifyOnFinish = false;
@@ -141,6 +142,15 @@ QString Updater::latestVersion() const
141142
return m_latestVersion;
142143
}
143144

145+
/**
146+
* Returns the type version defined by the update definitions file.
147+
* \warning Must is <Alpha> <Beta> <Release>
148+
*/
149+
QString Updater::typeVersion() const
150+
{
151+
return m_typeVersion;
152+
}
153+
144154
/**
145155
* Returns the user-agent header used by the client when communicating
146156
* with the server through HTTP
@@ -410,6 +420,10 @@ void Updater::onReply(QNetworkReply *reply)
410420
m_changelog = platform.value("changelog").toString();
411421
m_downloadUrl = platform.value("download-url").toString();
412422
m_latestVersion = platform.value("latest-version").toString();
423+
/* https://hexingxing.cn/alpha-beta-rc-release/ */
424+
/* <Alpha> <Beta> <Release> */
425+
m_typeVersion = platform.value("type-version").toString().isEmpty()
426+
? m_typeVersion : platform.value("type-version").toString();
413427
if (platform.contains("mandatory-update"))
414428
m_mandatoryUpdate = platform.value("mandatory-update").toBool();
415429

@@ -440,7 +454,7 @@ void Updater::setUpdateAvailable(const bool available)
440454
}
441455

442456
QString title
443-
= "<h3>" + tr("Version %1 of %2 has been released!").arg(latestVersion()).arg(moduleName()) + "</h3>";
457+
= "<h3>" + tr("Version %1(%2) of %3 has been released!").arg(latestVersion()).arg(typeVersion()).arg(moduleName()) + "</h3>";
444458

445459
box.setText(title);
446460
box.setInformativeText(text);

project/third-party/QSimpleUpdater/src/Updater.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class QSU_DECL Updater : public QObject
5656
QString platformKey() const;
5757
QString moduleVersion() const;
5858
QString latestVersion() const;
59+
QString typeVersion() const;
5960
QString userAgentString() const;
6061
bool mandatoryUpdate() const;
6162

@@ -106,7 +107,7 @@ private slots:
106107
QString m_downloadUrl;
107108
QString m_moduleVersion;
108109
QString m_latestVersion;
109-
110+
QString m_typeVersion;
110111
Downloader *m_downloader;
111112
QNetworkAccessManager *m_manager;
112113
};

project/widgets/mainwindow.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,34 @@
22
#include "ui_mainwindow.h"
33
#include <QDir>
44
#include <QDebug>
5+
#include <QSslSocket>
56
#include <QDesktopServices>
7+
#include <version.h>
68

79
MainWindow::MainWindow(QWidget *parent)
810
: QMainWindow(parent)
911
, ui(new Ui::MainWindow)
1012
{
1113
ui->setupUi(this);
1214
rtduino = RTduinoConfig::getInstance();
15+
/* QSimpleUpdater is single-instance */
16+
qDebug()<<"QSslSocket:"<<QSslSocket::sslLibraryBuildVersionString();
17+
qDebug() << "OpenSSL support:" << QSslSocket::supportsSsl();
18+
if (QSslSocket::supportsSsl() == true)
19+
{
20+
updater = QSimpleUpdater::getInstance();
21+
22+
/* Config for updates */
23+
updater->setModuleVersion(DEFS_URL, get_version_string());
24+
updater->setNotifyOnFinish(DEFS_URL, false);
25+
updater->setNotifyOnUpdate(DEFS_URL, true);
26+
updater->setUseCustomAppcast(DEFS_URL, false);
27+
updater->setDownloaderEnabled(DEFS_URL, true);
28+
updater->setMandatoryUpdate(DEFS_URL, false);
29+
30+
/* Check for updates */
31+
updater->checkForUpdates(DEFS_URL);
32+
}
1333
cfile = new CreateFile;
1434
}
1535

project/widgets/mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <projwidget.h>
99
#include <rtduinoconfig.h>
1010
#include <createfile.h>
11+
#include <QSimpleUpdater.h>
1112

1213
QT_BEGIN_NAMESPACE
1314
namespace Ui { class MainWindow; }
@@ -34,5 +35,6 @@ private slots:
3435
ProjWidget *ui_proj;
3536
RTduinoConfig *rtduino;
3637
CreateFile *cfile;
38+
QSimpleUpdater *updater;
3739
};
3840
#endif // MAINWINDOW_H

tools/updates.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22
"updates": {
33
"windows": {
44
"open-url": "",
5+
"type-version": "Alpha",
56
"latest-version": "2.0.3",
67
"download-url": "https://raw.githubusercontent.com/RTduino/pinout-generator/master/software/PinoutGenerator-v2.0.3-Setup.exe",
78
"changelog": "This is an example changelog for Windows. Go on...",
8-
"mandatory": true
9-
},
10-
"linux": {
11-
"open-url": "",
12-
"latest-version": "2.0.3",
13-
"download-url": "https://raw.githubusercontent.com/RTduino/pinout-generator/master/software/PinoutGenerator-v2.0.3-Setup.exe",
14-
"changelog": "This is an example changelog for Linux. Go on...",
15-
"mandatory": true
9+
"mandatory-update": false
1610
}
1711
}
1812
}

0 commit comments

Comments
 (0)