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

Idle timer #59

Open
Barragek0 opened this issue Dec 9, 2018 · 2 comments
Open

Idle timer #59

Barragek0 opened this issue Dec 9, 2018 · 2 comments
Labels
feature request This issue proposes a new feature help wanted Extra attention is needed

Comments

@Barragek0
Copy link

Barragek0 commented Dec 9, 2018

The option to remove rich presence if you stopped editing the code or were tabbed out of eclipse for 5-10 minutes and have it re-enabled when you're actively working on the file again would be a great feature to add.

@Barragek0 Barragek0 changed the title An 'idle timer' would be great Idle timer Dec 9, 2018
@echebbi echebbi self-assigned this Dec 15, 2018
@echebbi echebbi added the feature request This issue proposes a new feature label Dec 15, 2018
@echebbi
Copy link
Owner

echebbi commented Dec 15, 2018

Great idea, I will work on it!

@echebbi echebbi removed their assignment Apr 14, 2019
@echebbi echebbi added the help wanted Extra attention is needed label Apr 14, 2019
@echebbi
Copy link
Owner

echebbi commented Apr 14, 2019

I actually don't have the time to implement this right now. If anyone wants to submit a PR, here are my advices.

Add corresponding preferences

In order to let the user customize its experience, the following preferences should be added:

  • (boolean) stop Rich Presence when Eclipse IDE is minized
  • (boolean) stop Rich Presence when no file has been edited during a given delay
  • (int) the delay after which Rich Presence is stopped when no file has been edited

That requires:

  • adding corresponding fields to the fr.kazejiyu.discord.rpc.integration.settings.Settings enumeration
  • adding corresponding getters to the fr.kazejiyu.discord.rpc.integration.settings.UserPreferences interface.

The preferences pages can be updated by modifying:

  • fr.kazejiyu.discord.rpc.integration.ui.preferences.DiscordIntegrationPreferencesPage
  • fr.kazejiyu.discord.rpc.integration.ui.preferences.properties.ProjectPropertiesPage

Disable the Rich Presence when Eclipse IDE is minimized

Determine when Eclipse IDE is minimized

This can be achieved by implementing an IWindowListener. I would advise to do register it in the Activator as done here.

Actually hide / show the Rich Presence on minimize / maximize

Here is a naive implementation of the listener:

public class ShutdownDiscordOnMinimize implements IWindowListener {
    
    private final UserPreferences preferences;
    private final DiscordRpcLifecycle discord;
    private final FileChangeListener fileChangeListener;

    @Override
    public void windowActivated(IWorkbenchWindow window) {
        if (preferences.shouldHideDiscordOnMinimize()) {
            discord.initialize();
            // Shows info about current file on Discord
            fileChangeListener.notifyDiscordWithActivePart();
        }
    }

    @Override
    public void windowDeactivated(IWorkbenchWindow window) {
        if (preferences.shouldHideDiscordOnMinimize()) {
            discord.shutdown();
        }
    }
}

Hide the Rich Presence when no edition has been done during a given delay

Listen for edition

First of all, we have to know when the user is typing. Here are some clues:

The FileChangeListener.selectionChanged method is called each time a new file is selected by the user, so it may be the best place to put the listener.

Update the Rich Presence

Calling discord.shutdown() should be enough to hide the Rich Presence when the timer timeouts.
Calling

discord.initialize();
fileChangeListener.updateDiscord();

should allow to show the Rich Presence again.

Update the behavior when preferences change

When the user changes its preferences from the UI they should be taken into account immediately.

It requires the following changes:

  • update the fr.kazejiyu.discord.rpc.integration.settings.GlobalPreferencesListener class to take the new preferences into account
  • update the fr.kazejiyu.discord.rpc.integration.settings.ProjectPreferencesListener class to take the new preferences into account
  • add a listener that monitor preferences changes (such as here) in order to update the Rich Presence if needed (e.g. when the user has not typed in a while and activates the Hide Rich Presence after X times preference).

Test

Unit tests must ensure the good behavior of core features. UI features should at least be manually tested.

Contributing guide

Also see the contributing guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request This issue proposes a new feature help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants