Override player segment in case of inactive player

Let's say if the player is stopped (means the player has no track
queued), the player segment will still keep displaying the string
consisting just of the player status symbol ("stop" symbol) and
any other constants present in the `format` parameter.

With this commit, the new parameter `player_inactive_override` will
take over the player segment display in cases where the player is
stopped and with no tracks in queue.

If `player_inactive_override` is `None` (defaults), it will
maintain the previous behaviour (backwards compatibility).
This commit is contained in:
Ritiek Malhotra 2020-12-28 19:56:14 +05:30
parent 50d73bfbc8
commit ea8a9fb875

View File

@ -37,7 +37,7 @@ def _convert_seconds(seconds):
class PlayerSegment(Segment):
def __call__(self, format='{state_symbol} {artist} - {title} ({total})', state_symbols=STATE_SYMBOLS, **kwargs):
def __call__(self, format='{state_symbol} {artist} - {title} ({total})', state_symbols=STATE_SYMBOLS, player_inactive_override=None, **kwargs):
stats = {
'state': 'fallback',
'album': None,
@ -51,8 +51,12 @@ class PlayerSegment(Segment):
return None
stats.update(func_stats)
stats['state_symbol'] = state_symbols.get(stats['state'])
player_string = format.format(**stats)
player_inactive = stats["state"] == "stop" and not stats["artist"] and not stats["title"]
if player_inactive and player_inactive_override is not None:
player_string = str(player_inactive_override)
return [{
'contents': format.format(**stats),
'contents': player_string,
'highlight_groups': ['player_' + (stats['state'] or 'fallback'), 'player'],
}]