+function widget:popup_oneshot(timeout)
+ if self._notification then
+ self:popup_update()
+ self:popup_hide(5)
+ else
+ self:popup_show()
+ self:popup_hide(5)
+ end
+end
+
+function widget:error_handler(err)
+ self._textbox:set_text("Error: " .. tostring(err))
+ timer.start_new(10, function()
+ self._connection:send("ping")
+ end)
+end
+
+function widget:run()
+ self._connection = mpc.new(nil, nil, nil, function(err) self:error_handler(err) end,
+ "status", function(_, result)
+ if not self._status or result.state ~= self._status.state then
+ self._status = result
+ self:update_widget()
+ self:popup_oneshot(5)
+ end
+ end,
+ "currentsong", function(_, result)
+ if not self._currentsong or result.id ~= self._currentsong.id then
+ self._currentsong = result
+ self:update_widget()
+ self:popup_oneshot(5)
+ end
+ end
+ )
+