]> git.rmz.io Git - dotfiles.git/commitdiff
awesome/mpc: use a keep alive timer instead of ping on error
authorSamir Benmendil <me@rmz.io>
Mon, 18 Jan 2021 23:49:47 +0000 (23:49 +0000)
committerSamir Benmendil <me@rmz.io>
Sun, 24 Jan 2021 21:35:32 +0000 (21:35 +0000)
Basically just test if we are connected every second and reconnect if we
are not.

awesome/widgets/mpc.lua
awesome/widgets/mpd_widget.lua

index bd64fa85b4f6adfd2b5df9bf085b00d6411806ea..2ef26b503f94d8f36509678d2f2a85b00484c738 100644 (file)
@@ -32,7 +32,7 @@ function mpc.new(host, port, password, error_handler, ...)
         _try_reconnect = false,
         _idle_subsystems = { ... }
     }, { __index = mpc })
-    self:_connect()
+    self:connect()
     return self
 end
 
@@ -52,7 +52,7 @@ function mpc:_error(err)
     end
 end
 
-function mpc:_connect()
+function mpc:connect()
     if self._connected then return end
     -- Reset all of our state
     self._reply_handlers = {}
@@ -197,7 +197,7 @@ function mpc:_send(command, callback)
 end
 
 function mpc:send(...)
-    self:_connect()
+    self:connect()
     if not self._connected then
         return
     end
index 24e4cd27f7422d68f08c3b76a98f7654f938195e..2e4b215a0ad5ccf9989075c2e290f816f5f5bd8a 100644 (file)
@@ -137,9 +137,7 @@ end
 
 function widget:error_handler(err)
     self._textbox:set_text("Error: " .. tostring(err))
-    timer.start_new(10, function()
-        self._connection:send("ping")
-    end)
+    self._status = {}
 end
 
 function widget:run()
@@ -172,6 +170,13 @@ function widget:run()
         end
     )
 
+    self._keep_alive_timer = timer {
+      timeout = 1
+    , autostart = true
+    , callback = function() self._connection:connect() end
+    , call_now = true
+    }
+
     self._timer = timer({ timeout = 1 })
     self._timer:connect_signal("timeout", function() self:popup_update() end)