feat: allow cancel logging task.

This commit is contained in:
huanghongxun
2021-08-28 18:22:21 +08:00
parent fcafca2fdb
commit 3972683583
2 changed files with 12 additions and 8 deletions

View File

@@ -33,10 +33,7 @@ import javafx.scene.Node;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.*;
import org.jackhuang.hmcl.auth.*;
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorDownloadException;
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorServer;
@@ -47,6 +44,7 @@ import org.jackhuang.hmcl.game.TexturesLoader;
import org.jackhuang.hmcl.setting.Accounts;
import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.task.TaskExecutor;
import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.construct.*;
@@ -94,8 +92,11 @@ public class AddAccountPane extends StackPane {
private SpinnerPane acceptPane;
@FXML
private HBox linksContainer;
@FXML
private GridPane body;
private final TabHeader tabHeader;
private TaskExecutor loginTask;
private ListProperty<Hyperlink> links = new SimpleListProperty<>();
@@ -242,14 +243,14 @@ public class AddAccountPane extends StackPane {
acceptPane.showSpinner();
lblCreationWarning.setText("");
setDisable(true);
body.setDisable(true);
String username = txtUsername.getText();
String password = txtPassword.getText();
AccountFactory<?> factory = ((AccountFactory<?>) tabHeader.getSelectionModel().getSelectedItem().getUserData());
Object additionalData = getAuthAdditionalData();
Task.supplyAsync(() -> factory.create(new Selector(), username, password, additionalData))
loginTask = Task.supplyAsync(() -> factory.create(new Selector(), username, password, additionalData))
.whenComplete(Schedulers.javafx(), account -> {
int oldIndex = Accounts.getAccounts().indexOf(account);
if (oldIndex == -1) {
@@ -274,11 +275,14 @@ public class AddAccountPane extends StackPane {
}
setDisable(false);
acceptPane.hideSpinner();
}).start();
}).executor(true);
}
@FXML
private void onCreationCancel() {
if (loginTask != null) {
loginTask.cancel();
}
fireEvent(new DialogCloseEvent());
}

View File

@@ -16,7 +16,7 @@
<Label text="%account.create"/>
</heading>
<body>
<GridPane vgap="15" hgap="15" style="-fx-padding: 15 0 0 0;">
<GridPane fx:id="body" vgap="15" hgap="15" style="-fx-padding: 15 0 0 0;">
<columnConstraints>
<ColumnConstraints maxWidth="70" minWidth="70"/>
<ColumnConstraints/>