From 8031139aeb7f412ff3f8b9d7b1bd1d2fa16e7a2b Mon Sep 17 00:00:00 2001 From: ivan tkachenko Date: Wed, 1 Jun 2022 23:10:01 +0300 Subject: [PATCH] [applets/systemtray] Clean up QML/JavaScript code --- .../package/contents/applet/CompactApplet.qml | 10 +++--- .../package/contents/ui/HiddenItemsView.qml | 4 +-- .../contents/ui/items/AbstractItem.qml | 6 ++-- .../contents/ui/items/StatusNotifierItem.qml | 31 ++++++++-------- .../systemtray/package/contents/ui/main.qml | 36 +++++++++---------- 5 files changed, 41 insertions(+), 46 deletions(-) diff --git a/applets/systemtray/package/contents/applet/CompactApplet.qml b/applets/systemtray/package/contents/applet/CompactApplet.qml index d2e0f9b26..e6a750def 100644 --- a/applets/systemtray/package/contents/applet/CompactApplet.qml +++ b/applets/systemtray/package/contents/applet/CompactApplet.qml @@ -18,13 +18,13 @@ PlasmaCore.ToolTipArea { mainText: Plasmoid.toolTipMainText subText: Plasmoid.toolTipSubText location: if (Plasmoid.parent && Plasmoid.parent.inHiddenLayout && Plasmoid.location !== PlasmaCore.Types.LeftEdge) { - return PlasmaCore.Types.RightEdge; - } else { - return Plasmoid.location; - } + return PlasmaCore.Types.RightEdge; + } else { + return Plasmoid.location; + } active: !Plasmoid.expanded textFormat: Plasmoid.toolTipTextFormat - mainItem: Plasmoid.toolTipItem ? Plasmoid.toolTipItem : null + mainItem: Plasmoid.toolTipItem property Item fullRepresentation property Item compactRepresentation diff --git a/applets/systemtray/package/contents/ui/HiddenItemsView.qml b/applets/systemtray/package/contents/ui/HiddenItemsView.qml index ad1e5ff5e..7e913fa9e 100644 --- a/applets/systemtray/package/contents/ui/HiddenItemsView.qml +++ b/applets/systemtray/package/contents/ui/HiddenItemsView.qml @@ -71,9 +71,7 @@ PlasmaComponents3.ScrollView { model: PlasmaCore.SortFilterModel { sourceModel: Plasmoid.nativeInterface.systemTrayModel filterRole: "effectiveStatus" - filterCallback: function(source_row, value) { - return value === PlasmaCore.Types.PassiveStatus - } + filterCallback: (source_row, value) => value === PlasmaCore.Types.PassiveStatus } delegate: ItemLoader {} diff --git a/applets/systemtray/package/contents/ui/items/AbstractItem.qml b/applets/systemtray/package/contents/ui/items/AbstractItem.qml index 93ed3293e..a73cf85d6 100644 --- a/applets/systemtray/package/contents/ui/items/AbstractItem.qml +++ b/applets/systemtray/package/contents/ui/items/AbstractItem.qml @@ -64,9 +64,9 @@ PlasmaCore.ToolTipArea { PulseAnimation { targetItem: iconContainer - running: (abstractItem.status === PlasmaCore.Types.NeedsAttentionStatus || - abstractItem.status === PlasmaCore.Types.RequiresAttentionStatus ) && - PlasmaCore.Units.longDuration > 0 + running: (abstractItem.status === PlasmaCore.Types.NeedsAttentionStatus + || abstractItem.status === PlasmaCore.Types.RequiresAttentionStatus) + && PlasmaCore.Units.longDuration > 0 } function startActivatedAnimation() { diff --git a/applets/systemtray/package/contents/ui/items/StatusNotifierItem.qml b/applets/systemtray/package/contents/ui/items/StatusNotifierItem.qml index c07f0dc17..c527faa93 100644 --- a/applets/systemtray/package/contents/ui/items/StatusNotifierItem.qml +++ b/applets/systemtray/package/contents/ui/items/StatusNotifierItem.qml @@ -37,11 +37,11 @@ AbstractItem { } onActivated: { - let service = model.Service; - let operation = service.operationDescription("Activate"); + const service = model.Service; + const operation = service.operationDescription("Activate"); operation.x = pos.x; //mouseX operation.y = pos.y; //mouseY - let job = service.startOperationCall(operation); + const job = service.startOperationCall(operation); job.finished.connect(() => { if (!job.result) { // On error try to invoke the context menu. @@ -66,10 +66,9 @@ AbstractItem { openContextMenu(pos); break; case Qt.MiddleButton: - var operation = service.operationDescription("SecondaryActivate"); - let service = model.Service; + const operation = service.operationDescription("SecondaryActivate"); + const service = model.Service; operation.x = pos.x; - operation.y = pos.y; service.startOperationCall(operation); taskIcon.startActivatedAnimation() @@ -78,13 +77,13 @@ AbstractItem { } function openContextMenu(pos = Qt.point(width/2, height/2)) { - var service = model.Service; - var operation = service.operationDescription("ContextMenu"); + const service = model.Service; + const operation = service.operationDescription("ContextMenu"); operation.x = pos.x; operation.y = pos.y; - var job = service.startOperationCall(operation); - job.finished.connect(function () { + const job = service.startOperationCall(operation); + job.finished.connect(() => { Plasmoid.nativeInterface.showStatusNotifierContextMenu(job, taskIcon); }); } @@ -92,16 +91,16 @@ AbstractItem { onWheel: { //don't send activateVertScroll with a delta of 0, some clients seem to break (kmix) if (wheel.angleDelta.y !== 0) { - var service = model.Service; - var operation = service.operationDescription("Scroll"); - operation.delta =wheel.angleDelta.y; + const service = model.Service; + const operation = service.operationDescription("Scroll"); + operation.delta = wheel.angleDelta.y; operation.direction = "Vertical"; service.startOperationCall(operation); } if (wheel.angleDelta.x !== 0) { - var service = model.Service; - var operation = service.operationDescription("Scroll"); - operation.delta =wheel.angleDelta.x; + const service = model.Service; + const operation = service.operationDescription("Scroll"); + operation.delta = wheel.angleDelta.x; operation.direction = "Horizontal"; service.startOperationCall(operation); } diff --git a/applets/systemtray/package/contents/ui/main.qml b/applets/systemtray/package/contents/ui/main.qml index c5b5f0465..f7dd04aed 100644 --- a/applets/systemtray/package/contents/ui/main.qml +++ b/applets/systemtray/package/contents/ui/main.qml @@ -30,7 +30,7 @@ MouseArea { readonly property alias itemSize: tasksGrid.itemSize readonly property alias visibleLayout: tasksGrid readonly property alias hiddenLayout: expandedRepresentation.hiddenLayout - readonly property bool oneRowOrColumn: tasksGrid.rowsOrColumns == 1 + readonly property bool oneRowOrColumn: tasksGrid.rowsOrColumns === 1 onWheel: { // Don't propagate unhandled wheel events @@ -55,7 +55,7 @@ MouseArea { DnD.DropArea { anchors.fill: parent - preventStealing: true; + preventStealing: true /** Extracts the name of the system tray applet in the drag data if present * otherwise returns null*/ @@ -63,7 +63,7 @@ MouseArea { if (event.mimeData.formats.indexOf("text/x-plasmoidservicename") < 0) { return null; } - var plasmoidId = event.mimeData.getDataAsByteArray("text/x-plasmoidservicename"); + const plasmoidId = event.mimeData.getDataAsByteArray("text/x-plasmoidservicename"); if (!Plasmoid.nativeInterface.isSystemTrayApplet(plasmoidId)) { return null; @@ -78,14 +78,14 @@ MouseArea { } onDrop: { - var plasmoidId = systemTrayAppletName(event); + const plasmoidId = systemTrayAppletName(event); if (!plasmoidId) { event.ignore(); return; } if (Plasmoid.configuration.extraItems.indexOf(plasmoidId) < 0) { - var extraItems = Plasmoid.configuration.extraItems; + const extraItems = Plasmoid.configuration.extraItems; extraItems.push(plasmoidId); Plasmoid.configuration.extraItems = extraItems; } @@ -155,9 +155,7 @@ MouseArea { model: PlasmaCore.SortFilterModel { sourceModel: Plasmoid.nativeInterface.systemTrayModel filterRole: "effectiveStatus" - filterCallback: function(source_row, value) { - return value === PlasmaCore.Types.ActiveStatus - } + filterCallback: (source_row, value) => value === PlasmaCore.Types.ActiveStatus } delegate: ItemLoader { @@ -257,19 +255,19 @@ MouseArea { visible: [PlasmaCore.Types.TopEdge, PlasmaCore.Types.LeftEdge, PlasmaCore.Types.RightEdge, PlasmaCore.Types.BottomEdge] .includes(Plasmoid.location) anchors { - top: Plasmoid.location == PlasmaCore.Types.BottomEdge ? undefined : parent.top - left: Plasmoid.location == PlasmaCore.Types.RightEdge ? undefined : parent.left - right: Plasmoid.location == PlasmaCore.Types.LeftEdge ? undefined : parent.right - bottom: Plasmoid.location == PlasmaCore.Types.TopEdge ? undefined : parent.bottom - topMargin: Plasmoid.location == PlasmaCore.Types.BottomEdge ? undefined : -dialog.margins.top - leftMargin: Plasmoid.location == PlasmaCore.Types.RightEdge ? undefined : -dialog.margins.left - rightMargin: Plasmoid.location == PlasmaCore.Types.LeftEdge ? undefined : -dialog.margins.right - bottomMargin: Plasmoid.location == PlasmaCore.Types.TopEdge ? undefined : -dialog.margins.bottom + top: Plasmoid.location === PlasmaCore.Types.BottomEdge ? undefined : parent.top + left: Plasmoid.location === PlasmaCore.Types.RightEdge ? undefined : parent.left + right: Plasmoid.location === PlasmaCore.Types.LeftEdge ? undefined : parent.right + bottom: Plasmoid.location === PlasmaCore.Types.TopEdge ? undefined : parent.bottom + topMargin: Plasmoid.location === PlasmaCore.Types.BottomEdge ? undefined : -dialog.margins.top + leftMargin: Plasmoid.location === PlasmaCore.Types.RightEdge ? undefined : -dialog.margins.left + rightMargin: Plasmoid.location === PlasmaCore.Types.LeftEdge ? undefined : -dialog.margins.right + bottomMargin: Plasmoid.location === PlasmaCore.Types.TopEdge ? undefined : -dialog.margins.bottom } - height: (Plasmoid.location == PlasmaCore.Types.TopEdge || Plasmoid.location == PlasmaCore.Types.BottomEdge) ? 1 : undefined - width: (Plasmoid.location == PlasmaCore.Types.LeftEdge || Plasmoid.location == PlasmaCore.Types.RightEdge) ? 1 : undefined + height: (Plasmoid.location === PlasmaCore.Types.TopEdge || Plasmoid.location === PlasmaCore.Types.BottomEdge) ? 1 : undefined + width: (Plasmoid.location === PlasmaCore.Types.LeftEdge || Plasmoid.location === PlasmaCore.Types.RightEdge) ? 1 : undefined z: 999 /* Draw the line on top of the applet */ - elementId: (Plasmoid.location == PlasmaCore.Types.TopEdge || Plasmoid.location == PlasmaCore.Types.BottomEdge) ? "horizontal-line" : "vertical-line" + elementId: (Plasmoid.location === PlasmaCore.Types.TopEdge || Plasmoid.location === PlasmaCore.Types.BottomEdge) ? "horizontal-line" : "vertical-line" svg: PlasmaCore.Svg { imagePath: "widgets/line" }