Skip to content

Commit 85551ee

Browse files
committed
service/polkit: slightly simplify takeover logic
1 parent e393e8e commit 85551ee

File tree

4 files changed

+6
-14
lines changed

4 files changed

+6
-14
lines changed

src/services/polkit/agentimpl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ PolkitAgentImpl* PolkitAgentImpl::tryGet(const PolkitAgent* agent) {
6060
return nullptr;
6161
}
6262

63-
PolkitAgentImpl* PolkitAgentImpl::tryTakeover(PolkitAgent* agent) {
64-
if (instance == nullptr) return nullptr;
63+
PolkitAgentImpl* PolkitAgentImpl::tryTakeoverOrCreate(PolkitAgent* agent) {
64+
if (auto* impl = tryGetOrCreate(agent); impl != nullptr) return impl;
6565

6666
auto* prevGen = EngineGeneration::findObjectGeneration(instance->qmlAgent);
6767
auto* myGen = EngineGeneration::findObjectGeneration(agent);
6868
if (prevGen == myGen) return nullptr;
6969

7070
qCDebug(logPolkit) << "taking over listener from previous generation";
7171
instance->qmlAgent = agent;
72+
instance->setPath(agent->path());
7273

7374
return instance;
7475
}

src/services/polkit/agentimpl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class PolkitAgentImpl
2323

2424
static PolkitAgentImpl* tryGetOrCreate(PolkitAgent* agent);
2525
static PolkitAgentImpl* tryGet(const PolkitAgent* agent);
26-
static PolkitAgentImpl* tryTakeover(PolkitAgent* agent);
26+
static PolkitAgentImpl* tryTakeoverOrCreate(PolkitAgent* agent);
2727
static void onEndOfQmlAgent(PolkitAgent* agent);
2828

2929
[[nodiscard]] QBindable<AuthFlow*> activeFlow();

src/services/polkit/qml.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,14 @@ QS_LOGGING_CATEGORY(logPolkit, "quickshell.service.polkit");
1111
}
1212

1313
namespace qs::service::polkit {
14-
PolkitAgent::PolkitAgent(QObject* parent): QObject(parent) {
15-
// Try to takeover an existing PolkitAgentImpl from the previous QML engine generation.
16-
// If none exists, we wait until componentComplete to create one so we have the correct path.
17-
PolkitAgentImpl::tryTakeover(this);
18-
}
19-
2014
PolkitAgent::~PolkitAgent() { PolkitAgentImpl::onEndOfQmlAgent(this); };
2115

2216
void PolkitAgent::componentComplete() {
2317
if (this->mPath.isEmpty()) this->mPath = "/org/quickshell/Polkit";
2418

25-
auto* impl = PolkitAgentImpl::tryGetOrCreate(this);
19+
auto* impl = PolkitAgentImpl::tryTakeoverOrCreate(this);
2620
if (impl == nullptr) return;
2721

28-
impl->setPath(this->mPath);
29-
3022
this->bFlow.setBinding([impl]() { return impl->activeFlow().value(); });
3123
this->bIsActive.setBinding([impl]() { return impl->activeFlow().value() != nullptr; });
3224
this->bIsRegistered.setBinding([impl]() { return impl->isRegistered().value(); });

src/services/polkit/qml.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "../../core/model.hpp"
1313
#include "../../core/reload.hpp"
1414
#include "../../core/retainable.hpp"
15-
1615
#include "flow.hpp"
1716

1817
// The reserved identifier is exactly the struct I mean.
@@ -56,7 +55,7 @@ class PolkitAgent
5655
Q_PROPERTY(AuthFlow* flow READ default NOTIFY flowChanged BINDABLE flow);
5756

5857
public:
59-
explicit PolkitAgent(QObject* parent = nullptr);
58+
explicit PolkitAgent(QObject* parent = nullptr): QObject(parent) {};
6059
~PolkitAgent() override;
6160

6261
void classBegin() override {};

0 commit comments

Comments
 (0)