Files
bjarneo--cliamp/plugins/status-messages.lua
T
wehub-resource-sync ead81af521
Deploy to GitHub Pages / deploy (push) Failing after 0s
CI / go (push) Has been cancelled
CI / build (darwin, macos-14) (push) Has been cancelled
CI / build (windows, windows-2025) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:13 +08:00

44 lines
1.2 KiB
Lua

-- status-messages.lua — Demo of cliamp.message(): surface playback events
-- as transient messages in the status bar at the bottom of the UI.
--
-- Install by copying (or symlinking) this file to ~/.config/cliamp/plugins/
-- and restart cliamp.
local p = plugin.register({
name = "status-messages",
type = "hook",
description = "Show playback events in the status bar",
})
p:on("app.start", function()
cliamp.message("cliamp ready", 2)
end)
p:on("track.change", function(track)
local text = track.title or ""
if track.artist and track.artist ~= "" then
text = track.artist .. " — " .. text
end
cliamp.message("Now playing: " .. text, 3)
end)
-- playback.state fires on every tick (~1Hz) during playback, not just on
-- state transitions. Track the last status locally so the status bar is
-- only updated when it actually changes.
local last_status = nil
p:on("playback.state", function(ev)
if ev.status == last_status then
return
end
last_status = ev.status
if ev.status == "paused" then
cliamp.message("Paused", 1.5)
elseif ev.status == "stopped" then
cliamp.message("Stopped", 1.5)
end
end)
p:on("track.scrobble", function()
cliamp.message("Scrobble sent", 2)
end)