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

Add support for custom update checking logic #679

Closed

Conversation

henkelmax
Copy link
Contributor

This PR adds the ability for mods to add their own update checking logic.

Please let me know if you want anything changed.
I hope you consider merging this PR, because it would help modders add their own update checking logic, without needing to implementing their own GUI or notifications.
This would also help with compatibility across different mods having custom update checking logic.

The PR also allows for ModMenu to easily add more ways of checking for updates other than Modrinth.

Usage

In your ModMenuApi, implement the method getUpdateChecker:

@Override
public UpdateChecker getUpdateChecker() {
    return new MyUpdateChecker();
}

If this method returns null or is not implemented, ModMenu will work as always, checking updates using Modrinths API.
This custom update logic also still respects the disable_update_checker config option.

Implement your update checker:

public class MyUpdateChecker implements UpdateChecker {
    @Override
    public UpdateInfo checkForUpdates() {
        // The custom update checking logic goes here
    }
}

The UpdateInfo interface contains the information about available updates.

public class MyUpdateInfo implements UpdateInfo {

    @Override
    public boolean isUpdateAvailable() {
        // Return true if an update is available
    }

    @Override
    public @Nullable Text getUpdateMessage() {
        // Return a message to display when an update is available
        // If you don't implement this method, ModMenu will display a default message
    }

    @Override
    public @Nullable String getDownloadLink() {
        // Return a link to the download of the mod
        // If you don't implement this method, ModMenu will display a default message
    }

}

Screenshots

Here are some example screenshots:

Custom text but no download link provided
image

Custom text and download link provided
image

Download link provided, but no custom text provided
image

No custom text and no download link provided
image

@Prospector
Copy link
Member

While initially I didn't want to support this so that everyone has the same and trustworthy update-checking experience, I decided that I will merge this. I'm a little unsure about the option for there not to be a link available though. It seems like if it knows there's an update available it should tell you how to get it, right?

@haykam821
Copy link
Contributor

I think the 'Download link not available' text is a bit odd. If no download link continues to be supported in the API, I think it would make sense to provide a duplicate homepage link if one is available or simply not display the text if the mod does not define a homepage.

@henkelmax
Copy link
Contributor Author

While initially I didn't want to support this so that everyone has the same and trustworthy update-checking experience, I decided that I will merge this. I'm a little unsure about the option for there not to be a link available though. It seems like if it knows there's an update available it should tell you how to get it, right?

Sure, no problem, I'll change that.

@Prospector
Copy link
Member

I think I'm going to merge this into 1.20.3+ since it doesn't seem like 1.20.2 is a super widely used version at this point (at least, 1.20.1 and 1.19.2 are way more used)

@Prospector Prospector changed the base branch from 1.20.2 to 1.20.3 April 18, 2024 15:44
@Prospector
Copy link
Member

Rebased onto 1.20.3 on a different branch, PR here: #708

@Prospector Prospector closed this Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants