Check deadbeef is running and check if stopped as part of the query

deadbeef is checked to ensure it's running before doing anything,
otherwise a lot of useless data is pulled in, and the if statement to
check whether or not the player is stopped is now integrated into the
query at startup instead of running a separate query every time.
This commit is contained in:
WORD559 2019-09-23 16:15:53 +01:00
parent b7b0faf613
commit e42037ce6f

View file

@ -76,6 +76,13 @@ class Module(bumblebee.engine.Module):
engine.input.register_callback(self, button=buttons[pause_button], engine.input.register_callback(self, button=buttons[pause_button],
cmd=cmd + "--play-pause") cmd=cmd + "--play-pause")
# modify the tf_format if we don't want it to show on stop
# this adds conditions to the query itself, rather than
# polling to see if deadbeef is running
# doing this reduces the number of calls we have to make
if self._tf_format and not self._show_tf_when_stopped:
self._tf_format = "$if($or(%isplaying%,%ispaused%),{query})".format(query=self._tf_format)
@scrollable @scrollable
def deadbeef(self, widget): def deadbeef(self, widget):
return self.string_song return self.string_song
@ -92,13 +99,12 @@ class Module(bumblebee.engine.Module):
self._song = "error" self._song = "error"
def update_tf(self, widgets): def update_tf(self, widgets):
if not self._show_tf_when_stopped: ## ensure that deadbeef is actually running
## check if the player is paused or playing ## easiest way to do this is to check --nowplaying for
self.now_playing_tf[-1] = "%isplaying%%ispaused%" ## the string "nothing"
data = read_process(self.now_playing_tf) if read_process(self.now_playing) == "nothing":
if data == "": self._song = ""
self._song = "" return
return
## perform the actual query -- these can be much more sophisticated ## perform the actual query -- these can be much more sophisticated
self.now_playing_tf[-1] = self._tf_format self.now_playing_tf[-1] = self._tf_format
data = read_process(self.now_playing_tf) data = read_process(self.now_playing_tf)