From e714ed59ac82592ea7ad89ad46acd8da7c44fa56 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 16 Oct 2024 14:51:58 +0100 Subject: [PATCH] core: avoid crashes lol --- src/SigDaemon.hpp | 3 ++- src/core/Agent.cpp | 17 +++++++++++------ src/core/Agent.hpp | 6 +++--- src/core/PolkitListener.cpp | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/SigDaemon.hpp b/src/SigDaemon.hpp index 5b7efde..19c14a5 100644 --- a/src/SigDaemon.hpp +++ b/src/SigDaemon.hpp @@ -5,7 +5,8 @@ #include class CSigDaemon : public QObject { - Q_OBJECT; + Q_OBJECT; + public: CSigDaemon(QObject* parent = nullptr); diff --git a/src/core/Agent.cpp b/src/core/Agent.cpp index a5506c1..1a95555 100644 --- a/src/core/Agent.cpp +++ b/src/core/Agent.cpp @@ -37,8 +37,14 @@ bool CAgent::start() { void CAgent::resetAuthState() { if (authState.authing) { authState.authing = false; - authState.qmlEngine.reset(); - authState.qmlIntegration.reset(); + + if (authState.qmlEngine) + authState.qmlEngine->deleteLater(); + if (authState.qmlIntegration) + authState.qmlIntegration->deleteLater(); + + authState.qmlEngine = nullptr; + authState.qmlIntegration = nullptr; } } @@ -52,16 +58,15 @@ void CAgent::initAuthPrompt() { std::print("Spawning qml prompt\n"); - authState.qmlEngine.reset(); authState.authing = true; - authState.qmlIntegration = makeShared(); + authState.qmlIntegration = new CQMLIntegration(); if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) QQuickStyle::setStyle("org.kde.desktop"); - authState.qmlEngine = makeShared(); - authState.qmlEngine->rootContext()->setContextProperty("hpa", authState.qmlIntegration.get()); + authState.qmlEngine = new QQmlApplicationEngine(); + authState.qmlEngine->rootContext()->setContextProperty("hpa", authState.qmlIntegration); authState.qmlEngine->load(QUrl{u"qrc:/qt/qml/hpa/qml/main.qml"_qs}); authState.qmlIntegration->focusField(); diff --git a/src/core/Agent.hpp b/src/core/Agent.hpp index fb7984c..dfe5a40 100644 --- a/src/core/Agent.hpp +++ b/src/core/Agent.hpp @@ -30,9 +30,9 @@ class CAgent { private: struct { - bool authing = false; - SP qmlEngine; - SP qmlIntegration; + bool authing = false; + QQmlApplicationEngine* qmlEngine = nullptr; + CQMLIntegration* qmlIntegration = nullptr; } authState; struct { diff --git a/src/core/PolkitListener.cpp b/src/core/PolkitListener.cpp index 8138db5..8fd9613 100644 --- a/src/core/PolkitListener.cpp +++ b/src/core/PolkitListener.cpp @@ -14,7 +14,7 @@ CPolkitListener::CPolkitListener(QObject* parent) : Listener(parent) { } void CPolkitListener::initiateAuthentication(const QString& actionId, const QString& message, const QString& iconName, const PolkitQt1::Details& details, const QString& cookie, - const PolkitQt1::Identity::List& identities, AsyncResult* result) { + const PolkitQt1::Identity::List& identities, AsyncResult* result) { std::print("> New authentication session\n");