Skip to content

Commit d543958

Browse files
committed
service/polkit: slightly simplify takeover logic
1 parent 8db5f42 commit d543958

File tree

4 files changed

+6
-13
lines changed

4 files changed

+6
-13
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
@@ -12,22 +12,14 @@ QS_LOGGING_CATEGORY(logPolkit, "quickshell.service.polkit");
1212
}
1313

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

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

26-
auto* impl = PolkitAgentImpl::tryGetOrCreate(this);
20+
auto* impl = PolkitAgentImpl::tryTakeoverOrCreate(this);
2721
if (impl == nullptr) return;
2822

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

src/services/polkit/qml.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class PolkitAgent
5454
Q_PROPERTY(AuthFlow* flow READ default NOTIFY flowChanged BINDABLE flow);
5555

5656
public:
57-
explicit PolkitAgent(QObject* parent = nullptr);
57+
explicit PolkitAgent(QObject* parent = nullptr) : QObject(parent) {};
5858
~PolkitAgent() override;
5959

6060
void classBegin() override {};

0 commit comments

Comments
 (0)