diff --git a/Plugins/ZShell/lidwatcher.cpp b/Plugins/ZShell/lidwatcher.cpp index 212209c..7a6105f 100644 --- a/Plugins/ZShell/lidwatcher.cpp +++ b/Plugins/ZShell/lidwatcher.cpp @@ -1,6 +1,7 @@ #include "lidwatcher.hpp" #include +#include #include #include #include @@ -56,8 +57,34 @@ LidWatcher::LidState LidWatcher::state() const { void LidWatcher::tryConnect() { QDBusConnection bus = QDBusConnection::systemBus(); + const auto iface = bus.interface(); + if (!iface) { + queryLidState(); + if (!m_available) { + m_available = true; + emit availableChanged(); + } + if (!m_pollTimer->isActive()) { + m_pollTimer->start(); +} + return; + } + const auto reply = iface->isServiceRegistered(kLogin1Service); + if (!reply.isValid() || !reply.value()) { + queryLidState(); + qCInfo(lcLidWatcher) << "login1 not available, polling"; + if (!m_available) { + m_available = true; + emit availableChanged(); + } + if (!m_pollTimer->isActive()) { + m_pollTimer->start(); +} + return; + } + const auto connected = bus.connect( - QString(), + kLogin1Service, kLogin1Path, kDBusPropertiesInterface, "PropertiesChanged",