forked from quickshell/quickshell
		
	core/reloader: fix file watcher compatibility with vim
This commit is contained in:
		
							parent
							
								
									4e92d82992
								
							
						
					
					
						commit
						7ad3671dd1
					
				
					 2 changed files with 32 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -4,6 +4,8 @@
 | 
			
		|||
#include <qcontainerfwd.h>
 | 
			
		||||
#include <qcoreapplication.h>
 | 
			
		||||
#include <qdebug.h>
 | 
			
		||||
#include <qdir.h>
 | 
			
		||||
#include <qfileinfo.h>
 | 
			
		||||
#include <qfilesystemwatcher.h>
 | 
			
		||||
#include <qhash.h>
 | 
			
		||||
#include <qlogging.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -117,13 +119,21 @@ void EngineGeneration::setWatchingFiles(bool watching) {
 | 
			
		|||
 | 
			
		||||
			for (auto& file: this->scanner.scannedFiles) {
 | 
			
		||||
				this->watcher->addPath(file);
 | 
			
		||||
				this->watcher->addPath(QFileInfo(file).dir().absolutePath());
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			QObject::connect(
 | 
			
		||||
			    this->watcher,
 | 
			
		||||
			    &QFileSystemWatcher::fileChanged,
 | 
			
		||||
			    this,
 | 
			
		||||
			    &EngineGeneration::filesChanged
 | 
			
		||||
			    &EngineGeneration::onFileChanged
 | 
			
		||||
			);
 | 
			
		||||
 | 
			
		||||
			QObject::connect(
 | 
			
		||||
			    this->watcher,
 | 
			
		||||
			    &QFileSystemWatcher::directoryChanged,
 | 
			
		||||
			    this,
 | 
			
		||||
			    &EngineGeneration::onDirectoryChanged
 | 
			
		||||
			);
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
| 
						 | 
				
			
			@ -134,6 +144,24 @@ void EngineGeneration::setWatchingFiles(bool watching) {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EngineGeneration::onFileChanged(const QString& name) {
 | 
			
		||||
	if (!this->watcher->files().contains(name)) {
 | 
			
		||||
		this->deletedWatchedFiles.push_back(name);
 | 
			
		||||
	} else {
 | 
			
		||||
		emit this->filesChanged();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EngineGeneration::onDirectoryChanged() {
 | 
			
		||||
	// try to find any files that were just deleted from a replace operation
 | 
			
		||||
	for (auto& file: this->deletedWatchedFiles) {
 | 
			
		||||
		if (QFileInfo(file).exists()) {
 | 
			
		||||
			emit this->filesChanged();
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EngineGeneration::registerIncubationController(QQmlIncubationController* controller) {
 | 
			
		||||
	auto* obj = dynamic_cast<QObject*>(controller);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,6 +40,7 @@ public:
 | 
			
		|||
	ShellRoot* root = nullptr;
 | 
			
		||||
	SingletonRegistry singletonRegistry;
 | 
			
		||||
	QFileSystemWatcher* watcher = nullptr;
 | 
			
		||||
	QVector<QString> deletedWatchedFiles;
 | 
			
		||||
	DelayedQmlIncubationController delayedIncubationController;
 | 
			
		||||
	bool reloadComplete = false;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -50,6 +51,8 @@ signals:
 | 
			
		|||
	void reloadFinished();
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
	void onFileChanged(const QString& name);
 | 
			
		||||
	void onDirectoryChanged();
 | 
			
		||||
	void incubationControllerDestroyed();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue