Replace CONFIG with config()

This commit is contained in:
yushijinhun 2018-07-29 12:21:30 +08:00
parent 45c7e0c231
commit 82a62e73c1
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
17 changed files with 103 additions and 96 deletions

View File

@ -33,7 +33,7 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.logging.Level; import java.util.logging.Level;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
/** /**
* @author huangyuhui * @author huangyuhui

View File

@ -34,7 +34,7 @@ import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
public class HMCLGameRepository extends DefaultGameRepository { public class HMCLGameRepository extends DefaultGameRepository {
private final Profile profile; private final Profile profile;

View File

@ -44,7 +44,7 @@ import java.util.logging.Level;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
import static javafx.collections.FXCollections.observableArrayList; import static javafx.collections.FXCollections.observableArrayList;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import static org.jackhuang.hmcl.ui.FXUtils.onInvalidating; import static org.jackhuang.hmcl.ui.FXUtils.onInvalidating;
import static org.jackhuang.hmcl.util.Lang.mapOf; import static org.jackhuang.hmcl.util.Lang.mapOf;
import static org.jackhuang.hmcl.util.Logging.LOG; import static org.jackhuang.hmcl.util.Logging.LOG;
@ -125,7 +125,7 @@ public final class Accounts {
// selection is valid, store it // selection is valid, store it
if (!initialized) if (!initialized)
return; return;
CONFIG.setSelectedAccount(selected == null ? "" : accountId(selected)); config().setSelectedAccount(selected == null ? "" : accountId(selected));
} }
}; };
@ -144,7 +144,7 @@ public final class Accounts {
if (!initialized) if (!initialized)
return; return;
// update storage // update storage
CONFIG.getAccountStorages().setAll( config().getAccountStorages().setAll(
accounts.stream() accounts.stream()
.map(account -> { .map(account -> {
Map<Object, Object> storage = account.toStorage(); Map<Object, Object> storage = account.toStorage();
@ -155,14 +155,14 @@ public final class Accounts {
} }
/** /**
* Called when it's ready to load accounts from {@link ConfigHolder#CONFIG}. * Called when it's ready to load accounts from {@link ConfigHolder#config()}.
*/ */
static void init() { static void init() {
if (initialized) if (initialized)
throw new IllegalStateException("Already initialized"); throw new IllegalStateException("Already initialized");
// load accounts // load accounts
CONFIG.getAccountStorages().forEach(storage -> { config().getAccountStorages().forEach(storage -> {
AccountFactory<?> factory = type2factory.get(storage.get("type")); AccountFactory<?> factory = type2factory.get(storage.get("type"));
if (factory == null) { if (factory == null) {
LOG.warning("Unrecognized account type: " + storage); LOG.warning("Unrecognized account type: " + storage);
@ -180,12 +180,12 @@ public final class Accounts {
initialized = true; initialized = true;
CONFIG.getAuthlibInjectorServers().addListener(onInvalidating(Accounts::removeDanglingAuthlibInjectorAccounts)); config().getAuthlibInjectorServers().addListener(onInvalidating(Accounts::removeDanglingAuthlibInjectorAccounts));
// load selected account // load selected account
selectedAccount.set( selectedAccount.set(
accounts.stream() accounts.stream()
.filter(it -> accountId(it).equals(CONFIG.getSelectedAccount())) .filter(it -> accountId(it).equals(config().getSelectedAccount()))
.findFirst() .findFirst()
.orElse(null)); .orElse(null));
} }
@ -212,7 +212,7 @@ public final class Accounts {
// ==== authlib-injector ==== // ==== authlib-injector ====
private static AuthlibInjectorServer getOrCreateAuthlibInjectorServer(String url) { private static AuthlibInjectorServer getOrCreateAuthlibInjectorServer(String url) {
return CONFIG.getAuthlibInjectorServers().stream() return config().getAuthlibInjectorServers().stream()
.filter(server -> url.equals(server.getUrl())) .filter(server -> url.equals(server.getUrl()))
.findFirst() .findFirst()
.orElseGet(() -> { .orElseGet(() -> {
@ -226,7 +226,7 @@ public final class Accounts {
LOG.log(Level.WARNING, "Failed to migrate authlib injector server " + url, e); LOG.log(Level.WARNING, "Failed to migrate authlib injector server " + url, e);
} }
CONFIG.getAuthlibInjectorServers().add(server); config().getAuthlibInjectorServers().add(server);
return server; return server;
}); });
} }
@ -239,7 +239,7 @@ public final class Accounts {
accounts.stream() accounts.stream()
.filter(AuthlibInjectorAccount.class::isInstance) .filter(AuthlibInjectorAccount.class::isInstance)
.map(AuthlibInjectorAccount.class::cast) .map(AuthlibInjectorAccount.class::cast)
.filter(it -> !CONFIG.getAuthlibInjectorServers().contains(it.getServer())) .filter(it -> !config().getAuthlibInjectorServers().contains(it.getServer()))
.collect(toList()) .collect(toList())
.forEach(accounts::remove); .forEach(accounts::remove);
} }

View File

@ -36,7 +36,14 @@ public final class ConfigHolder {
public static final String CONFIG_FILENAME = "hmcl.json"; public static final String CONFIG_FILENAME = "hmcl.json";
public static final Path CONFIG_PATH = Paths.get(CONFIG_FILENAME).toAbsolutePath(); public static final Path CONFIG_PATH = Paths.get(CONFIG_FILENAME).toAbsolutePath();
public static final Config CONFIG = initSettings(); private static Config configInstance = initSettings();
public static Config config() {
if (configInstance == null) {
throw new IllegalStateException("Configuration hasn't been loaded");
}
return configInstance;
}
private static Config upgradeSettings(Config deserialized, Map<?, ?> rawJson) { private static Config upgradeSettings(Config deserialized, Map<?, ?> rawJson) {
if (!rawJson.containsKey("commonDirType")) if (!rawJson.containsKey("commonDirType"))
@ -67,7 +74,7 @@ public final class ConfigHolder {
static void saveConfig() { static void saveConfig() {
LOG.info("Saving config"); LOG.info("Saving config");
try { try {
Files.write(CONFIG_PATH, CONFIG.toJson().getBytes(UTF_8)); Files.write(CONFIG_PATH, configInstance.toJson().getBytes(UTF_8));
} catch (IOException ex) { } catch (IOException ex) {
LOG.log(Level.SEVERE, "Failed to save config", ex); LOG.log(Level.SEVERE, "Failed to save config", ex);
} }

View File

@ -17,7 +17,7 @@
*/ */
package org.jackhuang.hmcl.setting; package org.jackhuang.hmcl.setting;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import java.net.Authenticator; import java.net.Authenticator;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -38,18 +38,18 @@ public final class ProxyManager {
private static ObjectBinding<Proxy> proxyProperty = Bindings.createObjectBinding( private static ObjectBinding<Proxy> proxyProperty = Bindings.createObjectBinding(
() -> { () -> {
String host = CONFIG.getProxyHost(); String host = config().getProxyHost();
Integer port = Lang.toIntOrNull(CONFIG.getProxyPort()); Integer port = Lang.toIntOrNull(config().getProxyPort());
if (!CONFIG.hasProxy() || StringUtils.isBlank(host) || port == null || CONFIG.getProxyType() == Proxy.Type.DIRECT) { if (!config().hasProxy() || StringUtils.isBlank(host) || port == null || config().getProxyType() == Proxy.Type.DIRECT) {
return Proxy.NO_PROXY; return Proxy.NO_PROXY;
} else { } else {
return new Proxy(CONFIG.getProxyType(), new InetSocketAddress(host, port)); return new Proxy(config().getProxyType(), new InetSocketAddress(host, port));
} }
}, },
CONFIG.proxyTypeProperty(), config().proxyTypeProperty(),
CONFIG.proxyHostProperty(), config().proxyHostProperty(),
CONFIG.proxyPortProperty(), config().proxyPortProperty(),
CONFIG.hasProxyProperty()); config().hasProxyProperty());
public static Proxy getProxy() { public static Proxy getProxy() {
return proxyProperty.get(); return proxyProperty.get();
@ -68,9 +68,9 @@ public final class ProxyManager {
@Override @Override
protected PasswordAuthentication getPasswordAuthentication() { protected PasswordAuthentication getPasswordAuthentication() {
if (CONFIG.hasProxyAuth()) { if (config().hasProxyAuth()) {
String username = CONFIG.getProxyUser(); String username = config().getProxyUser();
String password = CONFIG.getProxyPass(); String password = config().getProxyPass();
if (username != null && password != null) { if (username != null && password != null) {
return new PasswordAuthentication(username, password.toCharArray()); return new PasswordAuthentication(username, password.toCharArray());
} }

View File

@ -30,7 +30,7 @@ import org.jackhuang.hmcl.util.i18n.Locales;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
public class Settings { public class Settings {
@ -39,7 +39,7 @@ public class Settings {
private final boolean firstLaunch; private final boolean firstLaunch;
private Settings() { private Settings() {
firstLaunch = CONFIG.isFirstLaunch(); firstLaunch = config().isFirstLaunch();
ProxyManager.init(); ProxyManager.init();
Accounts.init(); Accounts.init();
@ -52,15 +52,15 @@ public class Settings {
profileEntry.getValue().addPropertyChangedListener(e -> ConfigHolder.saveConfig()); profileEntry.getValue().addPropertyChangedListener(e -> ConfigHolder.saveConfig());
} }
CONFIG.addListener(source -> ConfigHolder.saveConfig()); config().addListener(source -> ConfigHolder.saveConfig());
CONFIG.setFirstLaunch(false); config().setFirstLaunch(false);
} }
public boolean isFirstLaunch() { public boolean isFirstLaunch() {
return firstLaunch; return firstLaunch;
} }
private Locales.SupportedLocale locale = Locales.getLocaleByName(CONFIG.getLocalization()); private Locales.SupportedLocale locale = Locales.getLocaleByName(config().getLocalization());
public Locales.SupportedLocale getLocale() { public Locales.SupportedLocale getLocale() {
return locale; return locale;
@ -68,28 +68,28 @@ public class Settings {
public void setLocale(Locales.SupportedLocale locale) { public void setLocale(Locales.SupportedLocale locale) {
this.locale = locale; this.locale = locale;
CONFIG.setLocalization(Locales.getNameByLocale(locale)); config().setLocalization(Locales.getNameByLocale(locale));
} }
public Font getFont() { public Font getFont() {
return Font.font(CONFIG.getFontFamily(), CONFIG.getFontSize()); return Font.font(config().getFontFamily(), config().getFontSize());
} }
public void setFont(Font font) { public void setFont(Font font) {
CONFIG.setFontFamily(font.getFamily()); config().setFontFamily(font.getFamily());
CONFIG.setFontSize(font.getSize()); config().setFontSize(font.getSize());
} }
public int getLogLines() { public int getLogLines() {
return Math.max(CONFIG.getLogLines(), 100); return Math.max(config().getLogLines(), 100);
} }
public void setLogLines(int logLines) { public void setLogLines(int logLines) {
CONFIG.setLogLines(logLines); config().setLogLines(logLines);
} }
public boolean isCommonDirectoryDisabled() { public boolean isCommonDirectoryDisabled() {
return CONFIG.getCommonDirType() == EnumCommonDirectory.DISABLED; return config().getCommonDirType() == EnumCommonDirectory.DISABLED;
} }
public static String getDefaultCommonDirectory() { public static String getDefaultCommonDirectory() {
@ -97,13 +97,13 @@ public class Settings {
} }
public String getCommonDirectory() { public String getCommonDirectory() {
switch (CONFIG.getCommonDirType()) { switch (config().getCommonDirType()) {
case DISABLED: case DISABLED:
return null; return null;
case DEFAULT: case DEFAULT:
return getDefaultCommonDirectory(); return getDefaultCommonDirectory();
case CUSTOM: case CUSTOM:
return CONFIG.getCommonDirectory(); return config().getCommonDirectory();
default: default:
return null; return null;
} }
@ -114,14 +114,14 @@ public class Settings {
****************************************/ ****************************************/
public DownloadProvider getDownloadProvider() { public DownloadProvider getDownloadProvider() {
return DownloadProviders.getDownloadProvider(CONFIG.getDownloadType()); return DownloadProviders.getDownloadProvider(config().getDownloadType());
} }
public void setDownloadProvider(DownloadProvider downloadProvider) { public void setDownloadProvider(DownloadProvider downloadProvider) {
int index = DownloadProviders.DOWNLOAD_PROVIDERS.indexOf(downloadProvider); int index = DownloadProviders.DOWNLOAD_PROVIDERS.indexOf(downloadProvider);
if (index == -1) if (index == -1)
throw new IllegalArgumentException("Unknown download provider: " + downloadProvider); throw new IllegalArgumentException("Unknown download provider: " + downloadProvider);
CONFIG.setDownloadType(index); config().setDownloadType(index);
} }
/**************************************** /****************************************
@ -131,18 +131,18 @@ public class Settings {
public Profile getSelectedProfile() { public Profile getSelectedProfile() {
checkProfileMap(); checkProfileMap();
if (!hasProfile(CONFIG.getSelectedProfile())) { if (!hasProfile(config().getSelectedProfile())) {
getProfileMap().keySet().stream().findFirst().ifPresent(selectedProfile -> { getProfileMap().keySet().stream().findFirst().ifPresent(selectedProfile -> {
CONFIG.setSelectedProfile(selectedProfile); config().setSelectedProfile(selectedProfile);
}); });
Schedulers.computation().schedule(this::onProfileChanged); Schedulers.computation().schedule(this::onProfileChanged);
} }
return getProfile(CONFIG.getSelectedProfile()); return getProfile(config().getSelectedProfile());
} }
public void setSelectedProfile(Profile selectedProfile) { public void setSelectedProfile(Profile selectedProfile) {
if (hasProfile(selectedProfile.getName()) && !Objects.equals(selectedProfile.getName(), CONFIG.getSelectedProfile())) { if (hasProfile(selectedProfile.getName()) && !Objects.equals(selectedProfile.getName(), config().getSelectedProfile())) {
CONFIG.setSelectedProfile(selectedProfile.getName()); config().setSelectedProfile(selectedProfile.getName());
Schedulers.computation().schedule(this::onProfileChanged); Schedulers.computation().schedule(this::onProfileChanged);
} }
} }
@ -159,7 +159,7 @@ public class Settings {
} }
public Map<String, Profile> getProfileMap() { public Map<String, Profile> getProfileMap() {
return CONFIG.getConfigurations(); return config().getConfigurations();
} }
public Collection<Profile> getProfiles() { public Collection<Profile> getProfiles() {

View File

@ -27,7 +27,7 @@ import org.jackhuang.hmcl.util.Logging;
import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter; import com.google.gson.stream.JsonWriter;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -120,7 +120,7 @@ public class Theme {
} }
public static ObjectBinding<Color> foregroundFillBinding() { public static ObjectBinding<Color> foregroundFillBinding() {
return Bindings.createObjectBinding(() -> CONFIG.getTheme().getForegroundColor(), CONFIG.themeProperty()); return Bindings.createObjectBinding(() -> config().getTheme().getForegroundColor(), config().themeProperty());
} }
public static ObjectBinding<Color> blackFillBinding() { public static ObjectBinding<Color> blackFillBinding() {

View File

@ -30,7 +30,7 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
/** /**
* *
@ -515,10 +515,10 @@ public final class VersionSetting {
.setFullscreen(isFullscreen()) .setFullscreen(isFullscreen())
.setServerIp(getServerIp()) .setServerIp(getServerIp())
.setWrapper(getWrapper()) .setWrapper(getWrapper())
.setProxyHost(CONFIG.getProxyHost()) .setProxyHost(config().getProxyHost())
.setProxyPort(CONFIG.getProxyPort()) .setProxyPort(config().getProxyPort())
.setProxyUser(CONFIG.getProxyUser()) .setProxyUser(config().getProxyUser())
.setProxyPass(CONFIG.getProxyPass()) .setProxyPass(config().getProxyPass())
.setPrecalledCommand(getPreLaunchCommand()) .setPrecalledCommand(getPreLaunchCommand())
.setNoGeneratedJVMArgs(isNoJVMArgs()) .setNoGeneratedJVMArgs(isNoJVMArgs())
.create(); .create();

View File

@ -54,7 +54,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.logging.Level; import java.util.logging.Level;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import static org.jackhuang.hmcl.ui.FXUtils.jfxListCellFactory; import static org.jackhuang.hmcl.ui.FXUtils.jfxListCellFactory;
import static org.jackhuang.hmcl.ui.FXUtils.onInvalidating; import static org.jackhuang.hmcl.ui.FXUtils.onInvalidating;
import static org.jackhuang.hmcl.ui.FXUtils.stringConverter; import static org.jackhuang.hmcl.ui.FXUtils.stringConverter;
@ -79,7 +79,7 @@ public class AddAccountPane extends StackPane {
cboServers.setCellFactory(jfxListCellFactory(server -> new TwoLineListItem(server.getName(), server.getUrl()))); cboServers.setCellFactory(jfxListCellFactory(server -> new TwoLineListItem(server.getName(), server.getUrl())));
cboServers.setConverter(stringConverter(AuthlibInjectorServer::getName)); cboServers.setConverter(stringConverter(AuthlibInjectorServer::getName));
Bindings.bindContent(cboServers.getItems(), CONFIG.getAuthlibInjectorServers()); Bindings.bindContent(cboServers.getItems(), config().getAuthlibInjectorServers());
cboServers.getItems().addListener(onInvalidating(this::selectDefaultServer)); cboServers.getItems().addListener(onInvalidating(this::selectDefaultServer));
selectDefaultServer(); selectDefaultServer();

View File

@ -39,7 +39,7 @@ import javafx.fxml.FXML;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
public class AddAuthlibInjectorServerPane extends StackPane { public class AddAuthlibInjectorServerPane extends StackPane {
@ -133,8 +133,8 @@ public class AddAuthlibInjectorServerPane extends StackPane {
@FXML @FXML
private void onAddFinish() { private void onAddFinish() {
if (!CONFIG.getAuthlibInjectorServers().contains(serverBeingAdded)) { if (!config().getAuthlibInjectorServers().contains(serverBeingAdded)) {
CONFIG.getAuthlibInjectorServers().add(serverBeingAdded); config().getAuthlibInjectorServers().add(serverBeingAdded);
} }
fireEvent(new DialogCloseEvent()); fireEvent(new DialogCloseEvent());
} }

View File

@ -34,7 +34,7 @@ import javafx.scene.control.ScrollPane;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
public class AuthlibInjectorServersPage extends StackPane implements DecoratorPage { public class AuthlibInjectorServersPage extends StackPane implements DecoratorPage {
private final StringProperty title = new SimpleStringProperty(this, "title", i18n("account.injector.manage.title")); private final StringProperty title = new SimpleStringProperty(this, "title", i18n("account.injector.manage.title"));
@ -49,13 +49,13 @@ public class AuthlibInjectorServersPage extends StackPane implements DecoratorPa
loadFXML(this, "/assets/fxml/authlib-injector-servers.fxml"); loadFXML(this, "/assets/fxml/authlib-injector-servers.fxml");
smoothScrolling(scrollPane); smoothScrolling(scrollPane);
serverItems = MappedObservableList.create(CONFIG.getAuthlibInjectorServers(), this::createServerItem); serverItems = MappedObservableList.create(config().getAuthlibInjectorServers(), this::createServerItem);
Bindings.bindContent(listPane.getChildren(), serverItems); Bindings.bindContent(listPane.getChildren(), serverItems);
} }
private AuthlibInjectorServerItem createServerItem(AuthlibInjectorServer server) { private AuthlibInjectorServerItem createServerItem(AuthlibInjectorServer server) {
return new AuthlibInjectorServerItem(server, return new AuthlibInjectorServerItem(server,
item -> CONFIG.getAuthlibInjectorServers().remove(item.getServer())); item -> config().getAuthlibInjectorServers().remove(item.getServer()));
} }
@FXML @FXML

View File

@ -34,7 +34,7 @@ import org.jackhuang.hmcl.ui.construct.TaskExecutorDialogPane;
import org.jackhuang.hmcl.util.FutureCallback; import org.jackhuang.hmcl.util.FutureCallback;
import org.jackhuang.hmcl.util.JavaVersion; import org.jackhuang.hmcl.util.JavaVersion;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -108,7 +108,7 @@ public final class Controllers {
decorator.setCustomMaximize(false); decorator.setCustomMaximize(false);
scene = new Scene(decorator, 804, 521); scene = new Scene(decorator, 804, 521);
scene.getStylesheets().setAll(CONFIG.getTheme().getStylesheets()); scene.getStylesheets().setAll(config().getTheme().getStylesheets());
stage.setMinWidth(804); stage.setMinWidth(804);
stage.setMaxWidth(804); stage.setMaxWidth(804);
stage.setMinHeight(521); stage.setMinHeight(521);

View File

@ -81,7 +81,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level; import java.util.logging.Level;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import static org.jackhuang.hmcl.util.Logging.LOG; import static org.jackhuang.hmcl.util.Logging.LOG;
public final class Decorator extends StackPane implements TaskExecutorDialogWizardDisplayer { public final class Decorator extends StackPane implements TaskExecutorDialogWizardDisplayer {
@ -228,8 +228,8 @@ public final class Decorator extends StackPane implements TaskExecutorDialogWiza
Bindings.createObjectBinding( Bindings.createObjectBinding(
() -> { () -> {
Image image = null; Image image = null;
if (CONFIG.getBackgroundImageType() == EnumBackgroundImage.CUSTOM && CONFIG.getBackgroundImage() != null) { if (config().getBackgroundImageType() == EnumBackgroundImage.CUSTOM && config().getBackgroundImage() != null) {
image = tryLoadImage(Paths.get(CONFIG.getBackgroundImage())) image = tryLoadImage(Paths.get(config().getBackgroundImage()))
.orElse(null); .orElse(null);
} }
if (image == null) { if (image == null) {
@ -237,8 +237,8 @@ public final class Decorator extends StackPane implements TaskExecutorDialogWiza
} }
return new Background(new BackgroundImage(image, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT, new BackgroundSize(800, 480, false, false, true, true))); return new Background(new BackgroundImage(image, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT, new BackgroundSize(800, 480, false, false, true, true)));
}, },
CONFIG.backgroundImageTypeProperty(), config().backgroundImageTypeProperty(),
CONFIG.backgroundImageProperty())); config().backgroundImageProperty()));
} }
private Image defaultBackground = new Image("/assets/img/background.jpg"); private Image defaultBackground = new Image("/assets/img/background.jpg");

View File

@ -43,7 +43,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -65,7 +65,7 @@ public final class LogWindow extends Stage {
public LogWindow() { public LogWindow() {
setScene(new Scene(impl, 800, 480)); setScene(new Scene(impl, 800, 480));
getScene().getStylesheets().addAll(CONFIG.getTheme().getStylesheets()); getScene().getStylesheets().addAll(config().getTheme().getStylesheets());
setTitle(i18n("logwindow.title")); setTitle(i18n("logwindow.title"));
getIcons().add(new Image("/assets/img/icon.png")); getIcons().add(new Image("/assets/img/icon.png"));
} }

View File

@ -47,7 +47,7 @@ import org.jackhuang.hmcl.ui.wizard.DecoratorPage;
import org.jackhuang.hmcl.util.Lang; import org.jackhuang.hmcl.util.Lang;
import org.jackhuang.hmcl.util.i18n.Locales; import org.jackhuang.hmcl.util.i18n.Locales;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
import java.net.Proxy; import java.net.Proxy;
@ -142,16 +142,16 @@ public final class SettingsPage extends StackPane implements DecoratorPage {
cboLanguage.getSelectionModel().selectedIndexProperty().addListener((a, b, newValue) -> Settings.INSTANCE.setLocale(Locales.getLocale(newValue.intValue()))); cboLanguage.getSelectionModel().selectedIndexProperty().addListener((a, b, newValue) -> Settings.INSTANCE.setLocale(Locales.getLocale(newValue.intValue())));
// ==== Proxy ==== // ==== Proxy ====
txtProxyHost.textProperty().bindBidirectional(CONFIG.proxyHostProperty()); txtProxyHost.textProperty().bindBidirectional(config().proxyHostProperty());
txtProxyPort.textProperty().bindBidirectional(CONFIG.proxyPortProperty()); txtProxyPort.textProperty().bindBidirectional(config().proxyPortProperty());
txtProxyUsername.textProperty().bindBidirectional(CONFIG.proxyUserProperty()); txtProxyUsername.textProperty().bindBidirectional(config().proxyUserProperty());
txtProxyPassword.textProperty().bindBidirectional(CONFIG.proxyPassProperty()); txtProxyPassword.textProperty().bindBidirectional(config().proxyPassProperty());
proxyPane.disableProperty().bind(chkEnableProxy.selectedProperty().not()); proxyPane.disableProperty().bind(chkEnableProxy.selectedProperty().not());
authPane.disableProperty().bind(chkProxyAuthentication.selectedProperty().not()); authPane.disableProperty().bind(chkProxyAuthentication.selectedProperty().not());
chkEnableProxy.selectedProperty().bindBidirectional(CONFIG.hasProxyProperty()); chkEnableProxy.selectedProperty().bindBidirectional(config().hasProxyProperty());
chkProxyAuthentication.selectedProperty().bindBidirectional(CONFIG.hasProxyAuthProperty()); chkProxyAuthentication.selectedProperty().bindBidirectional(config().hasProxyAuthProperty());
selectedProxyType = new SimpleObjectProperty<Proxy.Type>(Proxy.Type.HTTP) { selectedProxyType = new SimpleObjectProperty<Proxy.Type>(Proxy.Type.HTTP) {
{ {
@ -169,7 +169,7 @@ public final class SettingsPage extends StackPane implements DecoratorPage {
} }
} }
}; };
selectedProxyType.bindBidirectional(CONFIG.proxyTypeProperty()); selectedProxyType.bindBidirectional(config().proxyTypeProperty());
ToggleGroup proxyConfigurationGroup = new ToggleGroup(); ToggleGroup proxyConfigurationGroup = new ToggleGroup();
chkProxyHttp.setUserData(Proxy.Type.HTTP); chkProxyHttp.setUserData(Proxy.Type.HTTP);
@ -188,12 +188,12 @@ public final class SettingsPage extends StackPane implements DecoratorPage {
fileCommonLocation.createChildren(i18n("launcher.common_directory.disabled"), EnumCommonDirectory.DISABLED), fileCommonLocation.createChildren(i18n("launcher.common_directory.disabled"), EnumCommonDirectory.DISABLED),
fileCommonLocation.createChildren(i18n("launcher.common_directory.default"), EnumCommonDirectory.DEFAULT) fileCommonLocation.createChildren(i18n("launcher.common_directory.default"), EnumCommonDirectory.DEFAULT)
), EnumCommonDirectory.CUSTOM); ), EnumCommonDirectory.CUSTOM);
fileCommonLocation.selectedDataProperty().bindBidirectional(CONFIG.commonDirTypeProperty()); fileCommonLocation.selectedDataProperty().bindBidirectional(config().commonDirTypeProperty());
fileCommonLocation.customTextProperty().bindBidirectional(CONFIG.commonDirectoryProperty()); fileCommonLocation.customTextProperty().bindBidirectional(config().commonDirectoryProperty());
fileCommonLocation.subtitleProperty().bind( fileCommonLocation.subtitleProperty().bind(
Bindings.createObjectBinding(() -> Optional.ofNullable(Settings.INSTANCE.getCommonDirectory()) Bindings.createObjectBinding(() -> Optional.ofNullable(Settings.INSTANCE.getCommonDirectory())
.orElse(i18n("launcher.common_directory.disabled")), .orElse(i18n("launcher.common_directory.disabled")),
CONFIG.commonDirectoryProperty(), CONFIG.commonDirTypeProperty())); config().commonDirectoryProperty(), config().commonDirTypeProperty()));
FXUtils.installTooltip(btnUpdate, i18n("update.tooltip")); FXUtils.installTooltip(btnUpdate, i18n("update.tooltip"));
checkUpdate(); checkUpdate();
@ -202,22 +202,22 @@ public final class SettingsPage extends StackPane implements DecoratorPage {
backgroundItem.loadChildren(Collections.singletonList( backgroundItem.loadChildren(Collections.singletonList(
backgroundItem.createChildren(i18n("launcher.background.default"), EnumBackgroundImage.DEFAULT) backgroundItem.createChildren(i18n("launcher.background.default"), EnumBackgroundImage.DEFAULT)
), EnumBackgroundImage.CUSTOM); ), EnumBackgroundImage.CUSTOM);
backgroundItem.customTextProperty().bindBidirectional(CONFIG.backgroundImageProperty()); backgroundItem.customTextProperty().bindBidirectional(config().backgroundImageProperty());
backgroundItem.selectedDataProperty().bindBidirectional(CONFIG.backgroundImageTypeProperty()); backgroundItem.selectedDataProperty().bindBidirectional(config().backgroundImageTypeProperty());
backgroundItem.subtitleProperty().bind( backgroundItem.subtitleProperty().bind(
new When(backgroundItem.selectedDataProperty().isEqualTo(EnumBackgroundImage.DEFAULT)) new When(backgroundItem.selectedDataProperty().isEqualTo(EnumBackgroundImage.DEFAULT))
.then(i18n("launcher.background.default")) .then(i18n("launcher.background.default"))
.otherwise(CONFIG.backgroundImageProperty())); .otherwise(config().backgroundImageProperty()));
// ==== // ====
// ==== Theme ==== // ==== Theme ====
JFXColorPicker picker = new JFXColorPicker(Color.web(CONFIG.getTheme().getColor()), null); JFXColorPicker picker = new JFXColorPicker(Color.web(config().getTheme().getColor()), null);
picker.setCustomColorText(i18n("color.custom")); picker.setCustomColorText(i18n("color.custom"));
picker.setRecentColorsText(i18n("color.recent")); picker.setRecentColorsText(i18n("color.recent"));
picker.getCustomColors().setAll(Theme.SUGGESTED_COLORS); picker.getCustomColors().setAll(Theme.SUGGESTED_COLORS);
picker.setOnAction(e -> { picker.setOnAction(e -> {
Theme theme = Theme.custom(Theme.getColorDisplayName(picker.getValue())); Theme theme = Theme.custom(Theme.getColorDisplayName(picker.getValue()));
CONFIG.setTheme(theme); config().setTheme(theme);
Controllers.getScene().getStylesheets().setAll(theme.getStylesheets()); Controllers.getScene().getStylesheets().setAll(theme.getStylesheets());
}); });
themeColorPickerContainer.getChildren().setAll(picker); themeColorPickerContainer.getChildren().setAll(picker);

View File

@ -22,14 +22,14 @@ import javafx.scene.image.Image;
import javafx.scene.web.WebView; import javafx.scene.web.WebView;
import javafx.stage.Stage; import javafx.stage.Stage;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
public class WebStage extends Stage { public class WebStage extends Stage {
private final WebView webView = new WebView(); private final WebView webView = new WebView();
public WebStage() { public WebStage() {
setScene(new Scene(webView, 800, 480)); setScene(new Scene(webView, 800, 480));
getScene().getStylesheets().addAll(CONFIG.getTheme().getStylesheets()); getScene().getStylesheets().addAll(config().getTheme().getStylesheets());
getIcons().add(new Image("/assets/img/icon.png")); getIcons().add(new Image("/assets/img/icon.png"));
} }

View File

@ -37,7 +37,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
public final class ExportWizardProvider implements WizardProvider { public final class ExportWizardProvider implements WizardProvider {
private final Profile profile; private final Profile profile;
@ -83,11 +83,11 @@ public final class ExportWizardProvider implements WizardProvider {
try (ZipEngine zip = new ZipEngine(modpackFile)) { try (ZipEngine zip = new ZipEngine(modpackFile)) {
Config exported = new Config(); Config exported = new Config();
exported.setBackgroundImageType(CONFIG.getBackgroundImageType()); exported.setBackgroundImageType(config().getBackgroundImageType());
exported.setBackgroundImage(CONFIG.getBackgroundImage()); exported.setBackgroundImage(config().getBackgroundImage());
exported.setTheme(CONFIG.getTheme()); exported.setTheme(config().getTheme());
exported.setDownloadType(CONFIG.getDownloadType()); exported.setDownloadType(config().getDownloadType());
exported.getAuthlibInjectorServers().setAll(CONFIG.getAuthlibInjectorServers()); exported.getAuthlibInjectorServers().setAll(config().getAuthlibInjectorServers());
zip.putTextFile(exported.toJson(), ConfigHolder.CONFIG_FILENAME); zip.putTextFile(exported.toJson(), ConfigHolder.CONFIG_FILENAME);
zip.putFile(tempModpack, "modpack.zip"); zip.putFile(tempModpack, "modpack.zip");