Skip to content

Commit c699660

Browse files
committed
fix: fallback to gdbus for plasma 6.1
refs: #161
1 parent 56c2a4a commit c699660

File tree

6 files changed

+121
-23
lines changed

6 files changed

+121
-23
lines changed

package/contents/ui/DBusFallback.qml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
pragma ComponentBehavior: Bound
2+
pragma ValueTypeBehavior: Addressable
3+
4+
import QtQuick
5+
6+
Item {
7+
id: root
8+
property string busType
9+
property string service: ""
10+
property string objectPath: ""
11+
property string iface: ""
12+
property string method: ""
13+
property var arguments: []
14+
property var signature: null
15+
property var inSignature: null
16+
signal callFinished(reply: var)
17+
18+
function builCmd() {
19+
let cmd = "gdbus call --session --dest " + service + " --object-path " + objectPath + " --method " + iface + "." + method
20+
if (root.arguments.length !== 0) {
21+
cmd += ` '${root.arguments.join(" ")}'`
22+
}
23+
return cmd
24+
}
25+
26+
RunCommand {
27+
id: runCommand
28+
onExited: (cmd, exitCode, exitStatus, stdout, stderr) => {
29+
if (exitCode!==0) {
30+
console.error(cmd, exitCode, exitStatus, stdout, stderr)
31+
return
32+
}
33+
stdout = stdout
34+
.trim()
35+
.replace(/^\([']?/, "") // starting ( or ('
36+
.replace(/[']?,\)$/, "") // ending ,) or ',)
37+
const reply = {value: stdout}
38+
root.callFinished(reply)
39+
}
40+
}
41+
42+
function call(callback) {
43+
runCommand.run(builCmd())
44+
if (callback) callFinished.connect(callback)
45+
}
46+
}
+26-17
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,43 @@
1-
pragma ComponentBehavior: Bound
2-
pragma ValueTypeBehavior: Addressable
3-
41
import QtQuick
5-
import org.kde.plasma.workspace.dbus as DBus
62

7-
QtObject {
3+
Item {
84
id: root
9-
property string busType: DBus.BusType.Session
5+
property string busType
106
property string service: ""
117
property string objectPath: ""
128
property string iface: ""
139
property string method: ""
1410
property var arguments: []
1511
property var signature: null
1612
property var inSignature: null
13+
property bool useGdbus: false
14+
15+
onArgumentsChanged: dbusLoader.item.arguments = root.arguments
1716

18-
property DBus.dbusMessage msg: {
19-
"service": root.service,
20-
"path": root.objectPath,
21-
"iface": root.iface,
22-
"member": root.method,
23-
"arguments": root.arguments,
24-
"signature": root.signature,
25-
"inSignature": root.inSignature,
17+
Loader {
18+
id: dbusLoader
19+
source: root.useGdbus ? "DBusFallback.qml" : "DBusPrimary.qml"
20+
onStatusChanged: {
21+
if (status === Loader.Error) {
22+
dbusLoader.source = "DBusFallback.qml"
23+
}
24+
}
25+
onLoaded: {
26+
dbusLoader.item.service = root.service
27+
dbusLoader.item.objectPath = root.objectPath
28+
dbusLoader.item.iface = root.iface
29+
dbusLoader.item.method = root.method
30+
dbusLoader.item.arguments = root.arguments
31+
dbusLoader.item.signature = root.signature
32+
dbusLoader.item.inSignature = root.inSignature
33+
}
2634
}
2735

2836
function call(callback) {
29-
const reply = DBus.SessionBus.asyncCall(root.msg) as DBus.DBusPendingReply
30-
if (callback) {
31-
reply.finished.connect(() => callback(reply))
37+
if (dbusLoader.item && typeof dbusLoader.item.call === "function") {
38+
dbusLoader.item.call(callback);
39+
} else {
40+
console.error("No valid DBus implementation loaded.");
3241
}
3342
}
3443
}

package/contents/ui/DBusPrimary.qml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
pragma ComponentBehavior: Bound
2+
pragma ValueTypeBehavior: Addressable
3+
4+
import QtQuick
5+
import org.kde.plasma.workspace.dbus as DBus
6+
7+
QtObject {
8+
id: root
9+
property string busType: DBus.BusType.Session
10+
property string service: ""
11+
property string objectPath: ""
12+
property string iface: ""
13+
property string method: ""
14+
property var arguments: []
15+
property var signature: null
16+
property var inSignature: null
17+
18+
property DBus.dbusMessage msg: {
19+
"service": root.service,
20+
"path": root.objectPath,
21+
"iface": root.iface,
22+
"member": root.method,
23+
"arguments": root.arguments,
24+
"signature": root.signature,
25+
"inSignature": root.inSignature,
26+
}
27+
28+
function call(callback) {
29+
const reply = DBus.SessionBus.asyncCall(root.msg) as DBus.DBusPendingReply
30+
if (callback) {
31+
reply.finished.connect(() => callback(reply))
32+
}
33+
}
34+
}

package/contents/ui/DBusServiceModel.qml

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Item {
1515
property string serviceUtil: toolsDir+"service.py"
1616
property string pythonExecutable: plasmoid.configuration.pythonExecutable
1717
property string serviceCmd: pythonExecutable + " '" + serviceUtil + "' " + Plasmoid.containment.id + " " + Plasmoid.id
18-
property string quitServiceCmd: gdbusPartial +".quit"
1918

2019
readonly property string service: Plasmoid.metaData.pluginId + ".c" + Plasmoid.containment.id + ".w" + Plasmoid.id
2120
readonly property string path: "/preset"

package/contents/ui/code/utils.js

-4
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,6 @@ if (${panelSettings.opacity.enabled}) {
444444
return setPanelModeScript;
445445
}
446446

447-
function evaluateScript(script) {
448-
runCommand.run("gdbus call --session --dest org.kde.plasmashell --object-path /PlasmaShell --method org.kde.PlasmaShell.evaluateScript '" + script + "'")
449-
}
450-
451447
function getForceFgWidgetConfig(id, name, config) {
452448
return config.find((item) => item.id == id && item.name == name)
453449
}

package/contents/ui/main.qml

+15-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ PlasmoidItem {
145145
} else {
146146
panelView.visible = true
147147
}
148-
Utils.evaluateScript(script)
148+
dbusEvaluateScript.arguments = [script.toString().replace(/\n/g,' ').trim()]
149+
dbusEvaluateScript.call();
149150
reconfigure()
150151
})
151152
}
@@ -1449,6 +1450,19 @@ PlasmoidItem {
14491450
inSignature: null
14501451
}
14511452

1453+
DBusMethodCall {
1454+
id: dbusEvaluateScript
1455+
service: "org.kde.plasmashell"
1456+
objectPath: "/PlasmaShell"
1457+
iface: "org.kde.PlasmaShell"
1458+
method: "evaluateScript"
1459+
arguments: []
1460+
signature: null
1461+
inSignature: null
1462+
useGdbus: true
1463+
}
1464+
1465+
14521466
// temporarily show the panel
14531467
Timer {
14541468
id: tempActivationTimer

0 commit comments

Comments
 (0)