From 25f381887311879344baa359f2a9115652b732c8 Mon Sep 17 00:00:00 2001 From: Oded Arbel Date: Thu, 17 Jun 2021 10:07:42 +0000 Subject: [PATCH 1/2] Don't try to read properties of undefined objects See https://bugs.kde.org/show_bug.cgi?id=438478 (cherry picked from commit cfbb1995ebd33ec3c49727b62713c81c3c7526d8) --- applets/devicenotifier/package/contents/ui/DeviceItem.qml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/applets/devicenotifier/package/contents/ui/DeviceItem.qml b/applets/devicenotifier/package/contents/ui/DeviceItem.qml index a35856693..522ef3bac 100644 --- a/applets/devicenotifier/package/contents/ui/DeviceItem.qml +++ b/applets/devicenotifier/package/contents/ui/DeviceItem.qml @@ -44,7 +44,7 @@ PlasmaExtras.ExpandableListItem { readonly property double totalSpace: sdSource.data[udi] && sdSource.data[udi]["Size"] ? sdSource.data[udi]["Size"] : -1.0 property bool freeSpaceKnown: freeSpace > 0 && totalSpace > 0 - readonly property bool isRootVolume: sdSource.data[udi]["File Path"] ? sdSource.data[udi]["File Path"] == "/" : false + readonly property bool isRootVolume: (sdSource.data[udi] != undefined && sdSource.data[udi]["File Path"]) ? sdSource.data[udi]["File Path"] == "/" : false onOperationResultChanged: { if (!popupIconTimer.running) { @@ -196,7 +196,7 @@ PlasmaExtras.ExpandableListItem { defaultActionButtonAction: QQC2.Action { icon.name: { - if (!sdSource.data[udi].Removable) { + if (!(sdSource.data[udi] != undefined && sdSource.data[udi].Removable)) { return "document-open-folder" } else { return isMounted ? "media-eject" : "document-open-folder" @@ -204,7 +204,7 @@ PlasmaExtras.ExpandableListItem { } text: { // It's possible for the root volume to be on a removable disk - if (!sdSource.data[udi].Removable || deviceItem.isRootVolume) { + if (!(sdSource.data[udi] != undefined && sdSource.data[udi].Removable) || deviceItem.isRootVolume) { return i18n("Open in File Manager") } else { var types = model["Device Types"]; @@ -257,7 +257,7 @@ PlasmaExtras.ExpandableListItem { icon.name: "media-mount" // Only show for unmounted removable devices - enabled: sdSource.data[udi].Removable && !deviceItem.isMounted + enabled: (sdSource.data[udi] != undefined && sdSource.data[udi].Removable) && !deviceItem.isMounted onTriggered: { var service = sdSource.serviceForSource(udi); -- 2.33.0 From df93da9ca18bd2f2b08580de8e4edff604774abd Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Fri, 3 Sep 2021 19:23:20 +0200 Subject: [PATCH 2/2] Add isRemovable property and rework undefined checks on sdSource.data[udi] (cherry picked from commit 89c719113193a29bd608163a6f4d81e23e2a5513) --- .../package/contents/ui/DeviceItem.qml | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/applets/devicenotifier/package/contents/ui/DeviceItem.qml b/applets/devicenotifier/package/contents/ui/DeviceItem.qml index 522ef3bac..647bff95c 100644 --- a/applets/devicenotifier/package/contents/ui/DeviceItem.qml +++ b/applets/devicenotifier/package/contents/ui/DeviceItem.qml @@ -44,7 +44,8 @@ PlasmaExtras.ExpandableListItem { readonly property double totalSpace: sdSource.data[udi] && sdSource.data[udi]["Size"] ? sdSource.data[udi]["Size"] : -1.0 property bool freeSpaceKnown: freeSpace > 0 && totalSpace > 0 - readonly property bool isRootVolume: (sdSource.data[udi] != undefined && sdSource.data[udi]["File Path"]) ? sdSource.data[udi]["File Path"] == "/" : false + readonly property bool isRootVolume: sdSource.data[udi] && sdSource.data[udi]["File Path"] ? sdSource.data[udi]["File Path"] == "/" : false + readonly property bool isRemovable: sdSource.data[udi] && sdSource.data[udi]["Removable"] ? sdSource.data[udi]["Removable"] : false onOperationResultChanged: { if (!popupIconTimer.running) { @@ -123,7 +124,7 @@ PlasmaExtras.ExpandableListItem { var operationName var operation var wasMounted = isMounted; - if (!sdSource.data[udi].Removable || !isMounted) { + if (!isRemovable || !isMounted) { service = hpSource.serviceForSource(udi); operation = service.operationDescription('invokeAction'); operation.predicate = "test-predicate-openinwindow.desktop"; @@ -140,26 +141,23 @@ PlasmaExtras.ExpandableListItem { // When there's no better icon available, show a placeholder icon instead // of nothing - icon: sdSource.data[udi] == undefined ? "device-notifier" : sdSource.data[udi].Icon + icon: sdSource.data[udi] ? sdSource.data[udi].Icon : "device-notifier" iconEmblem: { - if (sdSource.data[udi] != undefined) { - if (deviceItem.hasMessage) { - if (deviceItem.message.solidError === 0) { - return "emblem-information" - } else { - return "emblem-error" - } - } else if (deviceItem.state == 0 && Emblems && Emblems[0]) { - return Emblems[0] + if (deviceItem.hasMessage) { + if (deviceItem.message.solidError === 0) { + return "emblem-information" } else { - return "" + return "emblem-error" } + } else if (deviceItem.state == 0 && Emblems && Emblems[0]) { + return Emblems[0] + } else { + return "" } - return "" } - title: sdSource.data[udi] == undefined ? "" : sdSource.data[udi].Description + title: sdSource.data[udi] ? sdSource.data[udi].Description : "" subtitle: { if (deviceItem.hasMessage) { @@ -196,15 +194,15 @@ PlasmaExtras.ExpandableListItem { defaultActionButtonAction: QQC2.Action { icon.name: { - if (!(sdSource.data[udi] != undefined && sdSource.data[udi].Removable)) { - return "document-open-folder" - } else { + if (isRemovable) { return isMounted ? "media-eject" : "document-open-folder" + } else { + return "document-open-folder" } } text: { // It's possible for the root volume to be on a removable disk - if (!(sdSource.data[udi] != undefined && sdSource.data[udi].Removable) || deviceItem.isRootVolume) { + if (!isRemovable || isRootVolume) { return i18n("Open in File Manager") } else { var types = model["Device Types"]; @@ -236,7 +234,7 @@ PlasmaExtras.ExpandableListItem { if (modelData.predicate != "test-predicate-openinwindow.desktop") { return true; } - return sdSource.data[udi].Removable && deviceItem.isMounted; + return deviceItem.isRemovable && deviceItem.isMounted; } onTriggered: { var service = hpSource.serviceForSource(udi); @@ -257,7 +255,7 @@ PlasmaExtras.ExpandableListItem { icon.name: "media-mount" // Only show for unmounted removable devices - enabled: (sdSource.data[udi] != undefined && sdSource.data[udi].Removable) && !deviceItem.isMounted + enabled: deviceItem.isRemovable && !deviceItem.isMounted onTriggered: { var service = sdSource.serviceForSource(udi); -- 2.33.0