Fix #4256: 修复游戏下载页面可能崩溃的问题 (#4257)

This commit is contained in:
Glavo
2025-08-13 16:14:26 +08:00
committed by GitHub
parent a705b7cf95
commit 5118ce4e62

View File

@@ -74,7 +74,6 @@ public final class VersionsPage extends Control implements WizardPage, Refreshab
private final Navigation navigation; private final Navigation navigation;
private final VersionList<?> versionList; private final VersionList<?> versionList;
private final Runnable callback; private final Runnable callback;
private Task<?> task;
private final ObservableList<RemoteVersion> versions = FXCollections.observableArrayList(); private final ObservableList<RemoteVersion> versions = FXCollections.observableArrayList();
private final ObjectProperty<Status> status = new SimpleObjectProperty<>(Status.LOADING); private final ObjectProperty<Status> status = new SimpleObjectProperty<>(Status.LOADING);
@@ -98,7 +97,7 @@ public final class VersionsPage extends Control implements WizardPage, Refreshab
@Override @Override
public void refresh() { public void refresh() {
status.set(Status.LOADING); status.set(Status.LOADING);
task = versionList.refreshAsync(gameVersion) Task<?> task = versionList.refreshAsync(gameVersion)
.thenSupplyAsync(() -> versionList.getVersions(gameVersion).stream().sorted().collect(Collectors.toList())) .thenSupplyAsync(() -> versionList.getVersions(gameVersion).stream().sorted().collect(Collectors.toList()))
.whenComplete(Schedulers.javafx(), (items, exception) -> { .whenComplete(Schedulers.javafx(), (items, exception) -> {
if (exception == null) { if (exception == null) {
@@ -120,8 +119,6 @@ public final class VersionsPage extends Control implements WizardPage, Refreshab
@Override @Override
public void cleanup(Map<String, Object> settings) { public void cleanup(Map<String, Object> settings) {
settings.remove(libraryId); settings.remove(libraryId);
if (task != null)
task.executor().cancel();
} }
private void onRefresh() { private void onRefresh() {