From 7d0f1a014c4363580889789da4ae3ac4844fd0df Mon Sep 17 00:00:00 2001 From: ivan tkachenko Date: Mon, 13 Dec 2021 23:18:06 +0300 Subject: [PATCH] [applets/batterymonitor] BatteryItem: Fix nullable property access Amends [supposedly] e9d926f6659b1968d98453e985f891087936de5f --- .../batterymonitor/package/contents/ui/BatteryItem.qml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/applets/batterymonitor/package/contents/ui/BatteryItem.qml b/applets/batterymonitor/package/contents/ui/BatteryItem.qml index 6aeab0864..38cc4df42 100644 --- a/applets/batterymonitor/package/contents/ui/BatteryItem.qml +++ b/applets/batterymonitor/package/contents/ui/BatteryItem.qml @@ -34,7 +34,7 @@ RowLayout { // State: "Discharging"|"Charging"|"FullyCharged"|etc., // Type: string, // Vendor: string, - // } + // }? property var battery // NOTE: According to the UPower spec this property is only valid for primary batteries, however @@ -150,7 +150,8 @@ RowLayout { wrapMode: Text.WordWrap } - readonly property bool remainingTimeRowVisible: batterymonitor.remainingTime > 0 + readonly property bool remainingTimeRowVisible: root.battery !== null + && batterymonitor.remainingTime > 0 && root.battery["Is Power Supply"] && ["Discharging", "Charging"].includes(root.battery.State) @@ -166,7 +167,8 @@ RowLayout { visible: details.remainingTimeRowVisible } - readonly property bool healthRowVisible: root.battery["Is Power Supply"] + readonly property bool healthRowVisible: root.battery !== null + && root.battery["Is Power Supply"] && root.battery.Capacity !== "" && typeof root.battery.Capacity === "number"