diff --git a/bumblebee/modules/pulseaudio.py b/bumblebee/modules/pulseaudio.py index c4eb000..97f1c4a 100644 --- a/bumblebee/modules/pulseaudio.py +++ b/bumblebee/modules/pulseaudio.py @@ -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,32 +80,43 @@ 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): - channel = "sinks" if self.name == "pasink" else "sources" - device = self._default_device() + try: + self._failed = False + channel = "sinks" if self.name == "pasink" else "sources" + device = self._default_device() - result = bumblebee.util.execute("pacmd list-{}".format(channel)) - found = False + result = bumblebee.util.execute("pacmd list-{}".format(channel)) + found = False - for line in result.split("\n"): - if device in line: - found = True - continue - if found == False: - continue - for pattern in self._patterns: - if not pattern["expr"] in line: + for line in result.split("\n"): + if device in line: + found = True continue - if pattern["callback"](line) == False and found == True: - return + if found == False: + continue + for pattern in self._patterns: + if not pattern["expr"] in line: + 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: