diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/pulse-dbus-receive.py | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/bin/pulse-dbus-receive.py b/bin/pulse-dbus-receive.py index 347fa66..3e00d6a 100755 --- a/bin/pulse-dbus-receive.py +++ b/bin/pulse-dbus-receive.py @@ -7,6 +7,8 @@ import gobject import subprocess from dbus.mainloop.glib import DBusGMainLoop import sys +from functools import partial +import time home = os.path.expanduser('~') safe = { @@ -75,15 +77,32 @@ def init(bus): update_muted(sink.Get('org.PulseAudio.Core1.Device', 'Mute'), True) update_volume(sink.Get('org.PulseAudio.Core1.Device', 'Volume'), True) -if __name__ == '__main__': - DBusGMainLoop(set_as_default=True) - bus = dbus_connect() +def setup(loop, conn=None): + bus = None + while True: + try: + if conn is not None: + time.sleep(2) + bus = dbus_connect() + break + except: + if conn is None: + break + + if bus is None: + print "Could not connect to dbus!" + sys.exit(1) + + bus.call_on_disconnection(partial(setup, loop)) init(bus) bus.add_signal_receiver(signal_cb, message_keyword='msg') core = bus.get_object(object_path="/org/pulseaudio/core1") core.ListenForSignal('org.PulseAudio.Core1.Device.VolumeUpdated', dbus.Array(signature='o')) core.ListenForSignal('org.PulseAudio.Core1.Device.MuteUpdated', dbus.Array(signature='o')) + loop.run() +if __name__ == '__main__': + DBusGMainLoop(set_as_default=True) loop = gobject.MainLoop() - loop.run() + setup(loop) |