Remember power profile choices per power source across reboots

Explicit profile selections from the power panel or menu are now saved
under an ac/battery key in ~/.local/state/omarchy/powerprofiles and
reapplied on boot and on plug/unplug. Only successful, user-made
selections are persisted, so the performance/balanced defaults still
apply when nothing has been chosen.

All entry points key off the same power signal, UPower's OnBattery:
the shell reads it natively and omarchy-powerprofiles-set autodetect
queries it via busctl. This replaces the sysfs online checks, which
disagreed with the shell on desktops without power_supply entries and
lagged behind plug events on some USB-C laptops.

Plug/unplug switching moves from the udev rule into the shell's battery
service, which already receives UPower's debounced state changes, so
the udev rule and its settle-sleep workaround are gone.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
David Heinemeier Hansson
2026-07-19 09:33:23 -07:00
co-authored by Claude Fable 5
parent 6ba0e9c234
commit 0f2f3f11cb
7 changed files with 159 additions and 45 deletions
+1 -1
View File
@@ -228,7 +228,7 @@ Item {
"power-profiles": {
script: "current=$(powerprofilesctl get 2>/dev/null); omarchy-powerprofiles-list 2>/dev/null | while read -r p; do [[ -z $p ]] && continue; printf '%s\\t%s\\t%s\\n' \"$p\" \"$p\" \"$current\"; done",
icon: "\udb81\udc0b",
actionFor: function(value) { return "powerprofilesctl set '" + value.replace(/'/g, "'\\''") + "'" },
actionFor: function(value) { return "omarchy-powerprofiles-set autodetect '" + value.replace(/'/g, "'\\''") + "'" },
keywordsFor: function(value) { return value + " power profile" }
}
})
+1 -1
View File
@@ -157,7 +157,7 @@ Panel {
function setProfile(profile) {
if (!profile || actionProc.running) return
actionProc.command = ["powerprofilesctl", "set", profile]
actionProc.command = ["omarchy-powerprofiles-set", root.discharging ? "battery" : "ac", profile]
actionProc.running = true
}
+21 -1
View File
@@ -11,6 +11,7 @@ Item {
property string omarchyPath: Quickshell.env("OMARCHY_PATH")
readonly property int batteryThreshold: 10
property string pendingPowerSource: ""
PersistentProperties {
id: persisted
@@ -41,8 +42,24 @@ Item {
warningProcess.running = true
}
function applyPowerProfile() {
pendingPowerSource = UPower.onBattery ? "battery" : "ac"
if (!powerProfileProcess.running) runPendingPowerProfile()
}
function runPendingPowerProfile() {
powerProfileProcess.command = ["omarchy-powerprofiles-set", pendingPowerSource]
pendingPowerSource = ""
powerProfileProcess.running = true
}
Process { id: warningProcess }
Process {
id: powerProfileProcess
onExited: if (root.pendingPowerSource !== "") root.runPendingPowerProfile()
}
Timer {
interval: 30000
running: true
@@ -53,6 +70,9 @@ Item {
Connections {
target: UPower
function onOnBatteryChanged() { root.checkBattery() }
function onOnBatteryChanged() {
root.checkBattery()
root.applyPowerProfile()
}
}
}