feat: refactor battery and network state to use file history and save logic

This commit is contained in:
Hannes
2026-09-02 16:03:45 +02:00
parent 0fad9baa5b
commit 31378f9769
4 changed files with 169 additions and 38 deletions
+23 -17
View File
@@ -1,6 +1,5 @@
import QtQuick
import Quickshell
import Quickshell.Hyprland
import "../../../config"
import "../states/Battery"
@@ -13,7 +12,7 @@ MouseArea {
visible: BatteryState.available
property bool expanded: false
Rectangle {
anchors.fill: parent
color: batteryButton.containsMouse ? Colors.tertiary : Qt.alpha(Colors.tertiaryContainer, 0.25)
@@ -24,7 +23,7 @@ MouseArea {
Text {
id: batteryText
visible : !expanded
visible : !batteryButton.expanded
anchors.centerIn: parent
text:(
BatteryState.percentage >= 90 ? "" :
@@ -37,7 +36,7 @@ MouseArea {
font.family: Config.font
color: (
BatteryState.charging ? (
BatteryState.full ? Colors.secondary :
BatteryState.full ? Colors.secondary :
Colors.tertiary
) :
BatteryState.percentage <= 5 ? Colors.errorContainer :
@@ -49,7 +48,7 @@ MouseArea {
Text {
id: chargeIcon
visible : !expanded && BatteryState.charging
visible : !batteryButton.expanded && BatteryState.charging
anchors.centerIn: parent
text: "󱐋"
font.pixelSize: Config.iconSize(batteryButton.height)
@@ -61,7 +60,7 @@ MouseArea {
Row {
id: expandedRow
visible: expanded
visible: batteryButton.expanded
anchors.centerIn: parent
spacing: Config.bar_spacing_fun(batteryButton.height)
@@ -89,7 +88,7 @@ MouseArea {
color: (
BatteryState.percentage <= 5 ? Colors.errorContainer :
BatteryState.charging ? (
BatteryState.full ? Colors.secondary :
BatteryState.full ? Colors.secondary :
Colors.tertiary
) :
BatteryState.percentage < 10 ? "yellow" :
@@ -100,7 +99,7 @@ MouseArea {
Text {
id: batteryPercentageText
text: BatteryState.percentage + "%"
text: Math.round(BatteryState.percentage) + "%"
font.pixelSize: Config.labelSize(batteryButton.height)
font.family: Config.font
@@ -125,9 +124,9 @@ MouseArea {
radiusValue: Config.radius_fun(batteryButton.height)
Column {
spacing: parent.spacing
spacing: batteryPopup.spacingValue
Text {
text: "State: " + BatteryState.state
text: "State: " + BatteryState.chargeState
wrapMode: Text.WordWrap
color: Colors.primary
anchors.horizontalCenter: parent.horizontalCenter
@@ -140,7 +139,7 @@ MouseArea {
visible: BatteryState.percentageHistoryExists
Text {
text: "percentage: " + BatteryState.percentage + "%"
text: "percentage: " + Math.round(BatteryState.percentage) + "%"
color: Colors.primary
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: Config.font_size_tiny(bar.height)
@@ -160,7 +159,7 @@ MouseArea {
visible: BatteryState.energyHistoryExists
Text {
text: "energy: " + Math.round(BatteryState.energy*10)/10 + " W"
text: "energy: " + BatteryState.energy_formated + " Wh"
color: Colors.primary
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: Config.font_size_tiny(bar.height)
@@ -195,10 +194,17 @@ MouseArea {
}
}
Text {
text: (
BatteryState.hour_to_empty > 0 ? "Remaining: " + BatteryState.hour_to_empty + "h " + BatteryState.min_to_empty + "min" :
BatteryState.min_to_empty > 0 ? "Remaining: " + BatteryState.min_to_empty + "min" :
"NaN")
text: {
if (BatteryState.charging) {
if (BatteryState.hour_to_full > 0) return "Remaining: " + BatteryState.hour_to_full + "h " + BatteryState.min_to_full + "min (to full)"
if (BatteryState.min_to_full > 0) return "Remaining: " + BatteryState.min_to_full + "min (to full)"
return BatteryState.full ? "Fully charged" : "Calculating..."
} else {
if (BatteryState.hour_to_empty > 0) return "Remaining: " + BatteryState.hour_to_empty + "h " + BatteryState.min_to_empty + "min"
if (BatteryState.min_to_empty > 0) return "Remaining: " + BatteryState.min_to_empty + "min"
return "Calculating..."
}
}
wrapMode: Text.WordWrap
color: Colors.primary
anchors.horizontalCenter: parent.horizontalCenter
@@ -206,7 +212,7 @@ MouseArea {
font.family: Config.font
}
Text {
text: "Health: " + BatteryState.health + " %"
text: "Health: " + Math.round(BatteryState.health) + " %"
visible: BatteryState.healthSupported
wrapMode: Text.WordWrap
color: Colors.primary