Skip to content

Commit d7cc36d

Browse files
committed
refactor: update config accessors to use property methods
1 parent b6487fd commit d7cc36d

29 files changed

Lines changed: 87 additions & 457 deletions

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -623,22 +623,22 @@ public static long getAllocatedMemory(long minimum, long available, boolean auto
623623
}
624624

625625
public static ProxyOption getProxyOption() {
626-
if (!config().hasProxy() || config().getProxyType() == null) {
626+
if (!config().hasProxyProperty().get() || config().proxyTypeProperty().get() == null) {
627627
return ProxyOption.Default.INSTANCE;
628628
}
629629

630-
return switch (config().getProxyType()) {
630+
return switch (config().proxyTypeProperty().get()) {
631631
case DIRECT -> ProxyOption.Direct.INSTANCE;
632632
case HTTP, SOCKS -> {
633-
String proxyHost = config().getProxyHost();
634-
int proxyPort = config().getProxyPort();
633+
String proxyHost = config().proxyHostProperty().get();
634+
int proxyPort = config().proxyPortProperty().get();
635635

636636
if (StringUtils.isBlank(proxyHost) || proxyPort < 0 || proxyPort > 0xFFFF) {
637637
yield ProxyOption.Default.INSTANCE;
638638
}
639639

640-
String proxyUser = config().getProxyUser();
641-
String proxyPass = config().getProxyPass();
640+
String proxyUser = config().proxyUserProperty().get();
641+
String proxyPass = config().proxyPassProperty().get();
642642

643643
if (StringUtils.isBlank(proxyUser)) {
644644
proxyUser = null;
@@ -647,7 +647,7 @@ public static ProxyOption getProxyOption() {
647647
proxyPass = "";
648648
}
649649

650-
if (config().getProxyType() == Proxy.Type.HTTP) {
650+
if (config().proxyTypeProperty().get() == Proxy.Type.HTTP) {
651651
yield new ProxyOption.Http(proxyHost, proxyPort, proxyUser, proxyPass);
652652
} else {
653653
yield new ProxyOption.Socks(proxyHost, proxyPort, proxyUser, proxyPass);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public final class Log {
2525
public static final int DEFAULT_LOG_LINES = 2000;
2626

2727
public static int getLogLines() {
28-
Integer lines = config().getLogLines();
28+
Integer lines = config().logLinesProperty().get();
2929
return lines != null && lines > 0 ? lines : DEFAULT_LOG_LINES;
3030
}
3131

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static void init() {
266266
}
267267
}
268268

269-
String selectedAccountIdentifier = config().getSelectedAccount();
269+
String selectedAccountIdentifier = config().selectedAccountProperty().get();
270270
if (selected == null && selectedAccountIdentifier != null) {
271271
boolean portable = true;
272272
if (selectedAccountIdentifier.startsWith(GLOBAL_PREFIX)) {
@@ -341,9 +341,9 @@ public void onChanged(Change<? extends Account> change) {
341341
selectedAccount.addListener(onInvalidating(() -> {
342342
Account account = selectedAccount.get();
343343
if (account != null)
344-
config().setSelectedAccount(account.isPortable() ? account.getIdentifier() : GLOBAL_PREFIX + account.getIdentifier());
344+
config().selectedAccountProperty().set(account.isPortable() ? account.getIdentifier() : GLOBAL_PREFIX + account.getIdentifier());
345345
else
346-
config().setSelectedAccount(null);
346+
config().selectedAccountProperty().set(null);
347347
}));
348348
accounts.addListener(listener);
349349
accounts.addListener(onInvalidating(Accounts::updateAccountStorages));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static void init() {
8282
}
8383

8484
if (!configInstance.urls.isEmpty()) {
85-
config().setPreferredLoginType(Accounts.getLoginType(Accounts.FACTORY_AUTHLIB_INJECTOR));
85+
config().preferredLoginTypeProperty().set(Accounts.getLoginType(Accounts.FACTORY_AUTHLIB_INJECTOR));
8686
for (String url : configInstance.urls) {
8787
Task.supplyAsync(Schedulers.io(), () -> AuthlibInjectorServer.locateServer(url))
8888
.thenAcceptAsync(Schedulers.javafx(), server -> {

0 commit comments

Comments
 (0)