Browse Source

#87 Notify if update is available

recurring
Aditya Kulkarni 5 years ago
parent
commit
fbdfe1fc33
  1. 1
      src/precompiled.h
  2. 53
      src/rpc.cpp
  3. 1
      src/rpc.h

1
src/precompiled.h

@ -28,6 +28,7 @@
#include <QPainter>
#include <QMovie>
#include <QPair>
#include <QVersionNumber>
#include <QDir>
#include <QMenu>
#include <QCompleter>

53
src/rpc.cpp

@ -4,6 +4,7 @@
#include "settings.h"
#include "senttxstore.h"
#include "turnstile.h"
#include "version.h"
using json = nlohmann::json;
@ -85,6 +86,7 @@ void RPC::setConnection(Connection* c) {
ui->statusBar->showMessage("Ready!");
refreshZECPrice();
checkForUpdate();
// Force update, because this might be coming from a settings update
// 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
void RPC::refreshZECPrice() {
if (conn == nullptr)

1
src/rpc.h

@ -38,6 +38,7 @@ public:
void refreshAddresses();
void checkForUpdate();
void refreshZECPrice();
void getZboardTopics(std::function<void(QMap<QString, QString>)> cb);

Loading…
Cancel
Save