From 3e72a2672bc3baa085b7ab9afa5e5b9626edfb3b Mon Sep 17 00:00:00 2001 From: ShirosakiMio <852468399@qq.com> Date: Sat, 23 Mar 2024 12:33:15 +0800 Subject: [PATCH] fix start failed when credential has expired --- .../com/tungsten/fcl/game/LauncherHelper.java | 45 ++++++++++++++++++- .../main/res/layout/dialog_tip_relogin.xml | 45 +++++++++++++++++++ FCL/src/main/res/values-zh/strings.xml | 1 + FCL/src/main/res/values/strings.xml | 1 + 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 FCL/src/main/res/layout/dialog_tip_relogin.xml diff --git a/FCL/src/main/java/com/tungsten/fcl/game/LauncherHelper.java b/FCL/src/main/java/com/tungsten/fcl/game/LauncherHelper.java index cc2e5d555..4d5e73c09 100644 --- a/FCL/src/main/java/com/tungsten/fcl/game/LauncherHelper.java +++ b/FCL/src/main/java/com/tungsten/fcl/game/LauncherHelper.java @@ -34,7 +34,6 @@ import com.tungsten.fcl.setting.Profile; import com.tungsten.fcl.setting.VersionSetting; import com.tungsten.fcl.ui.TaskDialog; -import com.tungsten.fcl.ui.account.AccountListItem; import com.tungsten.fcl.util.TaskCancellationAction; import com.tungsten.fclauncher.utils.FCLPath; import com.tungsten.fclcore.auth.Account; @@ -311,7 +310,12 @@ private static Task logIn(Context context, Account account) { } catch (CredentialExpiredException e) { LOG.log(Level.INFO, "Credential has expired", e); - return Task.completed(AccountListItem.logIn(account)); + CompletableFuture> future = new CompletableFuture<>(); + Schedulers.androidUIThread().execute(() -> { + TipReLoginLoginDialog dialog = new TipReLoginLoginDialog(context, account, future); + dialog.show(); + }); + return Task.fromCompletableFuture(future).thenComposeAsync(task -> task); } catch (AuthenticationException e) { LOG.log(Level.WARNING, "Authentication failed, try skipping refresh", e); @@ -368,4 +372,41 @@ public void onClick(View view) { } } + static class TipReLoginLoginDialog extends FCLDialog implements View.OnClickListener { + + private final Account account; + private final CompletableFuture> future; + + private FCLButton skip; + private FCLButton ok; + + public TipReLoginLoginDialog(@NonNull Context context, Account account, CompletableFuture> future) { + super(context); + this.account = account; + this.future = future; + setContentView(R.layout.dialog_tip_relogin); + setCancelable(false); + + skip = findViewById(R.id.skip); + ok = findViewById(R.id.ok); + skip.setOnClickListener(this); + ok.setOnClickListener(this); + } + + @Override + public void onClick(View view) { + if (view == skip) { + try { + future.complete(Task.completed(account.playOffline())); + } catch (AuthenticationException e2) { + future.completeExceptionally(e2); + } + } + if (view == ok) { + future.completeExceptionally(new CancellationException()); + } + dismiss(); + } + } + } diff --git a/FCL/src/main/res/layout/dialog_tip_relogin.xml b/FCL/src/main/res/layout/dialog_tip_relogin.xml new file mode 100644 index 000000000..093288b78 --- /dev/null +++ b/FCL/src/main/res/layout/dialog_tip_relogin.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/FCL/src/main/res/values-zh/strings.xml b/FCL/src/main/res/values-zh/strings.xml index 7adaf570d..7c00e8813 100644 --- a/FCL/src/main/res/values-zh/strings.xml +++ b/FCL/src/main/res/values-zh/strings.xml @@ -895,4 +895,5 @@ 显示全部 yyyy 年 MM 月 dd 日 HH:mm:ss 辅助瞄准区 + 凭据已过期,请删除账户重新登录。 \ No newline at end of file diff --git a/FCL/src/main/res/values/strings.xml b/FCL/src/main/res/values/strings.xml index 3fc2ec7cc..c7a75cc6b 100644 --- a/FCL/src/main/res/values/strings.xml +++ b/FCL/src/main/res/values/strings.xml @@ -57,6 +57,7 @@ External Account Microsoft Account Account refresh failed + Credential has expired, you must delete your account and re-login. There are no characters linked to this account. Unable to contact authentication servers, your Internet connection may be down. Unable to connect to the authentication server. Please check your network and make sure you entered the correct URL.