presence.nvim icon indicating copy to clipboard operation
presence.nvim copied to clipboard

Stop sending updates after x time of idling

Open mercxry opened this issue 4 years ago • 8 comments

Hello, would it be possible to add a setting to stop sending updates to discord presence after x seconds/minutes of idling?

Thank you for doing my previous request so quickly 😁

mercxry avatar Oct 26 '21 21:10 mercxry

Hi @mercxry! If I'm understanding correctly, what you're suggesting is a configuration option to expire/cancel a file's Rich Presence after some timeout, right?

I think that's a good idea, I have seen some weird looking Rich Presence activity when putting my computer to sleep overnight, like 10:12:47 elapsed (which basically says I've been editing 10 hours... 😅). It might make more sense to have it as the default behavior actually, and allow users to configure the timeout value.

Is this what you were suggesting?

andweeb avatar Oct 29 '21 18:10 andweeb

Yes, a VSCode extension that I use has the "Idling" state, but if it's not too much I would like to have a way to cancel the state (so it doesn't show nvim at all in the activity tab) until I start typing again.

I have the same problem, I rarely shut down my computer and I always keep nvim open in my terminal so I get high editing times like you.

mercxry avatar Oct 29 '21 19:10 mercxry

I would also like to have something like this.

If you are set on a way this should be implemented, I would also be interested in implementing it.

I would like to have a timeout value that just says after Neovim was not in focus for 5 minutes stop showing the presence (this also means the automatic game presence would kick in) but when Neovim is refocused it should start with the time before it paused.

So that if you edit for 2h, take a 40-min break, and then continue to work it would start at 2h (2:05h technically due to timeout time).

ModProg avatar Jul 18 '22 17:07 ModProg

Hi @ModProg, thanks for the interest in contributing!

I did start on this feature a while ago, but I haven't had time to work on it since like... earlier this year unfortunately :'). You can see the card I've cut out for this here:

[Feature] Idle activity: Set special activity when idle

  • [x] Add configs for idle activity
    • idling_text - text
    • idle_timeout - number
    • idle_treatment - 'update' | 'cancel' | nil (default: 'update')
  • [ ] Set idle activity after timeout when idle_treatment == 'update'
  • [ ] Cancel Rich Presence after timeout when idle_treatment == 'cancel'
  • [x] Add CursorMoved event
  • [x] Find and upload idle asset

You can see that it actually also includes the behavior you're requesting with the concept of "idle treatment" options:

  • update - showing an "Idling..." status on Discord (what @mercxry has in mind)
  • cancel - canceling Rich Presence until nvim is used again (what you have in mind)
  • nil - disabling any idle treatment, i.e. the current behavior of just allowing the Rich Presence to hang indefinitely while nvim is open

Regarding the elapsed time, I agree with what you've outlined! What I envisioned for the Idle activity would be the same as well: show edit status for 2h, show idle status for 40min, and show edit status for 2h + timeout value when the user refocuses on nvim after idling.

As for the work itself, you might be able to build off of what I currently have scaffolded, but just FYI this may be a non-trivial change. The logic for idle timeout and listening on CursorMoved events for a single nvim buffer is one thing, but the logic to ensure consistency in shared state across potentially multiple, however, may be a little interesting (internally presence.nvim uses a local P2P network to distribute and sync state across Neovim instances).

I've just pushed my initial WIP changes to the feature/idle-treatment branch for you to check out. If the work sounds interesting to you, feel free to hit me up at droob#1322 on Discord! :)

andweeb avatar Jul 18 '22 19:07 andweeb

Alright, thanks for the extensive explanaition, I'll have a look on the weekend.

Is there a reason not to use FocusLost events for the cancel behaviour? grafik

ModProg avatar Jul 19 '22 06:07 ModProg

No pressure! :)

Is there a reason not to use FocusLost events for the cancel behaviour?

Good question. The FocusLost event would work for cases in which Neovim no longer has active focus (e.g. user minimizes the nvim window), but it wouldn't cover the case in which the user is focused on nvim and idling, specifically the scenarios that were discussed in the original comments:

  • User edits a file on nvim but goes afk
  • User edits a file on nvim but puts their laptop to sleep

That's why I started with using CursorMoved, as I'm not sure other events would fully capture what we need in order to start the idle timer. Let me know if you find a potentially better option, since the CursorMoved event has a pretty big caveat that it will be called very frequently, as noted in the helptext:

Careful: This is triggered very often, don't do anything that the user does not expect or that is slow.

andweeb avatar Jul 19 '22 07:07 andweeb

Maybe this can be a setting, as there is also the problem that some tiling terminals don't send FocusLost events.

ModProg avatar Jul 19 '22 08:07 ModProg