Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elapsed time fixed for line numbers/no workspace #125

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions lua/presence/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ function Presence:get_buttons(buffer, parent_dirpath)
end

-- Update Rich Presence for the provided vim buffer
function Presence:update_for_buffer(buffer, should_debounce)
function Presence:update_for_buffer(buffer)
-- Avoid unnecessary updates if the previous activity was for the current buffer
-- (allow same-buffer updates when line numbers are enabled)
if self.options.enable_line_number == 0 and self.last_activity.file == buffer then
Expand Down Expand Up @@ -801,9 +801,8 @@ function Presence:update_for_buffer(buffer, should_debounce)
end

local activity_set_at = os.time()
-- If we shouldn't debounce and we trigger an activity, keep this value the same.
-- Otherwise set it to the current time.
local relative_activity_set_at = should_debounce and self.last_activity.relative_set_at or os.time()
-- Set the relative time if it does not already exist
local relative_activity_set_at = self.last_activity.relative_set_at or os.time()

self.log:debug(string.format("Setting activity for %s...", buffer and #buffer > 0 and buffer or "unnamed buffer"))

Expand Down Expand Up @@ -881,15 +880,15 @@ function Presence:update_for_buffer(buffer, should_debounce)

if self.workspaces[project_path] then
self.workspaces[project_path].updated_at = activity_set_at
activity.timestamps = self.options.show_time == 1 and {
start = self.workspaces[project_path].started_at,
} or nil
else
self.workspaces[project_path] = {
started_at = activity_set_at,
updated_at = activity_set_at,
}
end
activity.timestamps = self.options.show_time == 1 and {
start = self.workspaces[project_path].started_at,
} or nil
else
self.log:debug("No project detected")

Expand Down Expand Up @@ -954,10 +953,10 @@ Presence.update = Presence.discord_event(function(self, buffer, should_debounce)
end

if buffer then
self:update_for_buffer(buffer, should_debounce)
self:update_for_buffer(buffer)
else
vim.schedule(function()
self:update_for_buffer(self.get_current_buffer(), should_debounce)
self:update_for_buffer(self.get_current_buffer())
end)
end
end)
Expand Down