Pull low battery warning into shell
This commit is contained in:
@@ -19,6 +19,7 @@ User-installed plugins live alongside these conceptually but on disk under
|
||||
| Clipboard mgr | `omarchy.clipboard-picker`| `overlay` | `clipboard-picker/ClipboardPicker.qml`|
|
||||
| Omarchy menu | `omarchy.menu` | `menu` | `menu/Menu.qml` |
|
||||
| Notifications | `omarchy.notifications` | `service` | `notifications/Service.qml` |
|
||||
| Battery mon. | `omarchy.battery-monitor` | `service` | `battery-monitor/Service.qml` |
|
||||
| Idle monitor | `omarchy.idle` | `service` | `idle/Service.qml` |
|
||||
| Lock screen | `omarchy.lock` | `service` | `lock/Service.qml` |
|
||||
| OSD | `omarchy.osd` | `panel` | `osd/Osd.qml` |
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Quickshell.Services.UPower
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property var shell: null
|
||||
property string omarchyPath: Quickshell.env("OMARCHY_PATH")
|
||||
|
||||
readonly property int batteryThreshold: 10
|
||||
|
||||
PersistentProperties {
|
||||
id: persisted
|
||||
reloadableId: "omarchy-battery-monitor"
|
||||
property bool notifiedLowBattery: false
|
||||
}
|
||||
|
||||
function batteryPercentage() {
|
||||
var device = UPower.displayDevice
|
||||
if (!device || !device.isPresent) return -1
|
||||
return Math.round(Number(device.percentage || 0) * 100)
|
||||
}
|
||||
|
||||
function isDischarging() {
|
||||
var device = UPower.displayDevice
|
||||
return !!(device && device.isPresent
|
||||
&& UPower.onBattery
|
||||
&& device.state === UPowerDeviceState.Discharging)
|
||||
}
|
||||
|
||||
function checkBattery() {
|
||||
var level = batteryPercentage()
|
||||
if (level < 0) {
|
||||
persisted.notifiedLowBattery = false
|
||||
return
|
||||
}
|
||||
|
||||
if (isDischarging() && level <= batteryThreshold) {
|
||||
if (!persisted.notifiedLowBattery) {
|
||||
persisted.notifiedLowBattery = true
|
||||
sendLowBatteryWarning(level)
|
||||
}
|
||||
} else {
|
||||
persisted.notifiedLowBattery = false
|
||||
}
|
||||
}
|
||||
|
||||
function sendLowBatteryWarning(level) {
|
||||
if (warningProcess.running) return
|
||||
warningProcess.command = [
|
||||
"omarchy-battery-low",
|
||||
String(level)
|
||||
]
|
||||
warningProcess.running = true
|
||||
}
|
||||
|
||||
Process { id: warningProcess }
|
||||
|
||||
Timer {
|
||||
interval: 30000
|
||||
running: true
|
||||
repeat: true
|
||||
triggeredOnStart: true
|
||||
onTriggered: root.checkBattery()
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: UPower
|
||||
function onOnBatteryChanged() { root.checkBattery() }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "omarchy.battery-monitor",
|
||||
"name": "Battery Monitor",
|
||||
"version": "1.0.0",
|
||||
"author": "Omarchy",
|
||||
"description": "Low battery warning service",
|
||||
"kinds": [
|
||||
"service"
|
||||
],
|
||||
"entryPoints": {
|
||||
"service": "Service.qml"
|
||||
}
|
||||
}
|
||||
@@ -108,11 +108,10 @@ Item {
|
||||
// - omarchy-action: a user-action confirmation toast ("Theme changed",
|
||||
// "Screenshot saved"). The user JUST did something — their feedback
|
||||
// should show.
|
||||
// - urgency=critical AND app_name=notify-send: bare-CLI emergency alerts
|
||||
// (omarchy-battery-monitor uses this for low-battery; a few scripts
|
||||
// use it for emergency failures). Trusted because it's almost always
|
||||
// omarchy or system shell scripts — chat apps set app_name to
|
||||
// their brand (Discord/Slack/Vesktop) which falls outside this rule.
|
||||
// - urgency=critical AND app_name=notify-send: bare-CLI emergency alerts.
|
||||
// Trusted because it's almost always omarchy or system shell scripts —
|
||||
// chat apps set app_name to their brand (Discord/Slack/Vesktop), which
|
||||
// falls outside this rule.
|
||||
function shouldBypassDnd(notification) {
|
||||
var appName = String(notification.appName || "")
|
||||
if (appName === "omarchy-action") return true
|
||||
|
||||
Reference in New Issue
Block a user