commit 7367fcd3b56d8ff1caaa3d33b7dc6657c7138e4a Author: Aaron Bieber Date: Tue Jan 14 18:26:40 2025 -0700 Initial import diff --git a/README.md b/README.md new file mode 100644 index 0000000..f02b158 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +### krha + +This plugin provides a simple template for a KRunner plugin using dbus. + +The install script copies the Krunner config file and a dbus activation service file +to their appropriate locations. +This way the python script gets executed when KRunner +requests matches and it does not need to be autostarted. + +If you want to run the plugin manually to debug it you can do the following: +```bash +mkdir -p ~/.local/share/krunner/dbusplugins/ +cp plasma-runner-krha.desktop ~/.local/share/krunner/dbusplugins/ +kquitapp5 krunner +python3 krha.py +``` + +After that you should see your runner when typing `hello` in KRunner. + +More information can be found here: +https://invent.kde.org/frameworks/krunner/-/blob/master/src/data/org.kde.krunner1.xml +https://techbase.kde.org/Development/Tutorials/D-Bus/Introduction + + +If you feel confident about your runner you can upload it to the KDE Store +https://store.kde.org/browse/cat/628/order/latest/. diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..4b37123 --- /dev/null +++ b/install.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Exit if something fails +set -e + + +if [[ -z "$XDG_DATA_HOME" ]]; then + prefix=~/.local/share +else + prefix="$XDG_DATA_HOME" +fi + +mkdir -p $prefix/krunner/dbusplugins/ +mkdir -p $prefix/dbus-1/services/ + +cp plasma-runner-krha.desktop $prefix/krunner/dbusplugins/ +sed "s|/home/qbit/projects/krha/krha.py|${PWD}/krha.py|" "org.kde.krha.service" > $prefix/dbus-1/services/org.kde.krha.service + +kquitapp5 krunner + diff --git a/krha.py b/krha.py new file mode 100755 index 0000000..10195e2 --- /dev/null +++ b/krha.py @@ -0,0 +1,38 @@ +#!/usr/bin/python3 + +import dbus.service +from dbus.mainloop.glib import DBusGMainLoop +from gi.repository import GLib + +DBusGMainLoop(set_as_default=True) + +objpath = "/krha" + +iface = "org.kde.krunner1" + + +class Runner(dbus.service.Object): + def __init__(self): + dbus.service.Object.__init__(self, dbus.service.BusName("org.kde.krha", dbus.SessionBus()), objpath) + + @dbus.service.method(iface, in_signature='s', out_signature='a(sssida{sv})') + def Match(self, query: str): + """This method is used to get the matches and it returns a list of tupels""" + if query == "hello": + # data, text, icon, type (Plasma::QueryType), relevance (0-1), properties (subtext, category, multiline(bool) and urls) + return [("Hello", "Hello from krha!", "document-edit", 100, 1.0, {'subtext': 'Demo Subtext'})] + return [] + + @dbus.service.method(iface, out_signature='a(sss)') + def Actions(self): + # id, text, icon + return [("id", "Tooltip", "planetkde")] + + @dbus.service.method(iface, in_signature='ss') + def Run(self, data: str, action_id: str): + print(data, action_id) + + +runner = Runner() +loop = GLib.MainLoop() +loop.run() diff --git a/org.kde.krha.service b/org.kde.krha.service new file mode 100644 index 0000000..4f590fc --- /dev/null +++ b/org.kde.krha.service @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.kde.krha +Exec=/usr/bin/python3 "/home/qbit/projects/krha/krha.py" diff --git a/plasma-runner-krha.desktop b/plasma-runner-krha.desktop new file mode 100644 index 0000000..bc7aa80 --- /dev/null +++ b/plasma-runner-krha.desktop @@ -0,0 +1,15 @@ +[Desktop Entry] +Name=krha +Comment=krha Runner written in Python +X-KDE-ServiceTypes=Plasma/Runner +Type=Service +Icon=planetkde +X-KDE-PluginInfo-Author=%{AUTHOR} +X-KDE-PluginInfo-Email=%{EMAIL} +X-KDE-PluginInfo-Name=krha +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-License=LGPL +X-KDE-PluginInfo-EnabledByDefault=true +X-Plasma-API=DBus +X-Plasma-DBusRunner-Service=org.kde.krha +X-Plasma-DBusRunner-Path=/krha diff --git a/uninstall.sh b/uninstall.sh new file mode 100755 index 0000000..ff06f7f --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Exit if something fails +set -e + +if [[ -z "$XDG_DATA_HOME" ]]; then + prefix=~/.local/share +else + prefix="$XDG_DATA_HOME" +fi + +rm $prefix/krunner/dbusplugins/plasma-runner-krha.desktop +rm $prefix/dbus-1/services/org.kde.krha.service +kquitapp5 krunner +