#87 Notify if update is available
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QMovie>
|
#include <QMovie>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
|
#include <QVersionNumber>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QCompleter>
|
#include <QCompleter>
|
||||||
|
|||||||
53
src/rpc.cpp
53
src/rpc.cpp
@@ -4,6 +4,7 @@
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "senttxstore.h"
|
#include "senttxstore.h"
|
||||||
#include "turnstile.h"
|
#include "turnstile.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
@@ -85,6 +86,7 @@ void RPC::setConnection(Connection* c) {
|
|||||||
ui->statusBar->showMessage("Ready!");
|
ui->statusBar->showMessage("Ready!");
|
||||||
|
|
||||||
refreshZECPrice();
|
refreshZECPrice();
|
||||||
|
checkForUpdate();
|
||||||
|
|
||||||
// Force update, because this might be coming from a settings update
|
// Force update, because this might be coming from a settings update
|
||||||
// where we need to immediately refresh
|
// where we need to immediately refresh
|
||||||
@@ -903,6 +905,57 @@ void RPC::watchTxStatus() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RPC::checkForUpdate() {
|
||||||
|
if (conn == nullptr)
|
||||||
|
return noConnection();
|
||||||
|
|
||||||
|
QUrl cmcURL("https://api.github.com/repos/ZcashFoundation/zec-qt-wallet/releases");
|
||||||
|
|
||||||
|
QNetworkRequest req;
|
||||||
|
req.setUrl(cmcURL);
|
||||||
|
|
||||||
|
QNetworkReply *reply = conn->restclient->get(req);
|
||||||
|
|
||||||
|
QObject::connect(reply, &QNetworkReply::finished, [=] {
|
||||||
|
reply->deleteLater();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (reply->error() == QNetworkReply::NoError) {
|
||||||
|
|
||||||
|
auto releases = QJsonDocument::fromJson(reply->readAll()).array();
|
||||||
|
QVersionNumber maxVersion(0, 0, 0);
|
||||||
|
|
||||||
|
for (QJsonValue rel : releases) {
|
||||||
|
QString tag = rel.toObject()["tag_name"].toString();
|
||||||
|
if (tag.startsWith("v"))
|
||||||
|
tag = tag.right(tag.length() - 1);
|
||||||
|
|
||||||
|
auto v = QVersionNumber::fromString(tag);
|
||||||
|
if (v > maxVersion)
|
||||||
|
maxVersion = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto currentVersion = QVersionNumber::fromString(APP_VERSION);
|
||||||
|
qDebug() << "Version check: Current " << currentVersion << ", Available " << maxVersion;
|
||||||
|
if (maxVersion > currentVersion) {
|
||||||
|
auto ans = QMessageBox::information(main, QObject::tr("Update Available"),
|
||||||
|
QObject::tr("A new release v%1 is available! You have v%2.\n\nWould you like to visit the releases page?")
|
||||||
|
.arg(maxVersion.toString())
|
||||||
|
.arg(currentVersion.toString()),
|
||||||
|
QMessageBox::Yes, QMessageBox::Cancel);
|
||||||
|
if (ans == QMessageBox::Yes) {
|
||||||
|
QDesktopServices::openUrl(QUrl("https://github.com/ZcashFoundation/zec-qt-wallet/releases"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
// If anything at all goes wrong, just set the price to 0 and move on.
|
||||||
|
qDebug() << QString("Caught something nasty");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Get the ZEC->USD price from coinmarketcap using their API
|
// Get the ZEC->USD price from coinmarketcap using their API
|
||||||
void RPC::refreshZECPrice() {
|
void RPC::refreshZECPrice() {
|
||||||
if (conn == nullptr)
|
if (conn == nullptr)
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public:
|
|||||||
|
|
||||||
void refreshAddresses();
|
void refreshAddresses();
|
||||||
|
|
||||||
|
void checkForUpdate();
|
||||||
void refreshZECPrice();
|
void refreshZECPrice();
|
||||||
void getZboardTopics(std::function<void(QMap<QString, QString>)> cb);
|
void getZboardTopics(std::function<void(QMap<QString, QString>)> cb);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user