瀏覽代碼

another fix for startup crash

Malte Veerman 10 年之前
父節點
當前提交
9895b8e573
共有 2 個文件被更改,包括 24 次插入20 次删除
  1. 23 19
      fancontrol-gui/src/systemdcommunicator.cpp
  2. 1 1
      helper/CMakeLists.txt

+ 23 - 19
fancontrol-gui/src/systemdcommunicator.cpp

@@ -31,7 +31,6 @@ using namespace KAuth;
 
 SystemdCommunicator::SystemdCommunicator(QObject *parent) : QObject(parent)
 {
-    m_serviceName = "fancontrol";
     m_serviceInterface = nullptr;
     m_error = "Success";
 
@@ -40,7 +39,7 @@ SystemdCommunicator::SystemdCommunicator(QObject *parent) : QObject(parent)
                                             "org.freedesktop.systemd1.Manager",
                                             QDBusConnection::systemBus(),
                                             this);
-    serviceExists();
+    setServiceName("fancontrol");
 }
 
 void SystemdCommunicator::setServiceName(const QString &name)
@@ -50,26 +49,31 @@ void SystemdCommunicator::setServiceName(const QString &name)
         m_serviceName = name;
         emit serviceNameChanged();
 
-        if (m_serviceInterface)
-            m_serviceInterface->deleteLater();
+        if (serviceExists())
+        {
+            QList<QVariant> arguments;
+            arguments << QVariant(m_serviceName + ".service");
+            QDBusMessage dbusreply = m_managerInterface->callWithArgumentList(QDBus::AutoDetect, "LoadUnit", arguments);
+            if (dbusreply.type() == QDBusMessage::ErrorMessage)
+            {
+                m_error = dbusreply.errorMessage();
+                emit errorChanged();
+                m_servicePath.clear();
+            }
+            else
+            {
+                m_servicePath = qdbus_cast<QDBusObjectPath>(dbusreply.arguments().first()).path();
 
-        m_serviceInterface = new QDBusInterface("org.freedesktop.systemd1",
-                                                m_servicePath,
-                                                "org.freedesktop.systemd1.Unit",
-                                                QDBusConnection::systemBus(),
-                                                this);
+                if (m_serviceInterface)
+                    m_serviceInterface->deleteLater();
 
-        QList<QVariant> arguments;
-        arguments << QVariant(m_serviceName + ".service");
-        QDBusMessage dbusreply = m_managerInterface->callWithArgumentList(QDBus::AutoDetect, "LoadUnit", arguments);
-        if (dbusreply.type() == QDBusMessage::ErrorMessage)
-        {
-            m_error = dbusreply.errorMessage();
-            emit errorChanged();
-            m_servicePath.clear();
+                m_serviceInterface = new QDBusInterface("org.freedesktop.systemd1",
+                                                        m_servicePath,
+                                                        "org.freedesktop.systemd1.Unit",
+                                                        QDBusConnection::systemBus(),
+                                                        this);
+            }
         }
-        else
-            m_servicePath = qdbus_cast<QDBusObjectPath>(dbusreply.arguments().first()).path();
     }
 }
 

+ 1 - 1
helper/CMakeLists.txt

@@ -1,4 +1,4 @@
-kauth_install_helper_files(Fancontrol-GUIHelper fancontrol.gui.helper root)
+kauth_install_helper_files(fancontrol-gui-helper fancontrol.gui.helper root)
 kauth_install_actions(fancontrol.gui.helper fancontrol-gui.actions)
 
 set(LIBRARIES KF5::Auth)