commit
8387668e9c
|
@ -76,9 +76,9 @@ function mpc:_connect()
|
|||
self._input:read_line_async(GLib.PRIORITY_DEFAULT, nil, function(obj, res)
|
||||
local line, err = obj:read_line_finish(res)
|
||||
-- Ugly API. On success we get string, length-of-string
|
||||
-- and on error we get nil, error
|
||||
--if tostring(line) == "" and err == 1 then
|
||||
if tostring(line) == "" then
|
||||
-- and on error we get nil, error. Other versions of lgi
|
||||
-- behave differently.
|
||||
if line == nil or tostring(line) == "" then
|
||||
err = "Connection closed"
|
||||
end
|
||||
if type(err) ~= "number" then
|
||||
|
@ -95,9 +95,10 @@ function mpc:_connect()
|
|||
else
|
||||
arg = { line }
|
||||
end
|
||||
self._reply_handlers[1](success, arg)
|
||||
local handler = self._reply_handlers[1]
|
||||
table.remove(self._reply_handlers, 1)
|
||||
self._pending_reply = {}
|
||||
handler(success, arg)
|
||||
else
|
||||
local _, _, key, value = string.find(line, "([^:]+):%s(.+)")
|
||||
if key then
|
||||
|
|
|
@ -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