Skip to content

Commit

Permalink
feat: shut down connection in case it wasn't established within 15 se…
Browse files Browse the repository at this point in the history
…conds
  • Loading branch information
vyfor committed Apr 23, 2024
1 parent 3cb21e5 commit c7f0f7a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lua/cord.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c7f0f7a

Please sign in to comment.