From 588fe5cb5f6d500016cee5c8854471d61784dba7 Mon Sep 17 00:00:00 2001 From: Haowei Wen Date: Fri, 20 Aug 2021 01:44:40 +0800 Subject: [PATCH] fix: hide GameVersionList$1 task --- .../hmcl/download/game/GameVersionList.java | 46 ++++++++----------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameVersionList.java index d64553633..6e6cccee6 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameVersionList.java @@ -1,6 +1,6 @@ /* * Hello Minecraft! Launcher - * Copyright (C) 2020 huangyuhui and contributors + * Copyright (C) 2021 huangyuhui and contributors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,12 +21,13 @@ import org.jackhuang.hmcl.download.DownloadProvider; import org.jackhuang.hmcl.download.VersionList; import org.jackhuang.hmcl.task.GetTask; import org.jackhuang.hmcl.task.Task; -import org.jackhuang.hmcl.util.gson.JsonUtils; import org.jackhuang.hmcl.util.io.NetworkUtils; import java.util.Collection; import java.util.Collections; +import static org.jackhuang.hmcl.util.gson.JsonUtils.GSON; + /** * * @author huangyuhui @@ -50,33 +51,24 @@ public final class GameVersionList extends VersionList { @Override public Task refreshAsync() { - GetTask task = new GetTask(NetworkUtils.toURL(downloadProvider.getVersionListURL())); - return new Task() { - @Override - public Collection> getDependents() { - return Collections.singleton(task); - } + return new GetTask(NetworkUtils.toURL(downloadProvider.getVersionListURL())) + .thenAcceptAsync(json -> { + GameRemoteVersions root = GSON.fromJson(json, GameRemoteVersions.class); - @Override - public void execute() { - lock.writeLock().lock(); + lock.writeLock().lock(); + try { + versions.clear(); - try { - versions.clear(); - - GameRemoteVersions root = JsonUtils.GSON.fromJson(task.getResult(), GameRemoteVersions.class); - for (GameRemoteVersionInfo remoteVersion : root.getVersions()) { - versions.put(remoteVersion.getGameVersion(), new GameRemoteVersion( - remoteVersion.getGameVersion(), - remoteVersion.getGameVersion(), - Collections.singletonList(remoteVersion.getUrl()), - remoteVersion.getType(), remoteVersion.getReleaseTime()) - ); + for (GameRemoteVersionInfo remoteVersion : root.getVersions()) { + versions.put(remoteVersion.getGameVersion(), new GameRemoteVersion( + remoteVersion.getGameVersion(), + remoteVersion.getGameVersion(), + Collections.singletonList(remoteVersion.getUrl()), + remoteVersion.getType(), remoteVersion.getReleaseTime())); + } + } finally { + lock.writeLock().unlock(); } - } finally { - lock.writeLock().unlock(); - } - } - }; + }); } }