From bc4939e48f0a612aace24f0d9d02f4b2c72763d6 Mon Sep 17 00:00:00 2001 From: Nav Date: Fri, 14 Jul 2023 18:39:27 +0100 Subject: [PATCH] Added `shutdownOnClose` Insight config param, to trigger a shutdown when the user closes the main Insight window. --- src/Application.cpp | 10 ++++++++ src/Application.hpp | 7 ++++++ src/EventManager/Events/Event.hpp | 1 + src/EventManager/Events/Events.hpp | 1 + .../Events/InsightMainWindowClosed.hpp | 23 +++++++++++++++++++ src/Insight/Insight.cpp | 2 ++ src/Insight/Insight.hpp | 1 - src/ProjectConfig.cpp | 4 ++++ src/ProjectConfig.hpp | 8 +++++++ 9 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/EventManager/Events/InsightMainWindowClosed.hpp diff --git a/src/Application.cpp b/src/Application.cpp index 8798ba08..15ddd7ea 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -170,6 +170,10 @@ namespace Bloom applicationEventListener->registerCallbackForEventType( std::bind(&Application::onInsightActivationRequest, this, std::placeholders::_1) ); + + applicationEventListener->registerCallbackForEventType( + std::bind(&Application::onInsightMainWindowClosed, this, std::placeholders::_1) + ); #endif this->startTargetController(); this->startDebugServer(); @@ -586,6 +590,12 @@ namespace Bloom this->activateInsight(); } + + void Application::onInsightMainWindowClosed(const Events::InsightMainWindowClosed& event) { + if (this->insightConfig->shutdownOnClose) { + this->triggerShutdown(); + } + } #endif void Application::onShutdownApplicationRequest(const Events::ShutdownApplication&) { diff --git a/src/Application.hpp b/src/Application.hpp index d10cb7e6..1333ea09 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -282,6 +282,13 @@ namespace Bloom * Handles requests to start the Insight GUI. */ void onInsightActivationRequest(const Events::InsightActivationRequested&); + + /** + * Performs any post-insight-closed actions. + * + * @param event + */ + void onInsightMainWindowClosed(const Events::InsightMainWindowClosed& event); #endif /** diff --git a/src/EventManager/Events/Event.hpp b/src/EventManager/Events/Event.hpp index 5ab41b82..ef182974 100644 --- a/src/EventManager/Events/Event.hpp +++ b/src/EventManager/Events/Event.hpp @@ -31,6 +31,7 @@ namespace Bloom::Events PROGRAMMING_MODE_ENABLED, PROGRAMMING_MODE_DISABLED, INSIGHT_ACTIVATION_REQUESTED, + INSIGHT_MAIN_WINDOW_CLOSED, }; class Event diff --git a/src/EventManager/Events/Events.hpp b/src/EventManager/Events/Events.hpp index 1164f183..099a1ef1 100644 --- a/src/EventManager/Events/Events.hpp +++ b/src/EventManager/Events/Events.hpp @@ -21,6 +21,7 @@ #ifndef EXCLUDE_INSIGHT #include "InsightActivationRequested.hpp" +#include "InsightMainWindowClosed.hpp" #endif namespace Bloom::Events diff --git a/src/EventManager/Events/InsightMainWindowClosed.hpp b/src/EventManager/Events/InsightMainWindowClosed.hpp new file mode 100644 index 00000000..882c16ac --- /dev/null +++ b/src/EventManager/Events/InsightMainWindowClosed.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include + +#include "Event.hpp" + +namespace Bloom::Events +{ + class InsightMainWindowClosed: public Event + { + public: + static constexpr EventType type = EventType::INSIGHT_MAIN_WINDOW_CLOSED; + static const inline std::string name = "InsightMainWindowClosed"; + + [[nodiscard]] EventType getType() const override { + return InsightMainWindowClosed::type; + } + + [[nodiscard]] std::string getName() const override { + return InsightMainWindowClosed::name; + } + }; +} diff --git a/src/Insight/Insight.cpp b/src/Insight/Insight.cpp index 0c66a74e..d5a32a3f 100644 --- a/src/Insight/Insight.cpp +++ b/src/Insight/Insight.cpp @@ -6,6 +6,7 @@ #include "src/Services/PathService.hpp" #include "src/Logger/Logger.hpp" +#include "src/EventManager/EventManager.hpp" #include "UserInterfaces/InsightWindow/BloomProxyStyle.hpp" #include "src/Application.hpp" @@ -204,6 +205,7 @@ namespace Bloom void Insight::onInsightWindowDestroyed() { this->mainWindow = nullptr; + EventManager::triggerEvent(std::make_shared()); } void Insight::onTargetStoppedEvent(const Events::TargetExecutionStopped& event) { diff --git a/src/Insight/Insight.hpp b/src/Insight/Insight.hpp index f53c2eae..01b49b38 100644 --- a/src/Insight/Insight.hpp +++ b/src/Insight/Insight.hpp @@ -13,7 +13,6 @@ #include "src/ProjectConfig.hpp" #include "src/ProjectSettings.hpp" -#include "src/EventManager/EventManager.hpp" #include "src/EventManager/EventListener.hpp" #include "src/EventManager/Events/Events.hpp" diff --git a/src/ProjectConfig.cpp b/src/ProjectConfig.cpp index 81098998..76eee5a9 100644 --- a/src/ProjectConfig.cpp +++ b/src/ProjectConfig.cpp @@ -80,6 +80,10 @@ namespace Bloom if (insightNode["activateOnStartup"]) { this->activateOnStartup = insightNode["activateOnStartup"].as(this->activateOnStartup); } + + if (insightNode["shutdownOnClose"]) { + this->shutdownOnClose = insightNode["shutdownOnClose"].as(this->shutdownOnClose); + } } EnvironmentConfig::EnvironmentConfig(std::string name, const YAML::Node& environmentNode) diff --git a/src/ProjectConfig.hpp b/src/ProjectConfig.hpp index 59bbf472..c66972d1 100644 --- a/src/ProjectConfig.hpp +++ b/src/ProjectConfig.hpp @@ -126,8 +126,16 @@ namespace Bloom struct InsightConfig { + /** + * If true, the Insight GUI will be activated immediately at startup. + */ bool activateOnStartup = false; + /** + * If true, Bloom will shutdown when the user closes the Insight GUI. + */ + bool shutdownOnClose = false; + InsightConfig() = default; /**