Added a small battery popup to show information

This commit is contained in:
Runze
2025-08-05 17:21:36 +08:00
parent f8d162d995
commit 3a6c032782
5 changed files with 203 additions and 3 deletions
@@ -4,6 +4,8 @@ import qs
import qs.modules.common
import Quickshell
import Quickshell.Services.UPower
import QtQuick
import Quickshell.Io
Singleton {
property bool available: UPower.displayDevice.isLaptopBattery
@@ -21,6 +23,43 @@ Singleton {
property bool isCriticalAndNotCharging: isCritical && !isCharging
property bool isSuspendingAndNotCharging: allowAutomaticSuspend && isSuspending && !isCharging
property real energyRate: UPower.displayDevice.changeRate
property real timeToEmpty: UPower.displayDevice.timeToEmpty
property real timeToFull: UPower.displayDevice.timeToFull
property real temperature: 0
Process {
id: tempProcess
command: ["bash", "-c", "cat /sys/class/thermal/thermal_zone0/temp"]
stdout: StdioCollector {
onStreamFinished: {
if (text && text.trim() !== "") {
Battery.temperature = parseInt(text.trim()) / 1000
} else {
Battery.temperature = 0
}
}
}
}
Timer {
interval: 3000
repeat: true
running: true
onTriggered: {
if (!tempProcess.running) {
tempProcess.running = true
}
}
}
Component.onCompleted: {
if (!tempProcess.running) {
tempProcess.running = true;
}
}
onIsLowAndNotChargingChanged: {
if (available && isLowAndNotCharging) Quickshell.execDetached([
"notify-send",