diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2015-07-08 07:09:13 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2015-07-08 07:09:13 +0200 |
commit | 63cf3cb3d47563e3fdcd2a70bd49649d126645f4 (patch) | |
tree | e2bd07eae545bcdada7878aca78a905c7f27d053 | |
parent | 6876729d8e5c205d63eeb2b05c997ab1f4f92002 (diff) | |
download | dzen2-config-63cf3cb3d47563e3fdcd2a70bd49649d126645f4.tar.gz dzen2-config-63cf3cb3d47563e3fdcd2a70bd49649d126645f4.tar.xz dzen2-config-63cf3cb3d47563e3fdcd2a70bd49649d126645f4.zip |
pulse-dbus-receive: Reconnect if the bus disconnects
-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) |