Let TaskExecutorDialogPane close itself when finished
This commit is contained in:
@@ -30,7 +30,6 @@ import org.jackhuang.hmcl.launch.*;
|
|||||||
import org.jackhuang.hmcl.mod.CurseCompletionException;
|
import org.jackhuang.hmcl.mod.CurseCompletionException;
|
||||||
import org.jackhuang.hmcl.mod.CurseCompletionTask;
|
import org.jackhuang.hmcl.mod.CurseCompletionTask;
|
||||||
import org.jackhuang.hmcl.mod.ModpackConfiguration;
|
import org.jackhuang.hmcl.mod.ModpackConfiguration;
|
||||||
import org.jackhuang.hmcl.setting.Accounts;
|
|
||||||
import org.jackhuang.hmcl.setting.LauncherVisibility;
|
import org.jackhuang.hmcl.setting.LauncherVisibility;
|
||||||
import org.jackhuang.hmcl.setting.Profile;
|
import org.jackhuang.hmcl.setting.Profile;
|
||||||
import org.jackhuang.hmcl.setting.VersionSetting;
|
import org.jackhuang.hmcl.setting.VersionSetting;
|
||||||
@@ -197,7 +196,7 @@ public final class LauncherHelper {
|
|||||||
}))
|
}))
|
||||||
.executor();
|
.executor();
|
||||||
|
|
||||||
launchingStepsPane.setExecutor(executor);
|
launchingStepsPane.setExecutor(executor, false);
|
||||||
executor.addTaskListener(new TaskListener() {
|
executor.addTaskListener(new TaskListener() {
|
||||||
final AtomicInteger finished = new AtomicInteger(0);
|
final AtomicInteger finished = new AtomicInteger(0);
|
||||||
|
|
||||||
|
|||||||
@@ -126,10 +126,7 @@ public final class LeftPaneController extends AdvancedListBox {
|
|||||||
AtomicReference<Region> region = new AtomicReference<>();
|
AtomicReference<Region> region = new AtomicReference<>();
|
||||||
Modpack modpack = var.get("modpack");
|
Modpack modpack = var.get("modpack");
|
||||||
TaskExecutor executor = ModpackHelper.getInstallTask(repository.getProfile(), modpackFile, modpack.getName(), modpack)
|
TaskExecutor executor = ModpackHelper.getInstallTask(repository.getProfile(), modpackFile, modpack.getName(), modpack)
|
||||||
.with(Task.of(Schedulers.javafx(), () -> {
|
.with(Task.of(Schedulers.javafx(), this::checkAccount)).executor();
|
||||||
region.get().fireEvent(new DialogCloseEvent());
|
|
||||||
checkAccount();
|
|
||||||
})).executor();
|
|
||||||
region.set(Controllers.taskDialog(executor, i18n("modpack.installing"), ""));
|
region.set(Controllers.taskDialog(executor, i18n("modpack.installing"), ""));
|
||||||
executor.start();
|
executor.start();
|
||||||
})).start();
|
})).start();
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package org.jackhuang.hmcl.ui.construct;
|
|||||||
import com.jfoenix.concurrency.JFXUtilities;
|
import com.jfoenix.concurrency.JFXUtilities;
|
||||||
import com.jfoenix.controls.JFXButton;
|
import com.jfoenix.controls.JFXButton;
|
||||||
import com.jfoenix.controls.JFXProgressBar;
|
import com.jfoenix.controls.JFXProgressBar;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.beans.binding.Bindings;
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.beans.property.StringProperty;
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
@@ -27,6 +28,7 @@ import javafx.scene.control.Label;
|
|||||||
import javafx.scene.layout.Region;
|
import javafx.scene.layout.Region;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
import org.jackhuang.hmcl.task.TaskExecutor;
|
import org.jackhuang.hmcl.task.TaskExecutor;
|
||||||
|
import org.jackhuang.hmcl.task.TaskListener;
|
||||||
import org.jackhuang.hmcl.ui.FXUtils;
|
import org.jackhuang.hmcl.ui.FXUtils;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -66,10 +68,23 @@ public class TaskExecutorDialogPane extends StackPane {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setExecutor(TaskExecutor executor) {
|
public void setExecutor(TaskExecutor executor) {
|
||||||
|
setExecutor(executor, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExecutor(TaskExecutor executor, boolean autoClose) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
|
|
||||||
if (executor != null)
|
if (executor != null) {
|
||||||
taskListPane.setExecutor(executor);
|
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() {
|
public StringProperty titleProperty() {
|
||||||
|
|||||||
@@ -106,7 +106,6 @@ public final class UpdateHandler {
|
|||||||
Region dialog = Controllers.taskDialog(executor, i18n("message.downloading"), "", null);
|
Region dialog = Controllers.taskDialog(executor, i18n("message.downloading"), "", null);
|
||||||
thread(() -> {
|
thread(() -> {
|
||||||
boolean success = executor.test();
|
boolean success = executor.test();
|
||||||
Platform.runLater(() -> dialog.fireEvent(new DialogCloseEvent()));
|
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -257,8 +257,7 @@ public final class TaskExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
if (Thread.currentThread().getName().contains("pool"))
|
Thread.currentThread().setName(task.getName());
|
||||||
Thread.currentThread().setName(task.getName());
|
|
||||||
if (!executeTask(task))
|
if (!executeTask(task))
|
||||||
success.set(false);
|
success.set(false);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user