|
@@ -23,8 +23,38 @@ class ConnectionService {
|
|
ConnectionService(this.globalController, this.updateStatus);
|
|
ConnectionService(this.globalController, this.updateStatus);
|
|
|
|
|
|
|
|
|
|
- Future<void> startConnection() async {
|
|
|
|
|
|
+ Future<void> startConnectionWin() async {
|
|
try {
|
|
try {
|
|
|
|
+ updateStatus(ConnectionStatus.connecting);
|
|
|
|
+ globalController.updateMsg("正在启动连接...");
|
|
|
|
+ await globalController.updateNode();
|
|
|
|
+ // 等待连接建立
|
|
|
|
+ await Future.delayed(Duration(seconds: 2));
|
|
|
|
+ updateStatus(ConnectionStatus.connected);
|
|
|
|
+ globalController.connectStatus.value = true;
|
|
|
|
+ globalController.updateMsg("连接成功");
|
|
|
|
+
|
|
|
|
+ final proxyManager = WlBaseHelp();
|
|
|
|
+
|
|
|
|
+ if(Platform.isWindows){
|
|
|
|
+ int? port = controllers.config.mixedPort.value;
|
|
|
|
+ if (port == 0) {
|
|
|
|
+ port = null;
|
|
|
|
+ }
|
|
|
|
+ int? socksPort = controllers.config.mixedPort.value;
|
|
|
|
+ if (socksPort == 0) {
|
|
|
|
+ socksPort = null;
|
|
|
|
+ }
|
|
|
|
+ int? mixedPort = controllers.config.mixedPort.value;
|
|
|
|
+ if (mixedPort == 0) {
|
|
|
|
+ mixedPort = null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(port !=null){
|
|
|
|
+ await proxyManager.startProxy(port);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
// // 检查所有内核是否已停止
|
|
// // 检查所有内核是否已停止
|
|
// bool allCoresStopped = await globalController.checkAllCoresStopped();
|
|
// bool allCoresStopped = await globalController.checkAllCoresStopped();
|
|
@@ -51,98 +81,72 @@ class ConnectionService {
|
|
// globalController.updateMsg("端口已更新,正在重新启动...");
|
|
// globalController.updateMsg("端口已更新,正在重新启动...");
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
- updateStatus(ConnectionStatus.connecting);
|
|
|
|
- globalController.updateMsg("正在启动连接...");
|
|
|
|
-
|
|
|
|
- if(Platform.isMacOS){
|
|
|
|
- if (serviceController.serviceIsRuning) {
|
|
|
|
- await globalController.makeProxy();
|
|
|
|
- await serviceController.reloadClashCore();
|
|
|
|
- // await serviceController.fetchSetProxy();
|
|
|
|
- } else {
|
|
|
|
- // if (controllers.service.clashServiceIsRuning) {
|
|
|
|
- // await globalController.makeProxy();
|
|
|
|
- // await reloadClashCore();
|
|
|
|
- // }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- // if (controllers.service.clashServiceIsRuning) {
|
|
|
|
- // await globalController.makeProxy();
|
|
|
|
- // await reloadClashCore();
|
|
|
|
- // }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- await globalController.updateNode();
|
|
|
|
|
|
|
|
|
|
|
|
- // 等待连接建立
|
|
|
|
- await Future.delayed(Duration(seconds: 2));
|
|
|
|
-
|
|
|
|
- if(Platform.isMacOS){
|
|
|
|
- if (serviceController.serviceIsRuning) {
|
|
|
|
- //await serviceController.fetchStartInit();
|
|
|
|
- await serviceController.fetchSetProxy();
|
|
|
|
- await globalController.openProxy();
|
|
|
|
- } else {
|
|
|
|
- if (controllers.service.clashServiceIsRuning) {
|
|
|
|
- globalController.connectStatus.value = true;
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- throw Exception("内核启动失败");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if (controllers.service.clashServiceIsRuning) {
|
|
|
|
- updateStatus(ConnectionStatus.connected);
|
|
|
|
- globalController.connectStatus.value = true;
|
|
|
|
- globalController.updateMsg("连接成功");
|
|
|
|
|
|
+ // if(Platform.isMacOS){
|
|
|
|
+ // if (serviceController.serviceIsRuning) {
|
|
|
|
+ // await globalController.makeProxy();
|
|
|
|
+ // await serviceController.reloadClashCore();
|
|
|
|
+ // // await serviceController.fetchSetProxy();
|
|
|
|
+ // } else {
|
|
|
|
+ // // if (controllers.service.clashServiceIsRuning) {
|
|
|
|
+ // // await globalController.makeProxy();
|
|
|
|
+ // // await reloadClashCore();
|
|
|
|
+ // // }
|
|
|
|
+ // }
|
|
|
|
+ // } else {
|
|
|
|
+ // // if (controllers.service.clashServiceIsRuning) {
|
|
|
|
+ // // await globalController.makeProxy();
|
|
|
|
+ // // await reloadClashCore();
|
|
|
|
+ // // }
|
|
|
|
+ // }
|
|
|
|
|
|
- } else {
|
|
|
|
- throw Exception("内核启动失败");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
- final proxyManager = WlBaseHelp();
|
|
|
|
|
|
|
|
- if(Platform.isWindows){
|
|
|
|
- int? port = controllers.config.mixedPort.value;
|
|
|
|
- if (port == 0) {
|
|
|
|
- port = null;
|
|
|
|
- }
|
|
|
|
- int? socksPort = controllers.config.mixedPort.value;
|
|
|
|
- if (socksPort == 0) {
|
|
|
|
- socksPort = null;
|
|
|
|
- }
|
|
|
|
- int? mixedPort = controllers.config.mixedPort.value;
|
|
|
|
- if (mixedPort == 0) {
|
|
|
|
- mixedPort = null;
|
|
|
|
- }
|
|
|
|
|
|
|
|
- if(port !=null){
|
|
|
|
- await proxyManager.startProxy(port);
|
|
|
|
- }
|
|
|
|
|
|
|
|
- } else {
|
|
|
|
- controllers.global.systemProxySwitch(true);
|
|
|
|
- }
|
|
|
|
- updateStatus(ConnectionStatus.connected);
|
|
|
|
- globalController.updateMsg("连接成功");
|
|
|
|
- controllers.global.connectStatus.value = true;
|
|
|
|
|
|
|
|
- //检测系统代理并切换成网卡模式
|
|
|
|
- if(Platform.isWindows){
|
|
|
|
|
|
+ // if(Platform.isMacOS){
|
|
|
|
+ // if (serviceController.serviceIsRuning) {
|
|
|
|
+ // //await serviceController.fetchStartInit();
|
|
|
|
+ // await serviceController.fetchSetProxy();
|
|
|
|
+ // await globalController.openProxy();
|
|
|
|
+ // } else {
|
|
|
|
+ // if (controllers.service.clashServiceIsRuning) {
|
|
|
|
+ // globalController.connectStatus.value = true;
|
|
|
|
+ //
|
|
|
|
+ // } else {
|
|
|
|
+ // throw Exception("内核启动失败");
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // } else {
|
|
|
|
+ // if (controllers.service.clashServiceIsRuning) {
|
|
|
|
|
|
- if(!await proxyManager.isProxyEnabled()){
|
|
|
|
- globalController.updateMsg("当前没有设置系统代理,20秒后切换成网卡模式");
|
|
|
|
- await Future.delayed(Duration(seconds: 20)); // 等待核心状态更新
|
|
|
|
- // await globalController.TunProxySwitch(true);
|
|
|
|
- // await globalController.makeProxy();
|
|
|
|
- // await reloadClashCore();
|
|
|
|
- LogHelper().d("重置网卡模式");
|
|
|
|
- }
|
|
|
|
|
|
+ //
|
|
|
|
+ // } else {
|
|
|
|
+ // throw Exception("内核启动失败");
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ // updateStatus(ConnectionStatus.connected);
|
|
|
|
+ // globalController.updateMsg("连接成功");
|
|
|
|
+ // controllers.global.connectStatus.value = true;
|
|
|
|
+ //
|
|
|
|
+ // //检测系统代理并切换成网卡模式
|
|
|
|
+ // if(Platform.isWindows){
|
|
|
|
+ //
|
|
|
|
+ // if(!await proxyManager.isProxyEnabled()){
|
|
|
|
+ // globalController.updateMsg("当前没有设置系统代理,20秒后切换成网卡模式");
|
|
|
|
+ // await Future.delayed(Duration(seconds: 20)); // 等待核心状态更新
|
|
|
|
+ // // await globalController.TunProxySwitch(true);
|
|
|
|
+ // // await globalController.makeProxy();
|
|
|
|
+ // // await reloadClashCore();
|
|
|
|
+ // LogHelper().d("重置网卡模式");
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ //
|
|
|
|
+ // }
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
} catch (e) {
|