diff --git a/quickshell/Services/PowerProfileWatcher.qml b/quickshell/Services/PowerProfileWatcher.qml index 9d5efe50e..58b786cd7 100644 --- a/quickshell/Services/PowerProfileWatcher.qml +++ b/quickshell/Services/PowerProfileWatcher.qml @@ -4,14 +4,27 @@ pragma ComponentBehavior: Bound import QtQuick import Quickshell import Quickshell.Services.UPower +import qs.Services Singleton { id: root property int currentProfile: -1 property int previousProfile: -1 + property bool daemonRunning: true - readonly property bool available: typeof PowerProfiles !== "undefined" + readonly property bool available: typeof PowerProfiles !== "undefined" && daemonRunning + + function checkDaemon() { + if (!DMSService.isConnected || !DMSService.capabilities.includes("dbus")) + return; + + DMSService.dbusCall("system", "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameHasOwner", ["org.freedesktop.UPower.PowerProfiles"], response => { + if (response.error || !response.result) + return; + root.daemonRunning = response.result.values?.[0] === true; + }); + } readonly property var availableProfiles: { if (!available) @@ -78,6 +91,7 @@ Singleton { function onProfileChanged() { if (typeof PowerProfiles !== "undefined") { + root.daemonRunning = true; root.previousProfile = root.currentProfile; root.currentProfile = PowerProfiles.profile; if (root.previousProfile !== -1) { @@ -87,6 +101,14 @@ Singleton { } } + Connections { + target: DMSService + + function onCapabilitiesReceived() { + root.checkDaemon(); + } + } + Component.onCompleted: { if (typeof PowerProfiles !== "undefined") { root.currentProfile = PowerProfiles.profile;