Skip to content

Commit

Permalink
Change method of getting the preferred update channel
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Apr 18, 2024
1 parent 2cb269a commit b6b699b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
11 changes: 10 additions & 1 deletion src/main/java/com/terraformersmc/modmenu/api/UpdateChannel.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package com.terraformersmc.modmenu.api;

import com.terraformersmc.modmenu.config.ModMenuConfig;

/**
* Supported update channels, in ascending order by stability.
*/
public enum UpdateChannel {
ALPHA,
BETA,
RELEASE,
RELEASE;

/**
* @return the user's preferred update channel.
*/
public UpdateChannel getUserPreference() {
return ModMenuConfig.UPDATE_CHANNEL.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ 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.
* <p>Your update checker should aim to return an update on the same or a more stable channel than the user's preference which you can get via {@link UpdateChannel#getUserPreference()}.</p>
*
* @param updateChannel The end user's preferred update channel.
* @return The update info
*/
UpdateInfo checkForUpdates(UpdateChannel updateChannel);
UpdateInfo checkForUpdates();
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ 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(preferredChannel)));
UpdateCheckerThread.run(mod, () -> mod.setUpdateInfo(updateChecker.checkForUpdates()));
});
}

Expand Down

0 comments on commit b6b699b

Please sign in to comment.