alroyso 1 year ago
parent
commit
268a18cfe6
2 changed files with 11 additions and 1 deletions
  1. 1 0
      example/lib/main.dart
  2. 10 1
      lib/modes/clash/app.dart

+ 1 - 0
example/lib/main.dart

@@ -140,6 +140,7 @@ class _MyAppState extends State<MyApp> {
         .build();
 
     print("\n${appConfig.toYaml()}");
+    print("\n${appConfig.toJson()}");
   }
 
   // Platform messages are asynchronous, so we initialize in an async method.

+ 10 - 1
lib/modes/clash/app.dart

@@ -27,7 +27,16 @@ class AppConfig {
       rules: List<Rule>.from(map['rules'].map((x) => Rule.fromMap(x))),
     );
   }
-
+  Map<String, dynamic> toJson() {
+    return {
+      'basic': basicConfig.toJson(),
+      if (dnsConfig != null) 'dns': dnsConfig!.toJson(),
+      if (tunConfig != null) 'tun': tunConfig!.toJson(),
+      if (proxies != null) 'proxies': proxies!.map((proxy) => proxy.toJson()).toList(),
+      if (proxyGroups != null) 'proxy-groups': proxyGroups!.map((group) => group.toJson()).toList(),
+      'rules': rules.map((rule) => rule.toJson()).toList(),
+    };
+  }
   String toYaml() {
     var yaml = basicConfig.toYaml();
     if (dnsConfig != null) {