From 31264ac7d14d323eaff627d13b2d11501c3ee8a7 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Wed, 20 Mar 2024 01:37:30 -0700 Subject: [PATCH] core/singleton: fix PostReloadHook in singletons --- src/core/generation.cpp | 14 ++++++++------ src/core/generation.hpp | 1 + src/core/singleton.cpp | 6 ++++++ src/core/singleton.hpp | 1 + 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/core/generation.cpp b/src/core/generation.cpp index de5db17..2586b2a 100644 --- a/src/core/generation.cpp +++ b/src/core/generation.cpp @@ -55,16 +55,18 @@ void EngineGeneration::onReload(EngineGeneration* old) { delete old; if (old != nullptr) { - QTimer::singleShot(0, [this]() { - QuickshellPlugin::runOnReload(); - PostReloadHook::postReloadTree(this->root); - }); + QTimer::singleShot(0, [this]() { this->postReload(); }); } else { - QuickshellPlugin::runOnReload(); - PostReloadHook::postReloadTree(this->root); + this->postReload(); } } +void EngineGeneration::postReload() { + QuickshellPlugin::runOnReload(); + PostReloadHook::postReloadTree(this->root); + this->singletonRegistry.onPostReload(); +} + void EngineGeneration::setWatchingFiles(bool watching) { if (watching) { if (this->watcher == nullptr) { diff --git a/src/core/generation.hpp b/src/core/generation.hpp index 813190d..4b9ef1a 100644 --- a/src/core/generation.hpp +++ b/src/core/generation.hpp @@ -44,6 +44,7 @@ private slots: void incubationControllerDestroyed(); private: + void postReload(); void assignIncubationController(); QVector incubationControllers; }; diff --git a/src/core/singleton.cpp b/src/core/singleton.cpp index e3f0b33..2e5445a 100644 --- a/src/core/singleton.cpp +++ b/src/core/singleton.cpp @@ -51,3 +51,9 @@ void SingletonRegistry::onReload(SingletonRegistry* old) { singleton->onReload(old == nullptr ? nullptr : old->registry.value(url)); } } + +void SingletonRegistry::onPostReload() { + for (auto* singleton: this->registry.values()) { + PostReloadHook::postReloadTree(singleton); + } +} diff --git a/src/core/singleton.hpp b/src/core/singleton.hpp index 200c97f..e63ab12 100644 --- a/src/core/singleton.hpp +++ b/src/core/singleton.hpp @@ -26,6 +26,7 @@ public: void registerSingleton(const QUrl& url, Singleton* singleton); void onReload(SingletonRegistry* old); + void onPostReload(); private: QHash registry;