commit
8387668e9c
|
@ -76,9 +76,9 @@ function mpc:_connect()
|
||||||
self._input:read_line_async(GLib.PRIORITY_DEFAULT, nil, function(obj, res)
|
self._input:read_line_async(GLib.PRIORITY_DEFAULT, nil, function(obj, res)
|
||||||
local line, err = obj:read_line_finish(res)
|
local line, err = obj:read_line_finish(res)
|
||||||
-- Ugly API. On success we get string, length-of-string
|
-- Ugly API. On success we get string, length-of-string
|
||||||
-- and on error we get nil, error
|
-- and on error we get nil, error. Other versions of lgi
|
||||||
--if tostring(line) == "" and err == 1 then
|
-- behave differently.
|
||||||
if tostring(line) == "" then
|
if line == nil or tostring(line) == "" then
|
||||||
err = "Connection closed"
|
err = "Connection closed"
|
||||||
end
|
end
|
||||||
if type(err) ~= "number" then
|
if type(err) ~= "number" then
|
||||||
|
@ -95,9 +95,10 @@ function mpc:_connect()
|
||||||
else
|
else
|
||||||
arg = { line }
|
arg = { line }
|
||||||
end
|
end
|
||||||
self._reply_handlers[1](success, arg)
|
local handler = self._reply_handlers[1]
|
||||||
table.remove(self._reply_handlers, 1)
|
table.remove(self._reply_handlers, 1)
|
||||||
self._pending_reply = {}
|
self._pending_reply = {}
|
||||||
|
handler(success, arg)
|
||||||
else
|
else
|
||||||
local _, _, key, value = string.find(line, "([^:]+):%s(.+)")
|
local _, _, key, value = string.find(line, "([^:]+):%s(.+)")
|
||||||
if key then
|
if key then
|
||||||
|
|
|
@ -39,6 +39,7 @@ updates when the current MPD state changes.
|
||||||
|
|
||||||
local mpc = require("mpc")
|
local mpc = require("mpc")
|
||||||
local textbox = require("wibox.widget.textbox")
|
local textbox = require("wibox.widget.textbox")
|
||||||
|
local timer = require("gears.timer")
|
||||||
local mpd_widget = textbox()
|
local mpd_widget = textbox()
|
||||||
local state, title, artist, file = "stop", "", "", ""
|
local state, title, artist, file = "stop", "", "", ""
|
||||||
local function update_widget()
|
local function update_widget()
|
||||||
|
@ -52,10 +53,15 @@ updates when the current MPD state changes.
|
||||||
end
|
end
|
||||||
mpd_widget.text = text
|
mpd_widget.text = text
|
||||||
end
|
end
|
||||||
|
local connection
|
||||||
local function error_handler(err)
|
local function error_handler(err)
|
||||||
mpd_widget:set_text("Error: " .. tostring(err))
|
mpd_widget:set_text("Error: " .. tostring(err))
|
||||||
|
-- Try a reconnect soon-ish
|
||||||
|
timer.start_new(10, function()
|
||||||
|
connection:send("ping")
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
local connection = mpc.new(nil, nil, nil, error_handler,
|
connection = mpc.new(nil, nil, nil, error_handler,
|
||||||
"status", function(_, result)
|
"status", function(_, result)
|
||||||
state = result.state
|
state = result.state
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Reference in New Issue