From 0fad9baa5b0449e097c3112900383c57a6815e4b Mon Sep 17 00:00:00 2001 From: Hannes Date: Wed, 2 Sep 2026 15:08:26 +0200 Subject: [PATCH] fix: hide not given stats --- modules/bar/states/Battery/BatteryState.qml | 12 +++++++++--- modules/bar/widgets/Battery.qml | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/bar/states/Battery/BatteryState.qml b/modules/bar/states/Battery/BatteryState.qml index c02ef77..9ac8a93 100644 --- a/modules/bar/states/Battery/BatteryState.qml +++ b/modules/bar/states/Battery/BatteryState.qml @@ -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 } } diff --git a/modules/bar/widgets/Battery.qml b/modules/bar/widgets/Battery.qml index 5437a07..9df2b68 100644 --- a/modules/bar/widgets/Battery.qml +++ b/modules/bar/widgets/Battery.qml @@ -137,6 +137,7 @@ MouseArea { Column { width: parent.width spacing: 2 + visible: BatteryState.percentageHistoryExists Text { text: "percentage: " + BatteryState.percentage + "%" @@ -156,6 +157,7 @@ MouseArea { Column { width: parent.width spacing: 2 + visible: BatteryState.energyHistoryExists Text { text: "energy: " + Math.round(BatteryState.energy*10)/10 + " W" @@ -175,6 +177,8 @@ MouseArea { Column { width: parent.width spacing: 2 + visible: BatteryState.usageHistoryExists + Text { text: "Usage: " + BatteryState.energy_rate_formated + " W" color: Colors.primary