mpc: Make a reconnect happen
Without this, the connection might "almost never" be reestablished. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
1c52a20221
commit
9a549bdd7b
|
@ -39,6 +39,7 @@ updates when the current MPD state changes.
|
|||
|
||||
local mpc = require("mpc")
|
||||
local textbox = require("wibox.widget.textbox")
|
||||
local timer = require("gears.timer")
|
||||
local mpd_widget = textbox()
|
||||
local state, title, artist, file = "stop", "", "", ""
|
||||
local function update_widget()
|
||||
|
@ -52,10 +53,15 @@ updates when the current MPD state changes.
|
|||
end
|
||||
mpd_widget.text = text
|
||||
end
|
||||
local connection
|
||||
local function error_handler(err)
|
||||
mpd_widget:set_text("Error: " .. tostring(err))
|
||||
-- Try a reconnect soon-ish
|
||||
timer.start_new(10, function()
|
||||
connection:send("ping")
|
||||
end)
|
||||
end
|
||||
local connection = mpc.new(nil, nil, nil, error_handler,
|
||||
connection = mpc.new(nil, nil, nil, error_handler,
|
||||
"status", function(_, result)
|
||||
state = result.state
|
||||
end,
|
||||
|
|
Loading…
Reference in New Issue