forked from quickshell/quickshell
		
	core/reloader: trigger onPostReload if launched post-reload
This is similar to the check in Reloadable, and fixes a number of hard to debug issues with Process, IpcHandler, NotificationServer, and GlobalShortcut not working depending on where you put them in a QML file.
This commit is contained in:
		
							parent
							
								
									0e6518a706
								
							
						
					
					
						commit
						9708d8212a
					
				
					 8 changed files with 36 additions and 38 deletions
				
			
		| 
						 | 
					@ -126,12 +126,17 @@ QObject* Reloadable::getChildByReloadId(QObject* parent, const QString& reloadId
 | 
				
			||||||
	return nullptr;
 | 
						return nullptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PostReloadHook::postReloadTree(QObject* root) {
 | 
					void PostReloadHook::componentComplete() {
 | 
				
			||||||
	for (auto* child: root->children()) {
 | 
						auto* engineGeneration = EngineGeneration::findObjectGeneration(this);
 | 
				
			||||||
		PostReloadHook::postReloadTree(child);
 | 
						if (!engineGeneration || engineGeneration->reloadComplete) this->postReload();
 | 
				
			||||||
	}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (auto* self = dynamic_cast<PostReloadHook*>(root)) {
 | 
					void PostReloadHook::postReload() {
 | 
				
			||||||
		self->onPostReload();
 | 
						this->isPostReload = true;
 | 
				
			||||||
	}
 | 
						this->onPostReload();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void PostReloadHook::postReloadTree(QObject* root) {
 | 
				
			||||||
 | 
						for (auto* child: root->children()) PostReloadHook::postReloadTree(child);
 | 
				
			||||||
 | 
						if (auto* self = dynamic_cast<PostReloadHook*>(root)) self->postReload();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -119,16 +119,19 @@ private:
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Hook that runs after the old widget tree is dropped during a reload.
 | 
					/// Hook that runs after the old widget tree is dropped during a reload.
 | 
				
			||||||
class PostReloadHook {
 | 
					class PostReloadHook
 | 
				
			||||||
 | 
					    : public QObject
 | 
				
			||||||
 | 
					    , public QQmlParserStatus {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	PostReloadHook() = default;
 | 
						PostReloadHook(QObject* parent = nullptr): QObject(parent) {}
 | 
				
			||||||
	virtual ~PostReloadHook() = default;
 | 
						void classBegin() override {}
 | 
				
			||||||
	PostReloadHook(PostReloadHook&&) = default;
 | 
						void componentComplete() override;
 | 
				
			||||||
	PostReloadHook(const PostReloadHook&) = default;
 | 
					 | 
				
			||||||
	PostReloadHook& operator=(PostReloadHook&&) = default;
 | 
					 | 
				
			||||||
	PostReloadHook& operator=(const PostReloadHook&) = default;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void postReload();
 | 
				
			||||||
	virtual void onPostReload() = 0;
 | 
						virtual void onPostReload() = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	static void postReloadTree(QObject* root);
 | 
						static void postReloadTree(QObject* root);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					protected:
 | 
				
			||||||
 | 
						bool isPostReload = false;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -154,9 +154,7 @@ class IpcHandlerRegistry;
 | 
				
			||||||
/// #### Properties
 | 
					/// #### Properties
 | 
				
			||||||
/// Properties of an IpcHanlder can be read using `qs ipc prop get` as long as they are
 | 
					/// Properties of an IpcHanlder can be read using `qs ipc prop get` as long as they are
 | 
				
			||||||
/// of an IPC compatible type. See the table above for compatible types.
 | 
					/// of an IPC compatible type. See the table above for compatible types.
 | 
				
			||||||
class IpcHandler
 | 
					class IpcHandler: public PostReloadHook {
 | 
				
			||||||
    : public QObject
 | 
					 | 
				
			||||||
    , public PostReloadHook {
 | 
					 | 
				
			||||||
	Q_OBJECT;
 | 
						Q_OBJECT;
 | 
				
			||||||
	/// If the handler should be able to receive calls. Defaults to true.
 | 
						/// If the handler should be able to receive calls. Defaults to true.
 | 
				
			||||||
	Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged);
 | 
						Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged);
 | 
				
			||||||
| 
						 | 
					@ -166,7 +164,7 @@ class IpcHandler
 | 
				
			||||||
	QML_ELEMENT;
 | 
						QML_ELEMENT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	explicit IpcHandler(QObject* parent = nullptr): QObject(parent) {};
 | 
						explicit IpcHandler(QObject* parent = nullptr): PostReloadHook(parent) {};
 | 
				
			||||||
	~IpcHandler() override;
 | 
						~IpcHandler() override;
 | 
				
			||||||
	Q_DISABLE_COPY_MOVE(IpcHandler);
 | 
						Q_DISABLE_COPY_MOVE(IpcHandler);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,10 +15,11 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "../core/generation.hpp"
 | 
					#include "../core/generation.hpp"
 | 
				
			||||||
#include "../core/qmlglobal.hpp"
 | 
					#include "../core/qmlglobal.hpp"
 | 
				
			||||||
 | 
					#include "../core/reload.hpp"
 | 
				
			||||||
#include "datastream.hpp"
 | 
					#include "datastream.hpp"
 | 
				
			||||||
#include "processcore.hpp"
 | 
					#include "processcore.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Process::Process(QObject* parent): QObject(parent) {
 | 
					Process::Process(QObject* parent): PostReloadHook(parent) {
 | 
				
			||||||
	QObject::connect(
 | 
						QObject::connect(
 | 
				
			||||||
	    QuickshellSettings::instance(),
 | 
						    QuickshellSettings::instance(),
 | 
				
			||||||
	    &QuickshellSettings::workingDirectoryChanged,
 | 
						    &QuickshellSettings::workingDirectoryChanged,
 | 
				
			||||||
| 
						 | 
					@ -37,10 +38,7 @@ Process::~Process() {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Process::onPostReload() {
 | 
					void Process::onPostReload() { this->startProcessIfReady(); }
 | 
				
			||||||
	this->postReload = true;
 | 
					 | 
				
			||||||
	this->startProcessIfReady();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Process::isRunning() const { return this->process != nullptr; }
 | 
					bool Process::isRunning() const { return this->process != nullptr; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -180,9 +178,10 @@ void Process::setStdinEnabled(bool enabled) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Process::startProcessIfReady() {
 | 
					void Process::startProcessIfReady() {
 | 
				
			||||||
	if (this->process != nullptr || !this->postReload || !this->targetRunning
 | 
						if (this->process != nullptr || !this->isPostReload || !this->targetRunning
 | 
				
			||||||
	    || this->mCommand.isEmpty())
 | 
						    || this->mCommand.isEmpty())
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	this->targetRunning = false;
 | 
						this->targetRunning = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	auto& cmd = this->mCommand.first();
 | 
						auto& cmd = this->mCommand.first();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,9 +31,7 @@
 | 
				
			||||||
///   }
 | 
					///   }
 | 
				
			||||||
/// }
 | 
					/// }
 | 
				
			||||||
/// ```
 | 
					/// ```
 | 
				
			||||||
class Process
 | 
					class Process: public PostReloadHook {
 | 
				
			||||||
    : public QObject
 | 
					 | 
				
			||||||
    , public PostReloadHook {
 | 
					 | 
				
			||||||
	Q_OBJECT;
 | 
						Q_OBJECT;
 | 
				
			||||||
	// clang-format off
 | 
						// clang-format off
 | 
				
			||||||
	/// If the process is currently running. Defaults to false.
 | 
						/// If the process is currently running. Defaults to false.
 | 
				
			||||||
| 
						 | 
					@ -258,5 +256,4 @@ private:
 | 
				
			||||||
	bool targetRunning = false;
 | 
						bool targetRunning = false;
 | 
				
			||||||
	bool mStdinEnabled = false;
 | 
						bool mStdinEnabled = false;
 | 
				
			||||||
	bool mClearEnvironment = false;
 | 
						bool mClearEnvironment = false;
 | 
				
			||||||
	bool postReload = false;
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,7 +18,7 @@ void TestProcess::startAfterReload() {
 | 
				
			||||||
	QVERIFY(!process.isRunning());
 | 
						QVERIFY(!process.isRunning());
 | 
				
			||||||
	QCOMPARE(startedSpy.count(), 0);
 | 
						QCOMPARE(startedSpy.count(), 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	process.onPostReload();
 | 
						process.postReload();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QVERIFY(process.isRunning());
 | 
						QVERIFY(process.isRunning());
 | 
				
			||||||
	QVERIFY(startedSpy.wait(100));
 | 
						QVERIFY(startedSpy.wait(100));
 | 
				
			||||||
| 
						 | 
					@ -29,7 +29,7 @@ void TestProcess::testExec() {
 | 
				
			||||||
	auto startedSpy = QSignalSpy(&process, &Process::started);
 | 
						auto startedSpy = QSignalSpy(&process, &Process::started);
 | 
				
			||||||
	auto exitedSpy = QSignalSpy(&process, &Process::exited);
 | 
						auto exitedSpy = QSignalSpy(&process, &Process::exited);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	process.onPostReload();
 | 
						process.postReload();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	process.setCommand({"sleep", "30"});
 | 
						process.setCommand({"sleep", "30"});
 | 
				
			||||||
	process.setRunning(true);
 | 
						process.setRunning(true);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,9 +21,7 @@ namespace qs::service::notifications {
 | 
				
			||||||
/// The server does not advertise most capabilities by default. See the individual properties for details.
 | 
					/// The server does not advertise most capabilities by default. See the individual properties for details.
 | 
				
			||||||
///
 | 
					///
 | 
				
			||||||
/// [Desktop Notifications Specification]: https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html
 | 
					/// [Desktop Notifications Specification]: https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html
 | 
				
			||||||
class NotificationServerQml
 | 
					class NotificationServerQml: public PostReloadHook {
 | 
				
			||||||
    : public QObject
 | 
					 | 
				
			||||||
    , public PostReloadHook {
 | 
					 | 
				
			||||||
	Q_OBJECT;
 | 
						Q_OBJECT;
 | 
				
			||||||
	// clang-format off
 | 
						// clang-format off
 | 
				
			||||||
	/// If notifications should be re-emitted when quickshell reloads. Defaults to true.
 | 
						/// If notifications should be re-emitted when quickshell reloads. Defaults to true.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,9 +32,7 @@ namespace qs::hyprland::global_shortcuts {
 | 
				
			||||||
///
 | 
					///
 | 
				
			||||||
/// [hyprland_global_shortcuts_v1]: https://github.com/hyprwm/hyprland-protocols/blob/main/protocols/hyprland-global-shortcuts-v1.xml
 | 
					/// [hyprland_global_shortcuts_v1]: https://github.com/hyprwm/hyprland-protocols/blob/main/protocols/hyprland-global-shortcuts-v1.xml
 | 
				
			||||||
/// [the wiki]: https://wiki.hyprland.org/Configuring/Binds/#dbus-global-shortcuts
 | 
					/// [the wiki]: https://wiki.hyprland.org/Configuring/Binds/#dbus-global-shortcuts
 | 
				
			||||||
class GlobalShortcut
 | 
					class GlobalShortcut: public PostReloadHook {
 | 
				
			||||||
    : public QObject
 | 
					 | 
				
			||||||
    , public PostReloadHook {
 | 
					 | 
				
			||||||
	using ShortcutImpl = impl::GlobalShortcut;
 | 
						using ShortcutImpl = impl::GlobalShortcut;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Q_OBJECT;
 | 
						Q_OBJECT;
 | 
				
			||||||
| 
						 | 
					@ -59,7 +57,7 @@ class GlobalShortcut
 | 
				
			||||||
	QML_ELEMENT;
 | 
						QML_ELEMENT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	explicit GlobalShortcut(QObject* parent = nullptr): QObject(parent) {}
 | 
						explicit GlobalShortcut(QObject* parent = nullptr): PostReloadHook(parent) {}
 | 
				
			||||||
	~GlobalShortcut() override;
 | 
						~GlobalShortcut() override;
 | 
				
			||||||
	Q_DISABLE_COPY_MOVE(GlobalShortcut);
 | 
						Q_DISABLE_COPY_MOVE(GlobalShortcut);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue