Conversation
CiiLu
commented
Mar 28, 2026
- 在下载列表、模组列表中跳转时,使用 Singleton
- 在模组下载弹窗中以“依赖项”/“可选”等项目跳转时,创建新实例
There was a problem hiding this comment.
Pull request overview
该 PR 优化版本管理相关的模组下载跳转流程:在下载列表/模组列表跳转时复用 ui.versions.DownloadPage 单例以减少实例创建;在依赖项/可选项等弹窗内部跳转时仍创建新实例以避免状态互相干扰。
Changes:
- 将下载列表、模组列表跳转到“模组版本下载页”改为复用
Controllers中缓存的ui.versions.DownloadPage实例,并通过loadMod(...)重载内容 - 将
ui.versions.DownloadPage从“构造即加载”改为“可复用实例 +loadMod(...)重新加载” - 在依赖项条目跳转时继续创建新的
ui.versions.DownloadPage实例并调用loadMod(...)
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java | 模组信息弹窗中跳转到下载页时改为使用单例页并调用 loadMod(...) |
| HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadPage.java | 将“按构造参数固定内容”改为“可复用页 + loadMod”,并调整加载状态重置与刷新逻辑 |
| HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java | 下载列表点击条目跳转到下载页时改为使用单例页并调用 loadMod(...) |
| HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java | 新增 getDownloadVersionListPage() 返回 ui.versions.DownloadPage 的 Lazy 单例,并补充 @FXThread 注解 |
Comments suppressed due to low confidence (2)
HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadPage.java:112
loadModVersions()starts an async load and unconditionally applies results inwhenComplete(...). WhenDownloadPageis reused as a singleton andloadMod(...)is called again before the previous task finishes, the earlier completion can overwritethis.versions/loaded/failedfor the new addon, causing the UI to show mismatched versions. Consider adding a request/generation token (increment perloadModVersionscall) and inwhenCompleteonly apply results if the token (or currentaddon/repository) still matches; alternatively cancel the previous task if your task framework supports it.
Task.supplyAsync(() -> {
Stream<RemoteMod.Version> versions = addon.getData().loadVersions(repository, page.getDownloadProvider());
return sortVersions(versions);
}).whenComplete(Schedulers.javafx(), (result, exception) -> {
if (exception == null) {
this.versions = result;
loaded.set(true);
setFailed(false);
} else {
setFailed(true);
}
setLoading(false);
}).start();
HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadPage.java:90
loadMod(...)mutates multiple JavaFX properties (loading,failed,loaded,state) and can trigger UI updates; it should be constrained to run on the FX thread to avoid undefined behavior. Consider annotating it with@FXThread(and/or assertingPlatform.isFxApplicationThread()), similar to other UI entrypoints inControllers.
public void loadMod(DownloadListPage page, RemoteMod addon, Profile.ProfileVersion version, @Nullable DownloadCallback callback) {
this.page = page;
this.repository = page.repository;
this.addon = addon;
this.translations = ModTranslations.getTranslationsByRepositoryType(repository.getType());
this.mod = translations.getModByCurseForgeId(addon.getSlug());
this.version = version;
this.callback = callback;
loadModVersions();
this.state.set(State.fromTitle(addon.getTitle()));
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private static Lazy<org.jackhuang.hmcl.ui.versions.DownloadPage> downloadVersionListPage = new Lazy<>(org.jackhuang.hmcl.ui.versions.DownloadPage::new); | ||
| private static DecoratorController decorator; |
There was a problem hiding this comment.
The identifier downloadVersionListPage is a bit misleading because it holds a ui.versions.DownloadPage (mod version details), not a list page. Consider renaming it (and the accessor) to something like downloadVersionPage/downloadModVersionPage to avoid confusion with DownloadListPage and ui.download.DownloadPage.
|
|
||
| // FXThread | ||
| @FXThread | ||
| public static org.jackhuang.hmcl.ui.versions.DownloadPage getDownloadVersionListPage() { |
There was a problem hiding this comment.
Method name getDownloadVersionListPage() suggests returning a list page, but it returns a ui.versions.DownloadPage instance. Renaming the method to match the actual UI concept (e.g., getDownloadVersionPage) would make call sites clearer.
| public static org.jackhuang.hmcl.ui.versions.DownloadPage getDownloadVersionListPage() { | |
| public static org.jackhuang.hmcl.ui.versions.DownloadPage getDownloadVersionPage() { |
|
真的有必要减少创建新实例?我觉得似乎意义不大。 |