Move ProxyManager.proxyProperty initialization to init()
This commit is contained in:
@@ -35,20 +35,7 @@ public final class ProxyManager {
|
|||||||
private ProxyManager() {
|
private ProxyManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ObjectBinding<Proxy> proxyProperty = Bindings.createObjectBinding(
|
private static ObjectBinding<Proxy> proxyProperty;
|
||||||
() -> {
|
|
||||||
String host = config().getProxyHost();
|
|
||||||
Integer port = Lang.toIntOrNull(config().getProxyPort());
|
|
||||||
if (!config().hasProxy() || StringUtils.isBlank(host) || port == null || config().getProxyType() == Proxy.Type.DIRECT) {
|
|
||||||
return Proxy.NO_PROXY;
|
|
||||||
} else {
|
|
||||||
return new Proxy(config().getProxyType(), new InetSocketAddress(host, port));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
config().proxyTypeProperty(),
|
|
||||||
config().proxyHostProperty(),
|
|
||||||
config().proxyPortProperty(),
|
|
||||||
config().hasProxyProperty());
|
|
||||||
|
|
||||||
public static Proxy getProxy() {
|
public static Proxy getProxy() {
|
||||||
return proxyProperty.get();
|
return proxyProperty.get();
|
||||||
@@ -59,12 +46,25 @@ public final class ProxyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void init() {
|
static void init() {
|
||||||
proxyProperty.addListener(observable -> updateSystemProxy());
|
proxyProperty = Bindings.createObjectBinding(
|
||||||
|
() -> {
|
||||||
|
String host = config().getProxyHost();
|
||||||
|
Integer port = Lang.toIntOrNull(config().getProxyPort());
|
||||||
|
if (!config().hasProxy() || StringUtils.isBlank(host) || port == null || config().getProxyType() == Proxy.Type.DIRECT) {
|
||||||
|
return Proxy.NO_PROXY;
|
||||||
|
} else {
|
||||||
|
return new Proxy(config().getProxyType(), new InetSocketAddress(host, port));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
config().proxyTypeProperty(),
|
||||||
|
config().proxyHostProperty(),
|
||||||
|
config().proxyPortProperty(),
|
||||||
|
config().hasProxyProperty());
|
||||||
|
|
||||||
|
proxyProperty.addListener(any -> 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()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user