mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-14 14:26:43 -04:00
more precise warning in authlib injector add server page
This commit is contained in:
parent
e75ad64483
commit
7c8ac4fee8
@ -88,17 +88,13 @@ public final class Accounts {
|
|||||||
return jar.getAbsolutePath();
|
return jar.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getAuthlibInjectorServerName(String serverIp) {
|
public static String getAuthlibInjectorServerName(String serverIp) throws Exception {
|
||||||
if (AUTHLIB_INJECTOR_SERVER_NAMES.containsKey(serverIp))
|
if (AUTHLIB_INJECTOR_SERVER_NAMES.containsKey(serverIp))
|
||||||
return AUTHLIB_INJECTOR_SERVER_NAMES.get(serverIp);
|
return AUTHLIB_INJECTOR_SERVER_NAMES.get(serverIp);
|
||||||
else {
|
else {
|
||||||
try {
|
AuthlibInjectorServerResponse response = Constants.GSON.fromJson(NetworkUtils.doGet(NetworkUtils.toURL(serverIp)), AuthlibInjectorServerResponse.class);
|
||||||
AuthlibInjectorServerResponse response = Constants.GSON.fromJson(NetworkUtils.doGet(NetworkUtils.toURL(serverIp)), AuthlibInjectorServerResponse.class);
|
AUTHLIB_INJECTOR_SERVER_NAMES.put(serverIp, response.getMeta().getServerName());
|
||||||
AUTHLIB_INJECTOR_SERVER_NAMES.put(serverIp, response.getMeta().getServerName());
|
return response.getMeta().getServerName();
|
||||||
return response.getMeta().getServerName();
|
|
||||||
} catch (JsonParseException | IOException | NullPointerException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,13 +49,16 @@ import org.jackhuang.hmcl.ui.construct.AdvancedListBox;
|
|||||||
import org.jackhuang.hmcl.ui.construct.IconedItem;
|
import org.jackhuang.hmcl.ui.construct.IconedItem;
|
||||||
import org.jackhuang.hmcl.ui.construct.Validator;
|
import org.jackhuang.hmcl.ui.construct.Validator;
|
||||||
import org.jackhuang.hmcl.ui.wizard.DecoratorPage;
|
import org.jackhuang.hmcl.ui.wizard.DecoratorPage;
|
||||||
|
import org.jackhuang.hmcl.util.Logging;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public final class AccountsPage extends StackPane implements DecoratorPage {
|
public final class AccountsPage extends StackPane implements DecoratorPage {
|
||||||
private final StringProperty title = new SimpleStringProperty(this, "title", Main.i18n("account"));
|
private final StringProperty title = new SimpleStringProperty(this, "title", Main.i18n("account"));
|
||||||
@ -133,7 +136,14 @@ public final class AccountsPage extends StackPane implements DecoratorPage {
|
|||||||
|
|
||||||
public void loadServers() {
|
public void loadServers() {
|
||||||
Task.ofResult("list", () -> Settings.INSTANCE.getAuthlibInjectorServerURLs().parallelStream()
|
Task.ofResult("list", () -> Settings.INSTANCE.getAuthlibInjectorServerURLs().parallelStream()
|
||||||
.map(serverURL -> new TwoLineListItem(Accounts.getAuthlibInjectorServerName(serverURL), serverURL))
|
.flatMap(serverURL -> {
|
||||||
|
try {
|
||||||
|
return Stream.of(new TwoLineListItem(Accounts.getAuthlibInjectorServerName(serverURL), serverURL));
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logging.LOG.log(Level.WARNING, "Authlib-injector server root " + serverURL + " cannot be recognized.", e);
|
||||||
|
return Stream.empty();
|
||||||
|
}
|
||||||
|
})
|
||||||
.collect(Collectors.toList()))
|
.collect(Collectors.toList()))
|
||||||
.subscribe(Task.of(Schedulers.javafx(), variables -> {
|
.subscribe(Task.of(Schedulers.javafx(), variables -> {
|
||||||
cboServers.getItems().setAll(variables.<Collection<TwoLineListItem>>get("list"));
|
cboServers.getItems().setAll(variables.<Collection<TwoLineListItem>>get("list"));
|
||||||
|
@ -18,11 +18,14 @@ import org.jackhuang.hmcl.task.Task;
|
|||||||
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
|
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
|
||||||
import org.jackhuang.hmcl.ui.animation.TransitionHandler;
|
import org.jackhuang.hmcl.ui.animation.TransitionHandler;
|
||||||
import org.jackhuang.hmcl.ui.wizard.DecoratorPage;
|
import org.jackhuang.hmcl.ui.wizard.DecoratorPage;
|
||||||
|
import org.jackhuang.hmcl.util.Logging;
|
||||||
import org.jackhuang.hmcl.util.NetworkUtils;
|
import org.jackhuang.hmcl.util.NetworkUtils;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class AuthlibInjectorServersPage extends StackPane implements DecoratorPage {
|
public class AuthlibInjectorServersPage extends StackPane implements DecoratorPage {
|
||||||
private final StringProperty title = new SimpleStringProperty(this, "title", Main.i18n("account.injector.server"));
|
private final StringProperty title = new SimpleStringProperty(this, "title", Main.i18n("account.injector.server"));
|
||||||
@ -69,7 +72,14 @@ public class AuthlibInjectorServersPage extends StackPane implements DecoratorPa
|
|||||||
spinner.setVisible(true);
|
spinner.setVisible(true);
|
||||||
|
|
||||||
Task.ofResult("list", () -> Settings.INSTANCE.getAuthlibInjectorServerURLs().parallelStream()
|
Task.ofResult("list", () -> Settings.INSTANCE.getAuthlibInjectorServerURLs().parallelStream()
|
||||||
.map(serverURL -> new AuthlibInjectorServerItem(new AuthlibInjectorServerInfo(serverURL, Accounts.getAuthlibInjectorServerName(serverURL)), this::removeServer))
|
.flatMap(serverURL -> {
|
||||||
|
try {
|
||||||
|
return Stream.of(new AuthlibInjectorServerItem(new AuthlibInjectorServerInfo(serverURL, Accounts.getAuthlibInjectorServerName(serverURL)), this::removeServer));
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logging.LOG.log(Level.WARNING, "Authlib-injector server root " + serverURL + " cannot be recognized.", e);
|
||||||
|
return Stream.empty();
|
||||||
|
}
|
||||||
|
})
|
||||||
.collect(Collectors.toList()))
|
.collect(Collectors.toList()))
|
||||||
.subscribe(Task.of(Schedulers.javafx(), variables -> {
|
.subscribe(Task.of(Schedulers.javafx(), variables -> {
|
||||||
listPane.getChildren().setAll(variables.<Collection<? extends Node>>get("list"));
|
listPane.getChildren().setAll(variables.<Collection<? extends Node>>get("list"));
|
||||||
@ -105,7 +115,7 @@ public class AuthlibInjectorServersPage extends StackPane implements DecoratorPa
|
|||||||
progressBar.setVisible(true);
|
progressBar.setVisible(true);
|
||||||
addServerPane.setDisable(true);
|
addServerPane.setDisable(true);
|
||||||
|
|
||||||
Task.ofResult("serverName", () -> Objects.requireNonNull(Accounts.getAuthlibInjectorServerName(serverIp)))
|
Task.ofResult("serverName", () -> Accounts.getAuthlibInjectorServerName(serverIp))
|
||||||
.finalized(Schedulers.javafx(), (variables, isDependentsSucceeded) -> {
|
.finalized(Schedulers.javafx(), (variables, isDependentsSucceeded) -> {
|
||||||
progressBar.setVisible(false);
|
progressBar.setVisible(false);
|
||||||
addServerPane.setDisable(false);
|
addServerPane.setDisable(false);
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
<JFXTextField fx:id="txtServerIp" promptText="%account.injector.server_ip" labelFloat="true">
|
<JFXTextField fx:id="txtServerIp" promptText="%account.injector.server_ip" labelFloat="true">
|
||||||
<validators>
|
<validators>
|
||||||
<URLValidator message="%input.url">
|
<URLValidator message="%input.url">
|
||||||
|
</URLValidator>
|
||||||
|
<URLValidator message="%input.url.http">
|
||||||
<protocols>
|
<protocols>
|
||||||
<String fx:value="http" />
|
<String fx:value="http" />
|
||||||
<String fx:value="https" />
|
<String fx:value="https" />
|
||||||
|
@ -136,6 +136,7 @@ input.email=The username must be an e-mail.
|
|||||||
input.number=Must be a number.
|
input.number=Must be a number.
|
||||||
input.not_empty=Input Requrired!
|
input.not_empty=Input Requrired!
|
||||||
input.url=Must be a valid URL.
|
input.url=Must be a valid URL.
|
||||||
|
input.url.http=Only Http or Https accepted.
|
||||||
|
|
||||||
install=Install New Game
|
install=Install New Game
|
||||||
install.failed=Failed to install
|
install.failed=Failed to install
|
||||||
|
@ -136,6 +136,7 @@ input.email=用户名必须是邮箱
|
|||||||
input.number=必须是数字
|
input.number=必须是数字
|
||||||
input.not_empty=必填项
|
input.not_empty=必填项
|
||||||
input.url=必须是合法的链接
|
input.url=必须是合法的链接
|
||||||
|
input.url.http=只支持Http或Https协议
|
||||||
|
|
||||||
install=添加游戏
|
install=添加游戏
|
||||||
install.failed=安装失败
|
install.failed=安装失败
|
||||||
|
Loading…
x
Reference in New Issue
Block a user