From e42037ce6fad2786570295cfe5967f22eee210cf Mon Sep 17 00:00:00 2001 From: WORD559 Date: Mon, 23 Sep 2019 16:15:53 +0100 Subject: [PATCH] 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. --- bumblebee/modules/deadbeef.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bumblebee/modules/deadbeef.py b/bumblebee/modules/deadbeef.py index 8616fa4..5b74933 100644 --- a/bumblebee/modules/deadbeef.py +++ b/bumblebee/modules/deadbeef.py @@ -76,6 +76,13 @@ class Module(bumblebee.engine.Module): engine.input.register_callback(self, button=buttons[pause_button], 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 def deadbeef(self, widget): return self.string_song @@ -92,13 +99,12 @@ class Module(bumblebee.engine.Module): self._song = "error" def update_tf(self, widgets): - if not self._show_tf_when_stopped: - ## check if the player is paused or playing - self.now_playing_tf[-1] = "%isplaying%%ispaused%" - data = read_process(self.now_playing_tf) - if data == "": - self._song = "" - return + ## ensure that deadbeef is actually running + ## easiest way to do this is to check --nowplaying for + ## the string "nothing" + if read_process(self.now_playing) == "nothing": + self._song = "" + return ## perform the actual query -- these can be much more sophisticated self.now_playing_tf[-1] = self._tf_format data = read_process(self.now_playing_tf)