Let TaskExecutorDialogPane close itself when finished

This commit is contained in:
huanghongxun 2018-12-18 12:35:03 +08:00
parent bc34427793
commit a015585bd1
5 changed files with 19 additions and 10 deletions

View File

@ -30,7 +30,6 @@ import org.jackhuang.hmcl.launch.*;
import org.jackhuang.hmcl.mod.CurseCompletionException;
import org.jackhuang.hmcl.mod.CurseCompletionTask;
import org.jackhuang.hmcl.mod.ModpackConfiguration;
import org.jackhuang.hmcl.setting.Accounts;
import org.jackhuang.hmcl.setting.LauncherVisibility;
import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.setting.VersionSetting;
@ -197,7 +196,7 @@ public final class LauncherHelper {
}))
.executor();
launchingStepsPane.setExecutor(executor);
launchingStepsPane.setExecutor(executor, false);
executor.addTaskListener(new TaskListener() {
final AtomicInteger finished = new AtomicInteger(0);

View File

@ -126,10 +126,7 @@ public final class LeftPaneController extends AdvancedListBox {
AtomicReference<Region> region = new AtomicReference<>();
Modpack modpack = var.get("modpack");
TaskExecutor executor = ModpackHelper.getInstallTask(repository.getProfile(), modpackFile, modpack.getName(), modpack)
.with(Task.of(Schedulers.javafx(), () -> {
region.get().fireEvent(new DialogCloseEvent());
checkAccount();
})).executor();
.with(Task.of(Schedulers.javafx(), this::checkAccount)).executor();
region.set(Controllers.taskDialog(executor, i18n("modpack.installing"), ""));
executor.start();
})).start();

View File

@ -20,6 +20,7 @@ package org.jackhuang.hmcl.ui.construct;
import com.jfoenix.concurrency.JFXUtilities;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXProgressBar;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
@ -27,6 +28,7 @@ import javafx.scene.control.Label;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import org.jackhuang.hmcl.task.TaskExecutor;
import org.jackhuang.hmcl.task.TaskListener;
import org.jackhuang.hmcl.ui.FXUtils;
import java.util.Optional;
@ -66,10 +68,23 @@ public class TaskExecutorDialogPane extends StackPane {
}
public void setExecutor(TaskExecutor executor) {
setExecutor(executor, true);
}
public void setExecutor(TaskExecutor executor, boolean autoClose) {
this.executor = executor;
if (executor != null)
if (executor != null) {
taskListPane.setExecutor(executor);
if (autoClose)
executor.addTaskListener(new TaskListener() {
@Override
public void onStop(boolean success, TaskExecutor executor) {
Platform.runLater(() -> fireEvent(new DialogCloseEvent()));
}
});
}
}
public StringProperty titleProperty() {

View File

@ -106,7 +106,6 @@ public final class UpdateHandler {
Region dialog = Controllers.taskDialog(executor, i18n("message.downloading"), "", null);
thread(() -> {
boolean success = executor.test();
Platform.runLater(() -> dialog.fireEvent(new DialogCloseEvent()));
if (success) {
try {

View File

@ -257,8 +257,7 @@ public final class TaskExecutor {
@Override
public void run() {
try {
if (Thread.currentThread().getName().contains("pool"))
Thread.currentThread().setName(task.getName());
Thread.currentThread().setName(task.getName());
if (!executeTask(task))
success.set(false);
} finally {