mirror of
https://github.com/octopusYan/alist-gui.git
synced 2024-11-22 03:56:42 +08:00
fix: 修复网络代理设置端口时卡顿
This commit is contained in:
parent
c93837a7a9
commit
d65990791a
@ -9,6 +9,7 @@ import cn.octopusyan.alistgui.Application;
|
|||||||
import cn.octopusyan.alistgui.config.Constants;
|
import cn.octopusyan.alistgui.config.Constants;
|
||||||
import cn.octopusyan.alistgui.enums.ProxySetup;
|
import cn.octopusyan.alistgui.enums.ProxySetup;
|
||||||
import cn.octopusyan.alistgui.manager.http.HttpUtil;
|
import cn.octopusyan.alistgui.manager.http.HttpUtil;
|
||||||
|
import cn.octopusyan.alistgui.manager.thread.ThreadPoolManager;
|
||||||
import cn.octopusyan.alistgui.model.GuiConfig;
|
import cn.octopusyan.alistgui.model.GuiConfig;
|
||||||
import cn.octopusyan.alistgui.model.ProxyInfo;
|
import cn.octopusyan.alistgui.model.ProxyInfo;
|
||||||
import cn.octopusyan.alistgui.model.UpgradeConfig;
|
import cn.octopusyan.alistgui.model.UpgradeConfig;
|
||||||
@ -17,6 +18,7 @@ import cn.octopusyan.alistgui.model.upgrade.Gui;
|
|||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||||
|
import javafx.application.Platform;
|
||||||
import org.apache.commons.lang3.LocaleUtils;
|
import org.apache.commons.lang3.LocaleUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -29,6 +31,7 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -168,8 +171,6 @@ public class ConfigManager {
|
|||||||
if (!matcher.matches()) return;
|
if (!matcher.matches()) return;
|
||||||
|
|
||||||
getProxyInfo().setHost(host);
|
getProxyInfo().setHost(host);
|
||||||
|
|
||||||
checkProxy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String proxyPort() {
|
public static String proxyPort() {
|
||||||
@ -184,21 +185,24 @@ public class ConfigManager {
|
|||||||
if (!NumberUtil.isNumber(port)) return;
|
if (!NumberUtil.isNumber(port)) return;
|
||||||
|
|
||||||
getProxyInfo().setPort(port);
|
getProxyInfo().setPort(port);
|
||||||
|
|
||||||
checkProxy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkProxy() {
|
public static void checkProxy(BiConsumer<Boolean, String> consumer) {
|
||||||
if (!hasProxy()) return;
|
if (!hasProxy()) return;
|
||||||
|
|
||||||
try {
|
ThreadPoolManager.getInstance().execute(() -> {
|
||||||
InetSocketAddress address = NetUtil.createAddress(proxyHost(), getProxyPort());
|
try {
|
||||||
if (NetUtil.isOpen(address, 2000)) {
|
InetSocketAddress address = NetUtil.createAddress(proxyHost(), getProxyPort());
|
||||||
HttpUtil.getInstance().proxy(proxySetup(), ConfigManager.getProxyInfo());
|
if (NetUtil.isOpen(address, 5000)) {
|
||||||
|
Platform.runLater(() -> consumer.accept(true, "success"));
|
||||||
|
} else {
|
||||||
|
Platform.runLater(() -> consumer.accept(false, "connection timed out"));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(STR."host=\{proxyHost()},port=\{proxyPort()}", e);
|
||||||
|
Platform.runLater(() -> consumer.accept(false, e.getMessage()));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
});
|
||||||
logger.error(STR."host=\{proxyHost()},port=\{proxyPort()}", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------{ 语言 }------------------------------------------
|
// --------------------------------{ 语言 }------------------------------------------
|
||||||
|
@ -5,6 +5,7 @@ import cn.octopusyan.alistgui.base.BaseTask;
|
|||||||
import cn.octopusyan.alistgui.config.Context;
|
import cn.octopusyan.alistgui.config.Context;
|
||||||
import cn.octopusyan.alistgui.enums.ProxySetup;
|
import cn.octopusyan.alistgui.enums.ProxySetup;
|
||||||
import cn.octopusyan.alistgui.manager.ConfigManager;
|
import cn.octopusyan.alistgui.manager.ConfigManager;
|
||||||
|
import cn.octopusyan.alistgui.manager.http.HttpUtil;
|
||||||
import cn.octopusyan.alistgui.task.ProxyCheckTask;
|
import cn.octopusyan.alistgui.task.ProxyCheckTask;
|
||||||
import cn.octopusyan.alistgui.util.alert.AlertUtil;
|
import cn.octopusyan.alistgui.util.alert.AlertUtil;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
@ -81,7 +82,16 @@ public class SetupViewModel {
|
|||||||
|
|
||||||
proxyTestUrl.setValue(checkUrl);
|
proxyTestUrl.setValue(checkUrl);
|
||||||
|
|
||||||
getProxyCheckTask(checkUrl).execute();
|
ConfigManager.checkProxy((success, msg) -> {
|
||||||
|
if (!success) {
|
||||||
|
final var tmp = Context.getLanguageBinding("proxy.test.result.failed").getValue();
|
||||||
|
AlertUtil.error(STR."\{tmp}:\{msg}").show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpUtil.getInstance().proxy(ConfigManager.proxySetup(), ConfigManager.getProxyInfo());
|
||||||
|
getProxyCheckTask(checkUrl).execute();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ProxyCheckTask getProxyCheckTask(String checkUrl) {
|
private static ProxyCheckTask getProxyCheckTask(String checkUrl) {
|
||||||
@ -105,7 +115,8 @@ public class SetupViewModel {
|
|||||||
public void onFailed(Throwable throwable) {
|
public void onFailed(Throwable throwable) {
|
||||||
Platform.runLater(progress::close);
|
Platform.runLater(progress::close);
|
||||||
final var tmp = Context.getLanguageBinding("proxy.test.result.failed").getValue();
|
final var tmp = Context.getLanguageBinding("proxy.test.result.failed").getValue();
|
||||||
AlertUtil.error(tmp + throwable.getMessage()).show();
|
String throwableMessage = throwable.getMessage();
|
||||||
|
AlertUtil.error(tmp + (StringUtils.isEmpty(throwableMessage) ? "" : throwableMessage)).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return task;
|
return task;
|
||||||
|
Loading…
Reference in New Issue
Block a user