Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0fad9baa5b | ||
|
|
f9c14c84b4 |
@@ -4,7 +4,8 @@ import Quickshell
|
|||||||
import Quickshell.Services.UPower
|
import Quickshell.Services.UPower
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
property bool available: UPower.displayDevice.isLaptopBattery
|
id: root
|
||||||
|
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"
|
||||||
@@ -18,4 +19,44 @@ Item {
|
|||||||
property real energy_rate_formated: Math.round(energy_rate*10)/10
|
property real energy_rate_formated: Math.round(energy_rate*10)/10
|
||||||
property bool healthSupported: UPower.displayDevice.healthSupported
|
property bool healthSupported: UPower.displayDevice.healthSupported
|
||||||
property real health: healthSupported ? UPower.displayDevice.healthPercentage : NaN
|
property real health: healthSupported ? UPower.displayDevice.healthPercentage : NaN
|
||||||
|
|
||||||
|
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
|
||||||
|
interval: 1000
|
||||||
|
repeat: true
|
||||||
|
running: true
|
||||||
|
onTriggered: {
|
||||||
|
var now = Date.now()
|
||||||
|
|
||||||
|
// Creating percentage History
|
||||||
|
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: 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: energy_rate_formated})
|
||||||
|
if (uHist.length > root._maxHistory) uHist.shift()
|
||||||
|
usageHistoryExists = uHist.some(item => item.value !== 0 && item.value !== undefined)
|
||||||
|
root.usageHistory = uHist
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,14 +126,6 @@ MouseArea {
|
|||||||
|
|
||||||
Column {
|
Column {
|
||||||
spacing: parent.spacing
|
spacing: parent.spacing
|
||||||
Text {
|
|
||||||
text: "percentage: " + BatteryState.percentage + "%"
|
|
||||||
wrapMode: Text.WordWrap
|
|
||||||
color: Colors.primary
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
font.pixelSize: Config.font_size_tiny(bar.height)
|
|
||||||
font.family: Config.font
|
|
||||||
}
|
|
||||||
Text {
|
Text {
|
||||||
text: "State: " + BatteryState.state
|
text: "State: " + BatteryState.state
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
@@ -142,13 +134,65 @@ MouseArea {
|
|||||||
font.pixelSize: Config.font_size_tiny(bar.height)
|
font.pixelSize: Config.font_size_tiny(bar.height)
|
||||||
font.family: Config.font
|
font.family: Config.font
|
||||||
}
|
}
|
||||||
Text {
|
Column {
|
||||||
text: "energy: " + Math.round(BatteryState.energy*10)/10 + " W"
|
width: parent.width
|
||||||
wrapMode: Text.WordWrap
|
spacing: 2
|
||||||
color: Colors.primary
|
visible: BatteryState.percentageHistoryExists
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
font.pixelSize: Config.font_size_tiny(bar.height)
|
Text {
|
||||||
font.family: Config.font
|
text: "percentage: " + BatteryState.percentage + "%"
|
||||||
|
color: Colors.primary
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
font.pixelSize: Config.font_size_tiny(bar.height)
|
||||||
|
font.family: Config.font
|
||||||
|
}
|
||||||
|
|
||||||
|
Sparkline {
|
||||||
|
values: BatteryState.percentageHistory
|
||||||
|
lineColor: Colors.primary
|
||||||
|
width: parent.width
|
||||||
|
windowMs: BatteryState._maxHistory * 1000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Column {
|
||||||
|
width: parent.width
|
||||||
|
spacing: 2
|
||||||
|
visible: BatteryState.energyHistoryExists
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: "energy: " + Math.round(BatteryState.energy*10)/10 + " W"
|
||||||
|
color: Colors.primary
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
font.pixelSize: Config.font_size_tiny(bar.height)
|
||||||
|
font.family: Config.font
|
||||||
|
}
|
||||||
|
|
||||||
|
Sparkline {
|
||||||
|
values: BatteryState.energyHistory
|
||||||
|
lineColor: Colors.primary
|
||||||
|
width: parent.width
|
||||||
|
windowMs: BatteryState._maxHistory * 1000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Column {
|
||||||
|
width: parent.width
|
||||||
|
spacing: 2
|
||||||
|
visible: BatteryState.usageHistoryExists
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: "Usage: " + BatteryState.energy_rate_formated + " W"
|
||||||
|
color: Colors.primary
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
font.pixelSize: Config.font_size_tiny(bar.height)
|
||||||
|
font.family: Config.font
|
||||||
|
}
|
||||||
|
|
||||||
|
Sparkline {
|
||||||
|
values: BatteryState.usageHistory
|
||||||
|
lineColor: Colors.primary
|
||||||
|
width: parent.width
|
||||||
|
windowMs: BatteryState._maxHistory * 1000
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Text {
|
Text {
|
||||||
text: (
|
text: (
|
||||||
@@ -161,14 +205,6 @@ MouseArea {
|
|||||||
font.pixelSize: Config.font_size_tiny(bar.height)
|
font.pixelSize: Config.font_size_tiny(bar.height)
|
||||||
font.family: Config.font
|
font.family: Config.font
|
||||||
}
|
}
|
||||||
Text {
|
|
||||||
text: "Usage: " + BatteryState.energy_rate_formated + " W"
|
|
||||||
wrapMode: Text.WordWrap
|
|
||||||
color: Colors.primary
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
font.pixelSize: Config.font_size_tiny(bar.height)
|
|
||||||
font.family: Config.font
|
|
||||||
}
|
|
||||||
Text {
|
Text {
|
||||||
text: "Health: " + BatteryState.health + " %"
|
text: "Health: " + BatteryState.health + " %"
|
||||||
visible: BatteryState.healthSupported
|
visible: BatteryState.healthSupported
|
||||||
|
|||||||
Reference in New Issue
Block a user