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:
outfoxxed 2025-07-04 15:58:41 -07:00
parent 0e6518a706
commit 9708d8212a
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
8 changed files with 36 additions and 38 deletions

View file

@ -154,9 +154,7 @@ class IpcHandlerRegistry;
/// #### Properties
/// 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.
class IpcHandler
: public QObject
, public PostReloadHook {
class IpcHandler: public PostReloadHook {
Q_OBJECT;
/// If the handler should be able to receive calls. Defaults to true.
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged);
@ -166,7 +164,7 @@ class IpcHandler
QML_ELEMENT;
public:
explicit IpcHandler(QObject* parent = nullptr): QObject(parent) {};
explicit IpcHandler(QObject* parent = nullptr): PostReloadHook(parent) {};
~IpcHandler() override;
Q_DISABLE_COPY_MOVE(IpcHandler);

View file

@ -15,10 +15,11 @@
#include "../core/generation.hpp"
#include "../core/qmlglobal.hpp"
#include "../core/reload.hpp"
#include "datastream.hpp"
#include "processcore.hpp"
Process::Process(QObject* parent): QObject(parent) {
Process::Process(QObject* parent): PostReloadHook(parent) {
QObject::connect(
QuickshellSettings::instance(),
&QuickshellSettings::workingDirectoryChanged,
@ -37,10 +38,7 @@ Process::~Process() {
}
}
void Process::onPostReload() {
this->postReload = true;
this->startProcessIfReady();
}
void Process::onPostReload() { this->startProcessIfReady(); }
bool Process::isRunning() const { return this->process != nullptr; }
@ -180,9 +178,10 @@ void Process::setStdinEnabled(bool enabled) {
}
void Process::startProcessIfReady() {
if (this->process != nullptr || !this->postReload || !this->targetRunning
if (this->process != nullptr || !this->isPostReload || !this->targetRunning
|| this->mCommand.isEmpty())
return;
this->targetRunning = false;
auto& cmd = this->mCommand.first();

View file

@ -31,9 +31,7 @@
/// }
/// }
/// ```
class Process
: public QObject
, public PostReloadHook {
class Process: public PostReloadHook {
Q_OBJECT;
// clang-format off
/// If the process is currently running. Defaults to false.
@ -258,5 +256,4 @@ private:
bool targetRunning = false;
bool mStdinEnabled = false;
bool mClearEnvironment = false;
bool postReload = false;
};

View file

@ -18,7 +18,7 @@ void TestProcess::startAfterReload() {
QVERIFY(!process.isRunning());
QCOMPARE(startedSpy.count(), 0);
process.onPostReload();
process.postReload();
QVERIFY(process.isRunning());
QVERIFY(startedSpy.wait(100));
@ -29,7 +29,7 @@ void TestProcess::testExec() {
auto startedSpy = QSignalSpy(&process, &Process::started);
auto exitedSpy = QSignalSpy(&process, &Process::exited);
process.onPostReload();
process.postReload();
process.setCommand({"sleep", "30"});
process.setRunning(true);