[gnome-music/wip/jfelder/mpris-cleanup: 18/25] mpris: Asynchronously connect to session bus



commit b38af704f133534807faa04abf77856b132ef449
Author: Jean Felder <jfelder src gnome org>
Date:   Sat Jun 15 16:35:04 2019 +0200

    mpris: Asynchronously connect to session bus

 gnomemusic/mpris.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index cb52703b..8c494171 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -47,10 +47,19 @@ class DBusInterface:
         :param str name: interface name
         :param str path: object path
         """
-        self._con = Gio.bus_get_sync(Gio.BusType.SESSION, None)
+        self._path = path
+        Gio.bus_get(Gio.BusType.SESSION, None, self._bus_get_sync, name)
+
+    def _bus_get_sync(self, source, res, name):
+        try:
+            self._con = Gio.bus_get_finish(res)
+        except GLib.Error as e:
+            logger.warning(
+                "Unable to connect to to session bus: {}".format(e.message))
+            return
+
         Gio.bus_own_name_on_connection(
             self._con, name, Gio.BusNameOwnerFlags.NONE, None, None)
-        self._path = path
 
         method_outargs = {}
         method_inargs = {}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]