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:
Uli Schlachter 2017-01-29 11:57:10 +01:00
parent 1c52a20221
commit 9a549bdd7b
1 changed files with 7 additions and 1 deletions

View File

@ -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,