Skip to content

Commit

Permalink
refactor: Port to Plasma 6
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Breaks compatibility with Plasma 5
  • Loading branch information
korapp committed Dec 15, 2023
1 parent 0b65d86 commit 76a1a5e
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 86 deletions.
12 changes: 3 additions & 9 deletions package/contents/ui/CompactRepresentation.qml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import QtQuick 2.0

import org.kde.plasma.core 2.0 as PlasmaCore

Icon {
source: plasmoid.icon
active: mouseArea.containsMouse
Expand All @@ -13,7 +11,7 @@ Icon {
acceptedButtons: Qt.LeftButton | Qt.MiddleButton
anchors.fill: parent

onClicked: {
onClicked: function (mouse) {
if (plasmoid.configuration.toggleConnectionOnMiddleButton && mouse.button === Qt.MiddleButton) {
toggleConnection()
} else {
Expand All @@ -27,10 +25,6 @@ Icon {
}

function toggleExpanded() {
plasmoid.expanded = !plasmoid.expanded
root.expanded = !root.expanded
}

Accessible.name: plasmoid.title
Accessible.description: plasmoid.toolTipSubText
Accessible.role: Accessible.Button
}
}
7 changes: 4 additions & 3 deletions package/contents/ui/DetailsText.qml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import QtQuick 2.0

import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents3

import org.kde.kirigami 2.3 as Kirigami

Column {
property alias model: repeater.model

Expand All @@ -23,7 +24,7 @@ Column {

anchors {
left: parent.left
leftMargin: repeater.longestString - paintedWidth + Math.round(PlasmaCore.Units.gridUnit / 2)
leftMargin: repeater.longestString - paintedWidth + Math.round(Kirigami.Units.gridUnit / 2)
}

horizontalAlignment: Text.AlignRight
Expand All @@ -43,7 +44,7 @@ Column {
anchors {
left: parent.left
right: parent.right
leftMargin: repeater.longestString + Math.round(PlasmaCore.Units.gridUnit / 2)
leftMargin: repeater.longestString + Math.round(Kirigami.Units.gridUnit / 2)
}

elide: Text.ElideRight
Expand Down
12 changes: 6 additions & 6 deletions package/contents/ui/FullRepresentation.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ import QtQuick.Layouts 1.0

import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.kirigami 2.3 as Kirigami

PlasmaComponents3.Page {
readonly property var appletInterface: plasmoid.self

readonly property string mainText: client.status || client.errorMessage
readonly property string icon: client.errorMessage ? "error" : plasmoid.icon

Layout.preferredWidth: PlasmaCore.Units.gridUnit * 24
Layout.preferredHeight: PlasmaCore.Units.gridUnit * 24
Layout.preferredWidth: Kirigami.Units.gridUnit * 24
Layout.preferredHeight: Kirigami.Units.gridUnit * 24

ColumnLayout {
spacing: PlasmaCore.Units.largeSpacing
spacing: Kirigami.Units.largeSpacing
width: parent.width
enabled: !client.isBusy
anchors.centerIn: parent

Icon {
opacity: 0.5
source: icon
readonly property int size: Math.round(PlasmaCore.Units.iconSizes.huge * 1.5)
readonly property int size: Math.round(Kirigami.Units.iconSizes.huge * 1.5)
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: size
Layout.preferredHeight: size
Expand All @@ -50,7 +50,7 @@ PlasmaComponents3.Page {
action: client.isConnected ? actionDisconnect : actionConnect
visible: client.isServiceRunning
Layout.alignment: Qt.AlignHCenter
Layout.topMargin: PlasmaCore.Units.gridUnit
Layout.topMargin: Kirigami.Units.gridUnit
}
}

Expand Down
8 changes: 4 additions & 4 deletions package/contents/ui/Icon.qml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import QtQuick 2.0
import QtGraphicalEffects 1.0
import Qt5Compat.GraphicalEffects 1.0

import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.kirigami 2.3 as Kirigami

Item {
property alias source: icon.source
property alias active: icon.active

PlasmaCore.IconItem {
Kirigami.Icon {
id: icon
anchors.fill: parent
}

ColorOverlay {
anchors.fill: icon
source: icon
color: PlasmaCore.Theme.textColor
color: Kirigami.Theme.textColor
}
}
21 changes: 0 additions & 21 deletions package/contents/ui/Notifications.qml

This file was deleted.

12 changes: 6 additions & 6 deletions package/contents/ui/Warp.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import QtQuick 2.0

import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.plasma5support 2.0 as P5Support

Item {
property bool watchStats: false
Expand All @@ -16,7 +16,7 @@ Item {
readonly property var disableDefaultApp: p.disableDefaultApp
readonly property bool isBusy: p.isConnecting || p.isOperationInProgress

PlasmaCore.DataSource {
P5Support.DataSource {
id: watcher
readonly property string cmdStatus: "warp-cli status"
readonly property string cmdStats: "warp-cli warp-stats"
Expand All @@ -27,13 +27,13 @@ Item {
engine: "executable"
connectedSources: [cmdStatus]
interval: p.isServiceRunning ? 1000 : 5000
onNewData: handlers[sourceName](data)
onNewData: (sourceName, data) => handlers[sourceName](data)
}

PlasmaCore.DataSource {
P5Support.DataSource {
id: exec
engine: "executable"
onNewData: disconnectSource(sourceName)
onNewData: disconnectSource
readonly property var run: connectSource
}

Expand Down Expand Up @@ -84,7 +84,7 @@ Item {
const statusMessage = parseStdoutProperties(data.stdout)[0][1]
const newStatus = statusMessage.replace(". Reason: ", "\n")
errorMessage = ""
if (status != newStatus) {
if (status != newStatus) {
status = newStatus
isOperationInProgress = false
}
Expand Down
71 changes: 40 additions & 31 deletions package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ import QtQuick.Controls 2.3

import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.kirigami 2.3 as Kirigami
import org.kde.notification 1.0

Item {
PlasmoidItem {
id: root
Plasmoid.compactRepresentation: CompactRepresentation {}
Plasmoid.fullRepresentation: FullRepresentation {}
Plasmoid.toolTipSubText: {
compactRepresentation: CompactRepresentation {}
fullRepresentation: FullRepresentation {}
toolTipSubText: {
if (plasmoid.configuration.toggleConnectionOnMiddleButton) {
const hint = client.isConnected ? i18n("Middle-click to disconnect") : i18n("Middle-click to connect")
return client.status + "\n" + hint
}
return client.status
}
switchWidth: Kirigami.Units.gridUnit * 24
switchHeight: Kirigami.Units.gridUnit * 24
Plasmoid.busy: client.isBusy
Plasmoid.status: client.isServiceRunning && (client.isConnected || !plasmoid.configuration.hideWhenDisconnected)
? PlasmaCore.Types.ActiveStatus
: PlasmaCore.Types.PassiveStatus

Plasmoid.switchWidth: PlasmaCore.Units.gridUnit * 24
Plasmoid.switchHeight: PlasmaCore.Units.gridUnit * 24
Plasmoid.contextualActions: [
mapAction(actionDisconnect, client.isConnected),
mapAction(actionConnect, !client.isConnected)
]

Warp {
id: client
watchStats: plasmoid.expanded
onIsConnectedChanged: prepareContextualActions()

Component.onCompleted: {
disableDefaultApp()
prepareContextualActions()
}
watchStats: root.expanded
Component.onCompleted: disableDefaultApp()
}

Action {
Expand All @@ -49,33 +49,42 @@ Item {
onTriggered: client.disconnect()
}

function actionToContextual(action) {
return [action.text.toLowerCase(), action.text, action.icon.name]
}

Loader {
id: nLoader
active: plasmoid.configuration.showNotifications
source: "Notifications.qml"
Component {
id: actionComponent
PlasmaCore.Action {}
}

Connections {
target: client
enabled: nLoader.status === Loader.Ready
onStatusChanged: nLoader.item.createNotification(client.status)
enabled: plasmoid.configuration.showNotifications
function onStatusChanged() {
createNotification(client.status)
}
}

function prepareContextualActions() {
plasmoid.clearActions()
plasmoid.setAction(...actionToContextual(client.isConnected ? actionDisconnect : actionConnect))
function mapAction(action, visible) {
const ca = actionComponent.createObject(root, {
text: action.text,
'icon.name': action.icon.name,
visible
})
ca.onTriggered.connect(action.onTriggered)
return ca
}

function action_disconnect() {
client.disconnect()
Component {
id: notifications
Notification {
componentName: "plasma_workspace"
eventId: "notification"
title: plasmoid.title
iconName: plasmoid.icon
autoDelete: true
}
}

function action_connect() {
client.connect()
function createNotification(text) {
notifications.createObject(parent, { text })?.sendEvent()
}

function nmI18n(...args) {
Expand Down
8 changes: 2 additions & 6 deletions package/metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"KPackageStructure": "Plasma/Applet",
"KPlugin": {
"Authors": [
{
Expand All @@ -14,18 +15,13 @@
"Id": "com.github.korapp.cloudflare-warp",
"License": "GPLv3",
"Name": "Zero Trust",
"ServiceTypes": [
"Plasma/Applet"
],
"Version": "0.1",
"Website": "https://github.com/korapp/plasma-cloudflare-warp",
"BugReportUrl": "https://github.com/korapp/plasma-cloudflare-warp/issues/new"
},
"Keywords": "warp;zero;trust;cloudflare",
"X-KDE-ParentApp": "warp-cli",
"X-KDE-Version": "5.19",
"X-Plasma-API": "declarativeappletscript",
"X-Plasma-MainScript": "ui/main.qml",
"X-KDE-Version": "6.0",
"X-Plasma-NotificationArea": "true",
"X-Plasma-NotificationAreaCategory": "ApplicationStatus",
"X-Plasma-StandAloneApp": true
Expand Down

0 comments on commit 76a1a5e

Please sign in to comment.