From c7f0f7a86038f41bd97c30d63fcfeb8152dcb774 Mon Sep 17 00:00:00 2001 From: ReBlast Date: Tue, 23 Apr 2024 20:25:33 +0500 Subject: [PATCH] feat: shut down connection in case it wasn't established within 15 seconds --- lua/cord.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lua/cord.lua b/lua/cord.lua index c1efda3e..6fdd197f 100644 --- a/lua/cord.lua +++ b/lua/cord.lua @@ -51,6 +51,7 @@ cord.config = { } local discord +local connection_tries = 0 local timer = vim.loop.new_timer() local enabled = false local is_focused = true @@ -155,6 +156,16 @@ local function update_presence(config, initial) timer:stop() timer:start(0, config.timer.interval, vim.schedule_wrap(function() update_presence(config, false) end)) end + else + connection_tries = connection_tries + 1 + if connection_tries == 16 then + vim.notify('[cord.nvim] Failed to connect to Discord within 15 seconds, shutting down connection', vim.log.levels.WARN) + connection_tries = 0 + timer:stop() + discord.disconnect() + enabled = false + last_presence = nil + end end elseif not update_idle_presence(config) then return