Compare commits

...

2 commits

Author SHA1 Message Date
Benjamin Palko
be0fb14eab make optional 2025-09-04 14:56:05 -04:00
Benjamin Palko
cb6080d5d8 null 2025-09-04 14:50:34 -04:00
2 changed files with 8 additions and 9 deletions

View file

@ -21,9 +21,9 @@ Switch {
}
indicator: Rectangle {
id: indicator
id: indicator
property int padding: 8
property int padding: 8
implicitWidth: 48
implicitHeight: 24
@ -51,5 +51,5 @@ Switch {
}
}
background: undefined
background: null
}

View file

@ -1,7 +1,6 @@
import qs.components
import qs.config
import qs.constants
import qs.widgets
import QtQuick
import QtQuick.Layouts
import Quickshell.Services.UPower
@ -9,7 +8,7 @@ import Quickshell.Services.UPower
StyledButton {
id: root
property UPowerDevice laptopBattery: UPower.devices.values.find(device => device.isLaptopBattery)
property bool isCritical: laptopBattery.percentage < 0.10
property bool isCritical: laptopBattery?.percentage < 0.10
contentItem: RowLayout {
spacing: 4
@ -26,16 +25,16 @@ StyledButton {
}
font.pixelSize: 16
text: {
if (root.laptopBattery.state == UPowerDeviceState.Charging) {
if (root.laptopBattery?.state == UPowerDeviceState.Charging) {
return Icons.batteryCharging;
}
if (root.isCritical) {
return Icons.batteryWarning;
}
if (root.laptopBattery.percentage < 0.33) {
if (root.laptopBattery?.percentage < 0.33) {
return Icons.batteryLow;
}
if (root.laptopBattery.percentage < 0.66) {
if (root.laptopBattery?.percentage < 0.66) {
return Icons.batteryMedium;
}
return Icons.batteryFull;
@ -53,7 +52,7 @@ StyledButton {
}
return Theme.palette.basecontent;
}
text: `${(root.laptopBattery.percentage.toFixed(2) * 100)}%`
text: `${(root.laptopBattery?.percentage.toFixed(2) * 100)}%`
}
}
visible: laptopBattery