Skip to content

Commit

Permalink
Pass loop instance to NotifyWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdnyc committed Dec 1, 2021
1 parent bc474c6 commit ccd8394
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/mpDris2.in.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class MPDWrapper(object):
errors and similar
"""

def __init__(self, params):
def __init__(self, params, loop=None):
self.client = mpd.MPDClient()

self._dbus = dbus
Expand Down Expand Up @@ -281,6 +281,7 @@ def __init__(self, params):
if self._params['mmkeys']:
self.setup_mediakeys()

self._loop = loop
def run(self):
"""
Try to connect to MPD; retry every 5 seconds on failure.
Expand Down Expand Up @@ -995,7 +996,8 @@ def _name_owner_changed_callback(self, name, old_owner, new_owner):
except:
pid = None
logger.info("Replaced by %s (PID %s)" % (new_owner, pid or "unknown"))
loop.quit()
if self._loop:
self._loop.quit()

def acquire_name(self):
self._bus_name = dbus.service.BusName(self._name,
Expand Down Expand Up @@ -1477,7 +1479,7 @@ def usage(params):
notification = NotifyWrapper(params)

# Create wrapper to handle connection failures with MPD more gracefully
mpd_wrapper = MPDWrapper(params)
mpd_wrapper = MPDWrapper(params, loop=loop)
mpd_wrapper.run()

# Run idle loop
Expand Down

0 comments on commit ccd8394

Please sign in to comment.