Giter Club home page Giter Club logo

clash_flt's Introduction

clash_flt

A new Flutter plugin based on my ClashKit and my Tun2Socks-Android
My ClashKit forked from AppleClash/clash-apple, my Tun2Socks-Android forked from universal-android-tun2socks

Setup

pubspec.yaml

dependencies:
  clash_flt:
    git:
      url: https://github.com/LondonX/clash_flt.git

Android

  1. Requires minSdkVersion 21
  2. Copy ClashKit.aar into <project-root>/android/app/.
  3. Add implementation files("ClashKit.aar") in <project-root>/android/app/build.gradle's dependencies section.

iOS

  1. Requires iOS 13 or newer.
  2. As gomobile stop supporting armv7a, you need to exlude this architecture in XCode.
  • Open Runner.xcodeproj, select Runner in PROJECT list on the left.
  • In Build Settings->All->Architectures, set value to arm64.
  1. Modify Runner.xcodeproj
  • Open Runner's Signing & Capabilities tab.
  • You may need to enable Network Extension in Apple Developer Account page/Certificates, IDs & Profiles/Identifiers/YOUR_BUNDLE_ID/Edit/Network Extensions checkbox, before add Network Extension and provision.
  • Add Network Extension and Personal VPN.
  • Check App Proxy and Packet Tunnel of Network Extension.
  1. Add project Target of Network-Extension
  • Create a Target named PacketTunnel, the XCode will auto create a file named PacketTunnelProvider.swift.
  • Open PacketTunnel's Signing & Capabilities tab.
  • Add Network Extension and Personal VPN, just as step 3.
  • Add ClashKit.xcframework into PacketTunnel's Frameworks and Libraries an select Do Not Embed.
  • Modify PacketTunnelProvider.swift by paste from Example's PacketTunnelProvider.swfit
  1. Add app group
  • Create a App Group named group.<yourBundleId> both in Runner and PacketTunnel Target.

Basic usage

Initialize

await ClashFlt.instance.init(clashHome);

Download and load file of clash profile

final bool isDownloaded = await ClashFlt.instance.downloadProfile(clashProfileUrl, isForce: true);
final File? downloadedFile = await ClashFlt.instance.profileFile.value;
final bool isResolved = await ClashFlt.instance.resolveProfile();
final Profile? resolvedProfile = await ClashFlt.instance.profile.value;

Get proxy groups and proxy in profile

final Profile? resolvedProfile = await ClashFlt.instance.profile.value;
final List<ProxyGroup>? groups = resolvedProfile?.proxyGroups;
final List<Proxy>? proxies = resolvedProfile?.proxies;
final List<String>? proxyNames = groups?.first.proxies;
// use ClashFlt.instance.findProxy to link proxy name with Proxy object.

Selet Proxy

final ProxyGroup group;//assigned in somewhere else
final Proxy proxy;//assigned in somewhere else
if (!ClashFlt.instance.isProxySelectable(group, proxy)) return;
if(ClashFlt.instance.isProxySelected(group, proxy)) return;
ClashFlt.instance.selectProxy(group, proxy) return

Start/Stop Clash VPN service

// start
final bool isStarted = await ClashFlt.instance.startClash();
// stop(no value return)
await ClashFlt.instance.stopClash();

Supported APIs

Listenables

profileFile
profileDownloading
countryDBFile
countryDBDownloading
profile
profileResolving
healthChecking
state.isRunning

Methods

queryTrafficNow
queryTrafficTotal
applyConfig
isClashRunning
startClash
stopClash

clash_flt's People

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.