From 13dc798565a1a294fa43bbde281b96339dd0f907 Mon Sep 17 00:00:00 2001 From: Benjamin Palko Date: Thu, 4 Sep 2025 14:56:05 -0400 Subject: [PATCH] make optional --- modules/bar/components/Power.qml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/bar/components/Power.qml b/modules/bar/components/Power.qml index deb234a..a42a23c 100644 --- a/modules/bar/components/Power.qml +++ b/modules/bar/components/Power.qml @@ -1,15 +1,14 @@ import qs.components import qs.config import qs.constants -import qs.widgets import QtQuick import QtQuick.Layouts 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 UPowerDevice laptopBattery: UPower.devices.values.find(device => device.isLaptopBattery) ?? null + 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