[modules/pulseaudio] Automatically restart pulseaudio daemon

If the current volume and mute status cannot be retrieved, the most
likely explanation is that the pulseaudio daemon is not running.
Automatically start it in such a case.

Also, add a parameter "autostart" to the pulseaudio module to disable
this behaviour in case it causes issues.

see #108
This commit is contained in:
Tobias Witek 2017-06-15 11:09:00 +02:00
parent 7e45e797f1
commit 68e0b51178

View file

@ -4,6 +4,9 @@
Aliases: pasink, pasource
Parameters:
* pulseaudio.autostart: If set to "true" (default), automatically starts the pulseaudio daemon if it is not running
Requires the following executable:
* pactl
"""
@ -31,6 +34,7 @@ class Module(bumblebee.engine.Module):
self._right = 0
self._mono = 0
self._mute = False
self._failed = False
channel = "sink" if self.name == "pasink" else "source"
self._patterns = [
@ -76,15 +80,18 @@ class Module(bumblebee.engine.Module):
return "n/a"
def volume(self, widget):
if self._failed == True:
return "n/a"
if int(self._mono) > 0:
return "{}%".format(self._mono)
elif self._left == self._right:
return "{}%".format(self._left)
else:
return "{}%/{}%".format(self._left, self._right)
return "n/a"
def update(self, widgets):
try:
self._failed = False
channel = "sinks" if self.name == "pasink" else "sources"
device = self._default_device()
@ -102,6 +109,14 @@ class Module(bumblebee.engine.Module):
continue
if pattern["callback"](line) == False and found == True:
return
except Exception:
self._failed = True
if self.parameter("autostart", "true") == "true":
try:
bumblebee.util.execute("pulseaudio --start")
self.update(widgets)
except Exception:
pass
def state(self, widget):
if self._mute: