Skip to content

Commit

Permalink
feat: Replace dasbus with Gio since it gets rid of depencency
Browse files Browse the repository at this point in the history
  • Loading branch information
chookity-pokk committed Oct 30, 2024
1 parent 33909aa commit cb4676a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 17 deletions.
81 changes: 65 additions & 16 deletions pantalaimon/panctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@
import click

try:
from gi.repository import GLib
from gi.repository import GLib, Gio
except ModuleNotFoundError:
from pgi.repository import GLib
from pgi.repository import GLib, Gio

from prompt_toolkit import __version__ as ptk_version
from prompt_toolkit import HTML, PromptSession, print_formatted_text
from prompt_toolkit.completion import Completer, Completion, PathCompleter
from prompt_toolkit.document import Document
from prompt_toolkit.patch_stdout import patch_stdout
from dasbus.connection import SessionMessageBus

PTK2 = ptk_version.startswith("2.")

Expand Down Expand Up @@ -404,25 +403,75 @@ class PanCtl:
commands = list(command_help.keys())

def __attrs_post_init__(self):
self.bus = SessionMessageBus()
self.pan_bus = self.bus.get_connection("org.pantalaimon1")
"""
Setting up D-Bus proxies and signal connections.
This is automatically called after the object is initialized and performs the following tasks:
1. Establishes a connection to the D-Bus session bus.
2. Creates D-Bus proxies for interacting with the `org.pantalaimon1` service.
3. Connects various signals to their respective handler methods.
4. Initializes a `PanCompleter` instance for command completion.
Attributes:
bus (Gio.DBusConnection): The D-Bus connection to the session bus.
pan_bus (Gio.DBusProxy): Proxy for the main control interface of the `org.pantalaimon1` service.
ctl (Gio.DBusProxy): Another proxy for the main control interface of the `org.pantalaimon1` service.
devices (Gio.DBusProxy): Proxy for the devices interface of the `org.pantalaimon1` service.
completer (PanCompleter): Instance of `PanCompleter` for command completion.
Signal Handlers:
- `show_response`: Handles responses from the control interface.
- `unverified_devices`: Handles unverified device signals.
- `show_sas_invite`: Handles SAS (Short Authentication String) invite signals.
- `show_sas`: Handles SAS display signals.
- `sas_done`: Handles SAS completion signals.
- `show_key_request`: Handles key request signals.
- `show_key_request_cancel`: Handles key request cancellation signals.
"""

self.bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)

self.pan_bus = Gio.DBusProxy.new_sync(
self.bus,
Gio.DBusProxyFlags.NONE,
None,
"org.pantalaimon1", # Replace with actual service
"/", # Root object path
"org.pantalaimon1.control", # Main control interface
None,
)

self.ctl = self.pan_bus["org.pantalaimon1.control"]
self.devices = self.pan_bus["org.pantalaimon1.devices"]
self.ctl = Gio.DBusProxy.new_sync(
self.bus,
Gio.DBusProxyFlags.NONE,
None,
"org.pantalaimon1",
"/",
"org.pantalaimon1.control",
None,
)

self.own_message_ids = []
self.devices = Gio.DBusProxy.new_sync(
self.bus,
Gio.DBusProxyFlags.NONE,
None,
"org.pantalaimon1",
"/",
"org.pantalaimon1.devices",
None,
)

self.ctl.Response.connect(self.show_response)
self.ctl.UnverifiedDevices.connect(self.unverified_devices)
self.ctl.connect("g-signal", self.show_response)
self.ctl.connect("g-signal", self.unverified_devices)

self.completer = PanCompleter(self.commands, self.ctl, self.devices)

self.devices.VerificationInvite.connect(self.show_sas_invite)
self.devices.VerificationString.connect(self.show_sas)
self.devices.VerificationDone.connect(self.sas_done)

self.devices.KeyRequest.connect(self.show_key_request)
self.devices.KeyRequestCancel.connect(self.show_key_request_cancel)
self.devices.connect("g-signal", self.show_sas_invite)
self.devices.connect("g-signal", self.show_sas)
self.devices.connect("g-signal", self.sas_done)
self.devices.connect("g-signal", self.show_key_request)
self.devices.connect("g-signal", self.show_key_request_cancel)

def show_help(self, command):
print(self.command_help[command])
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"ui": [
"dbus-python >= 1.2, < 1.3",
"PyGObject >= 3.36, < 3.39",
"dasbus == 1.71",
"notify2 >= 0.3, < 0.4",
]
},
Expand Down

0 comments on commit cb4676a

Please sign in to comment.