Move ProxyManager.proxyProperty initialization to init()

This commit is contained in:
yushijinhun
2018-09-15 23:13:25 +08:00
parent 9950bef260
commit afad520669

View File

@@ -35,7 +35,18 @@ public final class ProxyManager {
private ProxyManager() { private ProxyManager() {
} }
private static ObjectBinding<Proxy> proxyProperty = Bindings.createObjectBinding( private static ObjectBinding<Proxy> proxyProperty;
public static Proxy getProxy() {
return proxyProperty.get();
}
public static ObservableObjectValue<Proxy> proxyProperty() {
return proxyProperty;
}
static void init() {
proxyProperty = Bindings.createObjectBinding(
() -> { () -> {
String host = config().getProxyHost(); String host = config().getProxyHost();
Integer port = Lang.toIntOrNull(config().getProxyPort()); Integer port = Lang.toIntOrNull(config().getProxyPort());
@@ -50,21 +61,10 @@ public final class ProxyManager {
config().proxyPortProperty(), config().proxyPortProperty(),
config().hasProxyProperty()); config().hasProxyProperty());
public static Proxy getProxy() { proxyProperty.addListener(any -> updateSystemProxy());
return proxyProperty.get();
}
public static ObservableObjectValue<Proxy> proxyProperty() {
return proxyProperty;
}
static void init() {
proxyProperty.addListener(observable -> updateSystemProxy());
updateSystemProxy(); updateSystemProxy();
Authenticator.setDefault(new Authenticator() { Authenticator.setDefault(new Authenticator() {
@Override @Override
protected PasswordAuthentication getPasswordAuthentication() { protected PasswordAuthentication getPasswordAuthentication() {
if (config().hasProxyAuth()) { if (config().hasProxyAuth()) {