fix: hide not given stats
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user