refaktor
This commit is contained in:
@@ -2,23 +2,18 @@ import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Hyprland
|
||||
import Quickshell.Io
|
||||
import "../../../colors"
|
||||
import "../../../config"
|
||||
import "../states/Battery"
|
||||
|
||||
MouseArea {
|
||||
id: batteryButton
|
||||
width: clicked ? Math.max(batteryPercentageText.width + parent.spacing*3, bar.height) : Math.max(batteryText.width + parent.spacing*2, bar.height)
|
||||
width: expanded ? Math.max(batteryPercentageText.width + Config.spacing_fun(height), bar.height) : Math.max(batteryText.width + Config.spacing_fun(height)*2, bar.height)
|
||||
height: bar.height
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
visible: false
|
||||
visible: BatteryState.available
|
||||
|
||||
property bool clicked: false
|
||||
|
||||
Component.onCompleted: {
|
||||
batteryAvailibleScript.running = true
|
||||
}
|
||||
property bool expanded: false
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
@@ -30,7 +25,7 @@ MouseArea {
|
||||
|
||||
Text {
|
||||
id: batteryText
|
||||
visible : !clicked
|
||||
visible : !expanded
|
||||
anchors.centerIn: parent
|
||||
text:(
|
||||
BatteryState.percentage >= 95 ? "" :
|
||||
@@ -39,10 +34,13 @@ MouseArea {
|
||||
BatteryState.percentage >= 25 ? "" :
|
||||
""
|
||||
)
|
||||
font.pixelSize: Config.big_font_size(bar.height)
|
||||
font.pixelSize: Config.font_size(batteryButton.height)
|
||||
font.family: Config.font
|
||||
color: (
|
||||
BatteryState.charging ? BatteryState.percentage == 100 ? "white" : Colors.tertiary :
|
||||
BatteryState.charging ? (
|
||||
BatteryState.percentage == 100 ? Colors.secondary :
|
||||
Colors.tertiary
|
||||
) :
|
||||
BatteryState.percentage <= 5 ? Colors.errorContainer :
|
||||
BatteryState.percentage < 10 ? "yellow" :
|
||||
batteryButton.containsMouse ? Colors.tertiary_fg :
|
||||
@@ -51,11 +49,11 @@ MouseArea {
|
||||
}
|
||||
|
||||
Text {
|
||||
id: batteryChargingText
|
||||
visible : !clicked && BatteryState.charging
|
||||
id: chargeIcon
|
||||
visible : !expanded && BatteryState.charging
|
||||
anchors.centerIn: parent
|
||||
text: ""
|
||||
font.pixelSize: Config.big_font_size(bar.height)
|
||||
font.pixelSize: Config.iconSize(batteryButton.height)
|
||||
font.family: Config.font
|
||||
style: Text.Outline
|
||||
styleColor: Qt.alpha(Colors.tertiaryContainer, 0.5)
|
||||
@@ -63,10 +61,10 @@ MouseArea {
|
||||
}
|
||||
|
||||
Row {
|
||||
id: batteryPercentageRow
|
||||
visible: clicked
|
||||
id: expandedRow
|
||||
visible: expanded
|
||||
anchors.centerIn: parent
|
||||
spacing: batteryButton.parent.spacing/2
|
||||
spacing: Config.spacing_fun(batteryButton.height)
|
||||
|
||||
Text {
|
||||
id: batteryPercentageSymbol
|
||||
@@ -85,13 +83,16 @@ MouseArea {
|
||||
""
|
||||
)
|
||||
|
||||
font.pixelSize: batteryText.font.pixelSize * 0.75
|
||||
font.family: "CodeNewRoman Nerd Font"
|
||||
font.pixelSize: Config.labelSize(batteryButton.height)
|
||||
font.family: Config.font
|
||||
font.bold: true
|
||||
|
||||
color: (
|
||||
BatteryState.percentage <= 5 ? "red" :
|
||||
BatteryState.charging ? "green" :
|
||||
BatteryState.percentage <= 5 ? Colors.errorContainer :
|
||||
BatteryState.charging ? (
|
||||
BatteryState.percentage == 100 ? Colors.secondary :
|
||||
Colors.tertiary
|
||||
) :
|
||||
BatteryState.percentage < 10 ? "yellow" :
|
||||
batteryButton.containsMouse ? Colors.tertiary_fg :
|
||||
Colors.primary
|
||||
@@ -102,8 +103,8 @@ MouseArea {
|
||||
id: batteryPercentageText
|
||||
text: BatteryState.percentage + "%"
|
||||
|
||||
font.pixelSize: batteryText.font.pixelSize * 0.75
|
||||
font.family: "CodeNewRoman Nerd Font"
|
||||
font.pixelSize: Config.labelSize(batteryButton.height)
|
||||
font.family: Config.font
|
||||
font.bold: true
|
||||
|
||||
color: batteryPercentageSymbol.color
|
||||
@@ -111,25 +112,9 @@ MouseArea {
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: batteryAvailibleScript
|
||||
command: ["sh", "-c", "upower -e | grep -q '^/org/freedesktop/UPower/devices/battery' && echo '1' || echo '0'"]
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
const hasBattery = this.text.trim() === "1"
|
||||
|
||||
batteryButton.visible = hasBattery
|
||||
if (hasBattery) {
|
||||
BatteryState.start()
|
||||
}
|
||||
|
||||
// console.log("battery available:", hasBattery)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
batteryButton.clicked = !batteryButton.clicked
|
||||
expanded = !expanded
|
||||
console.log("[Battery] Expanded: " + expanded + ", percentage: " + BatteryState.percentage + "%, charging: " + BatteryState.charging)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user