feat: WIP: account login progress

This commit is contained in:
huanghongxun
2021-09-04 15:49:34 +08:00
parent 72ca0f20a1
commit 1000cc1ab0
8 changed files with 51 additions and 61 deletions

View File

@@ -17,26 +17,17 @@
*/ */
package org.jackhuang.hmcl.ui.account; package org.jackhuang.hmcl.ui.account;
import static java.util.Collections.emptyList; import com.jfoenix.controls.*;
import static java.util.Collections.unmodifiableList; import javafx.application.Platform;
import static javafx.beans.binding.Bindings.bindContent; import javafx.beans.binding.BooleanBinding;
import static javafx.beans.binding.Bindings.createBooleanBinding; import javafx.geometry.HPos;
import static org.jackhuang.hmcl.setting.ConfigHolder.config; import javafx.geometry.Insets;
import static org.jackhuang.hmcl.ui.FXUtils.jfxListCellFactory; import javafx.geometry.Pos;
import static org.jackhuang.hmcl.ui.FXUtils.onChange; import javafx.scene.Node;
import static org.jackhuang.hmcl.ui.FXUtils.onChangeAndOperate; import javafx.scene.control.Hyperlink;
import static org.jackhuang.hmcl.ui.FXUtils.onEscPressed; import javafx.scene.control.Label;
import static org.jackhuang.hmcl.ui.FXUtils.onInvalidating; import javafx.scene.image.ImageView;
import static org.jackhuang.hmcl.ui.FXUtils.setValidateWhileTextChanged; import javafx.scene.layout.*;
import static org.jackhuang.hmcl.ui.FXUtils.stringConverter;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
import static org.jackhuang.hmcl.util.javafx.ExtendedProperties.classPropertyFor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import org.jackhuang.hmcl.auth.AccountFactory; import org.jackhuang.hmcl.auth.AccountFactory;
import org.jackhuang.hmcl.auth.CharacterSelector; import org.jackhuang.hmcl.auth.CharacterSelector;
import org.jackhuang.hmcl.auth.NoSelectedCharacterException; import org.jackhuang.hmcl.auth.NoSelectedCharacterException;
@@ -53,40 +44,22 @@ 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.SVG; import org.jackhuang.hmcl.ui.SVG;
import org.jackhuang.hmcl.ui.construct.AdvancedListBox; import org.jackhuang.hmcl.ui.construct.*;
import org.jackhuang.hmcl.ui.construct.DialogCloseEvent;
import org.jackhuang.hmcl.ui.construct.IconedItem;
import org.jackhuang.hmcl.ui.construct.RequiredValidator;
import org.jackhuang.hmcl.ui.construct.SpinnerPane;
import org.jackhuang.hmcl.ui.construct.TabControl;
import org.jackhuang.hmcl.ui.construct.TabHeader;
import org.jackhuang.hmcl.ui.construct.TwoLineListItem;
import org.jackhuang.hmcl.ui.construct.Validator;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.jfoenix.controls.JFXButton; import java.util.ArrayList;
import com.jfoenix.controls.JFXComboBox; import java.util.List;
import com.jfoenix.controls.JFXDialogLayout; import java.util.Map;
import com.jfoenix.controls.JFXPasswordField; import java.util.concurrent.CountDownLatch;
import com.jfoenix.controls.JFXTextField;
import javafx.application.Platform; import static java.util.Collections.emptyList;
import javafx.beans.binding.BooleanBinding; import static java.util.Collections.unmodifiableList;
import javafx.geometry.HPos; import static javafx.beans.binding.Bindings.bindContent;
import javafx.geometry.Insets; import static javafx.beans.binding.Bindings.createBooleanBinding;
import javafx.geometry.Pos; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import javafx.scene.Node; import static org.jackhuang.hmcl.ui.FXUtils.*;
import javafx.scene.control.Hyperlink; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
import javafx.scene.control.Label; import static org.jackhuang.hmcl.util.javafx.ExtendedProperties.classPropertyFor;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
public class CreateAccountPane extends JFXDialogLayout { public class CreateAccountPane extends JFXDialogLayout {
@@ -216,7 +189,7 @@ public class CreateAccountPane extends JFXDialogLayout {
additionalData = null; additionalData = null;
} }
loginTask = Task.supplyAsync(() -> factory.create(new DialogCharacterSelector(), username, password, additionalData)) loginTask = Task.supplyAsync(() -> factory.create(new DialogCharacterSelector(), username, password, null, 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) {

View File

@@ -58,6 +58,14 @@ account.manage=帳戶列表
account.methods=登入方式 account.methods=登入方式
account.methods.authlib_injector=authlib-injector 登入 account.methods.authlib_injector=authlib-injector 登入
account.methods.microsoft=微軟帳戶 account.methods.microsoft=微軟帳戶
account.methods.microsoft.close_page=已完成微軟帳號授權,接下來啟動器還需要完成剩餘登錄步驟。你已經可以關閉本頁面了。
account.methods.microsoft.error.add_family=由於你未滿 18 歲,你的帳號必須被加入到家庭中才能登錄遊戲。
account.methods.microsoft.error.missing_xbox_account=你的微軟帳號尚未關聯 XBox 帳號,你必須先創建 XBox 帳號,才能登錄遊戲。
account.methods.microsoft.error.unknown=登錄失敗,錯誤碼:%d
account.methods.microsoft.logging_in=登錄中...
account.methods.microsoft.hint=點擊確定以登錄
account.methods.microsoft.manual=您需要在新打開的瀏覽器窗口中完成登錄。若頁面未能打開,您可以點擊此處複製連結,並手動在瀏覽器中打開網頁。
account.methods.microsoft.waiting_browser=等待在新打開的瀏覽器窗口中完成登錄...
account.methods.offline=離線模式 account.methods.offline=離線模式
account.methods.yggdrasil=正版登入 account.methods.yggdrasil=正版登入
account.missing=沒有遊戲帳戶 account.missing=沒有遊戲帳戶

View File

@@ -76,6 +76,7 @@ account.methods.microsoft.error.add_family=由于你未满 18 岁,你的账号
account.methods.microsoft.error.missing_xbox_account=你的微软账号尚未关联 XBox 账号,你必须先创建 XBox 账号,才能登录游戏。 account.methods.microsoft.error.missing_xbox_account=你的微软账号尚未关联 XBox 账号,你必须先创建 XBox 账号,才能登录游戏。
account.methods.microsoft.error.unknown=登录失败,错误码:%d account.methods.microsoft.error.unknown=登录失败,错误码:%d
account.methods.microsoft.logging_in=登录中... account.methods.microsoft.logging_in=登录中...
account.methods.microsoft.hint=点击确定以登录
account.methods.microsoft.manual=您需要在新打开的浏览器窗口中完成登录。若页面未能打开,您可以点击此处复制链接,并手动在浏览器中打开网页。 account.methods.microsoft.manual=您需要在新打开的浏览器窗口中完成登录。若页面未能打开,您可以点击此处复制链接,并手动在浏览器中打开网页。
account.methods.microsoft.waiting_browser=等待在新打开的浏览器窗口中完成登录... account.methods.microsoft.waiting_browser=等待在新打开的浏览器窗口中完成登录...
account.methods.offline=离线模式 account.methods.offline=离线模式

View File

@@ -50,25 +50,33 @@ public abstract class AccountFactory<T extends Account> {
} }
} }
public interface ProgressCallback {
void onProgressChanged(String stageName);
}
/** /**
* Informs how this account factory verifies user's credential. * Informs how this account factory verifies user's credential.
*
* @see AccountLoginType * @see AccountLoginType
*/ */
public abstract AccountLoginType getLoginType(); public abstract AccountLoginType getLoginType();
/** /**
* Create a new(to be verified via network) account, and log in. * Create a new(to be verified via network) account, and log in.
* @param selector for character selection if multiple characters belong to single account. Pick out which character to act as. *
* @param username username of the account if needed. * @param selector for character selection if multiple characters belong to single account. Pick out which character to act as.
* @param password password of the account if needed. * @param username username of the account if needed.
* @param additionalData extra data for specific account factory. * @param password password of the account if needed.
* @param progressCallback notify login progress.
* @param additionalData extra data for specific account factory.
* @return logged-in account. * @return logged-in account.
* @throws AuthenticationException if an error occurs when logging in. * @throws AuthenticationException if an error occurs when logging in.
*/ */
public abstract T create(CharacterSelector selector, String username, String password, Object additionalData) throws AuthenticationException; public abstract T create(CharacterSelector selector, String username, String password, ProgressCallback progressCallback, Object additionalData) throws AuthenticationException;
/** /**
* Create a existing(stored in local files) account. * Create a existing(stored in local files) account.
*
* @param storage serialized account data. * @param storage serialized account data.
* @return account stored in local storage. Credentials may expired, and you should refresh account state later. * @return account stored in local storage. Credentials may expired, and you should refresh account state later.
*/ */

