[gnome-music/wip/jfelder/mpris-gsconnect-debug: 31/31] mpris: Handle clients which request the volume property



commit 2e6d563612675e3a3bf9411f4fe60bf9be29c628
Author: Jean Felder <jfelder src gnome org>
Date:   Thu May 30 16:38:22 2019 +0200

    mpris: Handle clients which request the volume property
    
    Volume property handling has been recently removed from Music (commit
    2bd7fb6b) but some MPRIS clients (for example GSConnect) try to get
    this property and this results in a crash at startup. The client
    should detect that the server (GNOME Music) does not handle the volume
    property but that's not always possible.
    
    Apply a workaround to prevent a crash: return a DBus error.
    
    Closes: #287

 gnomemusic/mpris.py | 42 +++++++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 15 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index a160cca1..772ee779 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -105,20 +105,23 @@ class DBusInterface:
                 args[i] = fd_list.get(args[i])
 
         method_snake_name = DBusInterface.camelcase_to_snake_case(method_name)
-        result = getattr(self, method_snake_name)(*args)
-
-        # out_args is at least (signature1). We therefore always wrap the
-        # result as a tuple.
-        # Reference:
-        # https://bugzilla.gnome.org/show_bug.cgi?id=765603
-        result = (result,)
-
-        out_args = self._method_outargs[method_name]
-        if out_args != '()':
-            variant = GLib.Variant(out_args, result)
-            invocation.return_value(variant)
-        else:
-            invocation.return_value(None)
+        try:
+            result = getattr(self, method_snake_name)(*args)
+
+            # out_args is at least (signature1). We therefore always wrap the
+            # result as a tuple.
+            # Reference:
+            # https://bugzilla.gnome.org/show_bug.cgi?id=765603
+            result = (result,)
+
+            out_args = self._method_outargs[method_name]
+            if out_args != '()':
+                variant = GLib.Variant(out_args, result)
+                invocation.return_value(variant)
+            else:
+                invocation.return_value(None)
+        except ValueError as e:
+            invocation.return_dbus_error(interface_name, str(e))
 
     def _dbus_emit_signal(self, signal_name, values):
         signal = self._signals[signal_name]
@@ -758,7 +761,16 @@ class MPRIS(DBusInterface):
         return mpris_playlists[index + max_count - 1:first_index:-1]
 
     def _get(self, interface_name, property_name):
-        return self._get_all(interface_name)[property_name]
+        # Some clients (for example GSConnect) try to acesss the volume
+        # property. This results in a crash at startup.
+        # Return nothing to prevent it.
+        try:
+            return self._get_all(interface_name)[property_name]
+        except KeyError:
+            msg = "MPRIS does not handle {} property from {} interface".format(
+                property_name, interface_name)
+            logger.warning(msg)
+            raise ValueError(msg)
 
     def _get_all(self, interface_name):
         if interface_name == MPRIS.MEDIA_PLAYER2_IFACE:


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