-
Notifications
You must be signed in to change notification settings - Fork 903
[Bugfix] 修复导出整合包文件选择界面UI线程阻塞 #6363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ToobLac
wants to merge
1
commit into
HMCL-dev:main
Choose a base branch
from
ToobLac:fix/6354
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+19
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,8 +29,10 @@ | |
| import javafx.scene.layout.HBox; | ||
| import org.jackhuang.hmcl.game.HMCLGameRepository; | ||
| import org.jackhuang.hmcl.modpack.ModAdviser; | ||
| import org.jackhuang.hmcl.task.Schedulers; | ||
| import org.jackhuang.hmcl.ui.FXUtils; | ||
| import org.jackhuang.hmcl.ui.construct.NoneMultipleSelectionModel; | ||
| import org.jackhuang.hmcl.ui.construct.SpinnerPane; | ||
| import org.jackhuang.hmcl.ui.wizard.WizardController; | ||
| import org.jackhuang.hmcl.ui.wizard.WizardPage; | ||
| import org.jackhuang.hmcl.util.Pair; | ||
|
|
@@ -44,6 +46,7 @@ | |
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| import static org.jackhuang.hmcl.ui.FXUtils.onEscPressed; | ||
| import static org.jackhuang.hmcl.util.Lang.mapOf; | ||
|
|
@@ -58,27 +61,37 @@ public final class ModpackFileSelectionPage extends BorderPane implements Wizard | |
| private final WizardController controller; | ||
| private final String version; | ||
| private final ModAdviser adviser; | ||
| private final ModpackFileTreeItem rootNode; | ||
| private ModpackFileTreeItem rootNode; | ||
|
|
||
| public ModpackFileSelectionPage(WizardController controller, HMCLGameRepository repository, String version, ModAdviser adviser) { | ||
| this.controller = controller; | ||
| this.version = version; | ||
| this.adviser = adviser; | ||
|
|
||
| JFXTreeView<String> treeView = new JFXTreeView<>(); | ||
| rootNode = getTreeItem(repository.getRunDirectory(version), "minecraft", 0); | ||
| treeView.setRoot(rootNode); | ||
| treeView.setSelectionModel(new NoneMultipleSelectionModel<>()); | ||
| onEscPressed(treeView, () -> controller.onPrev(true)); | ||
| setMargin(treeView, new Insets(10, 10, 5, 10)); | ||
| this.setCenter(treeView); | ||
|
|
||
| SpinnerPane spinnerPane = new SpinnerPane(); | ||
| spinnerPane.setContent(treeView); | ||
| setMargin(spinnerPane, new Insets(10, 10, 5, 10)); | ||
| this.setCenter(spinnerPane); | ||
|
|
||
| spinnerPane.setLoading(true); | ||
| CompletableFuture | ||
| .supplyAsync(() -> getTreeItem(repository.getRunDirectory(version), "minecraft", 0), Schedulers.io()) | ||
| .thenAcceptAsync(modpackFileTreeItem -> { | ||
| treeView.setRoot(rootNode = modpackFileTreeItem); | ||
| spinnerPane.setLoading(false); | ||
| }, Schedulers.javafx()); | ||
|
|
||
| HBox nextPane = new HBox(); | ||
| nextPane.setPadding(new Insets(16, 16, 16, 0)); | ||
| nextPane.setAlignment(Pos.CENTER_RIGHT); | ||
| { | ||
| JFXButton btnNext = FXUtils.newRaisedButton(i18n("wizard.next")); | ||
| btnNext.setPrefSize(100, 40); | ||
| btnNext.disableProperty().bind(spinnerPane.loadingProperty()); | ||
| btnNext.setOnAction(e -> onNext()); | ||
|
|
||
| nextPane.getChildren().setAll(btnNext); | ||
|
|
@@ -176,6 +189,7 @@ public void cleanup(SettingsMap settings) { | |
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 当游戏目录不存在、为空或所有内容均被过滤时, |
||
| private void onNext() { | ||
| if (rootNode == null) return; | ||
| ArrayList<String> list = new ArrayList<>(); | ||
| getFilesNeeded(rootNode, "minecraft", list); | ||
| controller.getSettings().put(MODPACK_FILE_SELECTION, list); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当遍历期间出现
UncheckedIOException等异常时,CompletableFuture会异常完成,导致thenAcceptAsync完全不执行;此时spinnerPane永远保持加载状态,“下一步”也始终禁用,且异常不会被记录或展示。应添加异常完成处理,在 JavaFX 线程中结束加载状态并向用户报告或允许重试。