View File

@@ -50,7 +50,7 @@ public class AuthlibInjectorAccountFactory extends AccountFactory<AuthlibInjecto
} }
@Override @Override
public AuthlibInjectorAccount create(CharacterSelector selector, String username, String password, Object additionalData) throws AuthenticationException { public AuthlibInjectorAccount create(CharacterSelector selector, String username, String password, ProgressCallback progressCallback, Object additionalData) throws AuthenticationException {
Objects.requireNonNull(selector); Objects.requireNonNull(selector);
Objects.requireNonNull(username); Objects.requireNonNull(username);
Objects.requireNonNull(password); Objects.requireNonNull(password);

View File

@@ -38,7 +38,7 @@ public class MicrosoftAccountFactory extends AccountFactory<MicrosoftAccount> {
} }
@Override @Override
public MicrosoftAccount create(CharacterSelector selector, String username, String password, Object additionalData) throws AuthenticationException { public MicrosoftAccount create(CharacterSelector selector, String username, String password, ProgressCallback progressCallback, Object additionalData) throws AuthenticationException {
Objects.requireNonNull(selector); Objects.requireNonNull(selector);
return new MicrosoftAccount(service, selector); return new MicrosoftAccount(service, selector);

View File

@@ -47,7 +47,7 @@ public final class OfflineAccountFactory extends AccountFactory<OfflineAccount>
} }
@Override @Override
public OfflineAccount create(CharacterSelector selector, String username, String password, Object additionalData) { public OfflineAccount create(CharacterSelector selector, String username, String password, ProgressCallback progressCallback, Object additionalData) {
return new OfflineAccount(username, getUUIDFromUserName(username)); return new OfflineAccount(username, getUUIDFromUserName(username));
} }

View File

@@ -48,7 +48,7 @@ public class YggdrasilAccountFactory extends AccountFactory<YggdrasilAccount> {
} }
@Override @Override
public YggdrasilAccount create(CharacterSelector selector, String username, String password, Object additionalData) throws AuthenticationException { public YggdrasilAccount create(CharacterSelector selector, String username, String password, ProgressCallback progressCallback, Object additionalData) throws AuthenticationException {
Objects.requireNonNull(selector); Objects.requireNonNull(selector);
Objects.requireNonNull(username); Objects.requireNonNull(username);
Objects.requireNonNull(password); Objects.requireNonNull(password);