alroyso 1 tahun lalu
induk
melakukan
bb9e72ffb6
2 mengubah file dengan 61 tambahan dan 22 penghapusan
  1. 5 0
      lib/app/const/const.dart
  2. 56 22
      lib/app/controller/GlobalController.dart

+ 5 - 0
lib/app/const/const.dart

@@ -56,6 +56,11 @@ class Files {
   static File get assetsCCore {
     return File(path.join(Paths.assetsBin.path, 'ccore-${ClashName.platform}-${ClashName.arch}${ClashName.ext}'));
   }
+
+  static File get assetsSysProxyWin {
+    return File(path.join(Paths.assetsBin.path, 'sysproxy64.exe'));
+  }
+
   static File get assetsCountryMmdb {
     return File(path.join(Paths.assetsDep.path, 'Country.mmdb'));
   }

+ 56 - 22
lib/app/controller/GlobalController.dart

@@ -36,6 +36,7 @@ class GlobalController extends GetxController {
   var tunProxySwitchIng = false.obs;
   bool allowStatusUpdate = false;
 
+
   final selectedNode = Rx<NodeMode?>(null);
   // 策略组
   var proxieGroups = <ProxieProxiesItem>[].obs;
@@ -371,6 +372,9 @@ class GlobalController extends GetxController {
   /// 打开代理
 
   Future<void> openProxy() async {
+
+
+
     int? port = controllers.config.mixedPort.value;
     if (port == 0) {
       port = null;
@@ -383,38 +387,68 @@ class GlobalController extends GetxController {
     if (mixedPort == 0) {
       mixedPort = null;
     }
-
     port = port ?? mixedPort ?? 0;
     if (port != 0) {
-      await proxyManager.setAsSystemProxy(
-        ProxyTypes.http,
-        "127.0.0.1",
-        port,
-      );
-      await proxyManager.setAsSystemProxy(
-        ProxyTypes.https,
-        "127.0.0.1",
-        port,
-      );
-      systemProxy = true;
-    }
-    socksPort = socksPort ?? mixedPort ?? 0;
-    if (socksPort != 0) {
-      if (!Platform.isWindows) {
-        await proxyManager.setAsSystemProxy(
-          ProxyTypes.socks,
-          "127.0.0.1",
-          socksPort,
+      String loa = '127.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;192.168.*';
+      int? exitCode;
+      // Process sysproxy = await Process.start(Files.assetsSysProxyWin.path,,mode: ProcessStartMode.inheritStdio);
+      // sysproxy.exitCode.then((code) => exitCode = code);
+      try {
+         await Process.run(
+          Files.assetsSysProxyWin.path,
+          ['global','127.0.0.1:$port',loa],
+          runInShell: true,
         );
+      } on ProcessException catch (e) {
+        //.e('Failed to start $coreName: ${e.message}');
+        throw Exception('Failed to start sysproxy: ${e.message}');
       }
-      systemProxy = true;
     }
+
+
+
+    //
+    // port = port ?? mixedPort ?? 0;
+    // if (port != 0) {
+    //   await proxyManager.setAsSystemProxy(
+    //     ProxyTypes.http,
+    //     "127.0.0.1",
+    //     port,
+    //   );
+    //   await proxyManager.setAsSystemProxy(
+    //     ProxyTypes.https,
+    //     "127.0.0.1",
+    //     port,
+    //   );
+    //   systemProxy = true;
+    // }
+    // socksPort = socksPort ?? mixedPort ?? 0;
+    // if (socksPort != 0) {
+    //   if (!Platform.isWindows) {
+    //     await proxyManager.setAsSystemProxy(
+    //       ProxyTypes.socks,
+    //       "127.0.0.1",
+    //       socksPort,
+    //     );
+    //   }
+    //   systemProxy = true;
+    // }
   }
 
   /// 关闭代理
 
   Future<void> closeProxy() async {
-    proxyManager.cleanSystemProxy();
+    // proxyManager.cleanSystemProxy();
+    try {
+      await Process.run(
+        Files.assetsSysProxyWin.path,
+        ['set','1','','',''],
+        runInShell: true,
+      );
+    } on ProcessException catch (e) {
+      //.e('Failed to start $coreName: ${e.message}');
+      throw Exception('Failed to start sysproxy: ${e.message}');
+    }
     systemProxy = false;
   }
   Future<void> stopAllCore() async {