Skip to content

Commit

Permalink
Make Manager DBusProxy calls asynchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
infirit committed May 22, 2024
1 parent 1bca848 commit 7ae0cc5
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions blueman/main/DBusProxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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:
Expand Down

0 comments on commit 7ae0cc5

Please sign in to comment.