Moved version number check to Application class

This commit is contained in:
Nav
2023-05-29 23:43:47 +01:00
parent 38989ae300
commit 2feccb7b6f
4 changed files with 43 additions and 44 deletions

View File

@@ -7,6 +7,11 @@
#include <unistd.h>
#include <yaml-cpp/yaml.h>
#include <yaml-cpp/exceptions.h>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QUrl>
#include <QUrlQuery>
#include "src/Services/ProcessService.hpp"
@@ -72,6 +77,7 @@ namespace Bloom
this->activateInsight();
}
#endif
this->checkBloomVersion();
/*
* We can't run our own event loop here - we have to use Qt's event loop. But we still need to be able to
@@ -514,6 +520,36 @@ namespace Bloom
this->applicationEventListener->dispatchCurrentEvents();
}
void Application::checkBloomVersion() {
const auto currentVersionNumber = Application::VERSION;
auto* networkAccessManager = new QNetworkAccessManager(this);
auto queryVersionEndpointUrl = QUrl(QString::fromStdString(Services::PathService::homeDomainName() + "/latest-version"));
queryVersionEndpointUrl.setScheme("http");
queryVersionEndpointUrl.setQuery(QUrlQuery({
{"currentVersionNumber", QString::fromStdString(currentVersionNumber.toString())}
}));
QObject::connect(
networkAccessManager,
&QNetworkAccessManager::finished,
this,
[this, currentVersionNumber] (QNetworkReply* response) {
const auto jsonResponseObject = QJsonDocument::fromJson(response->readAll()).object();
const auto latestVersionNumber = VersionNumber(jsonResponseObject.value("latestVersionNumber").toString());
if (latestVersionNumber > currentVersionNumber) {
Logger::warning(
"Bloom v" + latestVersionNumber.toString()
+ " is available to download - upgrade via " + Services::PathService::homeDomainName()
);
}
}
);
networkAccessManager->get(QNetworkRequest(queryVersionEndpointUrl));
}
#ifndef EXCLUDE_INSIGHT
void Application::activateInsight() {
assert(!this->insight);

View File

@@ -251,6 +251,13 @@ namespace Bloom
*/
void dispatchEvents();
/**
* Queries the Bloom server for the latest version number. If the current version number doesn't match the
* latest version number returned by the server, we'll display a warning in the logs to instruct the user to
* upgrade.
*/
void checkBloomVersion();
#ifndef EXCLUDE_INSIGHT
/**
* Activate the Insight GUI.

View File

@@ -2,11 +2,6 @@
#include <QTimer>
#include <QFontDatabase>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QUrl>
#include <QUrlQuery>
#include <QJsonDocument>
#include "src/Services/PathService.hpp"
@@ -167,8 +162,6 @@ namespace Bloom
workerThread->start();
}
this->checkBloomVersion();
this->mainWindow->init(this->targetControllerService.getTargetDescriptor());
this->mainWindow->show();
}
@@ -190,36 +183,6 @@ namespace Bloom
}
}
void Insight::checkBloomVersion() {
const auto currentVersionNumber = Application::VERSION;
auto* networkAccessManager = new QNetworkAccessManager(this);
auto queryVersionEndpointUrl = QUrl(QString::fromStdString(Services::PathService::homeDomainName() + "/latest-version"));
queryVersionEndpointUrl.setScheme("http");
queryVersionEndpointUrl.setQuery(QUrlQuery({
{"currentVersionNumber", QString::fromStdString(currentVersionNumber.toString())}
}));
QObject::connect(
networkAccessManager,
&QNetworkAccessManager::finished,
this,
[this, currentVersionNumber] (QNetworkReply* response) {
const auto jsonResponseObject = QJsonDocument::fromJson(response->readAll()).object();
const auto latestVersionNumber = VersionNumber(jsonResponseObject.value("latestVersionNumber").toString());
if (latestVersionNumber > currentVersionNumber) {
Logger::warning(
"Bloom v" + latestVersionNumber.toString()
+ " is available to download - upgrade via " + Services::PathService::homeDomainName()
);
}
}
);
networkAccessManager->get(QNetworkRequest(queryVersionEndpointUrl));
}
void Insight::onInsightWindowActivated() {
const auto getTargetStateTask = QSharedPointer<GetTargetState>(new GetTargetState(), &QObject::deleteLater);
QObject::connect(

View File

@@ -98,13 +98,6 @@ namespace Bloom
InsightSignals* insightSignals = InsightSignals::instance();
/**
* Queries the Bloom server for the latest version number. If the current version number doesn't match the
* latest version number returned by the server, we'll display a warning in the logs to instruct the user to
* upgrade.
*/
void checkBloomVersion();
void onInsightWindowActivated();
void onTargetStoppedEvent(const Events::TargetExecutionStopped& event);
void onTargetResumedEvent(const Events::TargetExecutionResumed& event);