From 7ae0cc56d4576b691d690eb401a9fb14c4036e79 Mon Sep 17 00:00:00 2001 From: Sander Sweers Date: Wed, 22 May 2024 13:53:35 +0200 Subject: [PATCH] Make Manager DBusProxy calls asynchronous --- blueman/main/DBusProxies.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/blueman/main/DBusProxies.py b/blueman/main/DBusProxies.py index 27524620b..6f509d335 100644 --- a/blueman/main/DBusProxies.py +++ b/blueman/main/DBusProxies.py @@ -32,7 +32,6 @@ def __init__(self, name: str, interface_name: str, object_path: str = "/", syste except GLib.Error as e: raise DBusProxyFailed(e.message) - class Mechanism(ProxyBase): def __init__(self) -> None: super().__init__(name='org.blueman.Mechanism', interface_name='org.blueman.Mechanism', @@ -52,22 +51,25 @@ def __init__(self) -> None: flags=Gio.DBusProxyFlags.DO_NOT_AUTO_START_AT_CONSTRUCTION) def activate(self) -> None: - try: - param = GLib.Variant('(a{sv})', ({},)) - self.call_sync("Activate", param, Gio.DBusCallFlags.NONE, -1, None) - except GLib.Error: - # This can different errors, depending on the system configuration, typically: - # * org.freedesktop.DBus.Error.Spawn.ChildExited if dbus-daemon tries to launch the service itself. - # * org.freedesktop.DBus.Error.NoReply if the systemd integration is used. - logging.error("Call to %s failed", self.get_name(), exc_info=True) - Notification( - _("Failed to reach blueman-manager"), - _("It seems like blueman-manager could no get activated via D-Bus. " - "A typical cause for this is a broken graphical setup in the D-Bus activation environment " - "that can get resolved with a call to dbus-update-activation-environment, " - "typically issued from xinitrc (respectively the Sway config or similar)."), - 0, - ).show() + def call_finish(proxy: "ManagerService", resp: Gio.AsyncResult) -> None: + try: + proxy.call_finish(resp) + except GLib.Error: + # This can different errors, depending on the system configuration, typically: + # * org.freedesktop.DBus.Error.Spawn.ChildExited if dbus-daemon tries to launch the service itself. + # * org.freedesktop.DBus.Error.NoReply if the systemd integration is used. + logging.error("Call to %s failed", self.get_name(), exc_info=True) + Notification( + _("Failed to reach blueman-manager"), + _("It seems like blueman-manager could no get activated via D-Bus. " + "A typical cause for this is a broken graphical setup in the D-Bus activation environment " + "that can get resolved with a call to dbus-update-activation-environment, " + "typically issued from xinitrc (respectively the Sway config or similar)."), + 0, + ).show() + + param = GLib.Variant('(a{sv})', ({},)) + self.call("Activate", param, Gio.DBusCallFlags.NONE, -1, None, call_finish) def _call_action(self, name: str) -> None: def call_finish(proxy: "ManagerService", resp: Gio.AsyncResult) -> None: