-
Notifications
You must be signed in to change notification settings - Fork 814
feat+fix:为HMCL启动时添加“Switch Working Directory”并修复文档的一些语法错误 #5260
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
base: main
Are you sure you want to change the base?
Conversation
Added a confirmation dialog when unexpected folders (resourcepacks, saves, mods, shaderpacks, crash-report) are detected in the version root, prompting the user to switch to 'Isolated' mode. Updated I18N.properties with new dialog strings for this feature.
Replaces manual string concatenation with Path.of() using varargs for directory checks in the ROOT_FOLDER case, improving code readability and reliability.
Added logic to process the user's selection from the working directory switch alert dialog, updating the game directory type or returning the appropriate directory based on the chosen button.
## 问题描述 在后台线程中直接调用JavaFX的Alert组件会导致`IllegalStateException: Not on FX application thread`异常,影响程序稳定性。 ## 修改内容 - 将原有的直接Alert调用包装在`Platform.runLater()`中,确保UI操作在JavaFX应用程序线程执行 - 使用`CompletableFuture`在JavaFX线程和非JavaFX线程之间传递用户选择结果 - 保持原有的业务逻辑和对话框选项不变 - 添加异常处理,在对话框异常时使用默认值继续执行 ## 技术细节 1. 创建`CompletableFuture<ButtonData>`用于接收用户选择 2. 在`Platform.runLater()`中: - 创建Confirmation类型的Alert对话框 - 设置三个按钮选项:是、否、仅本次启动 - 使用`showAndWait()`等待用户响应 - 将用户选择的按钮数据传递给CompletableFuture 3. 在后台线程中使用`future.get()`阻塞等待用户选择 4. 根据按钮数据执行相应的目录设置逻辑 ## 影响范围 - 修复启动器在非JavaFX线程中询问工作目录切换的问题 - 确保线程安全的同时保持原有功能不变 - 提升程序在多线程环境下的稳定性 ## 测试要点 ✅ 在后台线程中调用此代码段能正常显示对话框 ✅ 对话框的三个按钮功能与之前一致 ✅ 异常情况下能使用默认值继续执行 ✅ 不会出现线程阻塞或死锁问题 ## 关联问题 修复了在多线程环境下可能导致的UI崩溃问题
burningtnt
left a comment
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.
粗略的(在没有真正看代码逻辑的情况下)看了一眼,我认为你这里有一堆问题需要改动。
此外,简体中文和繁体中文的翻译是必须的。如果你不能熟练使用繁体中文,可使用机器翻译提供初稿,并注明需要社区成员在 PR 合并前检查润色。
HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameLauncher.java
Outdated
Show resolved
Hide resolved
HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameLauncher.java
Outdated
Show resolved
Hide resolved
HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameLauncher.java
Outdated
Show resolved
Hide resolved
HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java
Outdated
Show resolved
Hide resolved
HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java
Outdated
Show resolved
Hide resolved
HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameLauncher.java
Outdated
Show resolved
Hide resolved
√ 已解决 |
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.
说实话,这个弹窗不是太美观,也不适配深色模式。可否改成下面列出的 PR 中更新的形式?
burningtnt
left a comment
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.
显然你关闭了根本没解决的问题。此外,如果你不了解相关语言,请不要翻译非完全支持语言(比如日语)
Co-authored-by: 3gf8jv4dv <3gf8jv4dv@gmail.com>
Co-authored-by: 3gf8jv4dv <3gf8jv4dv@gmail.com>
Co-authored-by: 3gf8jv4dv <3gf8jv4dv@gmail.com>
Co-authored-by: 3gf8jv4dv <3gf8jv4dv@gmail.com>
Co-authored-by: 3gf8jv4dv <3gf8jv4dv@gmail.com>
Co-authored-by: 3gf8jv4dv <3gf8jv4dv@gmail.com>
Co-authored-by: 3gf8jv4dv <3gf8jv4dv@gmail.com>
所以我就把这个弹窗做出来了,由于个人精力原因,暂只翻译了en_US、zh-Hant、zh-CN。原理是HMCLGameLauncher生成options.txt的函数(generateOptionsTxt)里getRunDirectory()时先检测repository是否instanceof HMCLGameRepository,再创建变量,再检测:
(代码写的有点烂,请见谅😳)
2. 修复文档的一些语法错误
起因是我在准备提交37a03fc时,发现JavaDoc写了个:
(原句)
限定词(determiner)和物主代词(possessive pronoun)不能一起用!
就顺手修了,修成了:
谁叫我爱MC,爱HMCL呢~