Skip to content

Commit ae85a7f

Browse files
committed
refactor: update userSettings access to use ConfigHolder for property methods
1 parent 9329742 commit ae85a7f

7 files changed

Lines changed: 30 additions & 79 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,23 +290,25 @@ static void init() {
290290
selected = accounts.get(0);
291291
}
292292

293-
if (!userSettings().isEnableOfflineAccount())
293+
if (!ConfigHolder.userSettings().enableOfflineAccountProperty().get())
294294
for (Account account : accounts) {
295295
if (account instanceof MicrosoftAccount) {
296-
userSettings().setEnableOfflineAccount(true);
296+
UserSettings userSettings = userSettings();
297+
userSettings.enableOfflineAccountProperty().set(true);
297298
break;
298299
}
299300
}
300301

301-
if (!userSettings().isEnableOfflineAccount())
302+
if (!ConfigHolder.userSettings().enableOfflineAccountProperty().get())
302303
accounts.addListener(new ListChangeListener<Account>() {
303304
@Override
304305
public void onChanged(Change<? extends Account> change) {
305306
while (change.next()) {
306307
for (Account account : change.getAddedSubList()) {
307308
if (account instanceof MicrosoftAccount) {
308309
accounts.removeListener(this);
309-
userSettings().setEnableOfflineAccount(true);
310+
UserSettings userSettings = userSettings();
311+
userSettings.enableOfflineAccountProperty().set(true);
310312
return;
311313
}
312314
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ public static void init() throws IOException {
388388

389389
Locale.setDefault(config().languageProperty().get().getLocale());
390390
I18n.setLocale(configInstance.languageProperty().get());
391-
LOG.setLogRetention(userSettings().getLogRetention());
391+
LOG.setLogRetention(userSettings().logRetentionProperty().get());
392392
loadGameDirectories(migratedGameDirectories, !unsupportedVersion);
393393
loadGameSettingsPresets(migratedGameSettingsPresets, !unsupportedVersion);
394394
loadLauncherState(migratedLauncherState, !unsupportedVersion);

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

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,6 @@ public IntegerProperty agreementVersionProperty() {
6262
return agreementVersion;
6363
}
6464

65-
/// Returns the accepted launcher agreement version.
66-
public int getAgreementVersion() {
67-
return agreementVersion.get();
68-
}
69-
70-
/// Sets the accepted launcher agreement version.
71-
public void setAgreementVersion(int agreementVersion) {
72-
this.agreementVersion.set(agreementVersion);
73-
}
74-
7565
/// The accepted Terracotta agreement version.
7666
@SerializedName("terracottaAgreementVersion")
7767
private final IntegerProperty terracottaAgreementVersion = new SimpleIntegerProperty();
@@ -81,16 +71,6 @@ public IntegerProperty terracottaAgreementVersionProperty() {
8171
return terracottaAgreementVersion;
8272
}
8373

84-
/// Returns the accepted Terracotta agreement version.
85-
public int getTerracottaAgreementVersion() {
86-
return terracottaAgreementVersion.get();
87-
}
88-
89-
/// Sets the accepted Terracotta agreement version.
90-
public void setTerracottaAgreementVersion(int terracottaAgreementVersion) {
91-
this.terracottaAgreementVersion.set(terracottaAgreementVersion);
92-
}
93-
9474
/// The platform prompt version shown to the user.
9575
@SerializedName("platformPromptVersion")
9676
private final IntegerProperty platformPromptVersion = new SimpleIntegerProperty();
@@ -100,16 +80,6 @@ public IntegerProperty platformPromptVersionProperty() {
10080
return platformPromptVersion;
10181
}
10282

103-
/// Returns the platform prompt version shown to the user.
104-
public int getPlatformPromptVersion() {
105-
return platformPromptVersion.get();
106-
}
107-
108-
/// Sets the platform prompt version shown to the user.
109-
public void setPlatformPromptVersion(int platformPromptVersion) {
110-
this.platformPromptVersion.set(platformPromptVersion);
111-
}
112-
11383
/// The number of launcher log files to retain.
11484
@SerializedName("logRetention")
11585
private final IntegerProperty logRetention = new SimpleIntegerProperty(20);
@@ -119,16 +89,6 @@ public IntegerProperty logRetentionProperty() {
11989
return logRetention;
12090
}
12191

122-
/// Returns the number of launcher log files to retain.
123-
public int getLogRetention() {
124-
return logRetention.get();
125-
}
126-
127-
/// Sets the number of launcher log files to retain.
128-
public void setLogRetention(int logRetention) {
129-
this.logRetention.set(logRetention);
130-
}
131-
13292
/// Whether offline accounts are enabled for this user.
13393
@SerializedName("enableOfflineAccount")
13494
private final BooleanProperty enableOfflineAccount = new SimpleBooleanProperty(false);
@@ -138,16 +98,6 @@ public BooleanProperty enableOfflineAccountProperty() {
13898
return enableOfflineAccount;
13999
}
140100

141-
/// Returns whether offline accounts are enabled for this user.
142-
public boolean isEnableOfflineAccount() {
143-
return enableOfflineAccount.get();
144-
}
145-
146-
/// Sets whether offline accounts are enabled for this user.
147-
public void setEnableOfflineAccount(boolean value) {
148-
enableOfflineAccount.set(value);
149-
}
150-
151101
/// The JavaFX font antialiasing mode override.
152102
@SerializedName("fontAntiAliasing")
153103
private final StringProperty fontAntiAliasing = new SimpleStringProperty();
@@ -157,16 +107,6 @@ public StringProperty fontAntiAliasingProperty() {
157107
return fontAntiAliasing;
158108
}
159109

160-
/// Returns the JavaFX font antialiasing mode override.
161-
public @Nullable String getFontAntiAliasing() {
162-
return fontAntiAliasing.get();
163-
}
164-
165-
/// Sets the JavaFX font antialiasing mode override.
166-
public void setFontAntiAliasing(@Nullable String value) {
167-
this.fontAntiAliasing.set(value);
168-
}
169-
170110
/// User-added Java executable paths.
171111
@SerializedName("userJava")
172112
private final ObservableSet<String> userJava = FXCollections.observableSet(new LinkedHashSet<>());

HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public static void initialize(Stage stage) {
257257
LOG.info("April Fools: " + AprilFools.isEnabled());
258258

259259
if (System.getProperty("prism.lcdtext") == null) {
260-
@Nullable String fontAntiAliasing = userSettings().getFontAntiAliasing();
260+
@Nullable String fontAntiAliasing = ConfigHolder.userSettings().fontAntiAliasingProperty().get();
261261
if ("lcd".equalsIgnoreCase(fontAntiAliasing)) {
262262
LOG.info("Enable sub-pixel antialiasing");
263263
System.getProperties().put("prism.lcdtext", "true");
@@ -389,8 +389,11 @@ public static void initialize(Stage stage) {
389389
timeline.play();
390390
}
391391

392-
if (!Architecture.SYSTEM_ARCH.isX86() && userSettings().getPlatformPromptVersion() < 1) {
393-
Runnable continueAction = () -> userSettings().setPlatformPromptVersion(1);
392+
if (!Architecture.SYSTEM_ARCH.isX86() && ConfigHolder.userSettings().platformPromptVersionProperty().get() < 1) {
393+
Runnable continueAction = () -> {
394+
UserSettings userSettings = userSettings();
395+
userSettings.platformPromptVersionProperty().set(1);
396+
};
394397

395398
if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS && Architecture.SYSTEM_ARCH == Architecture.ARM64) {
396399
continueAction.run();
@@ -445,7 +448,7 @@ public static void initialize(Stage stage) {
445448
.build());
446449
}
447450

448-
if (userSettings().getAgreementVersion() < 1) {
451+
if (ConfigHolder.userSettings().agreementVersionProperty().get() < 1) {
449452
JFXDialogLayout agreementPane = new JFXDialogLayout();
450453
agreementPane.setHeading(new Label(i18n("launcher.agreement")));
451454
agreementPane.setBody(new Label(i18n("launcher.agreement.hint")));
@@ -454,7 +457,8 @@ public static void initialize(Stage stage) {
454457
JFXButton yesButton = new JFXButton(i18n("launcher.agreement.accept"));
455458
yesButton.getStyleClass().add("dialog-accept");
456459
yesButton.setOnAction(e -> {
457-
userSettings().setAgreementVersion(1);
460+
UserSettings userSettings = userSettings();
461+
userSettings.agreementVersionProperty().set(1);
458462
agreementPane.fireEvent(new DialogCloseEvent());
459463
});
460464
JFXButton noButton = new JFXButton(i18n("launcher.agreement.decline"));

HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountListPage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.jackhuang.hmcl.auth.Account;
3939
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorServer;
4040
import org.jackhuang.hmcl.setting.Accounts;
41+
import org.jackhuang.hmcl.setting.ConfigHolder;
4142
import org.jackhuang.hmcl.ui.Controllers;
4243
import org.jackhuang.hmcl.ui.FXUtils;
4344
import org.jackhuang.hmcl.ui.SVG;
@@ -65,7 +66,7 @@ public final class AccountListPage extends DecoratorAnimatedPage implements Deco
6566

6667
if ("false".equals(property)
6768
|| "auto".equals(property) && LocaleUtils.IS_CHINA_MAINLAND
68-
|| userSettings().isEnableOfflineAccount())
69+
|| ConfigHolder.userSettings().enableOfflineAccountProperty().get())
6970
RESTRICTED.set(false);
7071
else
7172
userSettings().enableOfflineAccountProperty().addListener(new ChangeListener<Boolean>() {

HMCL/src/main/java/org/jackhuang/hmcl/ui/main/PersonalizationPage.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
import javafx.scene.layout.*;
3434
import javafx.scene.text.Font;
3535
import javafx.scene.text.FontSmoothingType;
36+
import org.jackhuang.hmcl.setting.ConfigHolder;
3637
import org.jackhuang.hmcl.setting.EnumBackgroundImage;
3738
import org.jackhuang.hmcl.setting.FontManager;
39+
import org.jackhuang.hmcl.setting.UserSettings;
3840
import org.jackhuang.hmcl.theme.ThemeColor;
3941
import org.jackhuang.hmcl.ui.FXUtils;
4042
import org.jackhuang.hmcl.ui.SVG;
@@ -307,7 +309,7 @@ public void changed(ObservableValue<? extends EnumBackgroundImage> observable, E
307309
Optional.of(FontSmoothingType.GRAY)
308310
);
309311

310-
@Nullable String fontAntiAliasing = userSettings().getFontAntiAliasing();
312+
@Nullable String fontAntiAliasing = ConfigHolder.userSettings().fontAntiAliasingProperty().get();
311313
if ("lcd".equalsIgnoreCase(fontAntiAliasing)) {
312314
fontAntiAliasingPane.setValue(Optional.of(FontSmoothingType.LCD));
313315
} else if ("gray".equalsIgnoreCase(fontAntiAliasing)) {
@@ -317,8 +319,11 @@ public void changed(ObservableValue<? extends EnumBackgroundImage> observable, E
317319
}
318320

319321
FXUtils.onChange(fontAntiAliasingPane.valueProperty(), value ->
320-
userSettings().setFontAntiAliasing(value.map(it -> it.name().toLowerCase(Locale.ROOT))
321-
.orElse(null)));
322+
{
323+
UserSettings userSettings = userSettings();
324+
userSettings.fontAntiAliasingProperty().set(value.map(it -> it.name().toLowerCase(Locale.ROOT))
325+
.orElse(null));
326+
});
322327

323328
fontPane.getContent().add(fontAntiAliasingPane);
324329
}

HMCL/src/main/java/org/jackhuang/hmcl/ui/terracotta/TerracottaPage.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
import javafx.scene.layout.BorderPane;
2626
import javafx.scene.layout.Priority;
2727
import javafx.scene.layout.VBox;
28-
import org.jackhuang.hmcl.setting.Accounts;
29-
import org.jackhuang.hmcl.setting.Profile;
30-
import org.jackhuang.hmcl.setting.Profiles;
28+
import org.jackhuang.hmcl.setting.*;
3129
import org.jackhuang.hmcl.terracotta.TerracottaMetadata;
3230
import org.jackhuang.hmcl.ui.Controllers;
3331
import org.jackhuang.hmcl.ui.FXUtils;
@@ -114,9 +112,10 @@ public TerracottaPage() {
114112
public void onPageShown() {
115113
tab.onPageShown();
116114

117-
if (userSettings().getTerracottaAgreementVersion() < TERRACOTTA_AGREEMENT_VERSION) {
115+
if (ConfigHolder.userSettings().terracottaAgreementVersionProperty().get() < TERRACOTTA_AGREEMENT_VERSION) {
118116
Controllers.confirmWithCountdown(i18n("terracotta.confirm.desc"), i18n("terracotta.confirm.title"), 5, MessageDialogPane.MessageType.INFO, () -> {
119-
userSettings().setTerracottaAgreementVersion(TERRACOTTA_AGREEMENT_VERSION);
117+
UserSettings userSettings = userSettings();
118+
userSettings.terracottaAgreementVersionProperty().set(TERRACOTTA_AGREEMENT_VERSION);
120119
}, () -> fireEvent(new PageCloseEvent()));
121120
}
122121
}

0 commit comments

Comments
 (0)