From 9a549bdd7badfc5c9468db09c65cbeed672868f8 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 29 Jan 2017 11:57:10 +0100 Subject: [PATCH] mpc: Make a reconnect happen Without this, the connection might "almost never" be reestablished. Signed-off-by: Uli Schlachter --- recipes/mpc.mdwn | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/recipes/mpc.mdwn b/recipes/mpc.mdwn index 4bcc881..568ddd5 100644 --- a/recipes/mpc.mdwn +++ b/recipes/mpc.mdwn @@ -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,