diff --git a/launcher/src/main/java/com/skcraft/launcher/auth/MicrosoftLoginService.java b/launcher/src/main/java/com/skcraft/launcher/auth/MicrosoftLoginService.java index 0982414..9688343 100644 --- a/launcher/src/main/java/com/skcraft/launcher/auth/MicrosoftLoginService.java +++ b/launcher/src/main/java/com/skcraft/launcher/auth/MicrosoftLoginService.java @@ -29,7 +29,16 @@ private final String clientId; - public Session login() throws IOException, InterruptedException, AuthenticationException { + /** + * Trigger a full login sequence with the Microsoft authenticator. + * + * @param oauthDone Callback called when OAuth is complete and automatic login is about to begin. + * @return Valid {@link Session} instance representing the logged-in player. + * @throws IOException if any I/O error occurs. + * @throws InterruptedException if the current thread is interrupted + * @throws AuthenticationException if authentication fails in any way, this is thrown with a human-useful message. + */ + public Session login(Receiver oauthDone) throws IOException, InterruptedException, AuthenticationException { MicrosoftWebAuthorizer authorizer = new MicrosoftWebAuthorizer(clientId); OauthResult auth = authorizer.authorize(); @@ -44,6 +53,7 @@ form.add("code", ((OauthResult.Success) auth).getAuthCode()); }); + oauthDone.tell(); Profile session = performLogin(response.getAccessToken(), null); session.setRefreshToken(response.getRefreshToken()); @@ -159,4 +169,9 @@ private String error; private String errorDescription; } + + @FunctionalInterface + public interface Receiver { + void tell(); + } } diff --git a/launcher/src/main/java/com/skcraft/launcher/dialog/AccountSelectDialog.java b/launcher/src/main/java/com/skcraft/launcher/dialog/AccountSelectDialog.java index 8dc7331..aa26d45 100644 --- a/launcher/src/main/java/com/skcraft/launcher/dialog/AccountSelectDialog.java +++ b/launcher/src/main/java/com/skcraft/launcher/dialog/AccountSelectDialog.java @@ -3,9 +3,9 @@ import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import com.skcraft.concurrency.DefaultProgress; import com.skcraft.concurrency.ObservableFuture; import com.skcraft.concurrency.ProgressObservable; +import com.skcraft.concurrency.SettableProgress; import com.skcraft.launcher.Launcher; import com.skcraft.launcher.auth.LoginService; import com.skcraft.launcher.auth.OfflineSession; @@ -148,8 +148,12 @@ } private void attemptMicrosoftLogin() { + String status = SharedLocale.tr("login.microsoft.seeBrowser"); + SettableProgress progress = new SettableProgress(status, -1); + ListenableFuture future = launcher.getExecutor().submit(() -> { - Session newSession = launcher.getMicrosoftLogin().login(); + Session newSession = launcher.getMicrosoftLogin().login(() -> + progress.set(SharedLocale.tr("login.loggingInStatus"), -1)); if (newSession != null) { launcher.getAccounts().add(newSession.toSavedSession()); @@ -159,8 +163,7 @@ return null; }); - String status = SharedLocale.tr("login.loggingInStatus"); - ProgressDialog.showProgress(this, future, new DefaultProgress(-1, status), + ProgressDialog.showProgress(this, future, progress, SharedLocale.tr("login.loggingInTitle"), status); SwingHelper.addErrorDialogCallback(this, future); } diff --git a/launcher/src/main/resources/com/skcraft/launcher/lang/Launcher.properties b/launcher/src/main/resources/com/skcraft/launcher/lang/Launcher.properties index ec83350..12b1876 100644 --- a/launcher/src/main/resources/com/skcraft/launcher/lang/Launcher.properties +++ b/launcher/src/main/resources/com/skcraft/launcher/lang/Launcher.properties @@ -110,6 +110,7 @@ login.noLoginTitle=Missing Account login.minecraftNotOwnedError=Sorry, Minecraft is not owned on that account. +login.microsoft.seeBrowser=Check your browser to login with Microsoft. login.xbox.generic=Failed to authenticate with Xbox Live. login.xbox.noXboxAccount=That account does not have an Xbox account associated! login.xbox.isChild=The account is a child (under 18) and cannot proceed unless it is part of a Family.