diff --git a/src/core/generation.cpp b/src/core/generation.cpp index f91bc182..49451f4a 100644 --- a/src/core/generation.cpp +++ b/src/core/generation.cpp @@ -162,6 +162,11 @@ void EngineGeneration::setWatchingFiles(bool watching) { this->watcher->addPath(QFileInfo(file).dir().absolutePath()); } + for (auto& file: this->extraWatchedFiles) { + this->watcher->addPath(file); + this->watcher->addPath(QFileInfo(file).dir().absolutePath()); + } + QObject::connect( this->watcher, &QFileSystemWatcher::fileChanged, @@ -184,6 +189,22 @@ void EngineGeneration::setWatchingFiles(bool watching) { } } +bool EngineGeneration::setExtraWatchedFiles(const QVector& files) { + this->extraWatchedFiles.clear(); + for (const auto& file: files) { + if (!this->scanner.scannedFiles.contains(file)) { + this->extraWatchedFiles.append(file); + } + } + + if (this->watcher) { + this->setWatchingFiles(false); + this->setWatchingFiles(true); + } + + return !this->extraWatchedFiles.isEmpty(); +} + void EngineGeneration::onFileChanged(const QString& name) { if (!this->watcher->files().contains(name)) { this->deletedWatchedFiles.push_back(name); diff --git a/src/core/generation.hpp b/src/core/generation.hpp index f0c4d02a..b033cebc 100644 --- a/src/core/generation.hpp +++ b/src/core/generation.hpp @@ -36,6 +36,7 @@ public: // assumes root has been initialized, consumes old generation void onReload(EngineGeneration* old); void setWatchingFiles(bool watching); + bool setExtraWatchedFiles(const QVector& files); void registerIncubationController(QQmlIncubationController* controller); void deregisterIncubationController(QQmlIncubationController* controller); @@ -61,6 +62,7 @@ public: SingletonRegistry singletonRegistry; QFileSystemWatcher* watcher = nullptr; QVector deletedWatchedFiles; + QVector extraWatchedFiles; DelayedQmlIncubationController delayedIncubationController; bool reloadComplete = false; QuickshellGlobal* qsgInstance = nullptr; diff --git a/src/core/rootwrapper.cpp b/src/core/rootwrapper.cpp index 6950aa92..0656b558 100644 --- a/src/core/rootwrapper.cpp +++ b/src/core/rootwrapper.cpp @@ -16,6 +16,7 @@ #include "../window/floatingwindow.hpp" #include "generation.hpp" #include "instanceinfo.hpp" +#include "logging.hpp" #include "qmlglobal.hpp" #include "scan.hpp" @@ -63,16 +64,20 @@ void RootWrapper::reloadGraph(bool hard) { url.setScheme("qsintercept"); auto component = QQmlComponent(generation->engine, url); - auto* newRoot = component.beginCreate(generation->engine->rootContext()); + if (!component.isReady()) { + qCritical() << "Failed to load configuration:"; + auto error = component.errorString().trimmed(); + qCCritical(logBare).noquote() << error; - if (newRoot == nullptr) { - const QString error = "failed to create root component\n" + component.errorString(); - qWarning().noquote() << error; + auto newFiles = generation->scanner.scannedFiles; generation->destroy(); if (this->generation != nullptr) { - auto showPopup = true; + if (this->generation->setExtraWatchedFiles(newFiles)) { + qInfo() << "Watching additional files picked up in reload for changes..."; + } + auto showPopup = true; if (this->generation->qsgInstance != nullptr) { this->generation->qsgInstance->clearReloadPopupInhibit(); emit this->generation->qsgInstance->reloadFailed(error); @@ -89,6 +94,8 @@ void RootWrapper::reloadGraph(bool hard) { return; } + auto* newRoot = component.beginCreate(generation->engine->rootContext()); + if (auto* item = qobject_cast(newRoot)) { auto* window = new FloatingWindowInterface(); item->setParent(window);