From 0ec00ede70529620090e2131c271593c19e8ee5d Mon Sep 17 00:00:00 2001 From: Glavo Date: Sat, 14 Jan 2023 02:15:07 +0800 Subject: [PATCH] close #1980: Make LittleSkin optional (#1995) * close #1980: Make LittleSkin optional * update * update * update --- .../org/jackhuang/hmcl/setting/Accounts.java | 23 ++++++++----------- .../org/jackhuang/hmcl/setting/Config.java | 15 ++++++++++++ .../hmcl/ui/account/AccountListPage.java | 8 ------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java index 49f63b5ea..a351de585 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java @@ -85,7 +85,6 @@ public final class Accounts { public static final YggdrasilAccountFactory FACTORY_MOJANG = YggdrasilAccountFactory.MOJANG; public static final AuthlibInjectorAccountFactory FACTORY_AUTHLIB_INJECTOR = new AuthlibInjectorAccountFactory(AUTHLIB_INJECTOR_DOWNLOADER, Accounts::getOrCreateAuthlibInjectorServer); public static final MicrosoftAccountFactory FACTORY_MICROSOFT = new MicrosoftAccountFactory(new MicrosoftService(OAUTH_CALLBACK)); - public static final BoundAuthlibInjectorAccountFactory FACTORY_LITTLE_SKIN = getAccountFactoryByAuthlibInjectorServer(new AuthlibInjectorServer("https://littleskin.cn/api/yggdrasil/")); public static final List> FACTORIES = immutableListOf(FACTORY_OFFLINE, FACTORY_MOJANG, FACTORY_MICROSOFT, FACTORY_AUTHLIB_INJECTOR); // ==== login type / account factory mapping ==== @@ -227,6 +226,16 @@ public final class Accounts { if (initialized) throw new IllegalStateException("Already initialized"); + if (!config().isAddedLittleSkin()) { + AuthlibInjectorServer littleSkin = new AuthlibInjectorServer("https://littleskin.cn/api/yggdrasil/"); + + if (config().getAuthlibInjectorServers().stream().noneMatch(it -> littleSkin.getUrl().equals(it.getUrl()))) { + config().getAuthlibInjectorServers().add(0, littleSkin); + } + + config().setAddedLittleSkin(true); + } + loadGlobalAccountStorages(); // load accounts @@ -324,14 +333,6 @@ public final class Accounts { triggerAuthlibInjectorUpdateCheck(); - Schedulers.io().execute(() -> { - try { - FACTORY_LITTLE_SKIN.getServer().fetchMetadataResponse(); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to fetch authlib-injector server metdata: " + FACTORY_LITTLE_SKIN.getServer(), e); - } - }); - for (AuthlibInjectorServer server : config().getAuthlibInjectorServers()) { if (selected instanceof AuthlibInjectorAccount && ((AuthlibInjectorAccount) selected).getServer() == server) continue; @@ -385,10 +386,6 @@ public final class Accounts { } private static AuthlibInjectorServer getOrCreateAuthlibInjectorServer(String url) { - if (url.equals(FACTORY_LITTLE_SKIN.getServer().getUrl())) { - return FACTORY_LITTLE_SKIN.getServer(); - } - return config().getAuthlibInjectorServers().stream() .filter(server -> url.equals(server.getUrl())) .findFirst() diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java index 5d33a83e5..b622c5f06 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java @@ -166,6 +166,9 @@ public final class Config implements Cloneable, Observable { @SerializedName("authlibInjectorServers") private ObservableList authlibInjectorServers = FXCollections.observableArrayList(server -> new Observable[] { server }); + @SerializedName("addedLittleSkin") + private BooleanProperty addedLittleSkin = new SimpleBooleanProperty(false); + @SerializedName("promptedVersion") private StringProperty promptedVersion = new SimpleStringProperty(); @@ -550,6 +553,18 @@ public final class Config implements Cloneable, Observable { return authlibInjectorServers; } + public boolean isAddedLittleSkin() { + return addedLittleSkin.get(); + } + + public BooleanProperty addedLittleSkinProperty() { + return addedLittleSkin; + } + + public void setAddedLittleSkin(boolean addedLittleSkin) { + this.addedLittleSkin.set(addedLittleSkin); + } + public int getConfigVersion() { return configVersion.get(); } 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 d906cff17..921d2c235 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 @@ -124,14 +124,6 @@ public class AccountListPage extends DecoratorAnimatedPage implements DecoratorP microsoftItem.setOnAction(e -> Controllers.dialog(new CreateAccountPane(Accounts.FACTORY_MICROSOFT))); boxMethods.getChildren().add(microsoftItem); - AdvancedListItem littleSkinItem = new AdvancedListItem(); - littleSkinItem.getStyleClass().add("navigation-drawer-item"); - littleSkinItem.setActionButtonVisible(false); - littleSkinItem.setTitle(i18n("account.methods.little_skin")); - littleSkinItem.setLeftGraphic(wrap(SVG::server)); - littleSkinItem.setOnAction(e -> Controllers.dialog(new CreateAccountPane(Accounts.FACTORY_LITTLE_SKIN))); - boxMethods.getChildren().add(littleSkinItem); - VBox boxAuthServers = new VBox(); authServerItems = MappedObservableList.create(skinnable.authServersProperty(), server -> { AdvancedListItem item = new AdvancedListItem();