alroyso 4 months ago
parent
commit
584d3db642

+ 4 - 0
lib/wl_base_help.dart

@@ -52,4 +52,8 @@ class WlBaseHelp {
   Future<bool> isProxyEnabled() async {
     return WlBaseHelpPlatform.instance.isProxyEnabled();
   }
+
+  Future<bool> isDialUpEnabled() async {
+    return WlBaseHelpPlatform.instance.isProxyEnabled();
+  }
 }

+ 5 - 0
lib/wl_base_help_method_channel.dart

@@ -76,4 +76,9 @@ class MethodChannelWlBaseHelp extends WlBaseHelpPlatform {
   Future<bool> isProxyEnabled() async {
     return await methodChannel.invokeMethod('isProxyEnabled');
   }
+
+  @override
+  Future<bool> isDialUpEnabled() async {
+    return await methodChannel.invokeMethod('isDialUpEnabled');
+  }
 }

+ 3 - 0
lib/wl_base_help_platform_interface.dart

@@ -73,4 +73,7 @@ abstract class WlBaseHelpPlatform extends PlatformInterface {
   Future<bool> isProxyEnabled() async {
     throw UnimplementedError('isProxyEnabled() has not been implemented.');
   }
+  Future<bool> isDialUpEnabled() async {
+    throw UnimplementedError('isDialUpEnabled() has not been implemented.');
+  }
 }

+ 21 - 3
windows/wl_base_help_plugin.cpp

@@ -232,6 +232,22 @@ void KillProcess(const std::wstring& processName) {
     }
 }
 
+bool CheckPPPConnection() {
+    RASCONN rasConn[256];
+    DWORD dwSize = sizeof(rasConn);
+    DWORD dwConnections = 0;
+    rasConn[0].dwSize = sizeof(RASCONN);
+
+    if (RasEnumConnections(rasConn, &dwSize, &dwConnections) == ERROR_SUCCESS) {
+        for (DWORD i = 0; i < dwConnections; i++) {
+            if (rasConn[i].szDeviceType == RASDT_PPPoE) {
+                return true;  // 检测到 PPPoE 连接
+            }
+        }
+    }
+    return false;
+}
+
 namespace wl_base_help {
 
 // static
@@ -259,6 +275,7 @@ WlBaseHelpPlugin::~WlBaseHelpPlugin() {}
 void WlBaseHelpPlugin::HandleMethodCall(
     const flutter::MethodCall<flutter::EncodableValue>& method_call,
     std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
+
      if (method_call.method_name().compare("startProxy") == 0) {
         const auto* arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
         int port = std::get<int>(arguments->at(flutter::EncodableValue("port")));
@@ -270,9 +287,10 @@ void WlBaseHelpPlugin::HandleMethodCall(
       } else if (method_call.method_name().compare("isProxyEnabled") == 0) {
         bool enabled = isProxyEnabled();
         result->Success(flutter::EncodableValue(enabled));
-      }
-
-    if (method_call.method_name().compare("isProcessRunning") == 0) {
+      }  else if (method_call.method_name().compare("isDialUpEnabled") == 0) {
+                bool dialUpEnabled = isDialUpEnabled();
+                result->Success(flutter::EncodableValue(dialUpEnabled));
+      } else if (method_call.method_name().compare("isProcessRunning") == 0) {
         const auto* arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
         auto processName = std::get<std::string>(arguments->find(flutter::EncodableValue("processName"))->second);
         bool isRunning = IsProcessRunning(std::wstring(processName.begin(), processName.end()));