Skip to content

Commit 2e4cc76

Browse files
CiiLu3gf8jv4dvCopilot
authored
优化微软登录页面 (#4794)
Co-authored-by: 3gf8jv4dv <3gf8jv4dv@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 02e9d80 commit 2e4cc76

13 files changed

Lines changed: 127 additions & 235 deletions

HMCL/src/main/java/org/jackhuang/hmcl/game/OAuthServer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ public void grantDeviceCode(String userCode, String verificationURI) {
152152
@Override
153153
public void openBrowser(String url) throws IOException {
154154
lastlyOpenedURL = url;
155+
156+
try {
157+
Thread.sleep(1500);
158+
} catch (InterruptedException ignored) {
159+
}
160+
155161
FXUtils.openLink(url);
156162

157163
onOpenBrowser.fireEvent(new OpenBrowserEvent(this, url));

HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ public static String localizeErrorMessage(Exception exception) {
465465
} else if (exception instanceof MicrosoftService.NoMinecraftJavaEditionProfileException) {
466466
return i18n("account.methods.microsoft.error.no_character");
467467
} else if (exception instanceof MicrosoftService.NoXuiException) {
468-
return i18n("account.methods.microsoft.error.add_family_probably");
468+
return i18n("account.methods.microsoft.error.add_family");
469469
} else if (exception instanceof OAuthServer.MicrosoftAuthenticationNotSupportedException) {
470470
return i18n("account.methods.microsoft.snapshot");
471471
} else if (exception instanceof OAuthAccount.WrongAccountException) {

HMCL/src/main/java/org/jackhuang/hmcl/ui/account/CreateAccountPane.java

Lines changed: 77 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
import javafx.scene.control.Label;
3636
import javafx.scene.control.TextInputControl;
3737
import javafx.scene.layout.*;
38-
39-
import org.jackhuang.hmcl.Metadata;
4038
import org.jackhuang.hmcl.auth.AccountFactory;
4139
import org.jackhuang.hmcl.auth.CharacterSelector;
4240
import org.jackhuang.hmcl.auth.NoSelectedCharacterException;
@@ -64,11 +62,7 @@
6462
import org.jackhuang.hmcl.util.javafx.BindingMapping;
6563
import org.jetbrains.annotations.Nullable;
6664

67-
import java.util.ArrayList;
68-
import java.util.List;
69-
import java.util.Locale;
70-
import java.util.Map;
71-
import java.util.UUID;
65+
import java.util.*;
7266
import java.util.concurrent.CountDownLatch;
7367
import java.util.regex.Pattern;
7468

@@ -286,72 +280,95 @@ private void initDetailsPane() {
286280
btnAccept.disableProperty().unbind();
287281
detailsContainer.getChildren().remove(detailsPane);
288282
lblErrorMessage.setText("");
283+
lblErrorMessage.setVisible(true);
289284
}
285+
290286
if (factory == Accounts.FACTORY_MICROSOFT) {
291287
VBox vbox = new VBox(8);
292-
if (!Accounts.OAUTH_CALLBACK.getClientId().isEmpty()) {
293-
HintPane hintPane = new HintPane(MessageDialogPane.MessageType.INFO);
294-
FXUtils.onChangeAndOperate(deviceCode, deviceCode -> {
295-
if (deviceCode != null) {
296-
FXUtils.copyText(deviceCode.getUserCode());
297-
hintPane.setSegment(i18n("account.methods.microsoft.manual", deviceCode.getUserCode(), deviceCode.getVerificationUri()));
298-
} else {
299-
hintPane.setSegment(i18n("account.methods.microsoft.hint"));
300-
}
301-
});
302-
FXUtils.onClicked(hintPane, () -> {
303-
if (deviceCode.get() != null) {
304-
FXUtils.copyText(deviceCode.get().getUserCode());
305-
}
306-
});
307-
308-
holder.add(Accounts.OAUTH_CALLBACK.onGrantDeviceCode.registerWeak(value -> {
309-
runInFX(() -> deviceCode.set(value));
310-
}));
311-
FlowPane box = new FlowPane();
312-
box.setHgap(8);
313-
JFXHyperlink birthLink = new JFXHyperlink(i18n("account.methods.microsoft.birth"));
314-
birthLink.setExternalLink("https://support.microsoft.com/account-billing/837badbc-999e-54d2-2617-d19206b9540a");
315-
JFXHyperlink profileLink = new JFXHyperlink(i18n("account.methods.microsoft.profile"));
316-
profileLink.setExternalLink("https://account.live.com/editprof.aspx");
317-
JFXHyperlink purchaseLink = new JFXHyperlink(i18n("account.methods.microsoft.purchase"));
318-
purchaseLink.setExternalLink(YggdrasilService.PURCHASE_URL);
319-
JFXHyperlink deauthorizeLink = new JFXHyperlink(i18n("account.methods.microsoft.deauthorize"));
320-
deauthorizeLink.setExternalLink("https://account.live.com/consent/Edit?client_id=000000004C794E0A");
321-
JFXHyperlink forgotpasswordLink = new JFXHyperlink(i18n("account.methods.forgot_password"));
322-
forgotpasswordLink.setExternalLink("https://account.live.com/ResetPassword.aspx");
323-
JFXHyperlink createProfileLink = new JFXHyperlink(i18n("account.methods.microsoft.makegameidsettings"));
324-
createProfileLink.setExternalLink("https://www.minecraft.net/msaprofile/mygames/editprofile");
325-
JFXHyperlink bannedQueryLink = new JFXHyperlink(i18n("account.methods.ban_query"));
326-
bannedQueryLink.setExternalLink("https://enforcement.xbox.com/enforcement/showenforcementhistory");
327-
box.getChildren().setAll(profileLink, birthLink, purchaseLink, deauthorizeLink, forgotpasswordLink, createProfileLink, bannedQueryLink);
328-
GridPane.setColumnSpan(box, 2);
329-
330-
if (!IntegrityChecker.isOfficial()) {
331-
HintPane unofficialHint = new HintPane(MessageDialogPane.MessageType.WARNING);
332-
unofficialHint.setText(i18n("unofficial.hint"));
333-
vbox.getChildren().add(unofficialHint);
334-
}
335-
336-
vbox.getChildren().addAll(hintPane, box);
288+
detailsPane = vbox;
337289

338-
btnAccept.setDisable(false);
339-
} else {
290+
if (Accounts.OAUTH_CALLBACK.getClientId().isEmpty()) {
340291
HintPane hintPane = new HintPane(MessageDialogPane.MessageType.WARNING);
341292
hintPane.setSegment(i18n("account.methods.microsoft.snapshot"));
293+
vbox.getChildren().add(hintPane);
294+
return;
295+
}
342296

343-
JFXHyperlink officialWebsite = new JFXHyperlink(i18n("account.methods.microsoft.snapshot.website"));
344-
officialWebsite.setExternalLink(Metadata.PUBLISH_URL);
345-
346-
vbox.getChildren().setAll(hintPane, officialWebsite);
347-
btnAccept.setDisable(true);
297+
if (!IntegrityChecker.isOfficial()) {
298+
HintPane hintPane = new HintPane(MessageDialogPane.MessageType.WARNING);
299+
hintPane.setSegment(i18n("unofficial.hint"));
300+
vbox.getChildren().add(hintPane);
348301
}
349302

350-
detailsPane = vbox;
303+
VBox codeBox = new VBox(8);
304+
Label hint = new Label(i18n("account.methods.microsoft.code"));
305+
Label code = new Label();
306+
code.setMouseTransparent(true);
307+
code.setStyle("-fx-font-size: 24");
308+
codeBox.getChildren().addAll(hint, code);
309+
codeBox.setAlignment(Pos.CENTER);
310+
vbox.getChildren().add(codeBox);
311+
312+
HintPane hintPane = new HintPane(MessageDialogPane.MessageType.INFO);
313+
HintPane errHintPane = new HintPane(MessageDialogPane.MessageType.ERROR);
314+
errHintPane.setVisible(false);
315+
errHintPane.setManaged(false);
316+
317+
codeBox.setVisible(false);
318+
codeBox.setManaged(false);
319+
320+
FXUtils.onChangeAndOperate(deviceCode, deviceCode -> {
321+
if (deviceCode != null) {
322+
FXUtils.copyText(deviceCode.getUserCode());
323+
code.setText(deviceCode.getUserCode());
324+
hintPane.setSegment(i18n("account.methods.microsoft.manual", deviceCode.getVerificationUri()));
325+
codeBox.setVisible(true);
326+
codeBox.setManaged(true);
327+
} else {
328+
hintPane.setSegment(i18n("account.methods.microsoft.hint"));
329+
codeBox.setVisible(false);
330+
codeBox.setManaged(false);
331+
}
332+
});
333+
334+
lblErrorMessage.setVisible(false);
335+
lblErrorMessage.textProperty().addListener((obs, oldVal, newVal) -> {
336+
boolean hasError = !newVal.isEmpty();
337+
errHintPane.setSegment(newVal);
338+
errHintPane.setVisible(hasError);
339+
errHintPane.setManaged(hasError);
340+
hintPane.setVisible(!hasError);
341+
hintPane.setManaged(!hasError);
342+
codeBox.setVisible(!hasError && deviceCode.get() != null);
343+
codeBox.setManaged(!hasError && deviceCode.get() != null);
344+
});
345+
346+
FXUtils.onClicked(codeBox, () -> {
347+
if (deviceCode.get() != null) FXUtils.copyText(deviceCode.get().getUserCode());
348+
});
349+
350+
holder.add(Accounts.OAUTH_CALLBACK.onGrantDeviceCode.registerWeak(value ->
351+
runInFX(() -> deviceCode.set(value))
352+
));
353+
354+
HBox linkBox = new HBox();
355+
JFXHyperlink profileLink = new JFXHyperlink(i18n("account.methods.microsoft.profile"));
356+
profileLink.setExternalLink("https://account.live.com/editprof.aspx");
357+
JFXHyperlink purchaseLink = new JFXHyperlink(i18n("account.methods.microsoft.purchase"));
358+
purchaseLink.setExternalLink(YggdrasilService.PURCHASE_URL);
359+
JFXHyperlink deauthorizeLink = new JFXHyperlink(i18n("account.methods.microsoft.deauthorize"));
360+
deauthorizeLink.setExternalLink("https://account.live.com/consent/Edit?client_id=000000004C794E0A");
361+
JFXHyperlink forgotpasswordLink = new JFXHyperlink(i18n("account.methods.forgot_password"));
362+
forgotpasswordLink.setExternalLink("https://account.live.com/ResetPassword.aspx");
363+
linkBox.getChildren().setAll(profileLink, purchaseLink, deauthorizeLink, forgotpasswordLink);
364+
365+
vbox.getChildren().addAll(hintPane, errHintPane, linkBox);
366+
btnAccept.setDisable(false);
351367
} else {
352368
detailsPane = new AccountDetailsInputPane(factory, btnAccept::fire);
353369
btnAccept.disableProperty().bind(((AccountDetailsInputPane) detailsPane).validProperty().not());
354370
}
371+
355372
detailsContainer.getChildren().add(detailsPane);
356373
}
357374

HMCL/src/main/java/org/jackhuang/hmcl/ui/account/OAuthAccountLoginDialog.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ public OAuthAccountLoginDialog(OAuthAccount account, Consumer<AuthInfo> success,
6666

6767
HBox box = new HBox(8);
6868
JFXHyperlink birthLink = new JFXHyperlink(i18n("account.methods.microsoft.birth"));
69-
birthLink.setOnAction(e -> FXUtils.openLink("https://support.microsoft.com/account-billing/how-to-change-a-birth-date-on-a-microsoft-account-837badbc-999e-54d2-2617-d19206b9540a"));
69+
birthLink.setExternalLink("https://support.microsoft.com/account-billing/how-to-change-a-birth-date-on-a-microsoft-account-837badbc-999e-54d2-2617-d19206b9540a");
7070
JFXHyperlink profileLink = new JFXHyperlink(i18n("account.methods.microsoft.profile"));
71-
profileLink.setOnAction(e -> FXUtils.openLink("https://account.live.com/editprof.aspx"));
71+
profileLink.setExternalLink("https://account.live.com/editprof.aspx");
7272
JFXHyperlink purchaseLink = new JFXHyperlink(i18n("account.methods.microsoft.purchase"));
73-
purchaseLink.setOnAction(e -> FXUtils.openLink(YggdrasilService.PURCHASE_URL));
73+
purchaseLink.setExternalLink(YggdrasilService.PURCHASE_URL);
7474
box.getChildren().setAll(profileLink, birthLink, purchaseLink);
7575
GridPane.setColumnSpan(box, 2);
7676

HMCL/src/main/resources/assets/lang/I18N.properties

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,31 +100,31 @@ account.methods=Login Type
100100
account.methods.authlib_injector=authlib-injector
101101
account.methods.microsoft=Microsoft
102102
account.methods.microsoft.birth=How to Change Your Account Birth Date
103+
account.methods.microsoft.code=Code (Copied to Clipboard)
103104
account.methods.microsoft.close_page=Microsoft account authorization is now completed.\n\
104105
\n\
105106
There are some extra works for us, but you can safely close this tab for now.
106107
account.methods.microsoft.deauthorize=Deauthorize
107-
account.methods.microsoft.error.add_family=An adult must add you to a family in order for you to play Minecraft because you are not yet 18 years old.
108-
account.methods.microsoft.error.add_family_probably=Please check if the age indicated in your account settings is at least 18 years old. If not and you believe this is an error, you can click "How to Change Your Account Birth Date" to learn how to change it.
108+
account.methods.microsoft.error.add_family=Please click <a href="https://support.microsoft.com/account-billing/837badbc-999e-54d2-2617-d19206b9540a">here</a> to change your account birth date to be over 18 years old, or add your account to a family.
109109
account.methods.microsoft.error.country_unavailable=Xbox Live is not available in your current country/region.
110-
account.methods.microsoft.error.missing_xbox_account=Your Microsoft account does not have a linked Xbox account yet. Please click "Create Profile / Edit Profile Name" to create one before continuing.
111-
account.methods.microsoft.error.no_character=Please ensure you have purchased Minecraft: Java Edition.\nIf you have already purchased the game, a profile may not have been created yet.\nClick "Create Profile / Edit Profile Name" to create it.
112-
account.methods.microsoft.error.banned=Your account may have been banned by Xbox Live.\nYou can click "Ban Query" for more details.
110+
account.methods.microsoft.error.missing_xbox_account=Your Microsoft account does not have a linked Xbox account yet. Please click <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">here</a> to link one.
111+
account.methods.microsoft.error.no_character=Please confirm that you have purchased Minecraft: Java Edition.\n\
112+
If you have already purchased it, a game profile may not have been created. Please click <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">here</a> to create a game profile.
113+
account.methods.microsoft.error.banned=Your account may have been banned by Xbox Live.\n\
114+
You can click <a href="https://enforcement.xbox.com/enforcement/showenforcementhistory">here</a> to check the ban status of your account.
113115
account.methods.microsoft.error.unknown=Failed to log in, error code: %d.
114-
account.methods.microsoft.error.wrong_verify_method=Please log in using your password on the Microsoft account login page, and do not use a verification code to log in.
116+
account.methods.microsoft.error.wrong_verify_method=Failed to log in. Please try logging into your account using PASSWORD instead of other login methods.
115117
account.methods.microsoft.logging_in=Logging in...
116-
account.methods.microsoft.hint=Please click "Log in" and copy the code displayed here to complete the login process in the browser window that opens.\n\
117-
\n\
118-
If the token used to log in to the Microsoft account is leaked, you can click "Deauthorize" to deauthorize it.
119-
account.methods.microsoft.manual=Your device code is <b>%1$s</b>. Please click here to copy.\n\
120-
\n\
121-
After clicking "Log in", you should complete the login process in the opened browser window. If that does not show up, you can navigate to %2$s manually.\n\
122-
\n\
123-
If the token used to log in to the Microsoft account is leaked, you can click "Deauthorize" to deauthorize it.
124118
account.methods.microsoft.makegameidsettings=Create Profile / Edit Profile Name
119+
account.methods.microsoft.hint=Click the "Log in" button to start adding your Microsoft account.
120+
account.methods.microsoft.manual=Please enter the code shown above on the pop-up webpage to complete the login.\n\
121+
\n\
122+
If the website fails to load, please open %s manually in your browser.\n\
123+
\n\
124+
<b>If your internet connection is bad, it may cause web pages to load slowly or fail to load altogether. You may try again later or switch to a different internet connection.</b>
125125
account.methods.microsoft.profile=Account Profile
126126
account.methods.microsoft.purchase=Buy Minecraft
127-
account.methods.microsoft.snapshot=You are using an unofficial build of HMCL. Please download the official build to log in.
127+
account.methods.microsoft.snapshot=You are using an unofficial build of HMCL. Please download the <a href="https://hmcl.huangyuhui.net/download">official build</a> to log in.
128128
account.methods.microsoft.snapshot.website=Official Website
129129
account.methods.offline=Offline
130130
account.methods.offline.name.special_characters=Use only letters, numbers, and underscores (max 16 chars)

0 commit comments

Comments
 (0)