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
|
|
@ -1,71 +1,29 @@
|
|||
import QtQuick
|
||||
import Quickshell.Io
|
||||
import "." as M
|
||||
|
||||
M.BarIcon {
|
||||
id: root
|
||||
tooltip: "Power profile: " + (root.profile || "unknown")
|
||||
tooltip: "Power profile: " + (M.PowerProfileService.profile || "unknown")
|
||||
|
||||
property string profile: ""
|
||||
|
||||
color: root.profile === "performance" ? M.Theme.base09 : root.profile === "power-saver" ? M.Theme.base0B : parent?.accentColor ?? M.Theme.base05
|
||||
color: M.PowerProfileService.profile === "performance" ? M.Theme.base09 : M.PowerProfileService.profile === "power-saver" ? M.Theme.base0B : parent?.accentColor ?? M.Theme.base05
|
||||
|
||||
icon: {
|
||||
if (root.profile === "performance")
|
||||
if (M.PowerProfileService.profile === "performance")
|
||||
return "\uF0E7";
|
||||
if (root.profile === "power-saver")
|
||||
if (M.PowerProfileService.profile === "power-saver")
|
||||
return "\uF06C";
|
||||
if (root.profile === "balanced")
|
||||
if (M.PowerProfileService.profile === "balanced")
|
||||
return "\uF24E";
|
||||
return "\uF0E7";
|
||||
}
|
||||
|
||||
Process {
|
||||
id: proc
|
||||
running: true
|
||||
command: ["powerprofilesctl", "get"]
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: root.profile = text.trim()
|
||||
}
|
||||
}
|
||||
// Event-driven: watch power-profiles-daemon DBus changes
|
||||
Process {
|
||||
id: ppMonitor
|
||||
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()
|
||||
}
|
||||
}
|
||||
Timer {
|
||||
id: _debounce
|
||||
interval: 300
|
||||
onTriggered: proc.running = true
|
||||
}
|
||||
Timer {
|
||||
interval: 60000
|
||||
running: true
|
||||
repeat: true
|
||||
onTriggered: proc.running = true
|
||||
}
|
||||
|
||||
Process {
|
||||
id: setter
|
||||
property string next: ""
|
||||
command: ["powerprofilesctl", "set", next]
|
||||
onRunningChanged: if (!running && next !== "")
|
||||
proc.running = true
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
const cycle = ["performance", "balanced", "power-saver"];
|
||||
const idx = cycle.indexOf(root.profile);
|
||||
setter.next = cycle[(idx + 1) % cycle.length];
|
||||
setter.running = true;
|
||||
const idx = cycle.indexOf(M.PowerProfileService.profile);
|
||||
M.PowerProfileService.set(cycle[(idx + 1) % cycle.length]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue