diff --git a/src/Insight/CMakeLists.txt b/src/Insight/CMakeLists.txt index a8856e77..4c4bc01c 100755 --- a/src/Insight/CMakeLists.txt +++ b/src/Insight/CMakeLists.txt @@ -27,7 +27,6 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/SetTargetPinState.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadTargetMemory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadStackPointer.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/QueryLatestVersionNumber.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadProgramCounter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/GetTargetState.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/GetTargetDescriptor.cpp diff --git a/src/Insight/Insight.cpp b/src/Insight/Insight.cpp index da6c560f..4038bfcd 100644 --- a/src/Insight/Insight.cpp +++ b/src/Insight/Insight.cpp @@ -2,6 +2,12 @@ #include #include +#include +#include +#include +#include +#include +#include #include "src/Helpers/Paths.hpp" #include "src/Logger/Logger.hpp" @@ -9,7 +15,6 @@ #include "src/Application.hpp" -#include "InsightWorker/Tasks/QueryLatestVersionNumber.hpp" #include "InsightWorker/Tasks/GetTargetState.hpp" #include "InsightWorker/Tasks/GetTargetDescriptor.hpp" @@ -191,17 +196,12 @@ namespace Bloom this->insightWorkersById[insightWorker->id] = std::pair(insightWorker, workerThread); - // TODO: Remove this hack. Find a better way to trigger the latest version check. - if (i == 0) { - QObject::connect(insightWorker, &InsightWorker::ready, this, [this] { - this->checkBloomVersion(); - }); - } - Logger::debug("Starting InsightWorker" + std::to_string(insightWorker->id)); workerThread->start(); } + this->checkBloomVersion(); + this->mainWindow->init(this->targetControllerConsole.getTargetDescriptor()); this->mainWindow->show(); } @@ -231,17 +231,23 @@ namespace Bloom } void Insight::checkBloomVersion() { - auto currentVersionNumber = Application::VERSION; + const auto currentVersionNumber = Application::VERSION; - auto* versionQueryTask = new QueryLatestVersionNumber( - currentVersionNumber - ); + auto* networkAccessManager = new QNetworkAccessManager(this); + auto queryVersionEndpointUrl = QUrl(QString::fromStdString(Paths::homeDomainName() + "/latest-version")); + queryVersionEndpointUrl.setScheme("http"); + queryVersionEndpointUrl.setQuery(QUrlQuery({ + {"currentVersionNumber", QString::fromStdString(currentVersionNumber.toString())} + })); QObject::connect( - versionQueryTask, - &QueryLatestVersionNumber::latestVersionNumberRetrieved, + networkAccessManager, + &QNetworkAccessManager::finished, this, - [this, currentVersionNumber] (const VersionNumber& latestVersionNumber) { + [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() @@ -251,7 +257,7 @@ namespace Bloom } ); - InsightWorker::queueTask(versionQueryTask); + networkAccessManager->get(QNetworkRequest(queryVersionEndpointUrl)); } void Insight::onInsightWindowActivated() { diff --git a/src/Insight/InsightWorker/Tasks/QueryLatestVersionNumber.cpp b/src/Insight/InsightWorker/Tasks/QueryLatestVersionNumber.cpp deleted file mode 100644 index ac4fb012..00000000 --- a/src/Insight/InsightWorker/Tasks/QueryLatestVersionNumber.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "QueryLatestVersionNumber.hpp" - -#include -#include -#include -#include -#include -#include - -#include "src/Helpers/Paths.hpp" - -namespace Bloom -{ - using TargetController::TargetControllerConsole; - - void QueryLatestVersionNumber::run(TargetControllerConsole& targetControllerConsole) { - auto* networkAccessManager = new QNetworkAccessManager(this); - auto queryVersionEndpointUrl = QUrl(QString::fromStdString(Paths::homeDomainName() + "/latest-version")); - queryVersionEndpointUrl.setScheme("http"); - queryVersionEndpointUrl.setQuery(QUrlQuery({ - {"currentVersionNumber", QString::fromStdString(this->currentVersionNumber.toString())} - })); - - auto* response = networkAccessManager->get(QNetworkRequest(queryVersionEndpointUrl)); - QObject::connect(response, &QNetworkReply::finished, this, [this, response] { - const auto jsonResponseObject = QJsonDocument::fromJson(response->readAll()).object(); - - if (jsonResponseObject.contains("latestVersionNumber")) { - emit this->latestVersionNumberRetrieved( - VersionNumber( - jsonResponseObject.value("latestVersionNumber").toString() - ) - ); - } - }); - } -} diff --git a/src/Insight/InsightWorker/Tasks/QueryLatestVersionNumber.hpp b/src/Insight/InsightWorker/Tasks/QueryLatestVersionNumber.hpp deleted file mode 100644 index 7e6fd892..00000000 --- a/src/Insight/InsightWorker/Tasks/QueryLatestVersionNumber.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "InsightWorkerTask.hpp" - -#include "src/VersionNumber.hpp" - -namespace Bloom -{ - class QueryLatestVersionNumber: public InsightWorkerTask - { - Q_OBJECT - - public: - explicit QueryLatestVersionNumber(const VersionNumber& currentVersionNumber): - currentVersionNumber(currentVersionNumber) {} - - signals: - void latestVersionNumberRetrieved(const VersionNumber& latestVersionNumber); - - protected: - void run(TargetController::TargetControllerConsole& targetControllerConsole) override; - - private: - VersionNumber currentVersionNumber; - }; -}