fix: hide not given stats
This commit is contained in:
@@ -5,7 +5,7 @@ import Quickshell.Services.UPower
|
|||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
property bool available: UPower.displayDevice.isLaptopBattery
|
property bool available: UPower.displayDevice.isPresent
|
||||||
property real percentage: UPower.displayDevice.percentage*100
|
property real percentage: UPower.displayDevice.percentage*100
|
||||||
property string state: UPowerDeviceState.toString(UPower.displayDevice.state)
|
property string state: UPowerDeviceState.toString(UPower.displayDevice.state)
|
||||||
property bool charging: state == "Charging"
|
property bool charging: state == "Charging"
|
||||||
@@ -23,8 +23,11 @@ Item {
|
|||||||
property int _maxHistory: 60*60
|
property int _maxHistory: 60*60
|
||||||
|
|
||||||
property var percentageHistory: [{time: Date.now() - _maxHistory*1000, value: 0}, {time: Date.now(), value: 0}]
|
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 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 usageHistory: [{time: Date.now() - _maxHistory*1000, value: 0}, {time: Date.now(), value: 0}]
|
||||||
|
property var usageHistoryExists: true
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: statsTimer
|
id: statsTimer
|
||||||
@@ -38,18 +41,21 @@ Item {
|
|||||||
var pHist = root.percentageHistory
|
var pHist = root.percentageHistory
|
||||||
pHist.push({time: now, value: percentage})
|
pHist.push({time: now, value: percentage})
|
||||||
if (pHist.length > root._maxHistory) pHist.shift()
|
if (pHist.length > root._maxHistory) pHist.shift()
|
||||||
|
percentageHistoryExists = pHist.some(item => item.value !== 0 && item.value !== undefined)
|
||||||
root.percentageHistory = pHist
|
root.percentageHistory = pHist
|
||||||
|
|
||||||
// Creating percentage History
|
// Creating percentage History
|
||||||
var eHist = root.energyHistory
|
var eHist = root.energyHistory
|
||||||
eHist.push({time: now, value: percentage})
|
eHist.push({time: now, value: energy_formated})
|
||||||
if (eHist.length > root._maxHistory) eHist.shift()
|
if (eHist.length > root._maxHistory) eHist.shift()
|
||||||
|
energyHistoryExists = eHist.some(item => item.value !== 0 && item.value !== undefined)
|
||||||
root.energyHistory = eHist
|
root.energyHistory = eHist
|
||||||
|
|
||||||
// Creating percentage History
|
// Creating percentage History
|
||||||
var uHist = root.usageHistory
|
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()
|
if (uHist.length > root._maxHistory) uHist.shift()
|
||||||
|
usageHistoryExists = uHist.some(item => item.value !== 0 && item.value !== undefined)
|
||||||
root.usageHistory = uHist
|
root.usageHistory = uHist
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,6 +137,7 @@ MouseArea {
|
|||||||
Column {
|
Column {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
spacing: 2
|
spacing: 2
|
||||||
|
visible: BatteryState.percentageHistoryExists
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: "percentage: " + BatteryState.percentage + "%"
|
text: "percentage: " + BatteryState.percentage + "%"
|
||||||
@@ -156,6 +157,7 @@ MouseArea {
|
|||||||
Column {
|
Column {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
spacing: 2
|
spacing: 2
|
||||||
|
visible: BatteryState.energyHistoryExists
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: "energy: " + Math.round(BatteryState.energy*10)/10 + " W"
|
text: "energy: " + Math.round(BatteryState.energy*10)/10 + " W"
|
||||||
@@ -175,6 +177,8 @@ MouseArea {
|
|||||||
Column {
|
Column {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
spacing: 2
|
spacing: 2
|
||||||
|
visible: BatteryState.usageHistoryExists
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: "Usage: " + BatteryState.energy_rate_formated + " W"
|
text: "Usage: " + BatteryState.energy_rate_formated + " W"
|
||||||
color: Colors.primary
|
color: Colors.primary
|
||||||
|
|||||||
Reference in New Issue
Block a user