修复 新建隧道的重置bug

This commit is contained in:
octopusYan 2022-04-11 17:24:50 +08:00
parent 27e124dfaf
commit ca480243ae
3 changed files with 27 additions and 16 deletions

View File

@ -8,14 +8,15 @@ import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.stage.StageStyle; import javafx.stage.StageStyle;
import okhttp3.logging.HttpLoggingInterceptor;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import top.octopusyan.config.OkHttpClientConfig;
import top.octopusyan.controller.LoginController; import top.octopusyan.controller.LoginController;
import top.octopusyan.http.HttpConfig; import top.octopusyan.http.HttpConfig;
import top.octopusyan.http.config.LogStrategy; import top.octopusyan.http.config.LogStrategy;
import top.octopusyan.http.request.RequestHandler; import top.octopusyan.http.request.RequestHandler;
import top.octopusyan.manager.FrpManager; import top.octopusyan.manager.FrpManager;
import top.octopusyan.manager.http.OkHttpClientConfig;
import top.octopusyan.model.ApplicatonStore; import top.octopusyan.model.ApplicatonStore;
import top.octopusyan.utils.AlertUtil; import top.octopusyan.utils.AlertUtil;
import top.octopusyan.utils.EncryptionUtil; import top.octopusyan.utils.EncryptionUtil;
@ -46,12 +47,17 @@ public class YanFrpApplication extends Application {
// 初始化frp客户端临时文件 // 初始化frp客户端临时文件
FrpManager.initFrpc(); FrpManager.initFrpc();
// 网络请求日志
OkHttpClientConfig.showLog = false;
// 网络请求设置 // 网络请求设置
HttpConfig.with(OkHttpClientConfig.httpClient()) HttpConfig.with(OkHttpClientConfig.httpClient(
HttpLoggingInterceptor.Level.HEADERS
))
// 请求服务地址 // 请求服务地址
.serverPath("https://frp.octopusyan.top") .serverPath("https://frp.octopusyan.top")
// 是否打印日志 // 是否打印日志
.setLogEnabled(false) .setLogEnabled(true)
// 设置日志打印策略 // 设置日志打印策略
.setLogStrategy(new LogStrategy()) .setLogStrategy(new LogStrategy())
// 设置请求处理策略 // 设置请求处理策略

View File

@ -1,4 +1,4 @@
package top.octopusyan.manager.http; package top.octopusyan.config;
import kotlin.text.Charsets; import kotlin.text.Charsets;
import okhttp3.*; import okhttp3.*;
@ -26,19 +26,23 @@ import java.util.concurrent.TimeUnit;
* @create : 2022-4-2 15:27 * @create : 2022-4-2 15:27
*/ */
public class OkHttpClientConfig { public class OkHttpClientConfig {
public static boolean showLog = false;
public static final String TAG = "OkHttpLogger"; public static final String TAG = "OkHttpLogger";
private static final Logger log = LoggerFactory.getLogger(TAG); private static final Logger log = LoggerFactory.getLogger(TAG);
public static final HashMap<String, List<Cookie>> cookieStore = new HashMap<>(); public static final HashMap<String, List<Cookie>> cookieStore = new HashMap<>();
public static OkHttpClient httpClient() { /**
* 初始化okhttp client
* @param logLevel 日志等级
*/
public static OkHttpClient httpClient(HttpLoggingInterceptor.Level logLevel) {
HttpLoggingInterceptor logginInterceptor = new HttpLoggingInterceptor( HttpLoggingInterceptor logginInterceptor = new HttpLoggingInterceptor(
new HttpLoggingInterceptor.Logger() { new HttpLoggingInterceptor.Logger() {
@Override @Override
public void log(String message) { public void log(String message) {
try { try {
log.info(message); if(showLog) log.info(message);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error(message); log.error(message);
@ -48,11 +52,11 @@ public class OkHttpClientConfig {
); );
// setlevel用来设置日志打印的级别共包括了四个级别NONE,BASIC,HEADER,BODY // setlevel用来设置日志打印的级别共包括了四个级别NONE,BASIC,HEADER,BODY
// BASEIC:请求/响应行 // BASIC:请求/响应行
// HEADER:请求/响应行 + // HEADERS:请求/响应行 +
// BODY:请求/响应行 + + // BODY:请求/响应行 + +
//包含headerbody数据 //包含headerbody数据
logginInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); logginInterceptor.setLevel(logLevel);
Dispatcher dispatcher = new Dispatcher(); Dispatcher dispatcher = new Dispatcher();
dispatcher.setMaxRequests(16); dispatcher.setMaxRequests(16);

View File

@ -326,10 +326,11 @@ public class MainController extends BaseController<StackPane> implements Initial
// 重置 // 重置
resetProxyBtn.setOnMouseClicked(event -> { resetProxyBtn.setOnMouseClicked(event -> {
ProxySetup proxySetup = userProxy.get(proxySetupModel.getId()); ProxySetup proxySetup = userProxy.get(proxySetupModel.getId());
proxySetup = userProxy.get(proxySetup.getId()); if(proxySetup != null){
proxySetup.setRuning(proxySetupModel.isRunning()); proxySetup.setRuning(proxySetupModel.isRunning());
proxySetupModel.set(proxySetup); proxySetupModel.set(proxySetup);
domainTextField.resetValidation(); domainTextField.resetValidation();
}
}); });
// 日志清理 // 日志清理
@ -565,12 +566,12 @@ public class MainController extends BaseController<StackPane> implements Initial
private void start(ProxySetup setup) { private void start(ProxySetup setup) {
// 添加成功设置运行状态 // 添加成功设置运行状态
setup.setRuning(frpUtilMap.containsKey(setup.getId())); setup.setRuning(frpUtilMap.containsKey(setup.getId().toString()));
proxySetupModel.set(setup); proxySetupModel.set(setup);
// 初始化frputil // 初始化frputil
FrpManager frpManager; FrpManager frpManager;
if ((frpManager = frpUtilMap.get(setup.getId())) == null) if ((frpManager = frpUtilMap.get(setup.getId().toString())) == null)
frpUtilMap.put(proxySetupModel.getId(), frpManager = FrpManager.init(proxySetupModel)); frpUtilMap.put(proxySetupModel.getId(), frpManager = FrpManager.init(proxySetupModel));
// 设置文本域对象 // 设置文本域对象