Skip to content

优化 DownloadPage#5871

Draft
CiiLu wants to merge 1 commit intoHMCL-dev:mainfrom
CiiLu:qwqwqwqwqwqwq
Draft

优化 DownloadPage#5871
CiiLu wants to merge 1 commit intoHMCL-dev:mainfrom
CiiLu:qwqwqwqwqwqwq

Conversation

@CiiLu
Copy link
Copy Markdown
Contributor

@CiiLu CiiLu commented Mar 28, 2026

  • 在下载列表、模组列表中跳转时,使用 Singleton
  • 在模组下载弹窗中以“依赖项”/“可选”等项目跳转时,创建新实例

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in whenComplete(...). When DownloadPage is reused as a singleton and loadMod(...) is called again before the previous task finishes, the earlier completion can overwrite this.versions/loaded/failed for the new addon, causing the UI to show mismatched versions. Consider adding a request/generation token (increment per loadModVersions call) and in whenComplete only apply results if the token (or current addon/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 asserting Platform.isFxApplicationThread()), similar to other UI entrypoints in Controllers.
    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.

Comment on lines +115 to 116
private static Lazy<org.jackhuang.hmcl.ui.versions.DownloadPage> downloadVersionListPage = new Lazy<>(org.jackhuang.hmcl.ui.versions.DownloadPage::new);
private static DecoratorController decorator;
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

// FXThread
@FXThread
public static org.jackhuang.hmcl.ui.versions.DownloadPage getDownloadVersionListPage() {
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
public static org.jackhuang.hmcl.ui.versions.DownloadPage getDownloadVersionListPage() {
public static org.jackhuang.hmcl.ui.versions.DownloadPage getDownloadVersionPage() {

Copilot uses AI. Check for mistakes.
@Glavo
Copy link
Copy Markdown
Member

Glavo commented Mar 30, 2026

真的有必要减少创建新实例?我觉得似乎意义不大。

@CiiLu CiiLu marked this pull request as draft March 30, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants