forked from quickshell/quickshell
		
	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());
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			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<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) {
 | 
			
		||||
	if (!this->watcher->files().contains(name)) {
 | 
			
		||||
		this->deletedWatchedFiles.push_back(name);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<QString>& files);
 | 
			
		||||
 | 
			
		||||
	void registerIncubationController(QQmlIncubationController* controller);
 | 
			
		||||
	void deregisterIncubationController(QQmlIncubationController* controller);
 | 
			
		||||
| 
						 | 
				
			
			@ -61,6 +62,7 @@ public:
 | 
			
		|||
	SingletonRegistry singletonRegistry;
 | 
			
		||||
	QFileSystemWatcher* watcher = nullptr;
 | 
			
		||||
	QVector<QString> deletedWatchedFiles;
 | 
			
		||||
	QVector<QString> extraWatchedFiles;
 | 
			
		||||
	DelayedQmlIncubationController delayedIncubationController;
 | 
			
		||||
	bool reloadComplete = false;
 | 
			
		||||
	QuickshellGlobal* qsgInstance = nullptr;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<QQuickItem*>(newRoot)) {
 | 
			
		||||
		auto* window = new FloatingWindowInterface();
 | 
			
		||||
		item->setParent(window);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue