forked from quickshell/quickshell
		
	core: run full destruction sequence before exiting
Fixes QTimer messages.
This commit is contained in:
		
							parent
							
								
									3033cba52d
								
							
						
					
					
						commit
						6efa05a8eb
					
				
					 2 changed files with 34 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -52,6 +52,9 @@ EngineGeneration::~EngineGeneration() {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void EngineGeneration::destroy() {
 | 
			
		||||
	if (this->destroying) return;
 | 
			
		||||
	this->destroying = true;
 | 
			
		||||
 | 
			
		||||
	if (this->watcher != nullptr) {
 | 
			
		||||
		// Multiple generations can detect a reload at the same time.
 | 
			
		||||
		QObject::disconnect(this->watcher, nullptr, this, nullptr);
 | 
			
		||||
| 
						 | 
				
			
			@ -71,7 +74,12 @@ void EngineGeneration::destroy() {
 | 
			
		|||
 | 
			
		||||
			delete this->engine;
 | 
			
		||||
			this->engine = nullptr;
 | 
			
		||||
 | 
			
		||||
			auto terminate = this->shouldTerminate;
 | 
			
		||||
			auto code = this->exitCode;
 | 
			
		||||
			delete this;
 | 
			
		||||
 | 
			
		||||
			if (terminate) QCoreApplication::exit(code);
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		this->root->deleteLater();
 | 
			
		||||
| 
						 | 
				
			
			@ -80,11 +88,18 @@ void EngineGeneration::destroy() {
 | 
			
		|||
		// the engine has never been used, no need to clean up
 | 
			
		||||
		delete this->engine;
 | 
			
		||||
		this->engine = nullptr;
 | 
			
		||||
 | 
			
		||||
		auto terminate = this->shouldTerminate;
 | 
			
		||||
		auto code = this->exitCode;
 | 
			
		||||
		delete this;
 | 
			
		||||
 | 
			
		||||
		if (terminate) QCoreApplication::exit(code);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EngineGeneration::shutdown() {
 | 
			
		||||
	if (this->destroying) return;
 | 
			
		||||
 | 
			
		||||
	delete this->root;
 | 
			
		||||
	this->root = nullptr;
 | 
			
		||||
	delete this->engine;
 | 
			
		||||
| 
						 | 
				
			
			@ -100,9 +115,8 @@ void EngineGeneration::onReload(EngineGeneration* old) {
 | 
			
		|||
		old->assignIncubationController();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	auto* app = QCoreApplication::instance();
 | 
			
		||||
	QObject::connect(this->engine, &QQmlEngine::quit, app, &QCoreApplication::quit);
 | 
			
		||||
	QObject::connect(this->engine, &QQmlEngine::exit, app, &QCoreApplication::exit);
 | 
			
		||||
	QObject::connect(this->engine, &QQmlEngine::quit, this, &EngineGeneration::quit);
 | 
			
		||||
	QObject::connect(this->engine, &QQmlEngine::exit, this, &EngineGeneration::exit);
 | 
			
		||||
 | 
			
		||||
	this->root->reload(old == nullptr ? nullptr : old->root);
 | 
			
		||||
	this->singletonRegistry.onReload(old == nullptr ? nullptr : &old->singletonRegistry);
 | 
			
		||||
| 
						 | 
				
			
			@ -266,6 +280,17 @@ void EngineGeneration::incubationControllerDestroyed() {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EngineGeneration::quit() {
 | 
			
		||||
	this->shouldTerminate = true;
 | 
			
		||||
	this->destroy();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EngineGeneration::exit(int code) {
 | 
			
		||||
	this->shouldTerminate = true;
 | 
			
		||||
	this->exitCode = code;
 | 
			
		||||
	this->destroy();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EngineGeneration::assignIncubationController() {
 | 
			
		||||
	QQmlIncubationController* controller = nullptr;
 | 
			
		||||
	if (this->incubationControllers.isEmpty()) controller = &this->delayedIncubationController;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -61,9 +61,15 @@ private slots:
 | 
			
		|||
	void onFileChanged(const QString& name);
 | 
			
		||||
	void onDirectoryChanged();
 | 
			
		||||
	void incubationControllerDestroyed();
 | 
			
		||||
	void quit();
 | 
			
		||||
	void exit(int code);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	void postReload();
 | 
			
		||||
	void assignIncubationController();
 | 
			
		||||
	QVector<QPair<QQmlIncubationController*, QObject*>> incubationControllers;
 | 
			
		||||
 | 
			
		||||
	bool destroying = false;
 | 
			
		||||
	bool shouldTerminate = false;
 | 
			
		||||
	int exitCode = 0;
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue