mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-09 03:46:18 -04:00
InstallerPanel: show loading in the table instead of showing a task window
This commit is contained in:
parent
a34875e804
commit
926e276167
@ -250,7 +250,7 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (tabVersionEdit.getSelectedComponent() == pnlAutoInstall && !b) {
|
||||
b = true;
|
||||
TaskWindow.factory().execute(installerPanels[0].refreshVersionsTask());
|
||||
installerPanels[0].refreshVersions();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -116,19 +116,19 @@ public class InstallerPanel extends Page {
|
||||
}//GEN-LAST:event_btnInstallActionPerformed
|
||||
|
||||
private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed
|
||||
TaskWindow.factory().execute(refreshVersionsTask());
|
||||
refreshVersions();
|
||||
}//GEN-LAST:event_btnRefreshActionPerformed
|
||||
|
||||
transient List<InstallerVersionList.InstallerVersion> versions;
|
||||
InstallerVersionList list;
|
||||
InstallerType id;
|
||||
|
||||
Task refreshVersionsTask() {
|
||||
void refreshVersions() {
|
||||
DefaultTableModel model = SwingUtils.clearDefaultTable(lstInstallers);
|
||||
model.addRow(new Object[] { C.i18n("message.loading"), "", "" });
|
||||
Task t = list.refresh(new String[] { gsp.getMinecraftVersionFormatted() });
|
||||
if (t != null)
|
||||
return t.with(new TaskRunnable(this::loadVersions));
|
||||
else
|
||||
return null;
|
||||
t.with(new TaskRunnable(this::loadVersions)).runAsync();
|
||||
}
|
||||
|
||||
public synchronized InstallerVersionList.InstallerVersion getVersion(int idx) {
|
||||
@ -143,7 +143,7 @@ public class InstallerPanel extends Page {
|
||||
}
|
||||
TaskWindow.factory()
|
||||
.append(Settings.getLastProfile().service().install().download(Settings.getLastProfile().getSelectedVersion(), getVersion(idx), id))
|
||||
.append(refreshVersionsTask())
|
||||
.append(new TaskRunnable(() -> gsp.refreshVersions()))
|
||||
.execute();
|
||||
}
|
||||
|
||||
@ -158,6 +158,8 @@ public class InstallerPanel extends Page {
|
||||
for (InstallerVersionList.InstallerVersion v : versions)
|
||||
if (v != null)
|
||||
model.addRow(new Object[] { v.selfVersion == null ? "null" : v.selfVersion, v.mcVersion == null ? "null" : v.mcVersion });
|
||||
if (model.getRowCount() > 0)
|
||||
model.removeRow(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -168,7 +170,7 @@ public class InstallerPanel extends Page {
|
||||
public void onSelect(TopTabPage page) {
|
||||
super.onSelect(page);
|
||||
if (!refreshed) {
|
||||
TaskWindow.factory().execute(refreshVersionsTask());
|
||||
refreshVersions();
|
||||
refreshed = true;
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class AssetsMojangLoader extends IAssetsHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
if (!areDependTasksSucceeded)
|
||||
throw new IllegalStateException("Failed to get asset index");
|
||||
String result = FileUtils.read(f);
|
||||
|
@ -87,7 +87,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) {
|
||||
if (areDependTasksSucceeded) {
|
||||
if (renamedFinal != null && !renamedFinal.delete())
|
||||
HMCLog.warn("Failed to delete " + renamedFinal + ", maybe you should do it.");
|
||||
|
@ -75,7 +75,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
File vpath = new File(service.baseDirectory(), "versions/" + id);
|
||||
if (!areDependTasksSucceeded) {
|
||||
FileUtils.deleteDirectory(vpath);
|
||||
@ -131,7 +131,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
|
||||
public Task downloadMinecraftVersionJson(String id) {
|
||||
return new TaskInfo("Download Minecraft Json") {
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
List<MinecraftRemoteVersion> versions = MinecraftRemoteVersions.getRemoteVersions(service.getDownloadType()).justDo();
|
||||
MinecraftRemoteVersion currentVersion = null;
|
||||
for (MinecraftRemoteVersion v : versions)
|
||||
|
@ -61,7 +61,7 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
if (!areDependTasksSucceeded)
|
||||
return;
|
||||
String s = task.getResult();
|
||||
|
@ -61,7 +61,7 @@ public class LiteLoaderVersionList extends InstallerVersionList {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
if (!areDependTasksSucceeded)
|
||||
return;
|
||||
String s = task.getResult();
|
||||
|
@ -65,7 +65,7 @@ public class OptiFineBMCLVersionList extends InstallerVersionList {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
String s = task.getResult();
|
||||
|
||||
versionMap = new HashMap<>();
|
||||
|
@ -73,7 +73,7 @@ public class OptiFineVersionList extends InstallerVersionList {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
if (!areDependTasksSucceeded)
|
||||
return;
|
||||
String content = task.getResult();
|
||||
|
@ -86,7 +86,7 @@ public final class ModpackManager {
|
||||
Collection<Task> c = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
String id = idFUCK;
|
||||
String description = C.i18n("modpack.task.install.will");
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hmcl.util.task;
|
||||
|
||||
import java.util.Collection;
|
||||
import org.jackhuang.hmcl.util.AbstractSwingWorker;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -63,9 +64,10 @@ public abstract class Task {
|
||||
|
||||
/**
|
||||
* This method can be only invoked by TaskList.
|
||||
*
|
||||
* @param s what the `executeTask` throws.
|
||||
*/
|
||||
protected void setFailReason(Throwable s) {
|
||||
protected void setFailReason(Exception s) {
|
||||
failReason = s;
|
||||
}
|
||||
|
||||
@ -73,6 +75,7 @@ public abstract class Task {
|
||||
|
||||
/**
|
||||
* For FileDownloadTask: info replacement.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTag() {
|
||||
@ -105,7 +108,7 @@ public abstract class Task {
|
||||
return new DoubleTask(this, t);
|
||||
}
|
||||
|
||||
public void runWithException() throws Throwable {
|
||||
public void runWithException() throws Exception {
|
||||
Collection<Task> c = getDependTasks();
|
||||
if (c != null)
|
||||
for (Task t : c)
|
||||
@ -116,4 +119,13 @@ public abstract class Task {
|
||||
for (Task t : c)
|
||||
t.runWithException();
|
||||
}
|
||||
|
||||
public void runAsync() {
|
||||
new AbstractSwingWorker<Void>() {
|
||||
@Override
|
||||
protected void work() throws Exception {
|
||||
runWithException();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ public class TaskList extends Thread {
|
||||
boolean flag = true;
|
||||
try {
|
||||
t.executeTask(areDependTasksSucceeded);
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
t.setFailReason(e);
|
||||
flag = false;
|
||||
}
|
||||
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Hello Minecraft! Launcher.
|
||||
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||
*/
|
||||
package org.jackhuang.hmcl.util.task;
|
||||
|
||||
import java.util.List;
|
||||
import org.jackhuang.hmcl.api.func.Consumer;
|
||||
import org.jackhuang.hmcl.util.AbstractSwingWorker;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huang
|
||||
*/
|
||||
public abstract class TaskWorker<T> extends Task {
|
||||
|
||||
protected final AbstractSwingWorker<T> worker;
|
||||
|
||||
public TaskWorker() {
|
||||
worker = new AbstractSwingWorker<T>() {
|
||||
@Override
|
||||
protected void work() throws Exception {
|
||||
runWithException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public TaskWorker<T> reg(Consumer<T> c) {
|
||||
worker.reg(c);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskWorker<T> regDone(Runnable c) {
|
||||
worker.regDone(c);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void send(T... result) {
|
||||
worker.send(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfo() {
|
||||
return "TaskWorker";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAsync() {
|
||||
worker.execute();
|
||||
}
|
||||
|
||||
public List<T> justDo() throws Exception {
|
||||
return worker.justDo();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user