Fix for double signals

What I've found while using dbus-monitor is that playerctl sends a bunch of messages whenever media is changed, with the first one always having the artUrl empty.
If the media does have an artUrl, the next messages will contain the artUrl resulting in artUrl ~= last_artUrl becoming true and triggering another signal
The hacky method in the commit will only trigger a new signal if artUrl is not empty, or on the second message sent (as some media don't provide any art)
This commit is contained in:
Ksaper 2021-07-25 15:08:06 +03:00
parent e74671094a
commit aa052398a2
1 changed files with 5 additions and 2 deletions

View File

@ -74,6 +74,7 @@ local last_player = nil
local last_title = "" local last_title = ""
local last_artist = "" local last_artist = ""
local last_artUrl = "" local last_artUrl = ""
local index = 0
local function metadata_cb(player, metadata) local function metadata_cb(player, metadata)
if update_on_activity then if update_on_activity then
manager:move_player_to_top(player) manager:move_player_to_top(player)
@ -95,8 +96,9 @@ local function metadata_cb(player, metadata)
if player == manager.players[1] then if player == manager.players[1] then
-- Callback can be called even though values we care about haven't -- Callback can be called even though values we care about haven't
-- changed, so check to see if they have -- changed, so check to see if they have
if player ~= last_player or title ~= last_title or index = index + 1
artist ~= last_artist or artUrl ~= last_artUrl if (player ~= last_player or title ~= last_title or
artist ~= last_artist) and (artUrl ~= "" or index == 2)
then then
if artUrl ~= "" then if artUrl ~= "" then
awful.spawn.with_line_callback(get_album_art(artUrl), { awful.spawn.with_line_callback(get_album_art(artUrl), {
@ -120,6 +122,7 @@ local function metadata_cb(player, metadata)
last_artist = artist last_artist = artist
last_artUrl = artUrl last_artUrl = artUrl
end end
if index == 2 then index = 0 end
end end
end end