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>
79 lines
2.0 KiB
QML
79 lines
2.0 KiB
QML
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Io
|
|
import Quickshell.Services.UPower
|
|
import "BatteryModel.js" as BatteryModel
|
|
|
|
Item {
|
|
id: root
|
|
|
|
property var shell: null
|
|
property string omarchyPath: Quickshell.env("OMARCHY_PATH")
|
|
|
|
readonly property int batteryThreshold: 10
|
|
property string pendingPowerSource: ""
|
|
|
|
PersistentProperties {
|
|
id: persisted
|
|
reloadableId: "omarchy-battery"
|
|
property bool notifiedLowBattery: false
|
|
}
|
|
|
|
function batteryPercentage() {
|
|
return BatteryModel.batteryPercentage(UPower.displayDevice)
|
|
}
|
|
|
|
function isDischarging() {
|
|
return BatteryModel.isDischarging(UPower.displayDevice, UPower.onBattery, UPowerDeviceState.Discharging)
|
|
}
|
|
|
|
function checkBattery() {
|
|
var state = BatteryModel.shouldWarnLowBattery(UPower.displayDevice, UPower.onBattery, UPowerDeviceState.Discharging, batteryThreshold, persisted.notifiedLowBattery)
|
|
persisted.notifiedLowBattery = state.notifiedLowBattery
|
|
if (state.notify) sendLowBatteryWarning(state.level)
|
|
}
|
|
|
|
function sendLowBatteryWarning(level) {
|
|
if (warningProcess.running) return
|
|
warningProcess.command = [
|
|
"omarchy-battery-low",
|
|
String(level)
|
|
]
|
|
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
|
|
repeat: true
|
|
triggeredOnStart: true
|
|
onTriggered: root.checkBattery()
|
|
}
|
|
|
|
Connections {
|
|
target: UPower
|
|
function onOnBatteryChanged() {
|
|
root.checkBattery()
|
|
root.applyPowerProfile()
|
|
}
|
|
}
|
|
}
|