Skip to content

Commit 4472b27

Browse files
committed
core/reloader: watch new files detected in failed reloads
1 parent e931b85 commit 4472b27

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

src/core/generation.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ void EngineGeneration::setWatchingFiles(bool watching) {
162162
this->watcher->addPath(QFileInfo(file).dir().absolutePath());
163163
}
164164

165+
for (auto& file: this->extraWatchedFiles) {
166+
this->watcher->addPath(file);
167+
this->watcher->addPath(QFileInfo(file).dir().absolutePath());
168+
}
169+
165170
QObject::connect(
166171
this->watcher,
167172
&QFileSystemWatcher::fileChanged,
@@ -184,6 +189,22 @@ void EngineGeneration::setWatchingFiles(bool watching) {
184189
}
185190
}
186191

192+
bool EngineGeneration::setExtraWatchedFiles(const QVector<QString>& files) {
193+
this->extraWatchedFiles.clear();
194+
for (const auto& file: files) {
195+
if (!this->scanner.scannedFiles.contains(file)) {
196+
this->extraWatchedFiles.append(file);
197+
}
198+
}
199+
200+
if (this->watcher) {
201+
this->setWatchingFiles(false);
202+
this->setWatchingFiles(true);
203+
}
204+
205+
return !this->extraWatchedFiles.isEmpty();
206+
}
207+
187208
void EngineGeneration::onFileChanged(const QString& name) {
188209
if (!this->watcher->files().contains(name)) {
189210
this->deletedWatchedFiles.push_back(name);

src/core/generation.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class EngineGeneration: public QObject {
3636
// assumes root has been initialized, consumes old generation
3737
void onReload(EngineGeneration* old);
3838
void setWatchingFiles(bool watching);
39+
bool setExtraWatchedFiles(const QVector<QString>& files);
3940

4041
void registerIncubationController(QQmlIncubationController* controller);
4142
void deregisterIncubationController(QQmlIncubationController* controller);
@@ -61,6 +62,7 @@ class EngineGeneration: public QObject {
6162
SingletonRegistry singletonRegistry;
6263
QFileSystemWatcher* watcher = nullptr;
6364
QVector<QString> deletedWatchedFiles;
65+
QVector<QString> extraWatchedFiles;
6466
DelayedQmlIncubationController delayedIncubationController;
6567
bool reloadComplete = false;
6668
QuickshellGlobal* qsgInstance = nullptr;

src/core/rootwrapper.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "../window/floatingwindow.hpp"
1717
#include "generation.hpp"
1818
#include "instanceinfo.hpp"
19+
#include "logging.hpp"
1920
#include "qmlglobal.hpp"
2021
#include "scan.hpp"
2122

@@ -63,16 +64,20 @@ void RootWrapper::reloadGraph(bool hard) {
6364
url.setScheme("qsintercept");
6465
auto component = QQmlComponent(generation->engine, url);
6566

66-
auto* newRoot = component.beginCreate(generation->engine->rootContext());
67+
if (!component.isReady()) {
68+
qCritical() << "Failed to load configuration:";
69+
auto error = component.errorString().trimmed();
70+
qCCritical(logBare).noquote() << error;
6771

68-
if (newRoot == nullptr) {
69-
const QString error = "failed to create root component\n" + component.errorString();
70-
qWarning().noquote() << error;
72+
auto newFiles = generation->scanner.scannedFiles;
7173
generation->destroy();
7274

7375
if (this->generation != nullptr) {
74-
auto showPopup = true;
76+
if (this->generation->setExtraWatchedFiles(newFiles)) {
77+
qInfo() << "Watching additional files picked up in reload for changes...";
78+
}
7579

80+
auto showPopup = true;
7681
if (this->generation->qsgInstance != nullptr) {
7782
this->generation->qsgInstance->clearReloadPopupInhibit();
7883
emit this->generation->qsgInstance->reloadFailed(error);
@@ -89,6 +94,8 @@ void RootWrapper::reloadGraph(bool hard) {
8994
return;
9095
}
9196

97+
auto* newRoot = component.beginCreate(generation->engine->rootContext());
98+
9299
if (auto* item = qobject_cast<QQuickItem*>(newRoot)) {
93100
auto* window = new FloatingWindowInterface();
94101
item->setParent(window);

0 commit comments

Comments
 (0)