core/reloader: watch new files detected in failed reloads
This commit is contained in:
parent
e931b85464
commit
4472b27039
3 changed files with 35 additions and 5 deletions
|
@ -162,6 +162,11 @@ void EngineGeneration::setWatchingFiles(bool watching) {
|
||||||
this->watcher->addPath(QFileInfo(file).dir().absolutePath());
|
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(
|
QObject::connect(
|
||||||
this->watcher,
|
this->watcher,
|
||||||
&QFileSystemWatcher::fileChanged,
|
&QFileSystemWatcher::fileChanged,
|
||||||
|
@ -184,6 +189,22 @@ void EngineGeneration::setWatchingFiles(bool watching) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EngineGeneration::setExtraWatchedFiles(const QVector<QString>& 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) {
|
void EngineGeneration::onFileChanged(const QString& name) {
|
||||||
if (!this->watcher->files().contains(name)) {
|
if (!this->watcher->files().contains(name)) {
|
||||||
this->deletedWatchedFiles.push_back(name);
|
this->deletedWatchedFiles.push_back(name);
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
// assumes root has been initialized, consumes old generation
|
// assumes root has been initialized, consumes old generation
|
||||||
void onReload(EngineGeneration* old);
|
void onReload(EngineGeneration* old);
|
||||||
void setWatchingFiles(bool watching);
|
void setWatchingFiles(bool watching);
|
||||||
|
bool setExtraWatchedFiles(const QVector<QString>& files);
|
||||||
|
|
||||||
void registerIncubationController(QQmlIncubationController* controller);
|
void registerIncubationController(QQmlIncubationController* controller);
|
||||||
void deregisterIncubationController(QQmlIncubationController* controller);
|
void deregisterIncubationController(QQmlIncubationController* controller);
|
||||||
|
@ -61,6 +62,7 @@ public:
|
||||||
SingletonRegistry singletonRegistry;
|
SingletonRegistry singletonRegistry;
|
||||||
QFileSystemWatcher* watcher = nullptr;
|
QFileSystemWatcher* watcher = nullptr;
|
||||||
QVector<QString> deletedWatchedFiles;
|
QVector<QString> deletedWatchedFiles;
|
||||||
|
QVector<QString> extraWatchedFiles;
|
||||||
DelayedQmlIncubationController delayedIncubationController;
|
DelayedQmlIncubationController delayedIncubationController;
|
||||||
bool reloadComplete = false;
|
bool reloadComplete = false;
|
||||||
QuickshellGlobal* qsgInstance = nullptr;
|
QuickshellGlobal* qsgInstance = nullptr;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "../window/floatingwindow.hpp"
|
#include "../window/floatingwindow.hpp"
|
||||||
#include "generation.hpp"
|
#include "generation.hpp"
|
||||||
#include "instanceinfo.hpp"
|
#include "instanceinfo.hpp"
|
||||||
|
#include "logging.hpp"
|
||||||
#include "qmlglobal.hpp"
|
#include "qmlglobal.hpp"
|
||||||
#include "scan.hpp"
|
#include "scan.hpp"
|
||||||
|
|
||||||
|
@ -63,16 +64,20 @@ void RootWrapper::reloadGraph(bool hard) {
|
||||||
url.setScheme("qsintercept");
|
url.setScheme("qsintercept");
|
||||||
auto component = QQmlComponent(generation->engine, url);
|
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) {
|
auto newFiles = generation->scanner.scannedFiles;
|
||||||
const QString error = "failed to create root component\n" + component.errorString();
|
|
||||||
qWarning().noquote() << error;
|
|
||||||
generation->destroy();
|
generation->destroy();
|
||||||
|
|
||||||
if (this->generation != nullptr) {
|
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) {
|
if (this->generation->qsgInstance != nullptr) {
|
||||||
this->generation->qsgInstance->clearReloadPopupInhibit();
|
this->generation->qsgInstance->clearReloadPopupInhibit();
|
||||||
emit this->generation->qsgInstance->reloadFailed(error);
|
emit this->generation->qsgInstance->reloadFailed(error);
|
||||||
|
@ -89,6 +94,8 @@ void RootWrapper::reloadGraph(bool hard) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto* newRoot = component.beginCreate(generation->engine->rootContext());
|
||||||
|
|
||||||
if (auto* item = qobject_cast<QQuickItem*>(newRoot)) {
|
if (auto* item = qobject_cast<QQuickItem*>(newRoot)) {
|
||||||
auto* window = new FloatingWindowInterface();
|
auto* window = new FloatingWindowInterface();
|
||||||
item->setParent(window);
|
item->setParent(window);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue