Skip to content

Commit

Permalink
Mention new loader version in loader update info
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Apr 24, 2024
1 parent 8798223 commit 759daa1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -20,6 +21,7 @@
import net.fabricmc.loader.api.SemanticVersion;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.VersionParsingException;
import net.minecraft.text.Text;

public class FabricLoaderUpdateChecker implements UpdateChecker {
public static final Logger LOGGER = LoggerFactory.getLogger("Mod Menu/Fabric Update Checker");
Expand Down Expand Up @@ -111,7 +113,7 @@ private static UpdateInfo checkForUpdates0() throws IOException, InterruptedExce
}

LOGGER.debug("Fabric Loader has a matching update available!");
return new FabricLoaderUpdateInfo(stableVersion);
return new FabricLoaderUpdateInfo(match.getFriendlyString(), stableVersion);
}

private static boolean isNewer(Version self, Version other) {
Expand All @@ -123,9 +125,11 @@ private static Version getCurrentVersion() {
}

private static class FabricLoaderUpdateInfo implements UpdateInfo {
private final String version;
private final boolean isStable;

private FabricLoaderUpdateInfo(boolean isStable) {
private FabricLoaderUpdateInfo(String version, boolean isStable) {
this.version = version;
this.isStable = isStable;
}

Expand All @@ -134,6 +138,11 @@ public boolean isUpdateAvailable() {
return true;
}

@Override
public @Nullable Text getUpdateMessage() {
return Text.translatable("modmenu.install_version", this.version);
}

@Override
public String getDownloadLink() {
return "https://fabricmc.net/use/installer";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

import org.jetbrains.annotations.Nullable;
import org.quiltmc.loader.api.QuiltLoader;
import org.quiltmc.loader.api.Version;
import org.quiltmc.loader.api.VersionFormatException;
Expand All @@ -18,6 +19,8 @@
import com.terraformersmc.modmenu.util.HttpUtil;
import com.terraformersmc.modmenu.util.JsonUtil;

import net.minecraft.text.Text;

public class QuiltLoaderUpdateChecker implements UpdateChecker {
public static final Logger LOGGER = LoggerFactory.getLogger("Mod Menu/Quilt Update Checker");
private static final URI LOADER_VERSIONS = URI.create("https://meta.quiltmc.org/v3/versions/loader");
Expand Down Expand Up @@ -105,19 +108,7 @@ private static UpdateInfo checkForUpdates0() throws IOException, InterruptedExce
}

LOGGER.debug("Quilt Loader has a matching update available!");

UpdateChannel updateChannel;
var preRelease = match.preRelease();

if (preRelease.isEmpty()) {
updateChannel = UpdateChannel.RELEASE;
} else if (isStableOrBeta(preRelease)) {
updateChannel = UpdateChannel.BETA;
} else {
updateChannel = UpdateChannel.ALPHA;
}

return new QuiltLoaderUpdateInfo(updateChannel);
return new QuiltLoaderUpdateInfo(match);
}

private static boolean isNewer(Version.Semantic self, Version.Semantic other) {
Expand All @@ -133,25 +124,38 @@ private static boolean isStableOrBeta(String preRelease) {
}

private static class QuiltLoaderUpdateInfo implements UpdateInfo {
private final UpdateChannel updateChannel;
private final Version.Semantic version;

private QuiltLoaderUpdateInfo(UpdateChannel updateChannel) {
this.updateChannel = updateChannel;
private QuiltLoaderUpdateInfo(Version.Semantic version) {
this.version = version;
}

@Override
public boolean isUpdateAvailable() {
return true;
}

@Override
public @Nullable Text getUpdateMessage() {
return Text.translatable("modmenu.install_version", this.version.raw());
}

@Override
public String getDownloadLink() {
return "https://quiltmc.org/en/install/client";
}

@Override
public UpdateChannel getUpdateChannel() {
return this.updateChannel;
var preRelease = this.version.preRelease();

if (preRelease.isEmpty()) {
return UpdateChannel.RELEASE;
} else if (isStableOrBeta(preRelease)) {
return UpdateChannel.BETA;
} else {
return UpdateChannel.ALPHA;
}
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/modmenu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"modmenu.experimental": "(Mod Menu update checker is experimental!)",
"modmenu.childHasUpdate": "A child of this mod has an update available.",
"modmenu.updateText": "v%s on %s",
"modmenu.install_version": "Install version %s",
"modmenu.downloadLink": "Download",

"modmenu.buymeacoffee": "Buy Me a Coffee",
Expand Down

0 comments on commit 759daa1

Please sign in to comment.