[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:
parent
7e45e797f1
commit
68e0b51178
1 changed files with 30 additions and 15 deletions
|
@ -4,6 +4,9 @@
|
||||||
|
|
||||||
Aliases: pasink, pasource
|
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:
|
Requires the following executable:
|
||||||
* pactl
|
* pactl
|
||||||
"""
|
"""
|
||||||
|
@ -31,6 +34,7 @@ class Module(bumblebee.engine.Module):
|
||||||
self._right = 0
|
self._right = 0
|
||||||
self._mono = 0
|
self._mono = 0
|
||||||
self._mute = False
|
self._mute = False
|
||||||
|
self._failed = False
|
||||||
channel = "sink" if self.name == "pasink" else "source"
|
channel = "sink" if self.name == "pasink" else "source"
|
||||||
|
|
||||||
self._patterns = [
|
self._patterns = [
|
||||||
|
@ -76,32 +80,43 @@ class Module(bumblebee.engine.Module):
|
||||||
return "n/a"
|
return "n/a"
|
||||||
|
|
||||||
def volume(self, widget):
|
def volume(self, widget):
|
||||||
|
if self._failed == True:
|
||||||
|
return "n/a"
|
||||||
if int(self._mono) > 0:
|
if int(self._mono) > 0:
|
||||||
return "{}%".format(self._mono)
|
return "{}%".format(self._mono)
|
||||||
elif self._left == self._right:
|
elif self._left == self._right:
|
||||||
return "{}%".format(self._left)
|
return "{}%".format(self._left)
|
||||||
else:
|
else:
|
||||||
return "{}%/{}%".format(self._left, self._right)
|
return "{}%/{}%".format(self._left, self._right)
|
||||||
return "n/a"
|
|
||||||
|
|
||||||
def update(self, widgets):
|
def update(self, widgets):
|
||||||
channel = "sinks" if self.name == "pasink" else "sources"
|
try:
|
||||||
device = self._default_device()
|
self._failed = False
|
||||||
|
channel = "sinks" if self.name == "pasink" else "sources"
|
||||||
|
device = self._default_device()
|
||||||
|
|
||||||
result = bumblebee.util.execute("pacmd list-{}".format(channel))
|
result = bumblebee.util.execute("pacmd list-{}".format(channel))
|
||||||
found = False
|
found = False
|
||||||
|
|
||||||
for line in result.split("\n"):
|
for line in result.split("\n"):
|
||||||
if device in line:
|
if device in line:
|
||||||
found = True
|
found = True
|
||||||
continue
|
|
||||||
if found == False:
|
|
||||||
continue
|
|
||||||
for pattern in self._patterns:
|
|
||||||
if not pattern["expr"] in line:
|
|
||||||
continue
|
continue
|
||||||
if pattern["callback"](line) == False and found == True:
|
if found == False:
|
||||||
return
|
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):
|
def state(self, widget):
|
||||||
if self._mute:
|
if self._mute:
|
||||||
|
|
Loading…
Reference in a new issue