From d3083a6604103eff5ee5a46e9f17ebe4ecd0321f Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 28 Jan 2021 23:01:53 +0800 Subject: [PATCH] Use set_hint('image-path', ...) in notification So we can use 'uri' only for indicating playing state, and use 'image-path' for artUrl in notification --- src/mpDris2.in.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/mpDris2.in.py b/src/mpDris2.in.py index 4719dda..b004bdf 100755 --- a/src/mpDris2.in.py +++ b/src/mpDris2.in.py @@ -584,9 +584,12 @@ def update_metadata(self): (value, allowed_tags[key])) def notify_about_track(self, meta, state='play'): - uri = 'sound' + uri = 'media-playback-start-symbolic' + artUrl = '' if 'mpris:artUrl' in meta: - uri = meta['mpris:artUrl'] + artUrl = meta['mpris:artUrl'] + else: + pass title = 'Unknown Title' if 'xesam:title' in meta: @@ -602,9 +605,8 @@ def notify_about_track(self, meta, state='play'): if state == 'pause': uri = 'media-playback-pause-symbolic' - body += ' (%s)' % _('Paused') - notification.notify(title, body, uri) + notification.notify(title, body, uri, artUrl) def notify_about_state(self, state): if state == 'stop': @@ -939,10 +941,10 @@ def _bootstrap_notifications(self): return notif - def notify(self, title, body, uri=''): + def notify(self, title, body, uri='', artUrl=''): if not self._enabled: return - + # If we did not yet manage to get a notification service, # try again if not self._notification: @@ -950,11 +952,13 @@ def notify(self, title, body, uri=''): self._notification = self._bootstrap_notifications() if self._notification: logger.info('Notification service provider acquired!') - + if self._notification: try: + self._notification.close() self._notification.set_urgency(params['notify_urgency']) self._notification.update(title, body, uri) + self._notification.set_hint('image-path', GLib.Variant("s", artUrl)) self._notification.show() except GLib.GError as err: logger.error("Failed to show notification: %s" % err)