From 2cb269a256d2448a2a9b6f04a452b1f002712bf5 Mon Sep 17 00:00:00 2001 From: LostLuma Date: Tue, 16 Apr 2024 20:34:30 +0200 Subject: [PATCH] Pass user preferred update channel to UpdateChecker --- .../java/com/terraformersmc/modmenu/api/UpdateChannel.java | 3 +++ .../java/com/terraformersmc/modmenu/api/UpdateChecker.java | 7 ++++--- .../com/terraformersmc/modmenu/util/UpdateCheckerUtil.java | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/terraformersmc/modmenu/api/UpdateChannel.java b/src/main/java/com/terraformersmc/modmenu/api/UpdateChannel.java index ffe800ec..533ce5dc 100644 --- a/src/main/java/com/terraformersmc/modmenu/api/UpdateChannel.java +++ b/src/main/java/com/terraformersmc/modmenu/api/UpdateChannel.java @@ -1,5 +1,8 @@ package com.terraformersmc.modmenu.api; +/** + * Supported update channels, in ascending order by stability. + */ public enum UpdateChannel { ALPHA, BETA, diff --git a/src/main/java/com/terraformersmc/modmenu/api/UpdateChecker.java b/src/main/java/com/terraformersmc/modmenu/api/UpdateChecker.java index 1c2aa231..f9e8956f 100644 --- a/src/main/java/com/terraformersmc/modmenu/api/UpdateChecker.java +++ b/src/main/java/com/terraformersmc/modmenu/api/UpdateChecker.java @@ -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); } diff --git a/src/main/java/com/terraformersmc/modmenu/util/UpdateCheckerUtil.java b/src/main/java/com/terraformersmc/modmenu/util/UpdateCheckerUtil.java index fc39d28a..7a7dc93b 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/UpdateCheckerUtil.java +++ b/src/main/java/com/terraformersmc/modmenu/util/UpdateCheckerUtil.java @@ -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))); }); }