mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-02-05 16:44:47 +08:00
Let TaskExecutorDialogPane close itself when finished
This commit is contained in:
parent
bc34427793
commit
a015585bd1
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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() {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user