refactor: extract PowerProfileService singleton; reducedMotion auto-enables on power-saver profile
This commit is contained in:
parent
c96b023fbe
commit
dd5ca9d263
4 changed files with 63 additions and 51 deletions
52
modules/PowerProfileService.qml
Normal file
52
modules/PowerProfileService.qml
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
pragma Singleton
|
||||
|
||||
import QtQuick
|
||||
import Quickshell.Io
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
|
||||
property string profile: ""
|
||||
readonly property bool powerSaver: profile === "power-saver"
|
||||
|
||||
property var _proc: Process {
|
||||
running: true
|
||||
command: ["powerprofilesctl", "get"]
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: root.profile = text.trim()
|
||||
}
|
||||
}
|
||||
|
||||
property var _monitor: Process {
|
||||
running: true
|
||||
command: ["sh", "-c", "dbus-monitor --system \"interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',path='/net/hadess/PowerProfiles'\" 2>/dev/null"]
|
||||
stdout: SplitParser {
|
||||
splitMarker: "\n"
|
||||
onRead: _debounce.restart()
|
||||
}
|
||||
}
|
||||
|
||||
property var _debounce: Timer {
|
||||
interval: 300
|
||||
onTriggered: root._proc.running = true
|
||||
}
|
||||
|
||||
property var _poll: Timer {
|
||||
interval: 60000
|
||||
running: true
|
||||
repeat: true
|
||||
onTriggered: root._proc.running = true
|
||||
}
|
||||
|
||||
function set(p) {
|
||||
_setter.next = p;
|
||||
_setter.running = true;
|
||||
}
|
||||
|
||||
property var _setter: Process {
|
||||
property string next: ""
|
||||
command: ["powerprofilesctl", "set", next]
|
||||
onRunningChanged: if (!running && next !== "")
|
||||
root._proc.running = true
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue