From 2feccb7b6fc58b0e2ab93045e0d6cd4004a0ab69 Mon Sep 17 00:00:00 2001 From: Nav Date: Mon, 29 May 2023 23:43:47 +0100 Subject: [PATCH] Moved version number check to Application class --- src/Application.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/Application.hpp | 7 +++++++ src/Insight/Insight.cpp | 37 ------------------------------------- src/Insight/Insight.hpp | 7 ------- 4 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index 6d7e0f63..7a2b9a4a 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -7,6 +7,11 @@ #include #include #include +#include +#include +#include +#include +#include #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); diff --git a/src/Application.hpp b/src/Application.hpp index a46b37e0..68ac184b 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -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. diff --git a/src/Insight/Insight.cpp b/src/Insight/Insight.cpp index cc31f0e2..8bcc82d4 100644 --- a/src/Insight/Insight.cpp +++ b/src/Insight/Insight.cpp @@ -2,11 +2,6 @@ #include #include -#include -#include -#include -#include -#include #include #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(new GetTargetState(), &QObject::deleteLater); QObject::connect( diff --git a/src/Insight/Insight.hpp b/src/Insight/Insight.hpp index 56484b3e..3a9af303 100644 --- a/src/Insight/Insight.hpp +++ b/src/Insight/Insight.hpp @@ -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);