diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameDownloadTask.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameDownloadTask.java index 18e31d4ad..e1e15a72d 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameDownloadTask.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameDownloadTask.java @@ -63,7 +63,7 @@ public class HMCLGameDownloadTask extends Task { // Force using common directory will not affect the behaviour that repository acts // Since we always copy the downloaded jar to .minecraft/versions// - File cache = new File(Optional.ofNullable(Settings.INSTANCE.getCommonDirectory()) + File cache = new File(Optional.ofNullable(Settings.instance().getCommonDirectory()) .orElse(Settings.getDefaultCommonDirectory()), "jars/" + gameVersion + ".jar"); if (cache.exists()) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java index 8155fff0f..0033ae6bd 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java @@ -58,10 +58,10 @@ public class HMCLGameRepository extends DefaultGameRepository { @Override public File getAssetDirectory(String version, String assetId) { - if (Settings.INSTANCE.isCommonDirectoryDisabled() || useSelf(assetId)) + if (Settings.instance().isCommonDirectoryDisabled() || useSelf(assetId)) return super.getAssetDirectory(version, assetId); else - return new File(Settings.INSTANCE.getCommonDirectory(), "assets"); + return new File(Settings.instance().getCommonDirectory(), "assets"); } @Override @@ -83,10 +83,10 @@ public class HMCLGameRepository extends DefaultGameRepository { public File getLibraryFile(Version version, Library lib) { VersionSetting vs = profile.getVersionSetting(version.getId()); File self = super.getLibraryFile(version, lib); - if (Settings.INSTANCE.isCommonDirectoryDisabled() || self.exists()) + if (Settings.instance().isCommonDirectoryDisabled() || self.exists()) return self; else - return new File(Settings.INSTANCE.getCommonDirectory(), "libraries/" + lib.getPath()); + return new File(Settings.instance().getCommonDirectory(), "libraries/" + lib.getPath()); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java index e17bd7823..d36cc3d0e 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java @@ -378,7 +378,7 @@ public final class LauncherHelper { System.out.print(log); logs.add(pair(log, level)); - if (logs.size() > Settings.INSTANCE.getLogLines()) + if (logs.size() > Settings.instance().getLogLines()) logs.removeFirst(); if (setting.isShowLogs()) { 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 44a58ce80..5ac018d9c 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java @@ -60,7 +60,7 @@ public final class Accounts { public static final OfflineAccountFactory FACTORY_OFFLINE = OfflineAccountFactory.INSTANCE; public static final YggdrasilAccountFactory FACTORY_YGGDRASIL = new YggdrasilAccountFactory(MojangYggdrasilProvider.INSTANCE); public static final AuthlibInjectorAccountFactory FACTORY_AUTHLIB_INJECTOR = new AuthlibInjectorAccountFactory( - new AuthlibInjectorDownloader(Launcher.HMCL_DIRECTORY.toPath(), () -> Settings.INSTANCE.getDownloadProvider())::getArtifactInfo, + new AuthlibInjectorDownloader(Launcher.HMCL_DIRECTORY.toPath(), () -> Settings.instance().getDownloadProvider())::getArtifactInfo, Accounts::getOrCreateAuthlibInjectorServer); private static final String TYPE_OFFLINE = "offline"; diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Profile.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Profile.java index e6b134098..ffff683cd 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Profile.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Profile.java @@ -122,7 +122,7 @@ public final class Profile { } public HMCLDependencyManager getDependency() { - return new HMCLDependencyManager(this, Settings.INSTANCE.getDownloadProvider()); + return new HMCLDependencyManager(this, Settings.instance().getDownloadProvider()); } public VersionSetting getVersionSetting(String id) { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Settings.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Settings.java index d79581ddc..fd21827b7 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Settings.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Settings.java @@ -34,7 +34,11 @@ import static org.jackhuang.hmcl.setting.ConfigHolder.config; public class Settings { - public static final Settings INSTANCE = new Settings(); + private static Settings instance = new Settings(); + + public static Settings instance() { + return instance; + } private final boolean firstLaunch; diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java index 63495c4b0..99fb168ba 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java @@ -102,7 +102,7 @@ public final class Controllers { decorator.showPage(null); leftPaneController = new LeftPaneController(decorator.getLeftPane()); - Settings.INSTANCE.onProfileLoading(); + Settings.instance().onProfileLoading(); Task.of(JavaVersion::initialize).start(); decorator.setCustomMaximize(false); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Decorator.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Decorator.java index c2bbb588e..519cd8f90 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Decorator.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Decorator.java @@ -200,7 +200,7 @@ public final class Decorator extends StackPane implements TaskExecutorDialogWiza ); nowAnimation.play(); }); - if (!Settings.INSTANCE.isFirstLaunch() || Settings.INSTANCE.getLocale().getLocale() != Locale.CHINA) + if (!Settings.instance().isFirstLaunch() || Settings.instance().getLocale().getLocale() != Locale.CHINA) drawerWrapper.getChildren().remove(welcomeView); if (!min) buttonsContainer.getChildren().remove(btnMin); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java index 06d0beb70..343041dd1 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java @@ -216,11 +216,11 @@ public final class LeftPaneController { private void onProfilesLoading() { LinkedList list = new LinkedList<>(); - for (Profile profile : Settings.INSTANCE.getProfiles()) { + for (Profile profile : Settings.instance().getProfiles()) { VersionListItem item = new VersionListItem(Profiles.getProfileDisplayName(profile)); RipplerContainer ripplerContainer = new RipplerContainer(item); item.setOnSettingsButtonClicked(e -> Controllers.getDecorator().showPage(new ProfilePage(profile))); - ripplerContainer.setOnMouseClicked(e -> Settings.INSTANCE.setSelectedProfile(profile)); + ripplerContainer.setOnMouseClicked(e -> Settings.instance().setSelectedProfile(profile)); ripplerContainer.getProperties().put("profile", profile.getName()); ripplerContainer.maxWidthProperty().bind(leftPane.widthProperty()); list.add(ripplerContainer); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java index f7925e0d0..ac835799d 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java @@ -177,12 +177,12 @@ public final class LogWindow extends Stage { engine = webView.getEngine(); engine.loadContent(Lang.ignoringException(() -> IOUtils.readFullyAsString(getClass().getResourceAsStream("/assets/log-window-content.html"))) - .replace("${FONT}", Settings.INSTANCE.getFont().getSize() + "px \"" + Settings.INSTANCE.getFont().getFamily() + "\"")); + .replace("${FONT}", Settings.instance().getFont().getSize() + "px \"" + Settings.instance().getFont().getFamily() + "\"")); engine.getLoadWorker().stateProperty().addListener((a, b, newValue) -> { if (newValue == Worker.State.SUCCEEDED) { document = engine.getDocument(); body = document.getElementsByTagName("body").item(0); - engine.executeScript("limitedLogs=" + Settings.INSTANCE.getLogLines()); + engine.executeScript("limitedLogs=" + Settings.instance().getLogLines()); latch.countDown(); onDone.fireEvent(new Event(LogWindow.this)); } @@ -190,14 +190,14 @@ public final class LogWindow extends Stage { boolean flag = false; for (String i : cboLines.getItems()) - if (Integer.toString(Settings.INSTANCE.getLogLines()).equals(i)) { + if (Integer.toString(Settings.instance().getLogLines()).equals(i)) { cboLines.getSelectionModel().select(i); flag = true; } cboLines.getSelectionModel().selectedItemProperty().addListener((a, b, newValue) -> { - Settings.INSTANCE.setLogLines(newValue == null ? 100 : Integer.parseInt(newValue)); - engine.executeScript("limitedLogs=" + Settings.INSTANCE.getLogLines()); + Settings.instance().setLogLines(newValue == null ? 100 : Integer.parseInt(newValue)); + engine.executeScript("limitedLogs=" + Settings.instance().getLogLines()); }); if (!flag) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java index 8c973a6f8..1acbd7a67 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java @@ -101,7 +101,7 @@ public final class MainPage extends StackPane implements DecoratorPage { btnAdd.setOnMouseClicked(e -> Controllers.getDecorator().startWizard(new DownloadWizardProvider(), i18n("install"))); FXUtils.installTooltip(btnAdd, i18n("install")); - btnRefresh.setOnMouseClicked(e -> Settings.INSTANCE.getSelectedProfile().getRepository().refreshVersionsAsync().start()); + btnRefresh.setOnMouseClicked(e -> Settings.instance().getSelectedProfile().getRepository().refreshVersionsAsync().start()); FXUtils.installTooltip(btnRefresh, i18n("button.refresh")); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ProfilePage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ProfilePage.java index deface84d..c50b96c08 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ProfilePage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ProfilePage.java @@ -80,7 +80,7 @@ public final class ProfilePage extends StackPane implements DecoratorPage { @FXML private void onDelete() { if (profile != null) { - Settings.INSTANCE.deleteProfile(profile); + Settings.instance().deleteProfile(profile); Controllers.navigate(null); } } @@ -99,10 +99,10 @@ public final class ProfilePage extends StackPane implements DecoratorPage { } Profile newProfile = new Profile(txtProfileName.getText(), new File(getLocation())); newProfile.setUseRelativePath(toggleUseRelativePath.isSelected()); - Settings.INSTANCE.putProfile(newProfile); + Settings.instance().putProfile(newProfile); } - Settings.INSTANCE.onProfileLoading(); + Settings.instance().onProfileLoading(); Controllers.navigate(null); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java index b87710ca9..7a4411a54 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java @@ -111,35 +111,35 @@ public final class SettingsPage extends StackPane implements DecoratorPage { FXUtils.smoothScrolling(scroll); - cboDownloadSource.getSelectionModel().select(DownloadProviders.DOWNLOAD_PROVIDERS.indexOf(Settings.INSTANCE.getDownloadProvider())); - cboDownloadSource.getSelectionModel().selectedIndexProperty().addListener((a, b, newValue) -> Settings.INSTANCE.setDownloadProvider(DownloadProviders.getDownloadProvider(newValue.intValue()))); + cboDownloadSource.getSelectionModel().select(DownloadProviders.DOWNLOAD_PROVIDERS.indexOf(Settings.instance().getDownloadProvider())); + cboDownloadSource.getSelectionModel().selectedIndexProperty().addListener((a, b, newValue) -> Settings.instance().setDownloadProvider(DownloadProviders.getDownloadProvider(newValue.intValue()))); - cboFont.getSelectionModel().select(Settings.INSTANCE.getFont().getFamily()); + cboFont.getSelectionModel().select(Settings.instance().getFont().getFamily()); cboFont.valueProperty().addListener((a, b, newValue) -> { - Font font = Font.font(newValue, Settings.INSTANCE.getFont().getSize()); - Settings.INSTANCE.setFont(font); + Font font = Font.font(newValue, Settings.instance().getFont().getSize()); + Settings.instance().setFont(font); lblDisplay.setStyle("-fx-font: " + font.getSize() + " \"" + font.getFamily() + "\";"); }); - txtFontSize.setText(Double.toString(Settings.INSTANCE.getFont().getSize())); + txtFontSize.setText(Double.toString(Settings.instance().getFont().getSize())); txtFontSize.getValidators().add(new Validator(it -> Lang.toDoubleOrNull(it) != null)); txtFontSize.textProperty().addListener((a, b, newValue) -> { if (txtFontSize.validate()) { - Font font = Font.font(Settings.INSTANCE.getFont().getFamily(), Double.parseDouble(newValue)); - Settings.INSTANCE.setFont(font); + Font font = Font.font(Settings.instance().getFont().getFamily(), Double.parseDouble(newValue)); + Settings.instance().setFont(font); lblDisplay.setStyle("-fx-font: " + font.getSize() + " \"" + font.getFamily() + "\";"); } }); - lblDisplay.setStyle("-fx-font: " + Settings.INSTANCE.getFont().getSize() + " \"" + Settings.INSTANCE.getFont().getFamily() + "\";"); + lblDisplay.setStyle("-fx-font: " + Settings.instance().getFont().getSize() + " \"" + Settings.instance().getFont().getFamily() + "\";"); ObservableList