fix(download): cannot refresh mod download list. Mentioned in #1203.

This commit is contained in:
huanghongxun
2021-12-19 19:47:55 +08:00
parent ad5b260460
commit 3192d41fe3

View File

@@ -84,7 +84,12 @@ public class DownloadPage extends Control implements DecoratorPage {
this.mod = ModTranslations.getModByCurseForgeId(addon.getSlug()); this.mod = ModTranslations.getModByCurseForgeId(addon.getSlug());
this.version = version; this.version = version;
this.callback = callback; this.callback = callback;
loadModVersions();
this.state.set(State.fromTitle(addon.getTitle()));
}
private void loadModVersions() {
File versionJar = StringUtils.isNotBlank(version.getVersion()) File versionJar = StringUtils.isNotBlank(version.getVersion())
? version.getProfile().getRepository().getVersionJar(version.getVersion()) ? version.getProfile().getRepository().getVersionJar(version.getVersion())
: null; : null;
@@ -93,9 +98,9 @@ public class DownloadPage extends Control implements DecoratorPage {
setFailed(false); setFailed(false);
Task.allOf( Task.allOf(
Task.supplyAsync(() -> addon.getData().loadDependencies()), Task.supplyAsync(() -> addon.getData().loadDependencies()),
Task.supplyAsync(() -> { Task.supplyAsync(() -> {
Stream<RemoteMod.Version> versions = addon.getData().loadVersions(); Stream<RemoteMod.Version> versions = addon.getData().loadVersions();
// if (StringUtils.isNotBlank(version.getVersion())) { // if (StringUtils.isNotBlank(version.getVersion())) {
// Optional<String> gameVersion = GameVersion.minecraftVersion(versionJar); // Optional<String> gameVersion = GameVersion.minecraftVersion(versionJar);
// if (gameVersion.isPresent()) { // if (gameVersion.isPresent()) {
@@ -103,8 +108,8 @@ public class DownloadPage extends Control implements DecoratorPage {
// .filter(file -> file.getGameVersions().contains(gameVersion.get()))); // .filter(file -> file.getGameVersions().contains(gameVersion.get())));
// } // }
// } // }
return sortVersions(versions); return sortVersions(versions);
})) }))
.whenComplete(Schedulers.javafx(), (result, exception) -> { .whenComplete(Schedulers.javafx(), (result, exception) -> {
if (exception == null) { if (exception == null) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -122,8 +127,6 @@ public class DownloadPage extends Control implements DecoratorPage {
} }
setLoading(false); setLoading(false);
}).start(); }).start();
this.state.set(State.fromTitle(addon.getTitle()));
} }
private SimpleMultimap<String, RemoteMod.Version> sortVersions(Stream<RemoteMod.Version> versions) { private SimpleMultimap<String, RemoteMod.Version> sortVersions(Stream<RemoteMod.Version> versions) {
@@ -297,6 +300,7 @@ public class DownloadPage extends Control implements DecoratorPage {
return null; return null;
} }
}, getSkinnable().failedProperty())); }, getSkinnable().failedProperty()));
spinnerPane.setOnFailedAction(e -> getSkinnable().loadModVersions());
ComponentList list = new ComponentList(); ComponentList list = new ComponentList();
StackPane.setAlignment(list, Pos.TOP_CENTER); StackPane.setAlignment(list, Pos.TOP_CENTER);