fix: hide not given stats

This commit is contained in:
Hannes
2026-09-02 15:08:26 +02:00
parent f9c14c84b4
commit 0fad9baa5b
2 changed files with 13 additions and 3 deletions
+9 -3
View File
@@ -5,7 +5,7 @@ import Quickshell.Services.UPower
Item {
id: root
property bool available: UPower.displayDevice.isLaptopBattery
property bool available: UPower.displayDevice.isPresent
property real percentage: UPower.displayDevice.percentage*100
property string state: UPowerDeviceState.toString(UPower.displayDevice.state)
property bool charging: state == "Charging"
@@ -23,8 +23,11 @@ Item {
property int _maxHistory: 60*60
property var percentageHistory: [{time: Date.now() - _maxHistory*1000, value: 0}, {time: Date.now(), value: 0}]
property var percentageHistoryExists: true
property var energyHistory: [{time: Date.now() - _maxHistory*1000, value: 0}, {time: Date.now(), value: 0}]
property var energyHistoryExists: true
property var usageHistory: [{time: Date.now() - _maxHistory*1000, value: 0}, {time: Date.now(), value: 0}]
property var usageHistoryExists: true
Timer {
id: statsTimer
@@ -38,18 +41,21 @@ Item {
var pHist = root.percentageHistory
pHist.push({time: now, value: percentage})
if (pHist.length > root._maxHistory) pHist.shift()
percentageHistoryExists = pHist.some(item => item.value !== 0 && item.value !== undefined)
root.percentageHistory = pHist
// Creating percentage History
var eHist = root.energyHistory
eHist.push({time: now, value: percentage})
eHist.push({time: now, value: energy_formated})
if (eHist.length > root._maxHistory) eHist.shift()
energyHistoryExists = eHist.some(item => item.value !== 0 && item.value !== undefined)
root.energyHistory = eHist
// Creating percentage History
var uHist = root.usageHistory
uHist.push({time: now, value: percentage})
uHist.push({time: now, value: energy_rate_formated})
if (uHist.length > root._maxHistory) uHist.shift()
usageHistoryExists = uHist.some(item => item.value !== 0 && item.value !== undefined)
root.usageHistory = uHist
}
}