|
35 | 35 | import javafx.scene.control.Label; |
36 | 36 | import javafx.scene.control.TextInputControl; |
37 | 37 | import javafx.scene.layout.*; |
38 | | - |
39 | | -import org.jackhuang.hmcl.Metadata; |
40 | 38 | import org.jackhuang.hmcl.auth.AccountFactory; |
41 | 39 | import org.jackhuang.hmcl.auth.CharacterSelector; |
42 | 40 | import org.jackhuang.hmcl.auth.NoSelectedCharacterException; |
|
64 | 62 | import org.jackhuang.hmcl.util.javafx.BindingMapping; |
65 | 63 | import org.jetbrains.annotations.Nullable; |
66 | 64 |
|
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.*; |
72 | 66 | import java.util.concurrent.CountDownLatch; |
73 | 67 | import java.util.regex.Pattern; |
74 | 68 |
|
@@ -286,72 +280,95 @@ private void initDetailsPane() { |
286 | 280 | btnAccept.disableProperty().unbind(); |
287 | 281 | detailsContainer.getChildren().remove(detailsPane); |
288 | 282 | lblErrorMessage.setText(""); |
| 283 | + lblErrorMessage.setVisible(true); |
289 | 284 | } |
| 285 | + |
290 | 286 | if (factory == Accounts.FACTORY_MICROSOFT) { |
291 | 287 | 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; |
337 | 289 |
|
338 | | - btnAccept.setDisable(false); |
339 | | - } else { |
| 290 | + if (Accounts.OAUTH_CALLBACK.getClientId().isEmpty()) { |
340 | 291 | HintPane hintPane = new HintPane(MessageDialogPane.MessageType.WARNING); |
341 | 292 | hintPane.setSegment(i18n("account.methods.microsoft.snapshot")); |
| 293 | + vbox.getChildren().add(hintPane); |
| 294 | + return; |
| 295 | + } |
342 | 296 |
|
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); |
348 | 301 | } |
349 | 302 |
|
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); |
351 | 367 | } else { |
352 | 368 | detailsPane = new AccountDetailsInputPane(factory, btnAccept::fire); |
353 | 369 | btnAccept.disableProperty().bind(((AccountDetailsInputPane) detailsPane).validProperty().not()); |
354 | 370 | } |
| 371 | + |
355 | 372 | detailsContainer.getChildren().add(detailsPane); |
356 | 373 | } |
357 | 374 |
|
|
0 commit comments