feat: allow cancel logging task.
This commit is contained in:
@@ -33,10 +33,7 @@ import javafx.scene.Node;
|
|||||||
import javafx.scene.control.Hyperlink;
|
import javafx.scene.control.Hyperlink;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.*;
|
||||||
import javafx.scene.layout.HBox;
|
|
||||||
import javafx.scene.layout.Region;
|
|
||||||
import javafx.scene.layout.StackPane;
|
|
||||||
import org.jackhuang.hmcl.auth.*;
|
import org.jackhuang.hmcl.auth.*;
|
||||||
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorDownloadException;
|
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorDownloadException;
|
||||||
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorServer;
|
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.setting.Accounts;
|
||||||
import org.jackhuang.hmcl.task.Schedulers;
|
import org.jackhuang.hmcl.task.Schedulers;
|
||||||
import org.jackhuang.hmcl.task.Task;
|
import org.jackhuang.hmcl.task.Task;
|
||||||
|
import org.jackhuang.hmcl.task.TaskExecutor;
|
||||||
import org.jackhuang.hmcl.ui.Controllers;
|
import org.jackhuang.hmcl.ui.Controllers;
|
||||||
import org.jackhuang.hmcl.ui.FXUtils;
|
import org.jackhuang.hmcl.ui.FXUtils;
|
||||||
import org.jackhuang.hmcl.ui.construct.*;
|
import org.jackhuang.hmcl.ui.construct.*;
|
||||||
@@ -94,8 +92,11 @@ public class AddAccountPane extends StackPane {
|
|||||||
private SpinnerPane acceptPane;
|
private SpinnerPane acceptPane;
|
||||||
@FXML
|
@FXML
|
||||||
private HBox linksContainer;
|
private HBox linksContainer;
|
||||||
|
@FXML
|
||||||
|
private GridPane body;
|
||||||
|
|
||||||
private final TabHeader tabHeader;
|
private final TabHeader tabHeader;
|
||||||
|
private TaskExecutor loginTask;
|
||||||
|
|
||||||
private ListProperty<Hyperlink> links = new SimpleListProperty<>();
|
private ListProperty<Hyperlink> links = new SimpleListProperty<>();
|
||||||
|
|
||||||
@@ -242,14 +243,14 @@ public class AddAccountPane extends StackPane {
|
|||||||
|
|
||||||
acceptPane.showSpinner();
|
acceptPane.showSpinner();
|
||||||
lblCreationWarning.setText("");
|
lblCreationWarning.setText("");
|
||||||
setDisable(true);
|
body.setDisable(true);
|
||||||
|
|
||||||
String username = txtUsername.getText();
|
String username = txtUsername.getText();
|
||||||
String password = txtPassword.getText();
|
String password = txtPassword.getText();
|
||||||
AccountFactory<?> factory = ((AccountFactory<?>) tabHeader.getSelectionModel().getSelectedItem().getUserData());
|
AccountFactory<?> factory = ((AccountFactory<?>) tabHeader.getSelectionModel().getSelectedItem().getUserData());
|
||||||
Object additionalData = getAuthAdditionalData();
|
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 -> {
|
.whenComplete(Schedulers.javafx(), account -> {
|
||||||
int oldIndex = Accounts.getAccounts().indexOf(account);
|
int oldIndex = Accounts.getAccounts().indexOf(account);
|
||||||
if (oldIndex == -1) {
|
if (oldIndex == -1) {
|
||||||
@@ -274,11 +275,14 @@ public class AddAccountPane extends StackPane {
|
|||||||
}
|
}
|
||||||
setDisable(false);
|
setDisable(false);
|
||||||
acceptPane.hideSpinner();
|
acceptPane.hideSpinner();
|
||||||
}).start();
|
}).executor(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void onCreationCancel() {
|
private void onCreationCancel() {
|
||||||
|
if (loginTask != null) {
|
||||||
|
loginTask.cancel();
|
||||||
|
}
|
||||||
fireEvent(new DialogCloseEvent());
|
fireEvent(new DialogCloseEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<Label text="%account.create"/>
|
<Label text="%account.create"/>
|
||||||
</heading>
|
</heading>
|
||||||
<body>
|
<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>
|
||||||
<ColumnConstraints maxWidth="70" minWidth="70"/>
|
<ColumnConstraints maxWidth="70" minWidth="70"/>
|
||||||
<ColumnConstraints/>
|
<ColumnConstraints/>
|
||||||
|
|||||||
Reference in New Issue
Block a user