Skip to content

Commit

Permalink
Pass user preferred update channel to UpdateChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Apr 18, 2024
1 parent a3c203a commit 2cb269a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.terraformersmc.modmenu.api;

/**
* Supported update channels, in ascending order by stability.
*/
public enum UpdateChannel {
ALPHA,
BETA,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.terraformersmc.modmenu.api;

public interface UpdateChecker {

/**
* Gets called when ModMenu is checking for updates.
* This is done in a separate thread, so this call can/should be blocking.
*
* Your update checker should aim to return an update on the same or a more stable channel than requested.
*
* @param updateChannel The end user's preferred update channel.
* @return The update info
*/
UpdateInfo checkForUpdates();

UpdateInfo checkForUpdates(UpdateChannel updateChannel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ public static void checkForUpdates() {
}

public static void checkForCustomUpdates() {
UpdateChannel preferredChannel = ModMenuConfig.UPDATE_CHANNEL.getValue();

ModMenu.MODS.values().stream().filter(UpdateCheckerUtil::allowsUpdateChecks).forEach(mod -> {
UpdateChecker updateChecker = mod.getUpdateChecker();
if (updateChecker == null) {
return;
}
UpdateCheckerThread.run(mod, () -> mod.setUpdateInfo(updateChecker.checkForUpdates()));
UpdateCheckerThread.run(mod, () -> mod.setUpdateInfo(updateChecker.checkForUpdates(preferredChannel)));
});
}

Expand Down

0 comments on commit 2cb269a

Please sign in to comment.