Refactored insight startup code to accommodate on-demand activation.
Also created new event for activation request
This commit is contained in:
@@ -57,33 +57,19 @@ namespace Bloom
|
||||
this->startup();
|
||||
|
||||
#ifndef EXCLUDE_INSIGHT
|
||||
if (this->insightConfig->insightEnabled) {
|
||||
this->insight = std::make_unique<Insight>(
|
||||
*(this->applicationEventListener),
|
||||
this->projectConfig.value(),
|
||||
this->environmentConfig.value(),
|
||||
this->insightConfig.value(),
|
||||
this->projectSettings.value().insightSettings
|
||||
);
|
||||
|
||||
/*
|
||||
* Before letting Insight occupy the main thread, process any pending events that accumulated
|
||||
* during startup.
|
||||
*/
|
||||
this->applicationEventListener->dispatchCurrentEvents();
|
||||
|
||||
if (Thread::getThreadState() == ThreadState::READY) {
|
||||
this->insight->run();
|
||||
Logger::debug("Insight closed");
|
||||
}
|
||||
|
||||
this->shutdown();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
this->insightActivationPending = this->insightConfig->insightEnabled;
|
||||
#endif
|
||||
|
||||
// Main event loop
|
||||
while (Thread::getThreadState() == ThreadState::READY) {
|
||||
#ifndef EXCLUDE_INSIGHT
|
||||
if (this->insightActivationPending) {
|
||||
this->insightActivationPending = false;
|
||||
this->startInsight();
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
this->applicationEventListener->waitAndDispatch();
|
||||
}
|
||||
|
||||
@@ -159,6 +145,11 @@ namespace Bloom
|
||||
std::bind(&Application::onDebugSessionFinished, this, std::placeholders::_1)
|
||||
);
|
||||
|
||||
#ifndef EXCLUDE_INSIGHT
|
||||
applicationEventListener->registerCallbackForEventType<Events::InsightActivationRequested>(
|
||||
std::bind(&Application::onInsightActivationRequest, this, std::placeholders::_1)
|
||||
);
|
||||
#endif
|
||||
this->startTargetController();
|
||||
this->startDebugServer();
|
||||
|
||||
@@ -507,6 +498,41 @@ namespace Bloom
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef EXCLUDE_INSIGHT
|
||||
void Application::startInsight() {
|
||||
assert(!this->insight);
|
||||
|
||||
this->insight = std::make_unique<Insight>(
|
||||
*(this->applicationEventListener),
|
||||
this->projectConfig.value(),
|
||||
this->environmentConfig.value(),
|
||||
this->insightConfig.value(),
|
||||
this->projectSettings.value().insightSettings
|
||||
);
|
||||
|
||||
/*
|
||||
* Before letting Insight occupy the main thread, process any pending events that accumulated
|
||||
* during startup.
|
||||
*/
|
||||
this->applicationEventListener->dispatchCurrentEvents();
|
||||
|
||||
if (Thread::getThreadState() == ThreadState::READY) {
|
||||
this->insight->run();
|
||||
Logger::debug("Insight closed");
|
||||
}
|
||||
}
|
||||
|
||||
void Application::onInsightActivationRequest(const Events::InsightActivationRequested&) {
|
||||
if (this->insight) {
|
||||
// Insight has already been started
|
||||
this->insight->showMainWindow();
|
||||
return;
|
||||
}
|
||||
|
||||
this->insightActivationPending = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void Application::onShutdownApplicationRequest(const Events::ShutdownApplication&) {
|
||||
Logger::debug("ShutdownApplication event received.");
|
||||
this->shutdown();
|
||||
|
||||
@@ -86,8 +86,8 @@ namespace Bloom
|
||||
|
||||
#ifndef EXCLUDE_INSIGHT
|
||||
/**
|
||||
* Insight is, effectively, a small Qt application that serves a GUI to the user. It occupies the main thread,
|
||||
* as well as a single worker thread, and possibly other threads created by Qt.
|
||||
* Insight is a small Qt application that serves a GUI to the user. It occupies the main thread, as well as a
|
||||
* single worker thread, and possibly other threads created by Qt.
|
||||
*
|
||||
* Insight is optional - users can disable it via their project configuration.
|
||||
*
|
||||
@@ -100,6 +100,13 @@ namespace Bloom
|
||||
* as we want to manage the lifetime of the object here.
|
||||
*/
|
||||
std::unique_ptr<Insight> insight = nullptr;
|
||||
|
||||
/**
|
||||
* Activation of the Insight GUI can be requested by triggering an InsightActivationRequested event.
|
||||
*
|
||||
* This flag will be set upon that event being triggered. The Insight GUI will be started shortly after.
|
||||
*/
|
||||
bool insightActivationPending = false;
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -231,6 +238,20 @@ namespace Bloom
|
||||
*/
|
||||
void stopDebugServer();
|
||||
|
||||
#ifndef EXCLUDE_INSIGHT
|
||||
/**
|
||||
* Starts the Insight GUI.
|
||||
*
|
||||
* This function should never be called more than once.
|
||||
*/
|
||||
void startInsight();
|
||||
|
||||
/**
|
||||
* Handles requests to start the Insight GUI.
|
||||
*/
|
||||
void onInsightActivationRequest(const Events::InsightActivationRequested&);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Triggers a shutdown of Bloom and all of its components.
|
||||
*/
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace Bloom::Events
|
||||
TARGET_RESET,
|
||||
PROGRAMMING_MODE_ENABLED,
|
||||
PROGRAMMING_MODE_DISABLED,
|
||||
INSIGHT_ACTIVATION_REQUESTED,
|
||||
};
|
||||
|
||||
class Event
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
#include "ProgrammingModeEnabled.hpp"
|
||||
#include "ProgrammingModeDisabled.hpp"
|
||||
|
||||
#ifndef EXCLUDE_INSIGHT
|
||||
#include "InsightActivationRequested.hpp"
|
||||
#endif
|
||||
|
||||
namespace Bloom::Events
|
||||
{
|
||||
template <class EventType>
|
||||
|
||||
26
src/EventManager/Events/InsightActivationRequested.hpp
Normal file
26
src/EventManager/Events/InsightActivationRequested.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "Event.hpp"
|
||||
|
||||
namespace Bloom::Events
|
||||
{
|
||||
class InsightActivationRequested: public Event
|
||||
{
|
||||
public:
|
||||
static constexpr EventType type = EventType::INSIGHT_ACTIVATION_REQUESTED;
|
||||
static const inline std::string name = "InsightActivationRequested";
|
||||
|
||||
InsightActivationRequested() = default;
|
||||
|
||||
[[nodiscard]] EventType getType() const override {
|
||||
return InsightActivationRequested::type;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string getName() const override {
|
||||
return InsightActivationRequested::name;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -66,6 +66,11 @@ namespace Bloom
|
||||
this->shutdown();
|
||||
}
|
||||
|
||||
void Insight::showMainWindow() {
|
||||
this->mainWindow->show();
|
||||
this->mainWindow->activateWindow();
|
||||
}
|
||||
|
||||
void Insight::startup() {
|
||||
Logger::info("Starting Insight");
|
||||
this->setThreadState(ThreadState::STARTING);
|
||||
@@ -102,7 +107,7 @@ namespace Bloom
|
||||
std::bind(&Insight::onProgrammingModeDisabledEvent, this, std::placeholders::_1)
|
||||
);
|
||||
|
||||
QApplication::setQuitOnLastWindowClosed(true);
|
||||
QApplication::setQuitOnLastWindowClosed(false);
|
||||
QApplication::setStyle(new BloomProxyStyle());
|
||||
|
||||
auto globalStylesheet = QFile(
|
||||
|
||||
@@ -61,6 +61,11 @@ namespace Bloom
|
||||
*/
|
||||
void run();
|
||||
|
||||
/**
|
||||
* Opens main window and obtains focus.
|
||||
*/
|
||||
void showMainWindow();
|
||||
|
||||
/**
|
||||
* Shuts down Insight. Called when the user closes the Insight window or a ShutdownApplication event is fired.
|
||||
*/
|
||||
|
||||
@@ -318,6 +318,10 @@ namespace Bloom
|
||||
}
|
||||
|
||||
void InsightWindow::showEvent(QShowEvent* event) {
|
||||
if (!this->activated) {
|
||||
this->activate();
|
||||
}
|
||||
|
||||
this->adjustPanels();
|
||||
this->adjustMinimumSize();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user