Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

how to connect? #46

Open
pandabossli opened this issue Aug 7, 2023 · 0 comments
Open

how to connect? #46

pandabossli opened this issue Aug 7, 2023 · 0 comments
Assignees

Comments

@pandabossli
Copy link

I wrote a demo, but it couldn't be connected. Could you please give me some guidance on where the problem is

`import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:sail/models/app_model.dart';

import '../adapters/leaf_ffi/config.dart';

class Test extends StatefulWidget {
const Test({Key? key}) : super(key: key);

@OverRide
_TestState createState() => _TestState();
}

class _TestState extends State {
AppModel _appModel = AppModel();
@OverRide
Widget build(BuildContext context) {
return Container(
width: double.infinity,
height: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
GestureDetector(
onTap: () {
Config config = Config();
List proxyGroups = [];
print("play");

          General general = General(
              loglevel: 'info',
              logoutput: '{{leafLogFile}}',
              dnsServer: ['223.5.5.5', '114.114.114.114'],
              tunFd: '{{tunFd}}',
              routingDomainResolve: true);

          List<Proxy> proxies = [];

          proxies.add(Proxy(tag: 'Direct', protocol: 'direct'));
          proxies.add(Proxy(tag: 'Reject', protocol: 'reject'));

          List<Rule> rules = [];

          /*  rules.add(Rule(
              typeField: 'EXTERNAL',
              target: 'Direct',
              filter: 'site:geolocation-!cn'));
          rules.add(Rule(
              typeField: 'EXTERNAL', target: 'Direct', filter: 'site:cn')); */
          rules.add(Rule(typeField: 'FINAL', target: 'PROXY'));

          config.general = general;
          config.proxies = proxies;
          config.rules = rules;

         
          proxies.add(
            Proxy(
              tag: "nasname",
              protocol: "shadowsocks",
              address: "ipipipi3",
              port: 5127,
              encryptMethod: "chacha20-ietf-poly1305",
              password: "79518f9ef06a548a",
            ),
          );
          List<String> actors = [];
          actors.add("nasname");
          proxyGroups.add(ProxyGroup(
              tag: "UrlTest",
              protocol: 'url-test',
              actors: actors,
              checkInterval: 600));
          config.proxyGroups = proxyGroups;

          config.proxies = proxies;
          // config.general = General()

          print("-----------------config-----------------");
          print(config);
          print("-----------------config-----------------");

          _appModel.vpnManager.setTunnelConfiguration(config.toString());
          _appModel.vpnManager.toggle();
        },
        child: Icon(
          Icons.play_circle,
          size: 80,
          color: Colors.amber,
        ),
      ),
      GestureDetector(
        onTap: () {
          print("vpn status");
          _appModel.vpnManager
              .getStatus()
              .then((value) => {print("vpn status ==== ${value}")});
          _appModel.vpnManager.getTunnelConfiguration().then((value) {
            print("vpn config ==== ${value}");
          });
        },
        child: Icon(
          Icons.info,
          size: 80,
          color: Colors.amber,
        ),
      ),
      GestureDetector(
        onTap: () {
          print("vpn status");
          _appModel.vpnManager
            ..getTunnelLog().then((value) {
              print("tunnel log ${value}");
            });
        },
        child: Icon(
          Icons.signal_wifi_statusbar_4_bar,
          size: 80,
          color: Colors.amber,
        ),
      ),
      GestureDetector(
        onTap: () async {
          print("stop");
          // _appModel.vpnManager.setTunnelConfiguration(Config().toString());
          await _appModel.vpnManager.stop();
        },
        child: Icon(
          Icons.stop_circle,
          size: 80,
          color: Colors.amber,
        ),
      ),
    ],
  ),
);

}
}
`

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants