From 1d5ecb92360eb412bdd54965e5e2467eeaa540cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=9E=E5=BA=90?= <109708109+CiiLu@users.noreply.github.com> Date: Mon, 31 Aug 2026 21:25:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9B=B8=E5=90=8C=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E6=8F=90=E5=8F=96=E9=AA=8C=E8=AF=81=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E5=B1=95=E7=A4=BA=E5=9F=9F=E5=90=8D=20(#6762)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmcl/ui/account/AccountListPage.java | 18 +----- .../hmcl/ui/account/CreateAccountPane.java | 27 +-------- .../AuthlibInjectorServer.java | 60 ++++++++++++------- 3 files changed, 40 insertions(+), 65 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountListPage.java index cd77b84d9c..72c869ec68 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountListPage.java @@ -18,13 +18,7 @@ package org.jackhuang.hmcl.ui.account; import javafx.beans.binding.Bindings; -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.ListProperty; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.ReadOnlyObjectProperty; -import javafx.beans.property.ReadOnlyObjectWrapper; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.property.SimpleListProperty; +import javafx.beans.property.*; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; @@ -47,7 +41,6 @@ import org.jackhuang.hmcl.ui.construct.ClassTitle; import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage; import org.jackhuang.hmcl.ui.decorator.DecoratorPage; import org.jackhuang.hmcl.util.i18n.LocaleUtils; -import org.jackhuang.hmcl.util.io.NetworkUtils; import org.jackhuang.hmcl.util.javafx.BindingMapping; import org.jackhuang.hmcl.util.javafx.MappedObservableList; @@ -56,7 +49,6 @@ import java.util.Locale; import static org.jackhuang.hmcl.setting.SettingsManager.userSettings; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.javafx.ExtendedProperties.createSelectedItemPropertyFor; -import static org.jackhuang.hmcl.util.logging.Logger.LOG; public final class AccountListPage extends DecoratorAnimatedPage implements DecoratorPage { static final BooleanProperty RESTRICTED = new SimpleBooleanProperty(true); @@ -173,13 +165,7 @@ public final class AccountListPage extends DecoratorAnimatedPage implements Deco ObservableValue title = BindingMapping.of(server, AuthlibInjectorServer::getName); item.titleProperty().bind(title); - String host = ""; - try { - host = NetworkUtils.toURI(server.getUrl()).getHost(); - } catch (IllegalArgumentException e) { - LOG.warning("Unparsable authlib-injector server url " + server.getUrl(), e); - } - item.subtitleProperty().set(host); + item.setSubtitle(server.getDisplayHostUrl()); Tooltip tooltip = new Tooltip(); tooltip.textProperty().bind(Bindings.format("%s (%s)", title, server.getUrl())); FXUtils.installFastTooltip(item, tooltip); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/CreateAccountPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/CreateAccountPane.java index 341929ca08..4fef10a78f 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/CreateAccountPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/CreateAccountPane.java @@ -33,7 +33,6 @@ import javafx.scene.control.Hyperlink; import javafx.scene.control.Label; import javafx.scene.control.TextInputControl; import javafx.scene.layout.*; -import org.glavo.url.WebURL; import org.glavo.uuid.UUIDs; import org.jackhuang.hmcl.auth.Account; import org.jackhuang.hmcl.auth.AccountFactory; @@ -72,7 +71,6 @@ import static org.jackhuang.hmcl.setting.SettingsManager.getAuthlibInjectorServe import static org.jackhuang.hmcl.setting.SettingsManager.settings; import static org.jackhuang.hmcl.ui.FXUtils.*; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; -import static org.jackhuang.hmcl.util.logging.Logger.LOG; public class CreateAccountPane extends JFXDialogLayout implements DialogAware { private static final Pattern USERNAME_CHECKER_PATTERN = Pattern.compile("^[A-Za-z0-9_]+$"); @@ -389,30 +387,7 @@ public class CreateAccountPane extends JFXDialogLayout implements DialogAware { add(lblServers, 0, rowIndex); cboServers = new JFXComboBox<>(); - cboServers.setConverter(stringConverter(it -> { - String url = it.getUrl(); - - try { - WebURL parsed = WebURL.parseBrowserInput(url); - if ("https".equals(parsed.getScheme())) { - StringBuilder builder = new StringBuilder(); - builder.append(it.getName()).append(" ("); - - builder.append(parsed.getHost()); - if (parsed.getPort() != 443) { - builder.append(':').append(parsed.getPort()); - } - - if (!"/api/yggdrasil/".equals(parsed.getPath())) - builder.append(parsed.getPath()); - builder.append(")"); - return builder.toString(); - } - } catch (Exception e) { - LOG.warning("Unparsable authlib-injector server url " + url, e); - } - return it.getName() + " (" + url + ")"; - })); + cboServers.setConverter(stringConverter(it -> String.format("%s (%s)", it.getName(), it.getDisplayHostUrl()))); bindContent(cboServers.getItems(), getAuthlibInjectorServers()); cboServers.getItems().addListener(onInvalidating( () -> Platform.runLater( // the selection will not be updated as expected if we call it immediately diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorServer.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorServer.java index c80722047a..f1be6c6efb 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorServer.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorServer.java @@ -17,17 +17,11 @@ */ package org.jackhuang.hmcl.auth.authlibinjector; -import static java.util.Collections.emptyMap; -import static org.jackhuang.hmcl.util.Lang.tryCast; -import static org.jackhuang.hmcl.util.logging.Logger.LOG; - -import java.io.IOException; -import java.lang.reflect.Type; -import java.net.HttpURLConnection; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Optional; - +import com.google.gson.*; +import com.google.gson.annotations.JsonAdapter; +import javafx.application.Platform; +import javafx.beans.InvalidationListener; +import javafx.beans.Observable; import org.glavo.url.WebURL; import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilService; import org.jackhuang.hmcl.util.io.HttpRequest; @@ -36,19 +30,16 @@ import org.jackhuang.hmcl.util.javafx.ObservableHelper; import org.jetbrains.annotations.NotNullByDefault; import org.jetbrains.annotations.Nullable; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.annotations.JsonAdapter; +import java.io.IOException; +import java.lang.reflect.Type; +import java.net.HttpURLConnection; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Optional; -import javafx.application.Platform; -import javafx.beans.InvalidationListener; -import javafx.beans.Observable; +import static java.util.Collections.emptyMap; +import static org.jackhuang.hmcl.util.Lang.tryCast; +import static org.jackhuang.hmcl.util.logging.Logger.LOG; @JsonAdapter(AuthlibInjectorServer.Deserializer.class) @NotNullByDefault @@ -210,6 +201,29 @@ public class AuthlibInjectorServer implements Observable { metadataRefreshed = false; } + public String getDisplayHostUrl() { + String url = this.getUrl(); + + try { + WebURL parsed = WebURL.parseBrowserInput(url); + if ("https".equals(parsed.getScheme())) { + StringBuilder builder = new StringBuilder(); + builder.append(parsed.getHost()); + if (parsed.getPort() != 443) { + builder.append(':').append(parsed.getPort()); + } + + if (!"/api/yggdrasil/".equals(parsed.getPath())) + builder.append(parsed.getPath()); + + return builder.toString(); + } + } catch (Exception e) { + LOG.warning("Unparsable authlib-injector server url " + url, e); + } + return url; + } + @Override public int hashCode() { return url.hashCode();