Compare commits
1 Commits
v0.8.82-pr
...
v0.8.17-de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5d25c9dd5 |
58
.github/release_template.md
vendored
@@ -1,58 +0,0 @@
|
|||||||
<div align=center>
|
|
||||||
|
|
||||||
[](https://img.shields.io/github/downloads/chen08209/FlClash/vVERSION/)
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
**Download based on your OS:**
|
|
||||||
|
|
||||||
<div align=left>
|
|
||||||
<table>
|
|
||||||
<thead align=left>
|
|
||||||
<tr>
|
|
||||||
<th>OS</th>
|
|
||||||
<th>Download</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody align=left>
|
|
||||||
<tr>
|
|
||||||
<td>Android</td>
|
|
||||||
<td>
|
|
||||||
<a href="https://github.com/chen08209/FlClash/releases/download/vVERSION/FlClash-VERSION-android-arm64-v8a.apk"><img src="https://img.shields.io/badge/APK-ARMv8-168039.svg?logo=android"></a><br>
|
|
||||||
<a href="https://github.com/chen08209/FlClash/releases/download/vVERSION/FlClash-VERSION-android-armeabi-v7a.apk"><img src="https://img.shields.io/badge/APK-ARMv7-45bf55.svg?logo=android"></a><br>
|
|
||||||
<a href="https://github.com/chen08209/FlClash/releases/download/vVERSION/FlClash-VERSION-android-x86_64.apk"><img src="https://img.shields.io/badge/APK-x64-96ed89.svg?logo=android"></a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Windows</td>
|
|
||||||
<td>
|
|
||||||
<a href="https://github.com/chen08209/FlClash/releases/download/vVERSION/FlClash-VERSION-windows-amd64-setup.exe"><img src="https://img.shields.io/badge/Setup-x64-2d7d9a.svg?logo=windows"></a><br>
|
|
||||||
<a href="https://github.com/chen08209/FlClash/releases/download/vVERSION/FlClash-VERSION-windows-amd64.zip"><img src="https://img.shields.io/badge/Portable-x64-67b7d1.svg?logo=windows"></a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>macOS</td>
|
|
||||||
<td>
|
|
||||||
<a href="https://github.com/chen08209/FlClash/releases/download/vVERSION/FlClash-VERSION-macos-arm64.dmg"><img src="https://img.shields.io/badge/DMG-Apple%20Silicon-%23000000.svg?logo=apple"></a><br>
|
|
||||||
<a href="https://github.com/chen08209/FlClash/releases/download/vVERSION/FlClash-VERSION-macos-amd64.dmg"><img src="https://img.shields.io/badge/DMG-Intel%20X64-%2300A9E0.svg?logo=apple"></a><br>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Linux</td>
|
|
||||||
<td>
|
|
||||||
<a href="https://github.com/chen08209/FlClash/releases/download/vVERSION/FlClash-VERSION-linux-amd64.AppImage"><img src="https://img.shields.io/badge/AppImage-x64-f84e29.svg?logo=linux"> </a><br>
|
|
||||||
<a href="https://github.com/chen08209/FlClash/releases/download/vVERSION/FlClash-VERSION-linux-amd64.deb"><img src="https://img.shields.io/badge/DebPackage-x64-FF9966.svg?logo=debian"> </a><br>
|
|
||||||
<a href="https://github.com/chen08209/FlClash/releases/download/vVERSION/FlClash-VERSION-linux-amd64.deb"><img src="https://img.shields.io/badge/RpmPackage-x64-F1B42F.svg?logo=redhat"> </a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div dir="ltr">
|
|
||||||
|
|
||||||
**List of all changes:** [ChangeLog](https://github.com/chen08209/FlClash/blob/main/CHANGELOG.md)
|
|
||||||
|
|
||||||
</div>
|
|
||||||
245
.github/workflows/build.yaml
vendored
@@ -1,245 +0,0 @@
|
|||||||
name: build
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
env:
|
|
||||||
IS_STABLE: ${{ !contains(github.ref, '-') }}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- platform: android
|
|
||||||
os: ubuntu-latest
|
|
||||||
- platform: windows
|
|
||||||
os: windows-latest
|
|
||||||
arch: amd64
|
|
||||||
- platform: linux
|
|
||||||
os: ubuntu-latest
|
|
||||||
arch: amd64
|
|
||||||
- platform: macos
|
|
||||||
os: macos-13
|
|
||||||
arch: amd64
|
|
||||||
- platform: macos
|
|
||||||
os: macos-latest
|
|
||||||
arch: arm64
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
submodules: recursive
|
|
||||||
|
|
||||||
- name: Setup JAVA
|
|
||||||
if: startsWith(matrix.platform,'android')
|
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
|
||||||
distribution: 'zulu'
|
|
||||||
java-version: 17
|
|
||||||
|
|
||||||
- name: Setup NDK
|
|
||||||
if: startsWith(matrix.platform,'android')
|
|
||||||
uses: nttld/setup-ndk@v1
|
|
||||||
id: setup-ndk
|
|
||||||
with:
|
|
||||||
ndk-version: r26b
|
|
||||||
add-to-path: true
|
|
||||||
link-to-sdk: true
|
|
||||||
|
|
||||||
- name: Setup Android Signing
|
|
||||||
if: startsWith(matrix.platform,'android')
|
|
||||||
run: |
|
|
||||||
echo "${{ secrets.KEYSTORE }}" | base64 --decode > android/app/keystore.jks
|
|
||||||
echo "keyAlias=${{ secrets.KEY_ALIAS }}" >> android/local.properties
|
|
||||||
echo "storePassword=${{ secrets.STORE_PASSWORD }}" >> android/local.properties
|
|
||||||
echo "keyPassword=${{ secrets.KEY_PASSWORD }}" >> android/local.properties
|
|
||||||
|
|
||||||
|
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: 'stable'
|
|
||||||
cache-dependency-path: |
|
|
||||||
core/go.sum
|
|
||||||
|
|
||||||
- name: Setup Flutter
|
|
||||||
uses: subosito/flutter-action@v2
|
|
||||||
with:
|
|
||||||
channel: stable
|
|
||||||
cache: true
|
|
||||||
|
|
||||||
- name: Get Flutter Dependency
|
|
||||||
run: flutter pub get
|
|
||||||
|
|
||||||
- name: Setup
|
|
||||||
run: dart setup.dart ${{ matrix.platform }} ${{ matrix.arch && format('--arch {0}', matrix.arch) }} ${{ env.IS_STABLE == 'true' && '--env stable' || '' }}
|
|
||||||
|
|
||||||
- name: Upload
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: artifact-${{ matrix.platform }}${{ matrix.arch && format('-{0}', matrix.arch) }}
|
|
||||||
path: ./dist
|
|
||||||
overwrite: true
|
|
||||||
|
|
||||||
changelog:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [ build ]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
if: ${{ env.IS_STABLE == 'true' }}
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
ref: refs/heads/main
|
|
||||||
- name: Generate
|
|
||||||
if: ${{ env.IS_STABLE == 'true' }}
|
|
||||||
run: |
|
|
||||||
tags=($(git tag --merged $(git rev-parse HEAD) --sort=-creatordate))
|
|
||||||
preTag=$(grep -oP '^## \K.*' CHANGELOG.md | head -n 1)
|
|
||||||
currentTag=""
|
|
||||||
for ((i = 0; i <= ${#tags[@]}; i++)); do
|
|
||||||
if (( i < ${#tags[@]} )); then
|
|
||||||
tag=${tags[$i]}
|
|
||||||
else
|
|
||||||
tag=""
|
|
||||||
fi
|
|
||||||
if [ -n "$currentTag" ]; then
|
|
||||||
if [ "$(echo -e "$currentTag\n$preTag" | sort -V | head -n 1)" == "$currentTag" ]; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -n "$currentTag" ]; then
|
|
||||||
echo "## $currentTag" >> NEW_CHANGELOG.md
|
|
||||||
echo "" >> NEW_CHANGELOG.md
|
|
||||||
if [ -n "$tag" ]; then
|
|
||||||
git log --pretty=format:"%B" "$tag..$currentTag" | awk 'NF {print "- " $0} !NF {print ""}' >> NEW_CHANGELOG.md
|
|
||||||
else
|
|
||||||
git log --pretty=format:"%B" "$currentTag" | awk 'NF {print "- " $0} !NF {print ""}' >> NEW_CHANGELOG.md
|
|
||||||
fi
|
|
||||||
echo "" >> NEW_CHANGELOG.md
|
|
||||||
fi
|
|
||||||
currentTag=$tag
|
|
||||||
done
|
|
||||||
cat CHANGELOG.md >> NEW_CHANGELOG.md
|
|
||||||
cat NEW_CHANGELOG.md > CHANGELOG.md
|
|
||||||
|
|
||||||
- name: Commit
|
|
||||||
if: ${{ env.IS_STABLE == 'true' }}
|
|
||||||
run: |
|
|
||||||
git add CHANGELOG.md
|
|
||||||
if ! git diff --cached --quiet; then
|
|
||||||
echo "Commit pushing"
|
|
||||||
git config --local user.email "chen08209@gmail.com"
|
|
||||||
git config --local user.name "chen08209"
|
|
||||||
git commit -m "Update changelog"
|
|
||||||
git push
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo "Push succeeded"
|
|
||||||
else
|
|
||||||
echo "Push failed"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
upload:
|
|
||||||
permissions: write-all
|
|
||||||
needs: [ build ]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
services:
|
|
||||||
telegram-bot-api:
|
|
||||||
image: aiogram/telegram-bot-api:latest
|
|
||||||
env:
|
|
||||||
TELEGRAM_API_ID: ${{ secrets.TELEGRAM_API_ID }}
|
|
||||||
TELEGRAM_API_HASH: ${{ secrets.TELEGRAM_API_HASH }}
|
|
||||||
ports:
|
|
||||||
- 8081:8081
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Download
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
path: ./dist/
|
|
||||||
pattern: artifact-*
|
|
||||||
merge-multiple: true
|
|
||||||
|
|
||||||
- name: Generate release.md
|
|
||||||
run: |
|
|
||||||
tags=($(git tag --merged $(git rev-parse HEAD) --sort=-creatordate))
|
|
||||||
preTag=$(curl --silent "https://api.github.com/repos/chen08209/FlClash/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' || echo "")
|
|
||||||
currentTag=""
|
|
||||||
for ((i = 0; i <= ${#tags[@]}; i++)); do
|
|
||||||
if (( i < ${#tags[@]} )); then
|
|
||||||
tag=${tags[$i]}
|
|
||||||
else
|
|
||||||
tag=""
|
|
||||||
fi
|
|
||||||
if [ -n "$currentTag" ]; then
|
|
||||||
if [ "$(echo -e "$currentTag\n$preTag" | sort -V | head -n 1)" == "$currentTag" ]; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -n "$currentTag" ]; then
|
|
||||||
if [ -n "$tag" ]; then
|
|
||||||
git log --pretty=format:"%B" "$tag..$currentTag" | awk 'NF {print "- " $0} !NF {print ""}' >> release.md
|
|
||||||
else
|
|
||||||
git log --pretty=format:"%B" "$currentTag" | awk 'NF {print "- " $0} !NF {print ""}' >> release.md
|
|
||||||
fi
|
|
||||||
echo "" >> release.md
|
|
||||||
fi
|
|
||||||
currentTag=$tag
|
|
||||||
done
|
|
||||||
|
|
||||||
- name: Push to telegram
|
|
||||||
env:
|
|
||||||
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
|
||||||
TAG: ${{ github.ref_name }}
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install requests
|
|
||||||
python release_telegram.py
|
|
||||||
|
|
||||||
- name: Patch release.md
|
|
||||||
run: |
|
|
||||||
version=$(echo "${{ github.ref_name }}" | sed 's/^v//')
|
|
||||||
sed "s|VERSION|$version|g" ./.github/release_template.md >> release.md
|
|
||||||
|
|
||||||
- name: Release
|
|
||||||
if: ${{ env.IS_STABLE == 'true' }}
|
|
||||||
uses: softprops/action-gh-release@v2
|
|
||||||
with:
|
|
||||||
files: ./dist/*
|
|
||||||
body_path: './release.md'
|
|
||||||
|
|
||||||
- name: Create Fdroid Source Dir
|
|
||||||
if: ${{ env.IS_STABLE == 'true' }}
|
|
||||||
run: |
|
|
||||||
mkdir -p ./tmp
|
|
||||||
cp ./dist/*android-arm64-v8a* ./tmp/ || true
|
|
||||||
echo "Files copied successfully"
|
|
||||||
|
|
||||||
- name: Push to fdroid repo
|
|
||||||
if: ${{ env.IS_STABLE == 'true' }}
|
|
||||||
uses: cpina/github-action-push-to-another-repository@v1.7.2
|
|
||||||
env:
|
|
||||||
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
|
|
||||||
with:
|
|
||||||
source-directory: ./tmp/
|
|
||||||
destination-github-username: chen08209
|
|
||||||
destination-repository-name: FlClash-fdroid-repo
|
|
||||||
user-name: 'github-actions[bot]'
|
|
||||||
user-email: 'github-actions[bot]@users.noreply.github.com'
|
|
||||||
target-branch: main
|
|
||||||
commit-message: Update from ${{ github.ref_name }}
|
|
||||||
target-directory: /tmp/
|
|
||||||
|
|
||||||
118
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
name: build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- platform: android
|
||||||
|
os: ubuntu-latest
|
||||||
|
- platform: windows
|
||||||
|
os: windows-latest
|
||||||
|
- platform: linux
|
||||||
|
os: ubuntu-latest
|
||||||
|
# - platform: macos
|
||||||
|
# os: macos-13
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Setup JAVA
|
||||||
|
if: startsWith(matrix.platform,'android')
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: 'zulu'
|
||||||
|
java-version: 17
|
||||||
|
|
||||||
|
- name: Setup NDK
|
||||||
|
if: startsWith(matrix.platform,'android')
|
||||||
|
uses: nttld/setup-ndk@v1
|
||||||
|
id: setup-ndk
|
||||||
|
with:
|
||||||
|
ndk-version: r26b
|
||||||
|
add-to-path: true
|
||||||
|
link-to-sdk: true
|
||||||
|
|
||||||
|
- name: Setup Android Signing
|
||||||
|
if: startsWith(matrix.platform,'android')
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.KEYSTORE }}" | base64 --decode > android/app/keystore.jks
|
||||||
|
echo "keyAlias=${{ secrets.KEY_ALIAS }}" >> android/local.properties
|
||||||
|
echo "storePassword=${{ secrets.STORE_PASSWORD }}" >> android/local.properties
|
||||||
|
echo "keyPassword=${{ secrets.KEY_PASSWORD }}" >> android/local.properties
|
||||||
|
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: 'core/go.mod'
|
||||||
|
cache-dependency-path: |
|
||||||
|
core/go.sum
|
||||||
|
|
||||||
|
- name: Setup Flutter
|
||||||
|
uses: subosito/flutter-action@v2
|
||||||
|
with:
|
||||||
|
flutter-version: '3.x'
|
||||||
|
channel: 'stable'
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Get Flutter Dependency
|
||||||
|
run: flutter pub get
|
||||||
|
|
||||||
|
- name: Setup
|
||||||
|
run: |
|
||||||
|
dart setup.dart ${{ matrix.platform }}
|
||||||
|
|
||||||
|
- name: Upload
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: artifact-${{ matrix.platform }}
|
||||||
|
path: ./dist
|
||||||
|
retention-days: 1
|
||||||
|
overwrite: true
|
||||||
|
|
||||||
|
|
||||||
|
upload-release:
|
||||||
|
if: ${{ !endsWith(github.ref, '-debug') }}
|
||||||
|
permissions: write-all
|
||||||
|
needs: [ build ]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Download
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
path: ./dist/
|
||||||
|
pattern: artifact-*
|
||||||
|
merge-multiple: true
|
||||||
|
|
||||||
|
- name: Pre Release
|
||||||
|
run: |
|
||||||
|
pip install gitchangelog pystache mustache markdown
|
||||||
|
pre=$(curl --silent "https://api.github.com/repos/chen08209/FlClash/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' || echo "")
|
||||||
|
if [ -z "pre" ]; then
|
||||||
|
echo "init" > release.md
|
||||||
|
else
|
||||||
|
current="${{ github.ref_name }}"
|
||||||
|
echo -e "\n\n<details markdown=1><summary>All changes from $current to the latest commit:</summary>\n\n" >> release.md
|
||||||
|
gitchangelog "${pre}.." >> release.md 2>&1 || echo "Error in gitchangelog"
|
||||||
|
echo -e "\n\n</details>" >> release.md
|
||||||
|
fi
|
||||||
|
- name: Release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
files: ./dist/*
|
||||||
|
body_path: './release.md'
|
||||||
2
.gitignore
vendored
@@ -5,11 +5,9 @@
|
|||||||
*.swp
|
*.swp
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.atom/
|
.atom/
|
||||||
.build/
|
|
||||||
.buildlog/
|
.buildlog/
|
||||||
.history
|
.history
|
||||||
.svn/
|
.svn/
|
||||||
.swiftpm/
|
|
||||||
migrate_working_dir/
|
migrate_working_dir/
|
||||||
|
|
||||||
# IntelliJ related
|
# IntelliJ related
|
||||||
|
|||||||
6
.gitmodules
vendored
@@ -5,10 +5,4 @@
|
|||||||
[submodule "plugins/flutter_distributor"]
|
[submodule "plugins/flutter_distributor"]
|
||||||
path = plugins/flutter_distributor
|
path = plugins/flutter_distributor
|
||||||
url = git@github.com:chen08209/flutter_distributor.git
|
url = git@github.com:chen08209/flutter_distributor.git
|
||||||
branch = FlClash
|
|
||||||
[submodule "plugins/tray_manager"]
|
|
||||||
path = plugins/tray_manager
|
|
||||||
url = git@github.com:chen08209/tray_manager.git
|
|
||||||
branch = main
|
branch = main
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
824
CHANGELOG.md
@@ -1,824 +0,0 @@
|
|||||||
## v0.8.81
|
|
||||||
|
|
||||||
- Add rule override
|
|
||||||
|
|
||||||
- Update core
|
|
||||||
|
|
||||||
- Optimize more details
|
|
||||||
|
|
||||||
- Update changelog
|
|
||||||
|
|
||||||
## v0.8.80
|
|
||||||
|
|
||||||
- Optimize dashboard performance
|
|
||||||
|
|
||||||
- Fix some issues
|
|
||||||
|
|
||||||
- Fix unselected proxy group delay issues
|
|
||||||
|
|
||||||
- Fix asn url issues
|
|
||||||
|
|
||||||
- Update changelog
|
|
||||||
|
|
||||||
## v0.8.79
|
|
||||||
|
|
||||||
- Fix tab delay view issues
|
|
||||||
|
|
||||||
- Fix tray action issues
|
|
||||||
|
|
||||||
- Fix get profile redirect client ua issues
|
|
||||||
|
|
||||||
- Fix proxy card delay view issues
|
|
||||||
|
|
||||||
- Add Russian, Japanese adaptation
|
|
||||||
|
|
||||||
- Fix some issues
|
|
||||||
|
|
||||||
- Update changelog
|
|
||||||
|
|
||||||
## v0.8.78
|
|
||||||
|
|
||||||
- Fix list form input view issues
|
|
||||||
|
|
||||||
- Fix traffic view issues
|
|
||||||
|
|
||||||
- Update changelog
|
|
||||||
|
|
||||||
## v0.8.77
|
|
||||||
|
|
||||||
- Optimize performance
|
|
||||||
|
|
||||||
- Update core
|
|
||||||
|
|
||||||
- Optimize core stability
|
|
||||||
|
|
||||||
- Fix linux tun authority check error
|
|
||||||
|
|
||||||
- Fix some issues
|
|
||||||
|
|
||||||
- Fix scroll physics error
|
|
||||||
|
|
||||||
- Update changelog
|
|
||||||
|
|
||||||
## v0.8.75
|
|
||||||
|
|
||||||
- Add windows storage corruption detection
|
|
||||||
|
|
||||||
- Fix core crash caused by windows resource manager restart
|
|
||||||
|
|
||||||
- Optimize logs, requests, access to pages
|
|
||||||
|
|
||||||
- Fix macos bypass domain issues
|
|
||||||
|
|
||||||
- Update changelog
|
|
||||||
|
|
||||||
## v0.8.74
|
|
||||||
|
|
||||||
- Fix some issues
|
|
||||||
|
|
||||||
- Update changelog
|
|
||||||
|
|
||||||
## v0.8.73
|
|
||||||
|
|
||||||
- Update popup menu
|
|
||||||
|
|
||||||
- Add file editor
|
|
||||||
|
|
||||||
- Fix android service issues
|
|
||||||
|
|
||||||
- Optimize desktop background performance
|
|
||||||
|
|
||||||
- Optimize android main process performance
|
|
||||||
|
|
||||||
- Optimize delay test
|
|
||||||
|
|
||||||
- Optimize vpn protect
|
|
||||||
|
|
||||||
- Update changelog
|
|
||||||
|
|
||||||
## v0.8.72
|
|
||||||
|
|
||||||
- Update core
|
|
||||||
|
|
||||||
- Fix some issues
|
|
||||||
|
|
||||||
- Update changelog
|
|
||||||
|
|
||||||
## v0.8.71
|
|
||||||
|
|
||||||
- Remake dashboard
|
|
||||||
|
|
||||||
- Optimize theme
|
|
||||||
|
|
||||||
- Optimize more details
|
|
||||||
|
|
||||||
- Update flutter version
|
|
||||||
|
|
||||||
- Update changelog
|
|
||||||
|
|
||||||
## v0.8.70
|
|
||||||
|
|
||||||
- Support better window position memory
|
|
||||||
|
|
||||||
- Add windows arm64 and linux arm64 build script
|
|
||||||
|
|
||||||
- Optimize some details
|
|
||||||
|
|
||||||
## v0.8.69
|
|
||||||
|
|
||||||
- Remake desktop
|
|
||||||
|
|
||||||
- Optimize change proxy
|
|
||||||
|
|
||||||
- Optimize network check
|
|
||||||
|
|
||||||
- Fix fallback issues
|
|
||||||
|
|
||||||
- Optimize lots of details
|
|
||||||
|
|
||||||
- Update change.yaml
|
|
||||||
|
|
||||||
- Fix android tile issues
|
|
||||||
|
|
||||||
- Fix windows tray issues
|
|
||||||
|
|
||||||
- Support setting bypassDomain
|
|
||||||
|
|
||||||
- Update flutter version
|
|
||||||
|
|
||||||
- Fix android service issues
|
|
||||||
|
|
||||||
- Fix macos dock exit button issues
|
|
||||||
|
|
||||||
- Add route address setting
|
|
||||||
|
|
||||||
- Optimize provider view
|
|
||||||
|
|
||||||
- Update changelog
|
|
||||||
|
|
||||||
- Update CHANGELOG.md
|
|
||||||
|
|
||||||
## v0.8.67
|
|
||||||
|
|
||||||
- Add android shortcuts
|
|
||||||
|
|
||||||
- Fix init params issues
|
|
||||||
|
|
||||||
- Fix dynamic color issues
|
|
||||||
|
|
||||||
- Optimize navigator animate
|
|
||||||
|
|
||||||
- Optimize window init
|
|
||||||
|
|
||||||
- Optimize fab
|
|
||||||
|
|
||||||
- Optimize save
|
|
||||||
|
|
||||||
## v0.8.66
|
|
||||||
|
|
||||||
- Fix the collapse issues
|
|
||||||
|
|
||||||
- Add fontFamily options
|
|
||||||
|
|
||||||
## v0.8.65
|
|
||||||
|
|
||||||
- Update core version
|
|
||||||
|
|
||||||
- Update flutter version
|
|
||||||
|
|
||||||
- Optimize ip check
|
|
||||||
|
|
||||||
- Optimize url-test
|
|
||||||
|
|
||||||
## v0.8.64
|
|
||||||
|
|
||||||
- Update release message
|
|
||||||
|
|
||||||
- Init auto gen changelog
|
|
||||||
|
|
||||||
- Fix windows tray issues
|
|
||||||
|
|
||||||
- Fix urltest issues
|
|
||||||
|
|
||||||
- Add auto changelog
|
|
||||||
|
|
||||||
- Fix windows admin auto launch issues
|
|
||||||
|
|
||||||
- Add android vpn options
|
|
||||||
|
|
||||||
- Support proxies icon configuration
|
|
||||||
|
|
||||||
- Optimize android immersion display
|
|
||||||
|
|
||||||
- Fix some issues
|
|
||||||
|
|
||||||
- Optimize ip detection
|
|
||||||
|
|
||||||
- Support android vpn ipv6 inbound switch
|
|
||||||
|
|
||||||
- Support log export
|
|
||||||
|
|
||||||
- Optimize more details
|
|
||||||
|
|
||||||
- Fix android system dns issues
|
|
||||||
|
|
||||||
- Optimize dns default option
|
|
||||||
|
|
||||||
- Fix some issues
|
|
||||||
|
|
||||||
- Update readme
|
|
||||||
|
|
||||||
## v0.8.60
|
|
||||||
|
|
||||||
- Fix build error2
|
|
||||||
|
|
||||||
- Fix build error
|
|
||||||
|
|
||||||
- Support desktop hotkey
|
|
||||||
|
|
||||||
- Support android ipv6 inbound
|
|
||||||
|
|
||||||
- Support android system dns
|
|
||||||
|
|
||||||
- fix some bugs
|
|
||||||
|
|
||||||
## v0.8.59
|
|
||||||
|
|
||||||
- Fix delete profile error
|
|
||||||
|
|
||||||
## v0.8.58
|
|
||||||
|
|
||||||
- Fix submit error 2
|
|
||||||
|
|
||||||
- Fix submit error
|
|
||||||
|
|
||||||
- Optimize DNS strategy
|
|
||||||
|
|
||||||
- Fix the problem that the tray is not displayed in some cases
|
|
||||||
|
|
||||||
- Optimize tray
|
|
||||||
|
|
||||||
- Update core
|
|
||||||
|
|
||||||
- Fix some error
|
|
||||||
|
|
||||||
## v0.8.57
|
|
||||||
|
|
||||||
- Fix tun update issues
|
|
||||||
|
|
||||||
- Add DNS override
|
|
||||||
- Fixed some bugs
|
|
||||||
- Optimize more detail
|
|
||||||
|
|
||||||
- Add Hosts override
|
|
||||||
|
|
||||||
## v0.8.56
|
|
||||||
|
|
||||||
- fix android tip error
|
|
||||||
- fix windows auto launch error
|
|
||||||
|
|
||||||
## v0.8.55
|
|
||||||
|
|
||||||
- Fix windows tray issues
|
|
||||||
|
|
||||||
- Optimize windows logic
|
|
||||||
|
|
||||||
- Optimize app logic
|
|
||||||
|
|
||||||
- Support windows administrator auto launch
|
|
||||||
|
|
||||||
- Support android close vpn
|
|
||||||
|
|
||||||
## v0.8.53
|
|
||||||
|
|
||||||
- Change flutter version
|
|
||||||
|
|
||||||
- Support profiles sort
|
|
||||||
|
|
||||||
- Support windows country flags display
|
|
||||||
|
|
||||||
- Optimize proxies page and profiles page columns
|
|
||||||
|
|
||||||
## v0.8.52
|
|
||||||
|
|
||||||
- Update flutter version
|
|
||||||
|
|
||||||
- Update version
|
|
||||||
|
|
||||||
- Update timeout time
|
|
||||||
|
|
||||||
- Update access control page
|
|
||||||
|
|
||||||
- Fix bug
|
|
||||||
|
|
||||||
## v0.8.51
|
|
||||||
|
|
||||||
- Optimize provider page
|
|
||||||
|
|
||||||
- Optimize delay test
|
|
||||||
|
|
||||||
- Support local backup and recovery
|
|
||||||
|
|
||||||
- Fix android tile service issues
|
|
||||||
|
|
||||||
## v0.8.49
|
|
||||||
|
|
||||||
- Fix linux core build error
|
|
||||||
|
|
||||||
- Add proxy-only traffic statistics
|
|
||||||
|
|
||||||
- Update core
|
|
||||||
|
|
||||||
- Optimize more details
|
|
||||||
|
|
||||||
- Merge pull request #140 from txyyh/main
|
|
||||||
|
|
||||||
- 添加自建 F-Droid 仓库相关 workflow
|
|
||||||
- Rename readme fingerprint
|
|
||||||
|
|
||||||
- Rename workflow deploy repo name
|
|
||||||
|
|
||||||
- Add download guide to README
|
|
||||||
|
|
||||||
- Add push release files to fdroid-repo
|
|
||||||
|
|
||||||
## v0.8.48
|
|
||||||
|
|
||||||
- Optimize proxies page
|
|
||||||
|
|
||||||
- Fix ua issues
|
|
||||||
|
|
||||||
- Optimize more details
|
|
||||||
|
|
||||||
## v0.8.47
|
|
||||||
|
|
||||||
- Fix windows build error
|
|
||||||
|
|
||||||
## v0.8.46
|
|
||||||
|
|
||||||
- Update app icon
|
|
||||||
|
|
||||||
- Fix desktop backup error
|
|
||||||
|
|
||||||
- Optimize request ua
|
|
||||||
|
|
||||||
- Change android icon
|
|
||||||
|
|
||||||
- Optimize dashboard
|
|
||||||
|
|
||||||
## v0.8.44
|
|
||||||
|
|
||||||
- Remove request validate certificate
|
|
||||||
|
|
||||||
- Sync core
|
|
||||||
|
|
||||||
## v0.8.43
|
|
||||||
|
|
||||||
- Fix windows error
|
|
||||||
|
|
||||||
## v0.8.42
|
|
||||||
|
|
||||||
- Fix setup.dart error
|
|
||||||
|
|
||||||
- Fix android system proxy not effective
|
|
||||||
|
|
||||||
- Add macos arm64
|
|
||||||
|
|
||||||
## v0.8.41
|
|
||||||
|
|
||||||
- Optimize proxies page
|
|
||||||
|
|
||||||
- Support mouse drag scroll
|
|
||||||
|
|
||||||
- Adjust desktop ui
|
|
||||||
|
|
||||||
- Revert "Fix android vpn issues"
|
|
||||||
|
|
||||||
- This reverts commit 891977408e6938e2acd74e9b9adb959c48c79988.
|
|
||||||
|
|
||||||
## v0.8.40
|
|
||||||
|
|
||||||
- Fix android vpn issues
|
|
||||||
|
|
||||||
- Fix android vpn issues
|
|
||||||
|
|
||||||
- Rollback partial modification
|
|
||||||
|
|
||||||
## v0.8.39
|
|
||||||
|
|
||||||
- Fix the problem that ui can't be synchronized when android vpn is occupied by an external
|
|
||||||
|
|
||||||
- Override default socksPort,port
|
|
||||||
|
|
||||||
## v0.8.38
|
|
||||||
|
|
||||||
- Fix fab issues
|
|
||||||
|
|
||||||
## v0.8.37
|
|
||||||
|
|
||||||
- Update version
|
|
||||||
|
|
||||||
- Fix the problem that vpn cannot be started in some cases
|
|
||||||
|
|
||||||
- Fix the problem that geodata url does not take effect
|
|
||||||
|
|
||||||
## v0.8.36
|
|
||||||
|
|
||||||
- Update ua
|
|
||||||
|
|
||||||
- Fix change outbound mode without check ip issues
|
|
||||||
|
|
||||||
- Separate android ui and vpn
|
|
||||||
|
|
||||||
- Fix url validate issues 2
|
|
||||||
|
|
||||||
- Add android hidden from the recent task
|
|
||||||
|
|
||||||
- Add geoip file
|
|
||||||
|
|
||||||
- Support modify geoData URL
|
|
||||||
|
|
||||||
## v0.8.35
|
|
||||||
|
|
||||||
- Fix url validate issues
|
|
||||||
|
|
||||||
- Fix check ip performance problem
|
|
||||||
|
|
||||||
- Optimize resources page
|
|
||||||
|
|
||||||
## v0.8.34
|
|
||||||
|
|
||||||
- Add ua selector
|
|
||||||
|
|
||||||
- Support modify test url
|
|
||||||
|
|
||||||
- Optimize android proxy
|
|
||||||
|
|
||||||
- Fix the error that async proxy provider could not selected the proxy
|
|
||||||
|
|
||||||
## v0.8.33
|
|
||||||
|
|
||||||
- Fix android proxy error
|
|
||||||
|
|
||||||
- Fix submit error
|
|
||||||
|
|
||||||
- Add windows tun
|
|
||||||
|
|
||||||
- Optimize android proxy
|
|
||||||
|
|
||||||
- Optimize change profile
|
|
||||||
|
|
||||||
- Update application ua
|
|
||||||
|
|
||||||
- Optimize delay test
|
|
||||||
|
|
||||||
## v0.8.32
|
|
||||||
|
|
||||||
- Fix android repeated request notification issues
|
|
||||||
|
|
||||||
## v0.8.31
|
|
||||||
|
|
||||||
- Fix memory overflow issues
|
|
||||||
|
|
||||||
## v0.8.30
|
|
||||||
|
|
||||||
- Optimize proxies expansion panel 2
|
|
||||||
|
|
||||||
- Fix android scan qrcode error
|
|
||||||
|
|
||||||
## v0.8.29
|
|
||||||
|
|
||||||
- Optimize proxies expansion panel
|
|
||||||
|
|
||||||
- Fix text error
|
|
||||||
|
|
||||||
## v0.8.28
|
|
||||||
|
|
||||||
- Optimize proxy
|
|
||||||
|
|
||||||
- Optimize delayed sorting performance
|
|
||||||
|
|
||||||
- Add expansion panel proxies page
|
|
||||||
|
|
||||||
- Support to adjust the proxy card size
|
|
||||||
|
|
||||||
- Support to adjust proxies columns number
|
|
||||||
|
|
||||||
- Fix autoRun show issues
|
|
||||||
|
|
||||||
- Fix Android 10 issues
|
|
||||||
|
|
||||||
- Optimize ip show
|
|
||||||
|
|
||||||
## v0.8.26
|
|
||||||
|
|
||||||
- Add intranet IP display
|
|
||||||
|
|
||||||
- Add connections page
|
|
||||||
|
|
||||||
- Add search in connections, requests
|
|
||||||
|
|
||||||
- Add keyword search in connections, requests, logs
|
|
||||||
|
|
||||||
- Add basic viewing editing capabilities
|
|
||||||
|
|
||||||
- Optimize update profile
|
|
||||||
|
|
||||||
## v0.8.25
|
|
||||||
|
|
||||||
- Update version
|
|
||||||
|
|
||||||
- Fix the problem of excessive memory usage in traffic usage.
|
|
||||||
|
|
||||||
- Add lightBlue theme color
|
|
||||||
|
|
||||||
- Fix start unable to update profile issues
|
|
||||||
|
|
||||||
- Fix flashback caused by process
|
|
||||||
|
|
||||||
## v0.8.23
|
|
||||||
|
|
||||||
- Add build version
|
|
||||||
|
|
||||||
- Optimize quick start
|
|
||||||
|
|
||||||
- Update system default option
|
|
||||||
|
|
||||||
## v0.8.22
|
|
||||||
|
|
||||||
- Update build.yml
|
|
||||||
|
|
||||||
- Fix android vpn close issues
|
|
||||||
|
|
||||||
- Add requests page
|
|
||||||
|
|
||||||
- Fix checkUpdate dark mode style error
|
|
||||||
|
|
||||||
- Fix quickStart error open app
|
|
||||||
|
|
||||||
- Add memory proxies tab index
|
|
||||||
|
|
||||||
- Support hidden group
|
|
||||||
|
|
||||||
- Optimize logs
|
|
||||||
|
|
||||||
- Fix externalController hot load error
|
|
||||||
|
|
||||||
## v0.8.21
|
|
||||||
|
|
||||||
- Add tcp concurrent switch
|
|
||||||
|
|
||||||
- Add system proxy switch
|
|
||||||
|
|
||||||
- Add geodata loader switch
|
|
||||||
|
|
||||||
- Add external controller switch
|
|
||||||
|
|
||||||
- Add auto gc on trim memory
|
|
||||||
|
|
||||||
- Fix android notification error
|
|
||||||
|
|
||||||
## v0.8.20
|
|
||||||
|
|
||||||
- Fix ipv6 error
|
|
||||||
|
|
||||||
- Fix android udp direct error
|
|
||||||
|
|
||||||
- Add ipv6 switch
|
|
||||||
|
|
||||||
- Add access all selected button
|
|
||||||
|
|
||||||
- Remove android low version splash
|
|
||||||
|
|
||||||
## v0.8.19
|
|
||||||
|
|
||||||
- Update version
|
|
||||||
|
|
||||||
- Add allowBypass
|
|
||||||
|
|
||||||
- Fix Android only pick .text file issues
|
|
||||||
|
|
||||||
## v0.8.18
|
|
||||||
|
|
||||||
- Fix search issues
|
|
||||||
|
|
||||||
## v0.8.17
|
|
||||||
|
|
||||||
- Fix LoadBalance, Relay load error
|
|
||||||
|
|
||||||
- Fix build.yml4
|
|
||||||
|
|
||||||
- Fix build.yml3
|
|
||||||
|
|
||||||
- Fix build.yml2
|
|
||||||
|
|
||||||
- Fix build.yml
|
|
||||||
|
|
||||||
- Add search function at access control
|
|
||||||
|
|
||||||
- Fix the issues with the profile add button to cover the edit button
|
|
||||||
|
|
||||||
- Adapt LoadBalance and Relay
|
|
||||||
|
|
||||||
- Add arm
|
|
||||||
|
|
||||||
- Fix android notification icon error
|
|
||||||
|
|
||||||
## v0.8.16
|
|
||||||
|
|
||||||
- Add one-click update all profiles
|
|
||||||
- Add expire show
|
|
||||||
|
|
||||||
## v0.8.15
|
|
||||||
|
|
||||||
- Temp remove tun mode
|
|
||||||
|
|
||||||
- Remove macos in workflow
|
|
||||||
|
|
||||||
- Change go version
|
|
||||||
|
|
||||||
## v0.8.14
|
|
||||||
|
|
||||||
- Update Version
|
|
||||||
|
|
||||||
- Fix tun unable to open
|
|
||||||
|
|
||||||
## v0.8.13
|
|
||||||
|
|
||||||
- Optimize delay test2
|
|
||||||
|
|
||||||
- Optimize delay test
|
|
||||||
|
|
||||||
- Add check ip
|
|
||||||
|
|
||||||
- add check ip request
|
|
||||||
|
|
||||||
## v0.8.12
|
|
||||||
|
|
||||||
- Fix the problem that the download of remote resources failed after GeodataMode was turned on, which caused the
|
|
||||||
application to flash back.
|
|
||||||
|
|
||||||
- Fix edit profile error
|
|
||||||
|
|
||||||
- Fix quickStart change proxy error
|
|
||||||
|
|
||||||
- Fix core version
|
|
||||||
|
|
||||||
## v0.8.10
|
|
||||||
|
|
||||||
- Fix core version
|
|
||||||
|
|
||||||
## v0.8.9
|
|
||||||
|
|
||||||
- Update file_picker
|
|
||||||
|
|
||||||
- Add resources page
|
|
||||||
|
|
||||||
- Optimize more detail
|
|
||||||
|
|
||||||
- Add access selected sorted
|
|
||||||
|
|
||||||
- Fix notification duplicate creation issue
|
|
||||||
|
|
||||||
- Fix AccessControl click issue
|
|
||||||
|
|
||||||
## v0.8.7
|
|
||||||
|
|
||||||
- Fix Workflow
|
|
||||||
|
|
||||||
- Fix Linux unable to open
|
|
||||||
|
|
||||||
- Update README.md 3
|
|
||||||
|
|
||||||
- Create LICENSE
|
|
||||||
- Update README.md 2
|
|
||||||
|
|
||||||
- Update README.md
|
|
||||||
|
|
||||||
- Optimize workFlow
|
|
||||||
|
|
||||||
## v0.8.6
|
|
||||||
|
|
||||||
- optimize checkUpdate
|
|
||||||
|
|
||||||
## v0.8.5
|
|
||||||
|
|
||||||
- Fix submit error
|
|
||||||
|
|
||||||
## v0.8.4
|
|
||||||
|
|
||||||
- add WebDAV
|
|
||||||
|
|
||||||
- add Auto check updates
|
|
||||||
|
|
||||||
- Optimize more details
|
|
||||||
|
|
||||||
- optimize delayTest
|
|
||||||
|
|
||||||
## v0.8.2
|
|
||||||
|
|
||||||
- upgrade flutter version
|
|
||||||
|
|
||||||
## v0.8.1
|
|
||||||
|
|
||||||
- Update kernel
|
|
||||||
- Add import profile via QR code image
|
|
||||||
|
|
||||||
## v0.8.0
|
|
||||||
|
|
||||||
- Add compatibility mode and adapt clash scheme.
|
|
||||||
|
|
||||||
## v0.7.14
|
|
||||||
|
|
||||||
- update Version
|
|
||||||
|
|
||||||
- Reconstruction application proxy logic
|
|
||||||
|
|
||||||
## v0.7.13
|
|
||||||
|
|
||||||
- Fix Tab destroy error
|
|
||||||
|
|
||||||
## v0.7.12
|
|
||||||
|
|
||||||
- Optimize repeat healthcheck
|
|
||||||
|
|
||||||
## v0.7.11
|
|
||||||
|
|
||||||
- Optimize Direct mode ui
|
|
||||||
|
|
||||||
## v0.7.10
|
|
||||||
|
|
||||||
- Optimize Healthcheck
|
|
||||||
|
|
||||||
- Remove proxies position animation, improve performance
|
|
||||||
- Add Telegram Link
|
|
||||||
|
|
||||||
- Update healthcheck policy
|
|
||||||
|
|
||||||
- New Check URLTest
|
|
||||||
|
|
||||||
- Fix the problem of invalid auto-selection
|
|
||||||
|
|
||||||
## v0.7.8
|
|
||||||
|
|
||||||
- New Async UpdateConfig
|
|
||||||
|
|
||||||
- add changeProfileDebounce
|
|
||||||
|
|
||||||
- Update Workflow
|
|
||||||
|
|
||||||
- Fix ChangeProfile block
|
|
||||||
|
|
||||||
- Fix Release Message Error
|
|
||||||
|
|
||||||
## v0.7.7
|
|
||||||
|
|
||||||
- Update Selector 2
|
|
||||||
|
|
||||||
## v0.7.6
|
|
||||||
|
|
||||||
- Update Version
|
|
||||||
|
|
||||||
- Fix Proxies Select Error
|
|
||||||
|
|
||||||
## v0.7.5
|
|
||||||
|
|
||||||
- Fix the problem that the proxy group is empty in global mode.
|
|
||||||
|
|
||||||
- Fix the problem that the proxy group is empty in global mode.
|
|
||||||
|
|
||||||
## v0.7.4
|
|
||||||
|
|
||||||
- Add ProxyProvider2
|
|
||||||
|
|
||||||
## v0.7.3
|
|
||||||
|
|
||||||
- Add ProxyProvider
|
|
||||||
|
|
||||||
- Update Version
|
|
||||||
|
|
||||||
- Update ProxyGroup Sort
|
|
||||||
|
|
||||||
- Fix Android quickStart VpnService some problems
|
|
||||||
|
|
||||||
## v0.7.1
|
|
||||||
|
|
||||||
- Update version
|
|
||||||
|
|
||||||
- Set Android notification low importance
|
|
||||||
|
|
||||||
- Fix the issue that VpnService can't be closed correctly in special cases
|
|
||||||
|
|
||||||
- Fix the problem that TileService is not destroyed correctly in some cases
|
|
||||||
|
|
||||||
- Adjust tab animation defaults
|
|
||||||
|
|
||||||
- Add Telegram in README_zh_CN.md
|
|
||||||
|
|
||||||
- Add Telegram
|
|
||||||
|
|
||||||
## v0.7.0
|
|
||||||
|
|
||||||
- update mobile_scanner
|
|
||||||
|
|
||||||
- Initial commit
|
|
||||||
8
Makefile
@@ -1,8 +0,0 @@
|
|||||||
android_arm64:
|
|
||||||
dart ./setup.dart android --arch arm64
|
|
||||||
macos_arm64:
|
|
||||||
dart ./setup.dart macos --arch arm64
|
|
||||||
android_arm64_core:
|
|
||||||
dart ./setup.dart android --arch arm64 --out core
|
|
||||||
macos_arm64_core:
|
|
||||||
dart ./setup.dart macos --arch arm64 --out core
|
|
||||||
46
README.md
@@ -6,9 +6,13 @@
|
|||||||
|
|
||||||
## FlClash
|
## FlClash
|
||||||
|
|
||||||
[](https://github.com/chen08209/FlClash/releases/)[](https://github.com/chen08209/FlClash/releases/)[](LICENSE)
|
<p style="text-align: left;">
|
||||||
|
<img alt="stars" src="https://img.shields.io/github/stars/chen08209/FlClash?style=flat-square&logo=github"/>
|
||||||
[](https://t.me/FlClash)
|
<img alt="downloads" src="https://img.shields.io/github/downloads/chen08209/FlClash/total"/>
|
||||||
|
<a href="LICENSE">
|
||||||
|
<img alt="license" src="https://img.shields.io/github/license/chen08209/FlClash"/>
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
A multi-platform proxy client based on ClashMeta, simple and easy to use, open-source and ad-free.
|
A multi-platform proxy client based on ClashMeta, simple and easy to use, open-source and ad-free.
|
||||||
|
|
||||||
@@ -34,32 +38,9 @@ on Mobile:
|
|||||||
|
|
||||||
✨ Support subscription link, Dark mode
|
✨ Support subscription link, Dark mode
|
||||||
|
|
||||||
## Use
|
## Contact
|
||||||
|
|
||||||
### Linux
|
[Telegram](https://t.me/+G-veVtwBOl4wODc1)
|
||||||
|
|
||||||
⚠️ Make sure to install the following dependencies before using them
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo apt-get install appindicator3-0.1 libappindicator3-dev
|
|
||||||
sudo apt-get install keybinder-3.0
|
|
||||||
```
|
|
||||||
|
|
||||||
### Android
|
|
||||||
|
|
||||||
Support the following actions
|
|
||||||
|
|
||||||
```bash
|
|
||||||
com.follow.clash.action.START
|
|
||||||
|
|
||||||
com.follow.clash.action.STOP
|
|
||||||
|
|
||||||
com.follow.clash.action.CHANGE
|
|
||||||
```
|
|
||||||
|
|
||||||
## Download
|
|
||||||
|
|
||||||
<a href="https://chen08209.github.io/FlClash-fdroid-repo/repo?fingerprint=789D6D32668712EF7672F9E58DEEB15FBD6DCEEC5AE7A4371EA72F2AAE8A12FD"><img alt="Get it on F-Droid" src="snapshots/get-it-on-fdroid.svg" width="200px"/></a> <a href="https://github.com/chen08209/FlClash/releases"><img alt="Get it on GitHub" src="snapshots/get-it-on-github.svg" width="200px"/></a>
|
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
@@ -93,7 +74,7 @@ Support the following actions
|
|||||||
3. Run build script
|
3. Run build script
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dart .\setup.dart windows --arch <arm64 | amd64>
|
dart .\setup.dart
|
||||||
```
|
```
|
||||||
|
|
||||||
- linux
|
- linux
|
||||||
@@ -103,7 +84,7 @@ Support the following actions
|
|||||||
2. Run build script
|
2. Run build script
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dart .\setup.dart linux --arch <arm64 | amd64>
|
dart .\setup.dart
|
||||||
```
|
```
|
||||||
|
|
||||||
- macOS
|
- macOS
|
||||||
@@ -113,8 +94,11 @@ Support the following actions
|
|||||||
2. Run build script
|
2. Run build script
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dart .\setup.dart macos --arch <arm64 | amd64>
|
dart .\setup.dart
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Star
|
## Star
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,13 @@
|
|||||||
|
|
||||||
## FlClash
|
## FlClash
|
||||||
|
|
||||||
[](https://github.com/chen08209/FlClash/releases/)[](https://github.com/chen08209/FlClash/releases/)[](LICENSE)
|
<p style="text-align: left;">
|
||||||
|
<img alt="stars" src="https://img.shields.io/github/stars/chen08209/FlClash?style=flat-square&logo=github"/>
|
||||||
[](https://t.me/FlClash)
|
<img alt="downloads" src="https://img.shields.io/github/downloads/chen08209/FlClash/total"/>
|
||||||
|
<a href="LICENSE">
|
||||||
|
<img alt="license" src="https://img.shields.io/github/license/chen08209/FlClash"/>
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
基于ClashMeta的多平台代理客户端,简单易用,开源无广告。
|
基于ClashMeta的多平台代理客户端,简单易用,开源无广告。
|
||||||
|
|
||||||
@@ -34,32 +38,9 @@ on Mobile:
|
|||||||
|
|
||||||
✨ 支持一键导入订阅, 深色模式
|
✨ 支持一键导入订阅, 深色模式
|
||||||
|
|
||||||
## Use
|
## Contact
|
||||||
|
|
||||||
### Linux
|
[Telegram](https://t.me/+G-veVtwBOl4wODc1)
|
||||||
|
|
||||||
⚠️ 使用前请确保安装以下依赖
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo apt-get install appindicator3-0.1 libappindicator3-dev
|
|
||||||
sudo apt-get install keybinder-3.0
|
|
||||||
```
|
|
||||||
|
|
||||||
### Android
|
|
||||||
|
|
||||||
支持下列操作
|
|
||||||
|
|
||||||
```bash
|
|
||||||
com.follow.clash.action.START
|
|
||||||
|
|
||||||
com.follow.clash.action.STOP
|
|
||||||
|
|
||||||
com.follow.clash.action.CHANGE
|
|
||||||
```
|
|
||||||
|
|
||||||
## Download
|
|
||||||
|
|
||||||
<a href="https://chen08209.github.io/FlClash-fdroid-repo/repo?fingerprint=789D6D32668712EF7672F9E58DEEB15FBD6DCEEC5AE7A4371EA72F2AAE8A12FD"><img alt="Get it on F-Droid" src="snapshots/get-it-on-fdroid.svg" width="200px"/></a> <a href="https://github.com/chen08209/FlClash/releases"><img alt="Get it on GitHub" src="snapshots/get-it-on-github.svg" width="200px"/></a>
|
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
@@ -93,7 +74,7 @@ on Mobile:
|
|||||||
3. 运行构建脚本
|
3. 运行构建脚本
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dart .\setup.dart windows --arch <arm64 | amd64>
|
dart .\setup.dart
|
||||||
```
|
```
|
||||||
|
|
||||||
- linux
|
- linux
|
||||||
@@ -103,7 +84,7 @@ on Mobile:
|
|||||||
2. 运行构建脚本
|
2. 运行构建脚本
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dart .\setup.dart linux --arch <arm64 | amd64>
|
dart .\setup.dart
|
||||||
```
|
```
|
||||||
|
|
||||||
- macOS
|
- macOS
|
||||||
@@ -113,7 +94,7 @@ on Mobile:
|
|||||||
2. 运行构建脚本
|
2. 运行构建脚本
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dart .\setup.dart macos --arch <arm64 | amd64>
|
dart .\setup.dart
|
||||||
```
|
```
|
||||||
|
|
||||||
## Star History
|
## Star History
|
||||||
|
|||||||
@@ -1 +1,29 @@
|
|||||||
|
# This file configures the analyzer, which statically analyzes Dart code to
|
||||||
|
# check for errors, warnings, and lints.
|
||||||
|
#
|
||||||
|
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
|
||||||
|
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
|
||||||
|
# invoked from the command line by running `flutter analyze`.
|
||||||
|
|
||||||
|
# The following line activates a set of recommended lints for Flutter apps,
|
||||||
|
# packages, and plugins designed to encourage good coding practices.
|
||||||
include: package:flutter_lints/flutter.yaml
|
include: package:flutter_lints/flutter.yaml
|
||||||
|
|
||||||
|
linter:
|
||||||
|
# The lint rules applied to this project can be customized in the
|
||||||
|
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
|
||||||
|
# included above or to enable additional rules. A list of all available lints
|
||||||
|
# and their documentation is published at
|
||||||
|
# https://dart-lang.github.io/linter/lints/index.html.
|
||||||
|
#
|
||||||
|
# Instead of disabling a lint rule for the entire project in the
|
||||||
|
# section below, it can also be suppressed for a single line of code
|
||||||
|
# or a specific dart file by using the `// ignore: name_of_lint` and
|
||||||
|
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
|
||||||
|
# producing the lint.
|
||||||
|
rules:
|
||||||
|
# avoid_print: false # Uncomment to disable the `avoid_print` rule
|
||||||
|
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
|
||||||
|
|
||||||
|
# Additional information about this file can be found at
|
||||||
|
# https://dart.dev/guides/language/analysis-options
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import com.android.build.gradle.tasks.MergeSourceSetFolders
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "com.android.application"
|
id "com.android.application"
|
||||||
id "kotlin-android"
|
id "kotlin-android"
|
||||||
@@ -31,23 +33,23 @@ def isRelease = defStoreFile.exists() && defStorePassword != null && defKeyAlias
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
namespace "com.follow.clash"
|
namespace "com.follow.clash"
|
||||||
compileSdkVersion 35
|
compileSdkVersion 34
|
||||||
|
ndkVersion "25.1.8937393"
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_17
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
targetCompatibility JavaVersion.VERSION_17
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = '17'
|
jvmTarget = '1.8'
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main.java.srcDirs += 'src/main/kotlin'
|
main.java.srcDirs += 'src/main/kotlin'
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
if (isRelease) {
|
if (isRelease){
|
||||||
release {
|
release {
|
||||||
storeFile defStoreFile
|
storeFile defStoreFile
|
||||||
storePassword defStorePassword
|
storePassword defStorePassword
|
||||||
@@ -60,8 +62,8 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.follow.clash"
|
applicationId "com.follow.clash"
|
||||||
minSdkVersion 21
|
minSdkVersion 24
|
||||||
targetSdkVersion 35
|
targetSdkVersion 34
|
||||||
versionCode flutterVersionCode.toInteger()
|
versionCode flutterVersionCode.toInteger()
|
||||||
versionName flutterVersionName
|
versionName flutterVersionName
|
||||||
}
|
}
|
||||||
@@ -72,9 +74,10 @@ android {
|
|||||||
applicationIdSuffix '.debug'
|
applicationIdSuffix '.debug'
|
||||||
}
|
}
|
||||||
release {
|
release {
|
||||||
if (isRelease) {
|
minifyEnabled true
|
||||||
|
if(isRelease){
|
||||||
signingConfig signingConfigs.release
|
signingConfig signingConfigs.release
|
||||||
} else {
|
}else{
|
||||||
signingConfig signingConfigs.debug
|
signingConfig signingConfigs.debug
|
||||||
}
|
}
|
||||||
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
|
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
|
||||||
@@ -82,15 +85,28 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.register('copyNativeLibs', Copy) {
|
||||||
|
delete('src/main/jniLibs')
|
||||||
|
from('../../libclash/android')
|
||||||
|
into('src/main/jniLibs')
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(MergeSourceSetFolders).configureEach {
|
||||||
|
dependsOn copyNativeLibs
|
||||||
|
}
|
||||||
|
|
||||||
flutter {
|
flutter {
|
||||||
source '../..'
|
source '../..'
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(":core")
|
|
||||||
implementation 'androidx.core:core-splashscreen:1.0.1'
|
implementation 'androidx.core:core-splashscreen:1.0.1'
|
||||||
implementation 'com.google.code.gson:gson:2.10.1'
|
implementation 'com.google.code.gson:gson:2.10'
|
||||||
implementation("com.android.tools.smali:smali-dexlib2:3.0.9") {
|
}
|
||||||
exclude group: "com.google.guava", module: "guava"
|
|
||||||
}
|
|
||||||
}
|
afterEvaluate {
|
||||||
|
assembleDebug.dependsOn copyNativeLibs
|
||||||
|
|
||||||
|
assembleRelease.dependsOn copyNativeLibs
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
|
||||||
<!-- The INTERNET permission is required for development. Specifically,
|
<!-- The INTERNET permission is required for development. Specifically,
|
||||||
the Flutter tool needs it to communicate with the running application
|
the Flutter tool needs it to communicate with the running application
|
||||||
to allow setting breakpoints, to provide hot reload, etc.
|
to allow setting breakpoints, to provide hot reload, etc.
|
||||||
-->
|
-->
|
||||||
<application
|
<application android:label="FlClash Debug" tools:replace="android:label">
|
||||||
android:icon="@mipmap/ic_launcher"
|
|
||||||
android:label="FlClash Debug"
|
|
||||||
tools:replace="android:label">
|
|
||||||
<service
|
<service
|
||||||
android:name=".services.FlClashTileService"
|
android:name=".services.FlClashTileService"
|
||||||
android:label="FlClash Debug"
|
android:label="FlClash Debug"
|
||||||
tools:replace="android:label"
|
tools:replace="android:label">
|
||||||
tools:targetApi="24" />
|
</service>
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<uses-feature
|
<uses-feature
|
||||||
android:name="android.hardware.touchscreen"
|
android:name="android.hardware.touchscreen"
|
||||||
android:required="false" />
|
android:required="false" />
|
||||||
<uses-feature
|
<uses-feature
|
||||||
android:name="android.hardware.camera"
|
android:name="android.hardware.camera"
|
||||||
android:required="false" />
|
android:required="false" />
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
@@ -14,16 +14,15 @@
|
|||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"
|
||||||
|
tools:ignore="SystemPermissionTypo" />
|
||||||
<uses-permission
|
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||||
android:name="android.permission.QUERY_ALL_PACKAGES"
|
|
||||||
tools:ignore="QueryAllPackagesPermission" />
|
tools:ignore="QueryAllPackagesPermission" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".FlClashApplication"
|
android:name="${applicationName}"
|
||||||
android:hardwareAccelerated="true"
|
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
android:label="FlClash">
|
android:label="FlClash">
|
||||||
<activity
|
<activity
|
||||||
android:name="com.follow.clash.MainActivity"
|
android:name="com.follow.clash.MainActivity"
|
||||||
@@ -54,43 +53,29 @@
|
|||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
<category android:name="android.intent.category.BROWSABLE" />
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
|
||||||
<data android:scheme="clash" />
|
<data android:scheme="clash"/>
|
||||||
<data android:scheme="clashmeta" />
|
<data android:scheme="clashmeta"/>
|
||||||
<data android:scheme="flclash" />
|
<data android:scheme="flclash"/>
|
||||||
|
|
||||||
<data android:host="install-config" />
|
<data android:host="install-config"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<meta-data
|
<!-- <meta-data-->
|
||||||
android:name="io.flutter.embedding.android.EnableImpeller"
|
<!-- android:name="io.flutter.embedding.android.EnableImpeller"-->
|
||||||
android:value="false" />
|
<!-- android:value="true" />-->
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".TempActivity"
|
android:name=".TempActivity"
|
||||||
android:exported="true"
|
android:theme="@style/TransparentTheme" />
|
||||||
android:theme="@style/TransparentTheme">
|
|
||||||
<intent-filter>
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<action android:name="${applicationId}.action.START" />
|
|
||||||
</intent-filter>
|
|
||||||
<intent-filter>
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<action android:name="${applicationId}.action.STOP" />
|
|
||||||
</intent-filter>
|
|
||||||
<intent-filter>
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<action android:name="${applicationId}.action.CHANGE" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".services.FlClashTileService"
|
android:name=".services.FlClashTileService"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:icon="@drawable/ic_stat_name"
|
android:icon="@drawable/icon"
|
||||||
|
android:foregroundServiceType="specialUse"
|
||||||
android:label="FlClash"
|
android:label="FlClash"
|
||||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
|
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||||
tools:targetApi="n">
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
@@ -98,49 +83,14 @@
|
|||||||
android:name="android.service.quicksettings.TOGGLEABLE_TILE"
|
android:name="android.service.quicksettings.TOGGLEABLE_TILE"
|
||||||
android:value="true" />
|
android:value="true" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<provider
|
|
||||||
android:name=".FilesProvider"
|
|
||||||
android:authorities="${applicationId}.files"
|
|
||||||
android:exported="true"
|
|
||||||
android:grantUriPermissions="true"
|
|
||||||
android:permission="android.permission.MANAGE_DOCUMENTS"
|
|
||||||
android:process=":background">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.content.action.DOCUMENTS_PROVIDER" />
|
|
||||||
</intent-filter>
|
|
||||||
</provider>
|
|
||||||
|
|
||||||
<provider
|
|
||||||
android:name="androidx.core.content.FileProvider"
|
|
||||||
android:authorities="${applicationId}.fileProvider"
|
|
||||||
android:exported="false"
|
|
||||||
android:grantUriPermissions="true">
|
|
||||||
<meta-data
|
|
||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
|
||||||
android:resource="@xml/file_paths" />
|
|
||||||
</provider>
|
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".services.FlClashVpnService"
|
android:name=".services.FlClashVpnService"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:foregroundServiceType="dataSync"
|
android:foregroundServiceType="specialUse"
|
||||||
android:permission="android.permission.BIND_VPN_SERVICE">
|
android:permission="android.permission.BIND_VPN_SERVICE">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.net.VpnService" />
|
<action android:name="android.net.VpnService" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<property
|
|
||||||
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
|
|
||||||
android:value="vpn" />
|
|
||||||
</service>
|
|
||||||
|
|
||||||
<service
|
|
||||||
android:name=".services.FlClashService"
|
|
||||||
android:exported="false"
|
|
||||||
android:foregroundServiceType="dataSync">
|
|
||||||
<property
|
|
||||||
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
|
|
||||||
android:value="service" />
|
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 72 KiB |
@@ -1,112 +0,0 @@
|
|||||||
package com.follow.clash
|
|
||||||
|
|
||||||
import android.database.Cursor
|
|
||||||
import android.database.MatrixCursor
|
|
||||||
import android.os.CancellationSignal
|
|
||||||
import android.os.ParcelFileDescriptor
|
|
||||||
import android.provider.DocumentsContract.Document
|
|
||||||
import android.provider.DocumentsContract.Root
|
|
||||||
import android.provider.DocumentsProvider
|
|
||||||
import java.io.File
|
|
||||||
import java.io.FileNotFoundException
|
|
||||||
|
|
||||||
|
|
||||||
class FilesProvider : DocumentsProvider() {
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val DEFAULT_ROOT_ID = "0"
|
|
||||||
|
|
||||||
private val DEFAULT_DOCUMENT_COLUMNS = arrayOf(
|
|
||||||
Document.COLUMN_DOCUMENT_ID,
|
|
||||||
Document.COLUMN_DISPLAY_NAME,
|
|
||||||
Document.COLUMN_MIME_TYPE,
|
|
||||||
Document.COLUMN_FLAGS,
|
|
||||||
Document.COLUMN_SIZE,
|
|
||||||
)
|
|
||||||
private val DEFAULT_ROOT_COLUMNS = arrayOf(
|
|
||||||
Root.COLUMN_ROOT_ID,
|
|
||||||
Root.COLUMN_FLAGS,
|
|
||||||
Root.COLUMN_ICON,
|
|
||||||
Root.COLUMN_TITLE,
|
|
||||||
Root.COLUMN_SUMMARY,
|
|
||||||
Root.COLUMN_DOCUMENT_ID
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(): Boolean {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun queryRoots(projection: Array<String>?): Cursor {
|
|
||||||
return MatrixCursor(projection ?: DEFAULT_ROOT_COLUMNS).apply {
|
|
||||||
newRow().apply {
|
|
||||||
add(Root.COLUMN_ROOT_ID, DEFAULT_ROOT_ID)
|
|
||||||
add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY)
|
|
||||||
add(Root.COLUMN_ICON, R.mipmap.ic_launcher)
|
|
||||||
add(Root.COLUMN_TITLE, context!!.getString(R.string.fl_clash))
|
|
||||||
add(Root.COLUMN_SUMMARY, "Data")
|
|
||||||
add(Root.COLUMN_DOCUMENT_ID, "/")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override fun queryChildDocuments(
|
|
||||||
parentDocumentId: String,
|
|
||||||
projection: Array<String>?,
|
|
||||||
sortOrder: String?
|
|
||||||
): Cursor {
|
|
||||||
val result = MatrixCursor(resolveDocumentProjection(projection))
|
|
||||||
val parentFile = if (parentDocumentId == "/") {
|
|
||||||
context?.filesDir
|
|
||||||
} else {
|
|
||||||
File(parentDocumentId)
|
|
||||||
} ?: throw FileNotFoundException("Parent directory not found")
|
|
||||||
parentFile.listFiles()?.forEach { file ->
|
|
||||||
includeFile(result, file)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun queryDocument(documentId: String, projection: Array<String>?): Cursor {
|
|
||||||
val result = MatrixCursor(resolveDocumentProjection(projection))
|
|
||||||
val file = File(documentId)
|
|
||||||
includeFile(result, file)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun openDocument(
|
|
||||||
documentId: String,
|
|
||||||
mode: String,
|
|
||||||
signal: CancellationSignal?
|
|
||||||
): ParcelFileDescriptor {
|
|
||||||
val file = File(documentId)
|
|
||||||
val accessMode = ParcelFileDescriptor.parseMode(mode)
|
|
||||||
return ParcelFileDescriptor.open(file, accessMode)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun includeFile(result: MatrixCursor, file: File) {
|
|
||||||
result.newRow().apply {
|
|
||||||
add(Document.COLUMN_DOCUMENT_ID, file.absolutePath)
|
|
||||||
add(Document.COLUMN_DISPLAY_NAME, file.name)
|
|
||||||
add(Document.COLUMN_SIZE, file.length())
|
|
||||||
add(
|
|
||||||
Document.COLUMN_FLAGS,
|
|
||||||
Document.FLAG_SUPPORTS_WRITE or Document.FLAG_SUPPORTS_DELETE
|
|
||||||
)
|
|
||||||
add(Document.COLUMN_MIME_TYPE, getDocumentType(file))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getDocumentType(file: File): String {
|
|
||||||
return if (file.isDirectory) {
|
|
||||||
Document.MIME_TYPE_DIR
|
|
||||||
} else {
|
|
||||||
"application/octet-stream"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun resolveDocumentProjection(projection: Array<String>?): Array<String> {
|
|
||||||
return projection ?: DEFAULT_DOCUMENT_COLUMNS
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.follow.clash;
|
|
||||||
|
|
||||||
import android.app.Application
|
|
||||||
import android.content.Context
|
|
||||||
|
|
||||||
class FlClashApplication : Application() {
|
|
||||||
companion object {
|
|
||||||
private lateinit var instance: FlClashApplication
|
|
||||||
fun getAppContext(): Context {
|
|
||||||
return instance.applicationContext
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate() {
|
|
||||||
super.onCreate()
|
|
||||||
instance = this
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +1,9 @@
|
|||||||
package com.follow.clash
|
package com.follow.clash
|
||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import com.follow.clash.plugins.AppPlugin
|
|
||||||
import com.follow.clash.plugins.TilePlugin
|
import com.follow.clash.plugins.TilePlugin
|
||||||
import com.follow.clash.plugins.VpnPlugin
|
|
||||||
import io.flutter.FlutterInjector
|
|
||||||
import io.flutter.embedding.engine.FlutterEngine
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
import io.flutter.embedding.engine.dart.DartExecutor
|
import java.util.Date
|
||||||
import java.util.concurrent.locks.ReentrantLock
|
|
||||||
import kotlin.concurrent.withLock
|
|
||||||
|
|
||||||
enum class RunState {
|
enum class RunState {
|
||||||
START,
|
START,
|
||||||
@@ -16,92 +11,13 @@ enum class RunState {
|
|||||||
STOP
|
STOP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GlobalState {
|
||||||
object GlobalState {
|
companion object {
|
||||||
val runLock = ReentrantLock()
|
val runState: MutableLiveData<RunState> = MutableLiveData<RunState>(RunState.STOP)
|
||||||
|
var runTime: Date? = null
|
||||||
val runState: MutableLiveData<RunState> = MutableLiveData<RunState>(RunState.STOP)
|
var flutterEngine: FlutterEngine? = null
|
||||||
var flutterEngine: FlutterEngine? = null
|
fun getCurrentTilePlugin(): TilePlugin? =
|
||||||
private var serviceEngine: FlutterEngine? = null
|
flutterEngine?.plugins?.get(TilePlugin::class.java) as TilePlugin?
|
||||||
|
|
||||||
fun getCurrentAppPlugin(): AppPlugin? {
|
|
||||||
val currentEngine = if (flutterEngine != null) flutterEngine else serviceEngine
|
|
||||||
return currentEngine?.plugins?.get(AppPlugin::class.java) as AppPlugin?
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun getText(text: String): String {
|
|
||||||
return getCurrentAppPlugin()?.getText(text) ?: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getCurrentTilePlugin(): TilePlugin? {
|
|
||||||
val currentEngine = if (flutterEngine != null) flutterEngine else serviceEngine
|
|
||||||
return currentEngine?.plugins?.get(TilePlugin::class.java) as TilePlugin?
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getCurrentVPNPlugin(): VpnPlugin? {
|
|
||||||
return serviceEngine?.plugins?.get(VpnPlugin::class.java) as VpnPlugin?
|
|
||||||
}
|
|
||||||
|
|
||||||
fun handleToggle() {
|
|
||||||
val starting = handleStart()
|
|
||||||
if (!starting) {
|
|
||||||
handleStop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun handleStart(): Boolean {
|
|
||||||
if (runState.value == RunState.STOP) {
|
|
||||||
runState.value = RunState.PENDING
|
|
||||||
runLock.lock()
|
|
||||||
val tilePlugin = getCurrentTilePlugin()
|
|
||||||
if (tilePlugin != null) {
|
|
||||||
tilePlugin.handleStart()
|
|
||||||
} else {
|
|
||||||
initServiceEngine()
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
fun handleStop() {
|
|
||||||
if (runState.value == RunState.START) {
|
|
||||||
runState.value = RunState.PENDING
|
|
||||||
runLock.lock()
|
|
||||||
getCurrentTilePlugin()?.handleStop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun handleTryDestroy() {
|
|
||||||
if (flutterEngine == null) {
|
|
||||||
destroyServiceEngine()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun destroyServiceEngine() {
|
|
||||||
runLock.withLock {
|
|
||||||
serviceEngine?.destroy()
|
|
||||||
serviceEngine = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun initServiceEngine() {
|
|
||||||
if (serviceEngine != null) return
|
|
||||||
destroyServiceEngine()
|
|
||||||
runLock.withLock {
|
|
||||||
serviceEngine = FlutterEngine(FlClashApplication.getAppContext())
|
|
||||||
serviceEngine?.plugins?.add(VpnPlugin)
|
|
||||||
serviceEngine?.plugins?.add(AppPlugin())
|
|
||||||
serviceEngine?.plugins?.add(TilePlugin())
|
|
||||||
val vpnService = DartExecutor.DartEntrypoint(
|
|
||||||
FlutterInjector.instance().flutterLoader().findAppBundlePath(),
|
|
||||||
"_service"
|
|
||||||
)
|
|
||||||
serviceEngine?.dartExecutor?.executeDartEntrypoint(
|
|
||||||
vpnService,
|
|
||||||
if (flutterEngine == null) listOf("quick") else null
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
package com.follow.clash
|
package com.follow.clash
|
||||||
|
|
||||||
import com.follow.clash.core.Core
|
|
||||||
import com.follow.clash.plugins.AppPlugin
|
import com.follow.clash.plugins.AppPlugin
|
||||||
import com.follow.clash.plugins.ServicePlugin
|
import com.follow.clash.plugins.ProxyPlugin
|
||||||
import com.follow.clash.plugins.TilePlugin
|
import com.follow.clash.plugins.TilePlugin
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
import io.flutter.embedding.engine.FlutterEngine
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
|
|
||||||
class MainActivity : FlutterActivity() {
|
class MainActivity : FlutterActivity() {
|
||||||
|
|
||||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||||
|
GlobalState.flutterEngine?.destroy()
|
||||||
super.configureFlutterEngine(flutterEngine)
|
super.configureFlutterEngine(flutterEngine)
|
||||||
flutterEngine.plugins.add(AppPlugin())
|
flutterEngine.plugins.add(AppPlugin())
|
||||||
flutterEngine.plugins.add(ServicePlugin)
|
flutterEngine.plugins.add(ProxyPlugin())
|
||||||
flutterEngine.plugins.add(TilePlugin())
|
flutterEngine.plugins.add(TilePlugin())
|
||||||
GlobalState.flutterEngine = flutterEngine
|
GlobalState.flutterEngine = flutterEngine
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,24 +2,10 @@ package com.follow.clash
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import com.follow.clash.extensions.wrapAction
|
|
||||||
|
|
||||||
class TempActivity : Activity() {
|
class TempActivity : Activity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
when (intent.action) {
|
|
||||||
wrapAction("START") -> {
|
|
||||||
GlobalState.handleStart()
|
|
||||||
}
|
|
||||||
|
|
||||||
wrapAction("STOP") -> {
|
|
||||||
GlobalState.handleStop()
|
|
||||||
}
|
|
||||||
|
|
||||||
wrapAction("CHANGE") -> {
|
|
||||||
GlobalState.handleToggle()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finishAndRemoveTask()
|
finishAndRemoveTask()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.follow.clash.extensions
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.system.OsConstants.IPPROTO_TCP
|
||||||
|
import android.system.OsConstants.IPPROTO_UDP
|
||||||
|
import android.util.Base64
|
||||||
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
|
import com.follow.clash.models.Metadata
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun Drawable.getBase64(): String {
|
||||||
|
val drawable = this
|
||||||
|
return withContext(Dispatchers.IO) {
|
||||||
|
val bitmap = drawable.toBitmap()
|
||||||
|
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||||
|
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream)
|
||||||
|
Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.NO_WRAP)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Metadata.getProtocol(): Int? {
|
||||||
|
if (network.startsWith("tcp")) return IPPROTO_TCP
|
||||||
|
if (network.startsWith("udp")) return IPPROTO_UDP
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -1,196 +0,0 @@
|
|||||||
package com.follow.clash.extensions
|
|
||||||
|
|
||||||
import android.app.PendingIntent
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.graphics.drawable.Drawable
|
|
||||||
import android.net.ConnectivityManager
|
|
||||||
import android.net.Network
|
|
||||||
import android.os.Build
|
|
||||||
import android.system.OsConstants.IPPROTO_TCP
|
|
||||||
import android.system.OsConstants.IPPROTO_UDP
|
|
||||||
import android.util.Base64
|
|
||||||
import androidx.core.graphics.drawable.toBitmap
|
|
||||||
import com.follow.clash.TempActivity
|
|
||||||
import com.follow.clash.models.CIDR
|
|
||||||
import com.follow.clash.models.Metadata
|
|
||||||
import com.follow.clash.models.VpnOptions
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import java.io.ByteArrayOutputStream
|
|
||||||
import java.net.Inet4Address
|
|
||||||
import java.net.Inet6Address
|
|
||||||
import java.net.InetAddress
|
|
||||||
import java.util.concurrent.locks.ReentrantLock
|
|
||||||
import kotlin.coroutines.resume
|
|
||||||
import kotlin.coroutines.suspendCoroutine
|
|
||||||
|
|
||||||
|
|
||||||
suspend fun Drawable.getBase64(): String {
|
|
||||||
val drawable = this
|
|
||||||
return withContext(Dispatchers.IO) {
|
|
||||||
val bitmap = drawable.toBitmap()
|
|
||||||
val byteArrayOutputStream = ByteArrayOutputStream()
|
|
||||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream)
|
|
||||||
Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.NO_WRAP)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Metadata.getProtocol(): Int? {
|
|
||||||
if (network.startsWith("tcp")) return IPPROTO_TCP
|
|
||||||
if (network.startsWith("udp")) return IPPROTO_UDP
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
fun VpnOptions.getIpv4RouteAddress(): List<CIDR> {
|
|
||||||
return routeAddress.filter {
|
|
||||||
it.isIpv4()
|
|
||||||
}.map {
|
|
||||||
it.toCIDR()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun VpnOptions.getIpv6RouteAddress(): List<CIDR> {
|
|
||||||
return routeAddress.filter {
|
|
||||||
it.isIpv6()
|
|
||||||
}.map {
|
|
||||||
it.toCIDR()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun String.isIpv4(): Boolean {
|
|
||||||
val parts = split("/")
|
|
||||||
if (parts.size != 2) {
|
|
||||||
throw IllegalArgumentException("Invalid CIDR format")
|
|
||||||
}
|
|
||||||
val address = InetAddress.getByName(parts[0])
|
|
||||||
return address.address.size == 4
|
|
||||||
}
|
|
||||||
|
|
||||||
fun String.isIpv6(): Boolean {
|
|
||||||
val parts = split("/")
|
|
||||||
if (parts.size != 2) {
|
|
||||||
throw IllegalArgumentException("Invalid CIDR format")
|
|
||||||
}
|
|
||||||
val address = InetAddress.getByName(parts[0])
|
|
||||||
return address.address.size == 16
|
|
||||||
}
|
|
||||||
|
|
||||||
fun String.toCIDR(): CIDR {
|
|
||||||
val parts = split("/")
|
|
||||||
if (parts.size != 2) {
|
|
||||||
throw IllegalArgumentException("Invalid CIDR format")
|
|
||||||
}
|
|
||||||
val ipAddress = parts[0]
|
|
||||||
val prefixLength = parts[1].toIntOrNull()
|
|
||||||
?: throw IllegalArgumentException("Invalid prefix length")
|
|
||||||
|
|
||||||
val address = InetAddress.getByName(ipAddress)
|
|
||||||
|
|
||||||
val maxPrefix = if (address.address.size == 4) 32 else 128
|
|
||||||
if (prefixLength < 0 || prefixLength > maxPrefix) {
|
|
||||||
throw IllegalArgumentException("Invalid prefix length for IP version")
|
|
||||||
}
|
|
||||||
|
|
||||||
return CIDR(address, prefixLength)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun ConnectivityManager.resolveDns(network: Network?): List<String> {
|
|
||||||
val properties = getLinkProperties(network) ?: return listOf()
|
|
||||||
return properties.dnsServers.map { it.asSocketAddressText(53) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun InetAddress.asSocketAddressText(port: Int): String {
|
|
||||||
return when (this) {
|
|
||||||
is Inet6Address ->
|
|
||||||
"[${numericToTextFormat(this.address)}]:$port"
|
|
||||||
|
|
||||||
is Inet4Address ->
|
|
||||||
"${this.hostAddress}:$port"
|
|
||||||
|
|
||||||
else -> throw IllegalArgumentException("Unsupported Inet type ${this.javaClass}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Context.wrapAction(action: String): String {
|
|
||||||
return "${this.packageName}.action.$action"
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Context.getActionIntent(action: String): Intent {
|
|
||||||
val actionIntent = Intent(this, TempActivity::class.java)
|
|
||||||
actionIntent.action = wrapAction(action)
|
|
||||||
return actionIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Context.getActionPendingIntent(action: String): PendingIntent {
|
|
||||||
return if (Build.VERSION.SDK_INT >= 31) {
|
|
||||||
PendingIntent.getActivity(
|
|
||||||
this,
|
|
||||||
0,
|
|
||||||
getActionIntent(action),
|
|
||||||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
PendingIntent.getActivity(
|
|
||||||
this,
|
|
||||||
0,
|
|
||||||
getActionIntent(action),
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun numericToTextFormat(src: ByteArray): String {
|
|
||||||
val sb = StringBuilder(39)
|
|
||||||
for (i in 0 until 8) {
|
|
||||||
sb.append(
|
|
||||||
Integer.toHexString(
|
|
||||||
src[i shl 1].toInt() shl 8 and 0xff00
|
|
||||||
or (src[(i shl 1) + 1].toInt() and 0xff)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if (i < 7) {
|
|
||||||
sb.append(":")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun <T> MethodChannel.awaitResult(
|
|
||||||
method: String,
|
|
||||||
arguments: Any? = null
|
|
||||||
): T? = withContext(Dispatchers.Main) { // 切换到主线程
|
|
||||||
suspendCoroutine { continuation ->
|
|
||||||
invokeMethod(method, arguments, object : MethodChannel.Result {
|
|
||||||
override fun success(result: Any?) {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
continuation.resume(result as T)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(code: String, message: String?, details: Any?) {
|
|
||||||
continuation.resume(null)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun notImplemented() {
|
|
||||||
continuation.resume(null)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun ReentrantLock.safeLock() {
|
|
||||||
if (this.isLocked) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.lock()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun ReentrantLock.safeUnlock() {
|
|
||||||
if (!this.isLocked) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.unlock()
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.follow.clash.models
|
||||||
|
|
||||||
|
enum class AccessControlMode {
|
||||||
|
acceptSelected,
|
||||||
|
rejectSelected,
|
||||||
|
}
|
||||||
|
|
||||||
|
data class AccessControl(
|
||||||
|
val mode: AccessControlMode,
|
||||||
|
val acceptList: List<String>,
|
||||||
|
val rejectList: List<String>,
|
||||||
|
)
|
||||||
@@ -1,15 +1,11 @@
|
|||||||
package com.follow.clash.models
|
package com.follow.clash.models
|
||||||
|
|
||||||
data class Process(
|
|
||||||
val id: String,
|
|
||||||
val metadata: Metadata,
|
|
||||||
)
|
|
||||||
|
|
||||||
data class Metadata(
|
data class Metadata(
|
||||||
val network: String,
|
val network: String,
|
||||||
val sourceIP: String,
|
val sourceIP: String,
|
||||||
val sourcePort: Int,
|
val sourcePort: Int,
|
||||||
val destinationIP: String,
|
val destinationIP: String,
|
||||||
val destinationPort: Int,
|
val destinationPort: Int,
|
||||||
|
val remoteDestination: String,
|
||||||
val host: String
|
val host: String
|
||||||
)
|
)
|
||||||
@@ -3,6 +3,5 @@ package com.follow.clash.models
|
|||||||
data class Package(
|
data class Package(
|
||||||
val packageName: String,
|
val packageName: String,
|
||||||
val label: String,
|
val label: String,
|
||||||
val isSystem: Boolean,
|
val isSystem:Boolean
|
||||||
val lastUpdateTime: Long,
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
package com.follow.clash.models
|
|
||||||
|
|
||||||
import java.net.InetAddress
|
|
||||||
|
|
||||||
enum class AccessControlMode {
|
|
||||||
acceptSelected, rejectSelected,
|
|
||||||
}
|
|
||||||
|
|
||||||
data class AccessControl(
|
|
||||||
val enable: Boolean,
|
|
||||||
val mode: AccessControlMode,
|
|
||||||
val acceptList: List<String>,
|
|
||||||
val rejectList: List<String>,
|
|
||||||
)
|
|
||||||
|
|
||||||
data class CIDR(val address: InetAddress, val prefixLength: Int)
|
|
||||||
|
|
||||||
data class VpnOptions(
|
|
||||||
val enable: Boolean,
|
|
||||||
val port: Int,
|
|
||||||
val accessControl: AccessControl,
|
|
||||||
val allowBypass: Boolean,
|
|
||||||
val systemProxy: Boolean,
|
|
||||||
val bypassDomain: List<String>,
|
|
||||||
val routeAddress: List<String>,
|
|
||||||
val ipv4Address: String,
|
|
||||||
val ipv6Address: String,
|
|
||||||
val dnsServerAddress: String,
|
|
||||||
)
|
|
||||||
|
|
||||||
data class StartForegroundParams(
|
|
||||||
val title: String,
|
|
||||||
val content: String,
|
|
||||||
)
|
|
||||||
@@ -2,204 +2,121 @@ package com.follow.clash.plugins
|
|||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.ActivityManager
|
import android.content.Context
|
||||||
import android.content.Intent
|
|
||||||
import android.content.pm.ApplicationInfo
|
import android.content.pm.ApplicationInfo
|
||||||
import android.content.pm.ComponentInfo
|
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.net.VpnService
|
import android.net.ConnectivityManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.getSystemService
|
||||||
import androidx.core.content.ContextCompat.getSystemService
|
|
||||||
import androidx.core.content.FileProvider
|
|
||||||
import androidx.core.content.pm.ShortcutInfoCompat
|
|
||||||
import androidx.core.content.pm.ShortcutManagerCompat
|
|
||||||
import androidx.core.graphics.drawable.IconCompat
|
|
||||||
import com.android.tools.smali.dexlib2.dexbacked.DexBackedDexFile
|
|
||||||
import com.follow.clash.FlClashApplication
|
|
||||||
import com.follow.clash.GlobalState
|
|
||||||
import com.follow.clash.R
|
|
||||||
import com.follow.clash.extensions.awaitResult
|
|
||||||
import com.follow.clash.extensions.getActionIntent
|
|
||||||
import com.follow.clash.extensions.getBase64
|
import com.follow.clash.extensions.getBase64
|
||||||
|
import com.follow.clash.extensions.getProtocol
|
||||||
|
import com.follow.clash.models.Metadata
|
||||||
import com.follow.clash.models.Package
|
import com.follow.clash.models.Package
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
|
||||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||||
import io.flutter.embedding.engine.plugins.activity.ActivityAware
|
import io.flutter.embedding.engine.plugins.activity.ActivityAware
|
||||||
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
|
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
|
||||||
import io.flutter.plugin.common.MethodCall
|
import io.flutter.plugin.common.MethodCall
|
||||||
import io.flutter.plugin.common.MethodChannel
|
import io.flutter.plugin.common.MethodChannel
|
||||||
import io.flutter.plugin.common.MethodChannel.Result
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.io.File
|
import java.net.InetSocketAddress
|
||||||
import java.lang.ref.WeakReference
|
|
||||||
import java.util.zip.ZipFile
|
|
||||||
|
|
||||||
class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware {
|
class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware {
|
||||||
|
|
||||||
private var activityRef: WeakReference<Activity>? = null
|
private var activity: Activity? = null
|
||||||
|
|
||||||
|
private var toast: Toast? = null
|
||||||
|
|
||||||
|
private var context: Context? = null
|
||||||
|
|
||||||
private lateinit var channel: MethodChannel
|
private lateinit var channel: MethodChannel
|
||||||
|
|
||||||
private lateinit var scope: CoroutineScope
|
private lateinit var scope: CoroutineScope
|
||||||
|
|
||||||
private var vpnCallBack: (() -> Unit)? = null
|
private var connectivity: ConnectivityManager? = null
|
||||||
|
|
||||||
private val iconMap = mutableMapOf<String, String?>()
|
private val iconMap = mutableMapOf<String, String?>()
|
||||||
|
|
||||||
private val packages = mutableListOf<Package>()
|
|
||||||
|
|
||||||
private val skipPrefixList = listOf(
|
|
||||||
"com.google",
|
|
||||||
"com.android.chrome",
|
|
||||||
"com.android.vending",
|
|
||||||
"com.microsoft",
|
|
||||||
"com.apple",
|
|
||||||
"com.zhiliaoapp.musically", // Banned by China
|
|
||||||
)
|
|
||||||
|
|
||||||
private val chinaAppPrefixList = listOf(
|
|
||||||
"com.tencent",
|
|
||||||
"com.alibaba",
|
|
||||||
"com.umeng",
|
|
||||||
"com.qihoo",
|
|
||||||
"com.ali",
|
|
||||||
"com.alipay",
|
|
||||||
"com.amap",
|
|
||||||
"com.sina",
|
|
||||||
"com.weibo",
|
|
||||||
"com.vivo",
|
|
||||||
"com.xiaomi",
|
|
||||||
"com.huawei",
|
|
||||||
"com.taobao",
|
|
||||||
"com.secneo",
|
|
||||||
"s.h.e.l.l",
|
|
||||||
"com.stub",
|
|
||||||
"com.kiwisec",
|
|
||||||
"com.secshell",
|
|
||||||
"com.wrapper",
|
|
||||||
"cn.securitystack",
|
|
||||||
"com.mogosec",
|
|
||||||
"com.secoen",
|
|
||||||
"com.netease",
|
|
||||||
"com.mx",
|
|
||||||
"com.qq.e",
|
|
||||||
"com.baidu",
|
|
||||||
"com.bytedance",
|
|
||||||
"com.bugly",
|
|
||||||
"com.miui",
|
|
||||||
"com.oppo",
|
|
||||||
"com.coloros",
|
|
||||||
"com.iqoo",
|
|
||||||
"com.meizu",
|
|
||||||
"com.gionee",
|
|
||||||
"cn.nubia",
|
|
||||||
"com.oplus",
|
|
||||||
"andes.oplus",
|
|
||||||
"com.unionpay",
|
|
||||||
"cn.wps"
|
|
||||||
)
|
|
||||||
|
|
||||||
private val chinaAppRegex by lazy {
|
|
||||||
("(" + chinaAppPrefixList.joinToString("|").replace(".", "\\.") + ").*").toRegex()
|
|
||||||
}
|
|
||||||
|
|
||||||
val VPN_PERMISSION_REQUEST_CODE = 1001
|
|
||||||
|
|
||||||
val NOTIFICATION_PERMISSION_REQUEST_CODE = 1002
|
|
||||||
|
|
||||||
private var isBlockNotification: Boolean = false
|
|
||||||
|
|
||||||
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
||||||
scope = CoroutineScope(Dispatchers.Default)
|
context = flutterPluginBinding.applicationContext;
|
||||||
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "app")
|
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "app")
|
||||||
channel.setMethodCallHandler(this)
|
channel.setMethodCallHandler(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initShortcuts(label: String) {
|
|
||||||
val shortcut = ShortcutInfoCompat.Builder(FlClashApplication.getAppContext(), "toggle")
|
|
||||||
.setShortLabel(label)
|
|
||||||
.setIcon(
|
|
||||||
IconCompat.createWithResource(
|
|
||||||
FlClashApplication.getAppContext(),
|
|
||||||
R.mipmap.ic_launcher_round
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setIntent(FlClashApplication.getAppContext().getActionIntent("CHANGE"))
|
|
||||||
.build()
|
|
||||||
ShortcutManagerCompat.setDynamicShortcuts(
|
|
||||||
FlClashApplication.getAppContext(),
|
|
||||||
listOf(shortcut)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
|
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
|
||||||
channel.setMethodCallHandler(null)
|
channel.setMethodCallHandler(null)
|
||||||
scope.cancel()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tip(message: String?) {
|
private fun tip(message: String?) {
|
||||||
if (GlobalState.flutterEngine == null) {
|
if (toast != null) {
|
||||||
Toast.makeText(FlClashApplication.getAppContext(), message, Toast.LENGTH_LONG).show()
|
toast!!.cancel()
|
||||||
}
|
}
|
||||||
|
toast = Toast.makeText(context, message, Toast.LENGTH_SHORT)
|
||||||
|
toast!!.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMethodCall(call: MethodCall, result: Result) {
|
@RequiresApi(Build.VERSION_CODES.Q)
|
||||||
|
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
|
||||||
when (call.method) {
|
when (call.method) {
|
||||||
"moveTaskToBack" -> {
|
"moveTaskToBack" -> {
|
||||||
activityRef?.get()?.moveTaskToBack(true)
|
activity?.moveTaskToBack(true)
|
||||||
result.success(true)
|
result.success(true);
|
||||||
}
|
|
||||||
|
|
||||||
"updateExcludeFromRecents" -> {
|
|
||||||
val value = call.argument<Boolean>("value")
|
|
||||||
updateExcludeFromRecents(value)
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
"initShortcuts" -> {
|
|
||||||
initShortcuts(call.arguments as String)
|
|
||||||
result.success(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
"getPackages" -> {
|
"getPackages" -> {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
result.success(getPackagesToJson())
|
result.success(getPackages())
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"getChinaPackageNames" -> {
|
|
||||||
scope.launch {
|
|
||||||
result.success(getChinaPackageNames())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"getPackageIcon" -> {
|
"getPackageIcon" -> {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val packageName = call.argument<String>("packageName")
|
val packageName = call.argument<String>("packageName")
|
||||||
if (packageName == null) {
|
if (packageName != null) {
|
||||||
|
result.success(getPackageIcon(packageName))
|
||||||
|
} else {
|
||||||
result.success(null)
|
result.success(null)
|
||||||
return@launch
|
|
||||||
}
|
}
|
||||||
val packageIcon = getPackageIcon(packageName)
|
}
|
||||||
packageIcon.let {
|
}
|
||||||
if (it != null) {
|
|
||||||
result.success(it)
|
"getPackageName" -> {
|
||||||
return@launch
|
val data = call.argument<String>("data")
|
||||||
|
val metadata =
|
||||||
|
if (data != null) Gson().fromJson(
|
||||||
|
data,
|
||||||
|
Metadata::class.java
|
||||||
|
) else null
|
||||||
|
val protocol = metadata?.getProtocol()
|
||||||
|
if (protocol == null) {
|
||||||
|
result.success(null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
scope.launch {
|
||||||
|
withContext(Dispatchers.Default) {
|
||||||
|
if (context == null) result.success(null)
|
||||||
|
val source = InetSocketAddress(metadata.sourceIP, metadata.sourcePort)
|
||||||
|
val target = InetSocketAddress(
|
||||||
|
metadata.host.ifEmpty { metadata.destinationIP },
|
||||||
|
metadata.destinationPort
|
||||||
|
)
|
||||||
|
if (connectivity == null) {
|
||||||
|
connectivity = context!!.getSystemService<ConnectivityManager>()
|
||||||
}
|
}
|
||||||
if (iconMap["default"] == null) {
|
val uid =
|
||||||
iconMap["default"] =
|
connectivity?.getConnectionOwnerUid(protocol, source, target)
|
||||||
FlClashApplication.getAppContext().packageManager?.defaultActivityIcon?.getBase64()
|
if (uid == null || uid == -1) {
|
||||||
|
result.success(null)
|
||||||
|
return@withContext
|
||||||
}
|
}
|
||||||
result.success(iconMap["default"])
|
val packages = context?.packageManager?.getPackagesForUid(uid)
|
||||||
return@launch
|
result.success(packages?.first())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,264 +125,59 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware
|
|||||||
val message = call.argument<String>("message")
|
val message = call.argument<String>("message")
|
||||||
tip(message)
|
tip(message)
|
||||||
result.success(true)
|
result.success(true)
|
||||||
}
|
|
||||||
|
|
||||||
"openFile" -> {
|
|
||||||
val path = call.argument<String>("path")!!
|
|
||||||
openFile(path)
|
|
||||||
result.success(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
result.notImplemented()
|
result.notImplemented();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openFile(path: String) {
|
|
||||||
val file = File(path)
|
|
||||||
val uri = FileProvider.getUriForFile(
|
|
||||||
FlClashApplication.getAppContext(),
|
|
||||||
"${FlClashApplication.getAppContext().packageName}.fileProvider",
|
|
||||||
file
|
|
||||||
)
|
|
||||||
|
|
||||||
val intent = Intent(Intent.ACTION_VIEW).setDataAndType(
|
|
||||||
uri,
|
|
||||||
"text/plain"
|
|
||||||
)
|
|
||||||
|
|
||||||
val flags =
|
|
||||||
Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION
|
|
||||||
|
|
||||||
val resInfoList = FlClashApplication.getAppContext().packageManager.queryIntentActivities(
|
|
||||||
intent, PackageManager.MATCH_DEFAULT_ONLY
|
|
||||||
)
|
|
||||||
|
|
||||||
for (resolveInfo in resInfoList) {
|
|
||||||
val packageName = resolveInfo.activityInfo.packageName
|
|
||||||
FlClashApplication.getAppContext().grantUriPermission(
|
|
||||||
packageName,
|
|
||||||
uri,
|
|
||||||
flags
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
activityRef?.get()?.startActivity(intent)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
println(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateExcludeFromRecents(value: Boolean?) {
|
|
||||||
val am = getSystemService(FlClashApplication.getAppContext(), ActivityManager::class.java)
|
|
||||||
val task = am?.appTasks?.firstOrNull {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
it.taskInfo.taskId == activityRef?.get()?.taskId
|
|
||||||
} else {
|
|
||||||
it.taskInfo.id == activityRef?.get()?.taskId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
when (value) {
|
|
||||||
true -> task?.setExcludeFromRecents(value)
|
|
||||||
false -> task?.setExcludeFromRecents(value)
|
|
||||||
null -> task?.setExcludeFromRecents(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun getPackageIcon(packageName: String): String? {
|
private suspend fun getPackageIcon(packageName: String): String? {
|
||||||
val packageManager = FlClashApplication.getAppContext().packageManager
|
val packageManager = context?.packageManager
|
||||||
if (iconMap[packageName] == null) {
|
if (iconMap[packageName] == null) {
|
||||||
iconMap[packageName] = try {
|
iconMap[packageName] = packageManager?.getApplicationIcon(packageName)?.getBase64()
|
||||||
packageManager?.getApplicationIcon(packageName)?.getBase64()
|
|
||||||
} catch (_: Exception) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return iconMap[packageName]
|
return iconMap[packageName]
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPackages(): List<Package> {
|
private suspend fun getPackages(): String {
|
||||||
val packageManager = FlClashApplication.getAppContext().packageManager
|
return withContext(Dispatchers.Default){
|
||||||
if (packages.isNotEmpty()) return packages
|
val packageManager = context?.packageManager
|
||||||
packageManager?.getInstalledPackages(PackageManager.GET_META_DATA or PackageManager.GET_PERMISSIONS)
|
val packages: List<Package>? =
|
||||||
?.filter {
|
packageManager?.getInstalledPackages(PackageManager.GET_META_DATA)?.filter {
|
||||||
it.packageName != FlClashApplication.getAppContext().packageName && (
|
it.packageName != context?.packageName
|
||||||
it.requestedPermissions?.contains(Manifest.permission.INTERNET) == true
|
|| it.requestedPermissions?.contains(Manifest.permission.INTERNET) == true
|
||||||
|| it.packageName == "android"
|
|| it.packageName == "android"
|
||||||
)
|
|
||||||
|
|
||||||
}?.map {
|
}?.map {
|
||||||
Package(
|
Package(
|
||||||
packageName = it.packageName,
|
packageName = it.packageName,
|
||||||
label = it.applicationInfo?.loadLabel(packageManager).toString(),
|
label = it.applicationInfo.loadLabel(packageManager).toString(),
|
||||||
isSystem = (it.applicationInfo?.flags?.and(ApplicationInfo.FLAG_SYSTEM)) == 1,
|
isSystem = (it.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) == 1
|
||||||
lastUpdateTime = it.lastUpdateTime
|
)
|
||||||
)
|
}
|
||||||
}?.let { packages.addAll(it) }
|
|
||||||
return packages
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun getPackagesToJson(): String {
|
|
||||||
return withContext(Dispatchers.Default) {
|
|
||||||
Gson().toJson(getPackages())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun getChinaPackageNames(): String {
|
|
||||||
return withContext(Dispatchers.Default) {
|
|
||||||
val packages: List<String> =
|
|
||||||
getPackages().map { it.packageName }.filter { isChinaPackage(it) }
|
|
||||||
Gson().toJson(packages)
|
Gson().toJson(packages)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun requestVpnPermission(callBack: () -> Unit) {
|
|
||||||
vpnCallBack = callBack
|
|
||||||
val intent = VpnService.prepare(FlClashApplication.getAppContext())
|
|
||||||
if (intent != null) {
|
|
||||||
activityRef?.get()?.startActivityForResult(intent, VPN_PERMISSION_REQUEST_CODE)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
vpnCallBack?.invoke()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun requestNotificationsPermission() {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
||||||
val permission = ContextCompat.checkSelfPermission(
|
|
||||||
FlClashApplication.getAppContext(),
|
|
||||||
Manifest.permission.POST_NOTIFICATIONS
|
|
||||||
)
|
|
||||||
if (permission != PackageManager.PERMISSION_GRANTED) {
|
|
||||||
if (isBlockNotification) return
|
|
||||||
if (activityRef?.get() == null) return
|
|
||||||
activityRef?.get()?.let {
|
|
||||||
ActivityCompat.requestPermissions(
|
|
||||||
it,
|
|
||||||
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
|
|
||||||
NOTIFICATION_PERMISSION_REQUEST_CODE
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun getText(text: String): String? {
|
|
||||||
return withContext(Dispatchers.Default) {
|
|
||||||
channel.awaitResult<String>("getText", text)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isChinaPackage(packageName: String): Boolean {
|
|
||||||
val packageManager = FlClashApplication.getAppContext().packageManager ?: return false
|
|
||||||
skipPrefixList.forEach {
|
|
||||||
if (packageName == it || packageName.startsWith("$it.")) return false
|
|
||||||
}
|
|
||||||
val packageManagerFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
||||||
PackageManager.MATCH_UNINSTALLED_PACKAGES or PackageManager.GET_ACTIVITIES or PackageManager.GET_SERVICES or PackageManager.GET_RECEIVERS or PackageManager.GET_PROVIDERS
|
|
||||||
} else {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
PackageManager.GET_UNINSTALLED_PACKAGES or PackageManager.GET_ACTIVITIES or PackageManager.GET_SERVICES or PackageManager.GET_RECEIVERS or PackageManager.GET_PROVIDERS
|
|
||||||
}
|
|
||||||
if (packageName.matches(chinaAppRegex)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
||||||
packageManager.getPackageInfo(
|
|
||||||
packageName,
|
|
||||||
PackageManager.PackageInfoFlags.of(packageManagerFlags.toLong())
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
packageManager.getPackageInfo(
|
|
||||||
packageName, packageManagerFlags
|
|
||||||
)
|
|
||||||
}
|
|
||||||
mutableListOf<ComponentInfo>().apply {
|
|
||||||
packageInfo.services?.let { addAll(it) }
|
|
||||||
packageInfo.activities?.let { addAll(it) }
|
|
||||||
packageInfo.receivers?.let { addAll(it) }
|
|
||||||
packageInfo.providers?.let { addAll(it) }
|
|
||||||
}.forEach {
|
|
||||||
if (it.name.matches(chinaAppRegex)) return true
|
|
||||||
}
|
|
||||||
packageInfo.applicationInfo?.publicSourceDir?.let {
|
|
||||||
ZipFile(File(it)).use {
|
|
||||||
for (packageEntry in it.entries()) {
|
|
||||||
if (packageEntry.name.startsWith("firebase-")) return false
|
|
||||||
}
|
|
||||||
for (packageEntry in it.entries()) {
|
|
||||||
if (!(packageEntry.name.startsWith("classes") && packageEntry.name.endsWith(
|
|
||||||
".dex"
|
|
||||||
))
|
|
||||||
) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if (packageEntry.size > 15000000) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
val input = it.getInputStream(packageEntry).buffered()
|
|
||||||
val dexFile = try {
|
|
||||||
DexBackedDexFile.fromInputStream(null, input)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
for (clazz in dexFile.classes) {
|
|
||||||
val clazzName =
|
|
||||||
clazz.type.substring(1, clazz.type.length - 1).replace("/", ".")
|
|
||||||
.replace("$", ".")
|
|
||||||
if (clazzName.matches(chinaAppRegex)) return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (_: Exception) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
|
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
|
||||||
activityRef = WeakReference(binding.activity)
|
activity = binding.activity;
|
||||||
binding.addActivityResultListener(::onActivityResult)
|
scope = CoroutineScope(Dispatchers.Default)
|
||||||
binding.addRequestPermissionsResultListener(::onRequestPermissionsResultListener)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDetachedFromActivityForConfigChanges() {
|
override fun onDetachedFromActivityForConfigChanges() {
|
||||||
activityRef = null
|
activity = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
|
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
|
||||||
activityRef = WeakReference(binding.activity)
|
activity = binding.activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDetachedFromActivity() {
|
override fun onDetachedFromActivity() {
|
||||||
channel.invokeMethod("exit", null)
|
channel.invokeMethod("exit", null)
|
||||||
activityRef = null
|
scope.cancel()
|
||||||
}
|
activity = null;
|
||||||
|
|
||||||
private fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
|
|
||||||
if (requestCode == VPN_PERMISSION_REQUEST_CODE) {
|
|
||||||
if (resultCode == FlutterActivity.RESULT_OK) {
|
|
||||||
GlobalState.initServiceEngine()
|
|
||||||
vpnCallBack?.invoke()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onRequestPermissionsResultListener(
|
|
||||||
requestCode: Int,
|
|
||||||
permissions: Array<String>,
|
|
||||||
grantResults: IntArray
|
|
||||||
): Boolean {
|
|
||||||
if (requestCode == NOTIFICATION_PERMISSION_REQUEST_CODE) {
|
|
||||||
isBlockNotification = true
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,227 @@
|
|||||||
|
package com.follow.clash.plugins
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.ServiceConnection
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.net.VpnService
|
||||||
|
import android.os.Build.VERSION
|
||||||
|
import android.os.Build.VERSION_CODES
|
||||||
|
import android.os.IBinder
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.follow.clash.GlobalState
|
||||||
|
import com.follow.clash.RunState
|
||||||
|
import com.follow.clash.models.AccessControl
|
||||||
|
import com.follow.clash.services.FlClashVpnService
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
|
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||||
|
import io.flutter.embedding.engine.plugins.activity.ActivityAware
|
||||||
|
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
|
||||||
|
import io.flutter.plugin.common.MethodCall
|
||||||
|
import io.flutter.plugin.common.MethodChannel
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
|
||||||
|
class ProxyPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware {
|
||||||
|
|
||||||
|
|
||||||
|
val VPN_PERMISSION_REQUEST_CODE = 1001
|
||||||
|
val NOTIFICATION_PERMISSION_REQUEST_CODE = 1002
|
||||||
|
|
||||||
|
private lateinit var flutterMethodChannel: MethodChannel
|
||||||
|
|
||||||
|
private var activity: Activity? = null
|
||||||
|
private var context: Context? = null
|
||||||
|
private var flClashVpnService: FlClashVpnService? = null
|
||||||
|
private var isBound = false
|
||||||
|
private var port: Int? = null
|
||||||
|
private var accessControl: AccessControl? = null
|
||||||
|
private lateinit var title: String
|
||||||
|
private lateinit var content: String
|
||||||
|
|
||||||
|
private val connection = object : ServiceConnection {
|
||||||
|
override fun onServiceConnected(className: ComponentName, service: IBinder) {
|
||||||
|
val binder = service as FlClashVpnService.LocalBinder
|
||||||
|
flClashVpnService = binder.getService()
|
||||||
|
port?.let { startVpn(it) }
|
||||||
|
isBound = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onServiceDisconnected(arg0: ComponentName) {
|
||||||
|
flClashVpnService = null
|
||||||
|
isBound = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
||||||
|
context = flutterPluginBinding.applicationContext
|
||||||
|
flutterMethodChannel = MethodChannel(flutterPluginBinding.binaryMessenger, "proxy")
|
||||||
|
flutterMethodChannel.setMethodCallHandler(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDetachedFromEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
||||||
|
flutterMethodChannel.setMethodCallHandler(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) = when (call.method) {
|
||||||
|
"StartProxy" -> {
|
||||||
|
port = call.argument<Int>("port")
|
||||||
|
val args = call.argument<String>("args")
|
||||||
|
accessControl =
|
||||||
|
if (args != null) Gson().fromJson(args, AccessControl::class.java) else null
|
||||||
|
handleStartVpn()
|
||||||
|
result.success(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
"StopProxy" -> {
|
||||||
|
stopVpn()
|
||||||
|
result.success(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
"SetProtect" -> {
|
||||||
|
val fd = call.argument<Int>("fd")
|
||||||
|
if (fd != null) {
|
||||||
|
flClashVpnService?.protect(fd)
|
||||||
|
result.success(true)
|
||||||
|
} else {
|
||||||
|
result.success(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
"GetRunTimeStamp" -> {
|
||||||
|
result.success(GlobalState.runTime?.time)
|
||||||
|
}
|
||||||
|
|
||||||
|
"startForeground" -> {
|
||||||
|
title = call.argument<String>("title") as String
|
||||||
|
content = call.argument<String>("content") as String
|
||||||
|
requestNotificationsPermission()
|
||||||
|
result.success(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
result.notImplemented()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleStartVpn() {
|
||||||
|
val intent = VpnService.prepare(context)
|
||||||
|
if (intent != null) {
|
||||||
|
activity?.startActivityForResult(intent, VPN_PERMISSION_REQUEST_CODE)
|
||||||
|
} else {
|
||||||
|
bindService()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startVpn(port: Int) {
|
||||||
|
if (GlobalState.runState.value == RunState.START) return;
|
||||||
|
flClashVpnService?.start(port, accessControl)
|
||||||
|
GlobalState.runState.value = RunState.START
|
||||||
|
GlobalState.runTime = Date()
|
||||||
|
startAfter()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopVpn() {
|
||||||
|
if (GlobalState.runState.value == RunState.STOP) return
|
||||||
|
flClashVpnService?.stop()
|
||||||
|
unbindService()
|
||||||
|
GlobalState.runState.value = RunState.STOP;
|
||||||
|
GlobalState.runTime = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ForegroundServiceType")
|
||||||
|
private fun startForeground() {
|
||||||
|
if (GlobalState.runState.value != RunState.START) return
|
||||||
|
flClashVpnService?.startForeground(title, content)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun requestNotificationsPermission() {
|
||||||
|
if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) {
|
||||||
|
val permission = context?.let {
|
||||||
|
ContextCompat.checkSelfPermission(
|
||||||
|
it,
|
||||||
|
Manifest.permission.POST_NOTIFICATIONS
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (permission == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
startForeground()
|
||||||
|
} else {
|
||||||
|
activity?.let {
|
||||||
|
ActivityCompat.requestPermissions(
|
||||||
|
it,
|
||||||
|
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
|
||||||
|
NOTIFICATION_PERMISSION_REQUEST_CODE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
startForeground()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startAfter() {
|
||||||
|
flutterMethodChannel.invokeMethod("startAfter", flClashVpnService?.fd)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
|
||||||
|
activity = binding.activity
|
||||||
|
binding.addActivityResultListener(::onActivityResult)
|
||||||
|
binding.addRequestPermissionsResultListener(::onRequestPermissionsResultListener)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
|
||||||
|
if (requestCode == VPN_PERMISSION_REQUEST_CODE) {
|
||||||
|
if (resultCode == FlutterActivity.RESULT_OK) {
|
||||||
|
bindService()
|
||||||
|
} else {
|
||||||
|
stopVpn()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onRequestPermissionsResultListener(
|
||||||
|
requestCode: Int,
|
||||||
|
permissions: Array<String>,
|
||||||
|
grantResults: IntArray
|
||||||
|
): Boolean {
|
||||||
|
if (requestCode == NOTIFICATION_PERMISSION_REQUEST_CODE) {
|
||||||
|
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
startForeground()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override fun onDetachedFromActivityForConfigChanges() {
|
||||||
|
activity = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
|
||||||
|
activity = binding.activity
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDetachedFromActivity() {
|
||||||
|
stopVpn()
|
||||||
|
activity = null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bindService() {
|
||||||
|
val intent = Intent(context, FlClashVpnService::class.java)
|
||||||
|
context?.bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun unbindService() {
|
||||||
|
if (isBound) {
|
||||||
|
context?.unbindService(connection)
|
||||||
|
isBound = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
package com.follow.clash.plugins
|
|
||||||
|
|
||||||
import com.follow.clash.GlobalState
|
|
||||||
import com.follow.clash.models.VpnOptions
|
|
||||||
import com.google.gson.Gson
|
|
||||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
|
|
||||||
|
|
||||||
data object ServicePlugin : FlutterPlugin, MethodChannel.MethodCallHandler {
|
|
||||||
|
|
||||||
private lateinit var flutterMethodChannel: MethodChannel
|
|
||||||
|
|
||||||
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
|
||||||
flutterMethodChannel = MethodChannel(flutterPluginBinding.binaryMessenger, "service")
|
|
||||||
flutterMethodChannel.setMethodCallHandler(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDetachedFromEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
|
||||||
flutterMethodChannel.setMethodCallHandler(null)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) = when (call.method) {
|
|
||||||
"startVpn" -> {
|
|
||||||
val data = call.argument<String>("data")
|
|
||||||
val options = Gson().fromJson(data, VpnOptions::class.java)
|
|
||||||
GlobalState.getCurrentVPNPlugin()?.handleStart(options)
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
"stopVpn" -> {
|
|
||||||
GlobalState.getCurrentVPNPlugin()?.handleStop()
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
"init" -> {
|
|
||||||
GlobalState.getCurrentAppPlugin()
|
|
||||||
?.requestNotificationsPermission()
|
|
||||||
GlobalState.initServiceEngine()
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
"destroy" -> {
|
|
||||||
handleDestroy()
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
result.notImplemented()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleDestroy() {
|
|
||||||
GlobalState.destroyServiceEngine()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,10 +4,10 @@ import io.flutter.embedding.engine.plugins.FlutterPlugin
|
|||||||
import io.flutter.plugin.common.MethodCall
|
import io.flutter.plugin.common.MethodCall
|
||||||
import io.flutter.plugin.common.MethodChannel
|
import io.flutter.plugin.common.MethodChannel
|
||||||
|
|
||||||
class TilePlugin : FlutterPlugin, MethodChannel.MethodCallHandler {
|
class TilePlugin(private val onStart: (() -> Unit)? = null, private val onStop: (() -> Unit)? = null) : FlutterPlugin,
|
||||||
|
MethodChannel.MethodCallHandler {
|
||||||
|
|
||||||
private lateinit var channel: MethodChannel
|
private lateinit var channel: MethodChannel
|
||||||
|
|
||||||
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
||||||
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "tile")
|
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "tile")
|
||||||
channel.setMethodCallHandler(this)
|
channel.setMethodCallHandler(this)
|
||||||
@@ -19,11 +19,13 @@ class TilePlugin : FlutterPlugin, MethodChannel.MethodCallHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun handleStart() {
|
fun handleStart() {
|
||||||
|
onStart?.let { it() }
|
||||||
channel.invokeMethod("start", null)
|
channel.invokeMethod("start", null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleStop() {
|
fun handleStop() {
|
||||||
channel.invokeMethod("stop", null)
|
channel.invokeMethod("stop", null)
|
||||||
|
onStop?.let { it() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleDetached() {
|
private fun handleDetached() {
|
||||||
|
|||||||
@@ -1,266 +0,0 @@
|
|||||||
package com.follow.clash.plugins
|
|
||||||
|
|
||||||
import android.content.ComponentName
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.content.ServiceConnection
|
|
||||||
import android.net.ConnectivityManager
|
|
||||||
import android.net.Network
|
|
||||||
import android.net.NetworkCapabilities
|
|
||||||
import android.net.NetworkRequest
|
|
||||||
import android.os.Build
|
|
||||||
import android.os.IBinder
|
|
||||||
import androidx.core.content.getSystemService
|
|
||||||
import com.follow.clash.FlClashApplication
|
|
||||||
import com.follow.clash.GlobalState
|
|
||||||
import com.follow.clash.RunState
|
|
||||||
import com.follow.clash.core.Core
|
|
||||||
import com.follow.clash.extensions.awaitResult
|
|
||||||
import com.follow.clash.extensions.resolveDns
|
|
||||||
import com.follow.clash.models.StartForegroundParams
|
|
||||||
import com.follow.clash.models.VpnOptions
|
|
||||||
import com.follow.clash.services.BaseServiceInterface
|
|
||||||
import com.follow.clash.services.FlClashService
|
|
||||||
import com.follow.clash.services.FlClashVpnService
|
|
||||||
import com.google.gson.Gson
|
|
||||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.isActive
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import java.net.InetSocketAddress
|
|
||||||
import kotlin.concurrent.withLock
|
|
||||||
|
|
||||||
data object VpnPlugin : FlutterPlugin, MethodChannel.MethodCallHandler {
|
|
||||||
private lateinit var flutterMethodChannel: MethodChannel
|
|
||||||
private var flClashService: BaseServiceInterface? = null
|
|
||||||
private var options: VpnOptions? = null
|
|
||||||
private var isBind: Boolean = false
|
|
||||||
private lateinit var scope: CoroutineScope
|
|
||||||
private var lastStartForegroundParams: StartForegroundParams? = null
|
|
||||||
private var timerJob: Job? = null
|
|
||||||
private val uidPageNameMap = mutableMapOf<Int, String>()
|
|
||||||
|
|
||||||
private val connectivity by lazy {
|
|
||||||
FlClashApplication.getAppContext().getSystemService<ConnectivityManager>()
|
|
||||||
}
|
|
||||||
|
|
||||||
private val connection = object : ServiceConnection {
|
|
||||||
override fun onServiceConnected(className: ComponentName, service: IBinder) {
|
|
||||||
isBind = true
|
|
||||||
flClashService = when (service) {
|
|
||||||
is FlClashVpnService.LocalBinder -> service.getService()
|
|
||||||
is FlClashService.LocalBinder -> service.getService()
|
|
||||||
else -> throw Exception("invalid binder")
|
|
||||||
}
|
|
||||||
handleStartService()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onServiceDisconnected(arg: ComponentName) {
|
|
||||||
isBind = false
|
|
||||||
flClashService = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
|
||||||
scope = CoroutineScope(Dispatchers.Default)
|
|
||||||
scope.launch {
|
|
||||||
registerNetworkCallback()
|
|
||||||
}
|
|
||||||
flutterMethodChannel = MethodChannel(flutterPluginBinding.binaryMessenger, "vpn")
|
|
||||||
flutterMethodChannel.setMethodCallHandler(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDetachedFromEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
|
||||||
unRegisterNetworkCallback()
|
|
||||||
flutterMethodChannel.setMethodCallHandler(null)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
when (call.method) {
|
|
||||||
"start" -> {
|
|
||||||
val data = call.argument<String>("data")
|
|
||||||
result.success(handleStart(Gson().fromJson(data, VpnOptions::class.java)))
|
|
||||||
}
|
|
||||||
|
|
||||||
"stop" -> {
|
|
||||||
handleStop()
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
result.notImplemented()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun handleStart(options: VpnOptions): Boolean {
|
|
||||||
if (options.enable != this.options?.enable) {
|
|
||||||
this.flClashService = null
|
|
||||||
}
|
|
||||||
this.options = options
|
|
||||||
when (options.enable) {
|
|
||||||
true -> handleStartVpn()
|
|
||||||
false -> handleStartService()
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleStartVpn() {
|
|
||||||
GlobalState.getCurrentAppPlugin()?.requestVpnPermission {
|
|
||||||
handleStartService()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun requestGc() {
|
|
||||||
flutterMethodChannel.invokeMethod("gc", null)
|
|
||||||
}
|
|
||||||
|
|
||||||
val networks = mutableSetOf<Network>()
|
|
||||||
|
|
||||||
fun onUpdateNetwork() {
|
|
||||||
val dns = networks.flatMap { network ->
|
|
||||||
connectivity?.resolveDns(network) ?: emptyList()
|
|
||||||
}.toSet().joinToString(",")
|
|
||||||
scope.launch {
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
flutterMethodChannel.invokeMethod("dnsChanged", dns)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val callback = object : ConnectivityManager.NetworkCallback() {
|
|
||||||
override fun onAvailable(network: Network) {
|
|
||||||
networks.add(network)
|
|
||||||
onUpdateNetwork()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onLost(network: Network) {
|
|
||||||
networks.remove(network)
|
|
||||||
onUpdateNetwork()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val request = NetworkRequest.Builder().apply {
|
|
||||||
addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)
|
|
||||||
addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
|
||||||
addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
|
|
||||||
}.build()
|
|
||||||
|
|
||||||
private fun registerNetworkCallback() {
|
|
||||||
networks.clear()
|
|
||||||
connectivity?.registerNetworkCallback(request, callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun unRegisterNetworkCallback() {
|
|
||||||
connectivity?.unregisterNetworkCallback(callback)
|
|
||||||
networks.clear()
|
|
||||||
onUpdateNetwork()
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun startForeground() {
|
|
||||||
GlobalState.runLock.lock()
|
|
||||||
try {
|
|
||||||
if (GlobalState.runState.value != RunState.START) return
|
|
||||||
val data = flutterMethodChannel.awaitResult<String>("getStartForegroundParams")
|
|
||||||
val startForegroundParams = Gson().fromJson(
|
|
||||||
data, StartForegroundParams::class.java
|
|
||||||
)
|
|
||||||
if (lastStartForegroundParams != startForegroundParams) {
|
|
||||||
lastStartForegroundParams = startForegroundParams
|
|
||||||
flClashService?.startForeground(
|
|
||||||
startForegroundParams.title,
|
|
||||||
startForegroundParams.content,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
GlobalState.runLock.unlock()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun startForegroundJob() {
|
|
||||||
stopForegroundJob()
|
|
||||||
timerJob = CoroutineScope(Dispatchers.Main).launch {
|
|
||||||
while (isActive) {
|
|
||||||
startForeground()
|
|
||||||
delay(1000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun stopForegroundJob() {
|
|
||||||
timerJob?.cancel()
|
|
||||||
timerJob = null
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleStartService() {
|
|
||||||
if (flClashService == null) {
|
|
||||||
bindService()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
GlobalState.runLock.withLock {
|
|
||||||
if (GlobalState.runState.value == RunState.START) return
|
|
||||||
GlobalState.runState.value = RunState.START
|
|
||||||
val fd = flClashService?.start(options!!)
|
|
||||||
Core.startTun(
|
|
||||||
fd = fd ?: 0,
|
|
||||||
protect = this::protect,
|
|
||||||
resolverProcess = this::resolverProcess,
|
|
||||||
)
|
|
||||||
startForegroundJob()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun protect(fd: Int): Boolean {
|
|
||||||
return (flClashService as? FlClashVpnService)?.protect(fd) == true
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun resolverProcess(
|
|
||||||
protocol: Int,
|
|
||||||
source: InetSocketAddress,
|
|
||||||
target: InetSocketAddress,
|
|
||||||
uid: Int,
|
|
||||||
): String {
|
|
||||||
val nextUid = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
connectivity?.getConnectionOwnerUid(protocol, source, target) ?: -1
|
|
||||||
} else {
|
|
||||||
uid
|
|
||||||
}
|
|
||||||
if (nextUid == -1) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
if (!uidPageNameMap.containsKey(nextUid)) {
|
|
||||||
uidPageNameMap[nextUid] =
|
|
||||||
FlClashApplication.getAppContext().packageManager?.getPackagesForUid(nextUid)
|
|
||||||
?.first() ?: ""
|
|
||||||
}
|
|
||||||
return uidPageNameMap[nextUid] ?: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
fun handleStop() {
|
|
||||||
GlobalState.runLock.withLock {
|
|
||||||
if (GlobalState.runState.value == RunState.STOP) return
|
|
||||||
GlobalState.runState.value = RunState.STOP
|
|
||||||
stopForegroundJob()
|
|
||||||
Core.stopTun()
|
|
||||||
flClashService?.stop()
|
|
||||||
GlobalState.handleTryDestroy()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun bindService() {
|
|
||||||
if (isBind) {
|
|
||||||
FlClashApplication.getAppContext().unbindService(connection)
|
|
||||||
}
|
|
||||||
val intent = when (options?.enable == true) {
|
|
||||||
true -> Intent(FlClashApplication.getAppContext(), FlClashVpnService::class.java)
|
|
||||||
false -> Intent(FlClashApplication.getAppContext(), FlClashService::class.java)
|
|
||||||
}
|
|
||||||
FlClashApplication.getAppContext().bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.follow.clash.services
|
|
||||||
|
|
||||||
import com.follow.clash.models.VpnOptions
|
|
||||||
|
|
||||||
interface BaseServiceInterface {
|
|
||||||
|
|
||||||
fun start(options: VpnOptions): Int
|
|
||||||
|
|
||||||
fun stop()
|
|
||||||
|
|
||||||
suspend fun startForeground(title: String, content: String)
|
|
||||||
}
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
package com.follow.clash.services
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.app.Notification.FOREGROUND_SERVICE_IMMEDIATE
|
|
||||||
import android.app.NotificationChannel
|
|
||||||
import android.app.NotificationManager
|
|
||||||
import android.app.PendingIntent
|
|
||||||
import android.app.Service
|
|
||||||
import android.content.Intent
|
|
||||||
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
|
|
||||||
import android.os.Binder
|
|
||||||
import android.os.Build
|
|
||||||
import android.os.IBinder
|
|
||||||
import androidx.core.app.NotificationCompat
|
|
||||||
import com.follow.clash.GlobalState
|
|
||||||
import com.follow.clash.MainActivity
|
|
||||||
import com.follow.clash.extensions.getActionPendingIntent
|
|
||||||
import com.follow.clash.models.VpnOptions
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Deferred
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.async
|
|
||||||
|
|
||||||
|
|
||||||
class FlClashService : Service(), BaseServiceInterface {
|
|
||||||
|
|
||||||
private val binder = LocalBinder()
|
|
||||||
|
|
||||||
inner class LocalBinder : Binder() {
|
|
||||||
fun getService(): FlClashService = this@FlClashService
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBind(intent: Intent): IBinder {
|
|
||||||
return binder
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onUnbind(intent: Intent?): Boolean {
|
|
||||||
return super.onUnbind(intent)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val CHANNEL = "FlClash"
|
|
||||||
|
|
||||||
private val notificationId: Int = 1
|
|
||||||
|
|
||||||
private val notificationBuilderDeferred: Deferred<NotificationCompat.Builder> by lazy {
|
|
||||||
CoroutineScope(Dispatchers.Main).async {
|
|
||||||
val stopText = GlobalState.getText("stop")
|
|
||||||
|
|
||||||
val intent = Intent(
|
|
||||||
this@FlClashService, MainActivity::class.java
|
|
||||||
)
|
|
||||||
|
|
||||||
val pendingIntent = if (Build.VERSION.SDK_INT >= 31) {
|
|
||||||
PendingIntent.getActivity(
|
|
||||||
this@FlClashService,
|
|
||||||
0,
|
|
||||||
intent,
|
|
||||||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
PendingIntent.getActivity(
|
|
||||||
this@FlClashService,
|
|
||||||
0,
|
|
||||||
intent,
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
with(NotificationCompat.Builder(this@FlClashService, CHANNEL)) {
|
|
||||||
setSmallIcon(com.follow.clash.R.drawable.ic_stat_name)
|
|
||||||
setContentTitle("FlClash")
|
|
||||||
setContentIntent(pendingIntent)
|
|
||||||
setCategory(NotificationCompat.CATEGORY_SERVICE)
|
|
||||||
priority = NotificationCompat.PRIORITY_MIN
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
||||||
foregroundServiceBehavior = FOREGROUND_SERVICE_IMMEDIATE
|
|
||||||
}
|
|
||||||
addAction(
|
|
||||||
0,
|
|
||||||
stopText, // 使用 suspend 函数获取的文本
|
|
||||||
getActionPendingIntent("STOP")
|
|
||||||
)
|
|
||||||
setOngoing(true)
|
|
||||||
setShowWhen(false)
|
|
||||||
setOnlyAlertOnce(true)
|
|
||||||
setAutoCancel(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun getNotificationBuilder(): NotificationCompat.Builder {
|
|
||||||
return notificationBuilderDeferred.await()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun start(options: VpnOptions) = 0
|
|
||||||
|
|
||||||
override fun stop() {
|
|
||||||
stopSelf()
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressLint("ForegroundServiceType")
|
|
||||||
override suspend fun startForeground(title: String, content: String) {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
val manager = getSystemService(NotificationManager::class.java)
|
|
||||||
var channel = manager?.getNotificationChannel(CHANNEL)
|
|
||||||
if (channel == null) {
|
|
||||||
channel =
|
|
||||||
NotificationChannel(CHANNEL, "FlClash", NotificationManager.IMPORTANCE_LOW)
|
|
||||||
manager?.createNotificationChannel(channel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val notification =
|
|
||||||
getNotificationBuilder()
|
|
||||||
.setContentTitle(title)
|
|
||||||
.setContentText(content).build()
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
||||||
try {
|
|
||||||
startForeground(notificationId, notification, FOREGROUND_SERVICE_TYPE_DATA_SYNC)
|
|
||||||
} catch (_: Exception) {
|
|
||||||
startForeground(notificationId, notification)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
startForeground(notificationId, notification)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,9 +11,14 @@ import androidx.lifecycle.Observer
|
|||||||
import com.follow.clash.GlobalState
|
import com.follow.clash.GlobalState
|
||||||
import com.follow.clash.RunState
|
import com.follow.clash.RunState
|
||||||
import com.follow.clash.TempActivity
|
import com.follow.clash.TempActivity
|
||||||
|
import com.follow.clash.plugins.AppPlugin
|
||||||
|
import com.follow.clash.plugins.ProxyPlugin
|
||||||
|
import com.follow.clash.plugins.TilePlugin
|
||||||
|
import io.flutter.FlutterInjector
|
||||||
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
|
import io.flutter.embedding.engine.dart.DartExecutor
|
||||||
|
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.N)
|
|
||||||
class FlClashTileService : TileService() {
|
class FlClashTileService : TileService() {
|
||||||
|
|
||||||
private val observer = Observer<RunState> { runState ->
|
private val observer = Observer<RunState> { runState ->
|
||||||
@@ -37,10 +42,9 @@ class FlClashTileService : TileService() {
|
|||||||
GlobalState.runState.observeForever(observer)
|
GlobalState.runState.observeForever(observer)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("StartActivityAndCollapseDeprecated")
|
|
||||||
private fun activityTransfer() {
|
private fun activityTransfer() {
|
||||||
val intent = Intent(this, TempActivity::class.java)
|
val intent = Intent(this, TempActivity::class.java)
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
val pendingIntent = if (Build.VERSION.SDK_INT >= 31) {
|
val pendingIntent = if (Build.VERSION.SDK_INT >= 31) {
|
||||||
PendingIntent.getActivity(
|
PendingIntent.getActivity(
|
||||||
this,
|
this,
|
||||||
@@ -58,15 +62,44 @@ class FlClashTileService : TileService() {
|
|||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||||
startActivityAndCollapse(pendingIntent)
|
startActivityAndCollapse(pendingIntent)
|
||||||
} else {
|
}else{
|
||||||
startActivityAndCollapse(intent)
|
startActivityAndCollapse(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var flutterEngine: FlutterEngine? = null;
|
||||||
|
|
||||||
|
private fun initFlutterEngine() {
|
||||||
|
flutterEngine = FlutterEngine(this)
|
||||||
|
flutterEngine?.plugins?.add(ProxyPlugin())
|
||||||
|
flutterEngine?.plugins?.add(TilePlugin())
|
||||||
|
flutterEngine?.plugins?.add(AppPlugin())
|
||||||
|
GlobalState.flutterEngine = flutterEngine
|
||||||
|
if (flutterEngine?.dartExecutor?.isExecutingDart != true) {
|
||||||
|
val vpnService = DartExecutor.DartEntrypoint(
|
||||||
|
FlutterInjector.instance().flutterLoader().findAppBundlePath(),
|
||||||
|
"vpnService"
|
||||||
|
)
|
||||||
|
flutterEngine?.dartExecutor?.executeDartEntrypoint(vpnService)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onClick() {
|
override fun onClick() {
|
||||||
super.onClick()
|
super.onClick()
|
||||||
activityTransfer()
|
activityTransfer()
|
||||||
GlobalState.handleToggle()
|
val currentTilePlugin = GlobalState.getCurrentTilePlugin()
|
||||||
|
if (GlobalState.runState.value == RunState.STOP) {
|
||||||
|
GlobalState.runState.value = RunState.PENDING
|
||||||
|
if(currentTilePlugin == null){
|
||||||
|
initFlutterEngine()
|
||||||
|
}else{
|
||||||
|
currentTilePlugin.handleStart()
|
||||||
|
}
|
||||||
|
} else if(GlobalState.runState.value == RunState.START){
|
||||||
|
GlobalState.runState.value = RunState.PENDING
|
||||||
|
currentTilePlugin?.handleStop()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
|||||||
@@ -1,234 +1,165 @@
|
|||||||
package com.follow.clash.services
|
package com.follow.clash.services
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.app.Notification.FOREGROUND_SERVICE_IMMEDIATE
|
import android.app.Notification.FOREGROUND_SERVICE_IMMEDIATE
|
||||||
import android.app.NotificationChannel
|
import android.app.NotificationChannel
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
|
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
|
||||||
import android.net.ProxyInfo
|
import android.net.ProxyInfo
|
||||||
import android.net.VpnService
|
import android.net.VpnService
|
||||||
import android.os.Binder
|
import android.os.Binder
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.Parcel
|
|
||||||
import android.os.RemoteException
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import com.follow.clash.GlobalState
|
import com.follow.clash.GlobalState
|
||||||
import com.follow.clash.MainActivity
|
import com.follow.clash.MainActivity
|
||||||
import com.follow.clash.R
|
import com.follow.clash.R
|
||||||
import com.follow.clash.extensions.getActionPendingIntent
|
import com.follow.clash.models.AccessControl
|
||||||
import com.follow.clash.extensions.getIpv4RouteAddress
|
|
||||||
import com.follow.clash.extensions.getIpv6RouteAddress
|
|
||||||
import com.follow.clash.extensions.toCIDR
|
|
||||||
import com.follow.clash.models.AccessControlMode
|
import com.follow.clash.models.AccessControlMode
|
||||||
import com.follow.clash.models.VpnOptions
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Deferred
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.async
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
|
|
||||||
class FlClashVpnService : VpnService(), BaseServiceInterface {
|
class FlClashVpnService : VpnService() {
|
||||||
override fun onCreate() {
|
|
||||||
super.onCreate()
|
|
||||||
GlobalState.initServiceEngine()
|
private val CHANNEL = "FlClash"
|
||||||
|
|
||||||
|
var fd: Int? = null
|
||||||
|
private val notificationId: Int = 1
|
||||||
|
|
||||||
|
private val passList = listOf(
|
||||||
|
"*zhihu.com",
|
||||||
|
"*zhimg.com",
|
||||||
|
"*jd.com",
|
||||||
|
"100ime-iat-api.xfyun.cn",
|
||||||
|
"*360buyimg.com",
|
||||||
|
"localhost",
|
||||||
|
"*.local",
|
||||||
|
"127.*",
|
||||||
|
"10.*",
|
||||||
|
"172.16.*",
|
||||||
|
"172.17.*",
|
||||||
|
"172.18.*",
|
||||||
|
"172.19.*",
|
||||||
|
"172.2*",
|
||||||
|
"172.30.*",
|
||||||
|
"172.31.*",
|
||||||
|
"192.168.*"
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
|
return START_STICKY
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun start(options: VpnOptions): Int {
|
fun start(port: Int, accessControl: AccessControl?) {
|
||||||
return with(Builder()) {
|
fd = with(Builder()) {
|
||||||
if (options.ipv4Address.isNotEmpty()) {
|
addAddress("172.16.0.1", 30)
|
||||||
val cidr = options.ipv4Address.toCIDR()
|
|
||||||
addAddress(cidr.address, cidr.prefixLength)
|
|
||||||
val routeAddress = options.getIpv4RouteAddress()
|
|
||||||
if (routeAddress.isNotEmpty()) {
|
|
||||||
try {
|
|
||||||
routeAddress.forEach { i ->
|
|
||||||
Log.d(
|
|
||||||
"addRoute4",
|
|
||||||
"address: ${i.address} prefixLength:${i.prefixLength}"
|
|
||||||
)
|
|
||||||
addRoute(i.address, i.prefixLength)
|
|
||||||
}
|
|
||||||
} catch (_: Exception) {
|
|
||||||
addRoute("0.0.0.0", 0)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
addRoute("0.0.0.0", 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (options.ipv6Address.isNotEmpty()) {
|
|
||||||
val cidr = options.ipv6Address.toCIDR()
|
|
||||||
addAddress(cidr.address, cidr.prefixLength)
|
|
||||||
val routeAddress = options.getIpv6RouteAddress()
|
|
||||||
if (routeAddress.isNotEmpty()) {
|
|
||||||
try {
|
|
||||||
routeAddress.forEach { i ->
|
|
||||||
Log.d(
|
|
||||||
"addRoute6",
|
|
||||||
"address: ${i.address} prefixLength:${i.prefixLength}"
|
|
||||||
)
|
|
||||||
addRoute(i.address, i.prefixLength)
|
|
||||||
}
|
|
||||||
} catch (_: Exception) {
|
|
||||||
addRoute("::", 0)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
addRoute("::", 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addDnsServer(options.dnsServerAddress)
|
|
||||||
setMtu(9000)
|
setMtu(9000)
|
||||||
options.accessControl.let { accessControl ->
|
addRoute("0.0.0.0", 0)
|
||||||
if (accessControl.enable) {
|
if (accessControl != null) {
|
||||||
when (accessControl.mode) {
|
when (accessControl.mode) {
|
||||||
AccessControlMode.acceptSelected -> {
|
AccessControlMode.acceptSelected -> {
|
||||||
(accessControl.acceptList + packageName).forEach {
|
(accessControl.acceptList + packageName).forEach {
|
||||||
addAllowedApplication(it)
|
addAllowedApplication(it)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AccessControlMode.rejectSelected -> {
|
AccessControlMode.rejectSelected -> {
|
||||||
(accessControl.rejectList - packageName).forEach {
|
(accessControl.rejectList - packageName).forEach {
|
||||||
addDisallowedApplication(it)
|
addDisallowedApplication(it)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
addDnsServer("172.16.0.2")
|
||||||
setSession("FlClash")
|
setSession("FlClash")
|
||||||
setBlocking(false)
|
setBlocking(false)
|
||||||
if (Build.VERSION.SDK_INT >= 29) {
|
if (Build.VERSION.SDK_INT >= 29) {
|
||||||
setMetered(false)
|
setMetered(false)
|
||||||
}
|
}
|
||||||
if (options.allowBypass) {
|
allowBypass()
|
||||||
allowBypass()
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
}
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && options.systemProxy) {
|
|
||||||
setHttpProxy(
|
setHttpProxy(
|
||||||
ProxyInfo.buildDirectProxy(
|
ProxyInfo.buildDirectProxy(
|
||||||
"127.0.0.1",
|
"127.0.0.1",
|
||||||
options.port,
|
port,
|
||||||
options.bypassDomain
|
passList
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
establish()?.detachFd()
|
establish()?.detachFd()
|
||||||
?: throw NullPointerException("Establish VPN rejected by system")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun stop() {
|
fun stop() {
|
||||||
stopSelf()
|
stopSelf()
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
stopForeground()
|
||||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private val notificationBuilder: NotificationCompat.Builder by lazy {
|
||||||
|
val intent = Intent(this, MainActivity::class.java)
|
||||||
|
|
||||||
|
val pendingIntent = if (Build.VERSION.SDK_INT >= 31) {
|
||||||
|
PendingIntent.getActivity(
|
||||||
|
this,
|
||||||
|
0,
|
||||||
|
intent,
|
||||||
|
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
PendingIntent.getActivity(
|
||||||
|
this,
|
||||||
|
0,
|
||||||
|
intent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
with(NotificationCompat.Builder(this, CHANNEL)) {
|
||||||
|
setSmallIcon(R.drawable.ic_stat_name)
|
||||||
|
setContentTitle("FlClash")
|
||||||
|
setContentIntent(pendingIntent)
|
||||||
|
setCategory(NotificationCompat.CATEGORY_SERVICE)
|
||||||
|
priority = NotificationCompat.PRIORITY_MIN
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
foregroundServiceBehavior = FOREGROUND_SERVICE_IMMEDIATE
|
||||||
|
}
|
||||||
|
setOngoing(true)
|
||||||
|
setShowWhen(false)
|
||||||
|
setOnlyAlertOnce(true)
|
||||||
|
setAutoCancel(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val CHANNEL = "FlClash"
|
|
||||||
|
|
||||||
private val notificationId: Int = 1
|
fun startForeground(title: String, content: String) {
|
||||||
|
|
||||||
private val notificationBuilderDeferred: Deferred<NotificationCompat.Builder> by lazy {
|
|
||||||
CoroutineScope(Dispatchers.Main).async {
|
|
||||||
val stopText = GlobalState.getText("stop")
|
|
||||||
val intent = Intent(this@FlClashVpnService, MainActivity::class.java)
|
|
||||||
|
|
||||||
val pendingIntent = if (Build.VERSION.SDK_INT >= 31) {
|
|
||||||
PendingIntent.getActivity(
|
|
||||||
this@FlClashVpnService,
|
|
||||||
0,
|
|
||||||
intent,
|
|
||||||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
PendingIntent.getActivity(
|
|
||||||
this@FlClashVpnService,
|
|
||||||
0,
|
|
||||||
intent,
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
with(NotificationCompat.Builder(this@FlClashVpnService, CHANNEL)) {
|
|
||||||
setSmallIcon(R.drawable.ic_stat_name)
|
|
||||||
setContentTitle("FlClash")
|
|
||||||
setContentIntent(pendingIntent)
|
|
||||||
setCategory(NotificationCompat.CATEGORY_SERVICE)
|
|
||||||
priority = NotificationCompat.PRIORITY_MIN
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
||||||
foregroundServiceBehavior = FOREGROUND_SERVICE_IMMEDIATE
|
|
||||||
}
|
|
||||||
setOngoing(true)
|
|
||||||
addAction(
|
|
||||||
0,
|
|
||||||
stopText,
|
|
||||||
getActionPendingIntent("STOP")
|
|
||||||
)
|
|
||||||
setShowWhen(false)
|
|
||||||
setOnlyAlertOnce(true)
|
|
||||||
setAutoCancel(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun getNotificationBuilder(): NotificationCompat.Builder {
|
|
||||||
return notificationBuilderDeferred.await()
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("ForegroundServiceType")
|
|
||||||
override suspend fun startForeground(title: String, content: String) {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
val channel =
|
||||||
|
NotificationChannel(CHANNEL, "FlClash", NotificationManager.IMPORTANCE_LOW)
|
||||||
val manager = getSystemService(NotificationManager::class.java)
|
val manager = getSystemService(NotificationManager::class.java)
|
||||||
var channel = manager?.getNotificationChannel(CHANNEL)
|
manager.createNotificationChannel(channel)
|
||||||
if (channel == null) {
|
channel.setShowBadge(false)
|
||||||
channel =
|
|
||||||
NotificationChannel(CHANNEL, "FlClash", NotificationManager.IMPORTANCE_LOW)
|
|
||||||
manager?.createNotificationChannel(channel)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
val notification =
|
val notification =
|
||||||
getNotificationBuilder()
|
notificationBuilder.setContentTitle(title).setContentText(content).build()
|
||||||
.setContentTitle(title)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
.setContentText(content)
|
startForeground(notificationId, notification, FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
|
||||||
.build()
|
}else{
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
||||||
try {
|
|
||||||
startForeground(notificationId, notification, FOREGROUND_SERVICE_TYPE_DATA_SYNC)
|
|
||||||
} catch (_: Exception) {
|
|
||||||
startForeground(notificationId, notification)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
startForeground(notificationId, notification)
|
startForeground(notificationId, notification)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTrimMemory(level: Int) {
|
private fun stopForeground() {
|
||||||
super.onTrimMemory(level)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
GlobalState.getCurrentVPNPlugin()?.requestGc()
|
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val binder = LocalBinder()
|
private val binder = LocalBinder()
|
||||||
|
|
||||||
inner class LocalBinder : Binder() {
|
inner class LocalBinder : Binder() {
|
||||||
fun getService(): FlClashVpnService = this@FlClashVpnService
|
fun getService(): FlClashVpnService = this@FlClashVpnService
|
||||||
|
|
||||||
override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean {
|
|
||||||
try {
|
|
||||||
val isSuccess = super.onTransact(code, data, reply, flags)
|
|
||||||
if (!isSuccess) {
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
|
||||||
GlobalState.getCurrentTilePlugin()?.handleStop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return isSuccess
|
|
||||||
} catch (e: RemoteException) {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBind(intent: Intent): IBinder {
|
override fun onBind(intent: Intent): IBinder {
|
||||||
@@ -236,6 +167,7 @@ class FlClashVpnService : VpnService(), BaseServiceInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onUnbind(intent: Intent?): Boolean {
|
override fun onUnbind(intent: Intent?): Boolean {
|
||||||
|
GlobalState.getCurrentTilePlugin()?.handleStop();
|
||||||
return super.onUnbind(intent)
|
return super.onUnbind(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 618 B After Width: | Height: | Size: 763 B |
|
Before Width: | Height: | Size: 423 B After Width: | Height: | Size: 520 B |
|
Before Width: | Height: | Size: 803 B After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 2.1 KiB |
@@ -1,25 +0,0 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="108dp"
|
|
||||||
android:height="108dp"
|
|
||||||
android:viewportWidth="240"
|
|
||||||
android:viewportHeight="240">
|
|
||||||
<group android:scaleX="0.924"
|
|
||||||
android:scaleY="0.924"
|
|
||||||
android:translateX="9.12"
|
|
||||||
android:translateY="9.12">
|
|
||||||
<group android:scaleX="0.63461536"
|
|
||||||
android:scaleY="0.63461536"
|
|
||||||
android:translateX="45.96154"
|
|
||||||
android:translateY="43.846153">
|
|
||||||
<path
|
|
||||||
android:pathData="M60.65,89.6L154.18,35.6A18,18 107.59,0 1,178.77 42.19L178.77,42.19A18,18 107.59,0 1,172.18 66.78L78.65,120.78A18,18 106.67,0 1,54.06 114.19L54.06,114.19A18,18 106.67,0 1,60.65 89.6z"
|
|
||||||
android:fillColor="#6666FB"/>
|
|
||||||
<path
|
|
||||||
android:pathData="M84.65,131.17L131.42,104.17A18,18 107.83,0 1,156 110.76L156,110.76A18,18 107.83,0 1,149.42 135.35L102.65,162.35A18,18 106.67,0 1,78.06 155.76L78.06,155.76A18,18 106.67,0 1,84.65 131.17z"
|
|
||||||
android:fillColor="#336AB6"/>
|
|
||||||
<path
|
|
||||||
android:pathData="M108.65,172.74L108.65,172.74A18,18 116.03,0 1,133.24 179.33L133.24,179.33A18,18 116.03,0 1,126.65 203.92L126.65,203.92A18,18 116.03,0 1,102.06 197.33L102.06,197.33A18,18 116.03,0 1,108.65 172.74z"
|
|
||||||
android:fillColor="#5CA8E9"/>
|
|
||||||
</group>
|
|
||||||
</group>
|
|
||||||
</vector>
|
|
||||||
BIN
android/app/src/main/res/drawable/icon.png
Normal file
|
After Width: | Height: | Size: 118 KiB |
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<background android:drawable="@color/ic_launcher_background"/>
|
<background android:drawable="@color/ic_launcher_background"/>
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
<monochrome android:drawable="@mipmap/ic_launcher_foreground" />
|
||||||
</adaptive-icon>
|
</adaptive-icon>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<background android:drawable="@color/ic_launcher_background"/>
|
<background android:drawable="@color/ic_launcher_background"/>
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
<monochrome android:drawable="@mipmap/ic_launcher_foreground" />
|
||||||
</adaptive-icon>
|
</adaptive-icon>
|
||||||
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.9 KiB |
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.webp
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 886 B After Width: | Height: | Size: 1.2 KiB |
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.webp
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 7.2 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 13 KiB |
@@ -6,7 +6,7 @@
|
|||||||
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
|
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
|
||||||
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
||||||
<item name="android:windowSplashScreenBackground" tools:targetApi="s">#121212</item>
|
<item name="android:windowSplashScreenBackground" tools:targetApi="s">#121212</item>
|
||||||
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="s">@drawable/ic_launcher_foreground</item>
|
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="s">@mipmap/ic_launcher_foreground</item>
|
||||||
<item name="postSplashScreenTheme">@style/NormalTheme</item>
|
<item name="postSplashScreenTheme">@style/NormalTheme</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
||||||
<!-- Show a splash screen on the activity. Automatically removed when
|
<!-- Show a splash screen on the activity. Automatically removed when
|
||||||
the Flutter engine draws its first frame -->
|
the Flutter engine draws its first frame -->
|
||||||
|
<item name="android:windowBackground">@mipmap/ic_launcher_foreground</item>
|
||||||
</style>
|
</style>
|
||||||
<!-- Theme applied to the Android Window as soon as the process has started.
|
<!-- Theme applied to the Android Window as soon as the process has started.
|
||||||
This theme determines the color of the Android Window while your
|
This theme determines the color of the Android Window while your
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
|
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
|
||||||
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
||||||
<item name="android:windowSplashScreenBackground" tools:targetApi="s">@color/ic_launcher_background</item>
|
<item name="android:windowSplashScreenBackground" tools:targetApi="s">@color/ic_launcher_background</item>
|
||||||
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="s">@drawable/ic_launcher_foreground</item>
|
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="s">@mipmap/ic_launcher_foreground</item>
|
||||||
<item name="postSplashScreenTheme">@style/NormalTheme</item>
|
<item name="postSplashScreenTheme">@style/NormalTheme</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<color name="ic_launcher_background">#FAFAFA</color>
|
<color name="ic_launcher_background">#EFEFEF</color>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
|
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
|
||||||
<!-- Show a splash screen on the activity. Automatically removed when
|
<!-- Show a splash screen on the activity. Automatically removed when
|
||||||
the Flutter engine draws its first frame -->
|
the Flutter engine draws its first frame -->
|
||||||
|
<item name="android:windowBackground">@mipmap/ic_launcher_foreground</item>
|
||||||
</style>
|
</style>
|
||||||
<!-- Theme applied to the Android Window as soon as the process has started.
|
<!-- Theme applied to the Android Window as soon as the process has started.
|
||||||
This theme determines the color of the Android Window while your
|
This theme determines the color of the Android Window while your
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
<paths>
|
|
||||||
<files-path
|
|
||||||
name="files"
|
|
||||||
path="."/>
|
|
||||||
</paths>
|
|
||||||
|
|
||||||
@@ -7,8 +7,4 @@
|
|||||||
<certificates src="user" />
|
<certificates src="user" />
|
||||||
</trust-anchors>
|
</trust-anchors>
|
||||||
</base-config>
|
</base-config>
|
||||||
<domain-config cleartextTrafficPermitted="true">
|
|
||||||
<domain includeSubdomains="true">localhost</domain>
|
|
||||||
<domain includeSubdomains="true">127.0.0.1</domain>
|
|
||||||
</domain-config>
|
|
||||||
</network-security-config>
|
</network-security-config>
|
||||||
@@ -24,7 +24,6 @@ subprojects {
|
|||||||
}
|
}
|
||||||
subprojects {
|
subprojects {
|
||||||
project.evaluationDependsOn(':app')
|
project.evaluationDependsOn(':app')
|
||||||
project.evaluationDependsOn(':core')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register("clean", Delete) {
|
tasks.register("clean", Delete) {
|
||||||
|
|||||||
1
android/core/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
/build
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
import com.android.build.gradle.tasks.MergeSourceSetFolders
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
id("com.android.library")
|
|
||||||
id("org.jetbrains.kotlin.android")
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
|
||||||
namespace = "com.follow.clash.core"
|
|
||||||
compileSdk = 35
|
|
||||||
ndkVersion = "27.1.12297006"
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdk = 21
|
|
||||||
consumerProguardFiles("consumer-rules.pro")
|
|
||||||
}
|
|
||||||
|
|
||||||
buildTypes {
|
|
||||||
release {
|
|
||||||
proguardFiles(
|
|
||||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
|
||||||
"proguard-rules.pro"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
getByName("main") {
|
|
||||||
jniLibs.srcDirs("src/main/jniLibs")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
externalNativeBuild {
|
|
||||||
cmake {
|
|
||||||
path("src/main/cpp/CMakeLists.txt")
|
|
||||||
version = "3.22.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
|
||||||
}
|
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = "11"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.register<Copy>("copyNativeLibs") {
|
|
||||||
doFirst {
|
|
||||||
delete("src/main/jniLibs")
|
|
||||||
}
|
|
||||||
from("../../libclash/android")
|
|
||||||
into("src/main/jniLibs")
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType<MergeSourceSetFolders>().configureEach {
|
|
||||||
dependsOn("copyNativeLibs")
|
|
||||||
}
|
|
||||||
|
|
||||||
afterEvaluate {
|
|
||||||
tasks.named("assembleDebug").configure {
|
|
||||||
dependsOn("copyNativeLibs")
|
|
||||||
}
|
|
||||||
tasks.named("assembleRelease").configure {
|
|
||||||
dependsOn("copyNativeLibs")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation("androidx.core:core-ktx:1.16.0")
|
|
||||||
}
|
|
||||||
21
android/core/proguard-rules.pro
vendored
@@ -1,21 +0,0 @@
|
|||||||
# Add project specific ProGuard rules here.
|
|
||||||
# You can control the set of applied configuration files using the
|
|
||||||
# proguardFiles setting in build.gradle.
|
|
||||||
#
|
|
||||||
# For more details, see
|
|
||||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
|
||||||
|
|
||||||
# If your project uses WebView with JS, uncomment the following
|
|
||||||
# and specify the fully qualified class name to the JavaScript interface
|
|
||||||
# class:
|
|
||||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
|
||||||
# public *;
|
|
||||||
#}
|
|
||||||
|
|
||||||
# Uncomment this to preserve the line number information for
|
|
||||||
# debugging stack traces.
|
|
||||||
#-keepattributes SourceFile,LineNumberTable
|
|
||||||
|
|
||||||
# If you keep the line number information, uncomment this to
|
|
||||||
# hide the original source file name.
|
|
||||||
#-renamesourcefileattribute SourceFile
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
</manifest>
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.22.1)
|
|
||||||
|
|
||||||
|
|
||||||
project("core")
|
|
||||||
|
|
||||||
|
|
||||||
if (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
|
||||||
add_compile_options(-O3)
|
|
||||||
|
|
||||||
add_compile_options(-flto)
|
|
||||||
|
|
||||||
add_compile_options(-g0)
|
|
||||||
|
|
||||||
add_compile_options(-ffunction-sections -fdata-sections)
|
|
||||||
|
|
||||||
add_compile_options(-fno-exceptions -fno-rtti)
|
|
||||||
|
|
||||||
add_link_options(
|
|
||||||
-flto
|
|
||||||
-Wl,--gc-sections
|
|
||||||
-Wl,--strip-all
|
|
||||||
-Wl,--exclude-libs=ALL
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
set(LIB_CLASH_PATH "${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libclash.so")
|
|
||||||
if (EXISTS ${LIB_CLASH_PATH})
|
|
||||||
message(STATUS "Found libclash.so for ABI ${ANDROID_ABI}")
|
|
||||||
add_definitions(-D_LIBCLASH)
|
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI})
|
|
||||||
link_directories(${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI})
|
|
||||||
add_library(${CMAKE_PROJECT_NAME} SHARED
|
|
||||||
jni_helper.cpp
|
|
||||||
core.cpp)
|
|
||||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
|
||||||
clash)
|
|
||||||
else ()
|
|
||||||
add_library(${CMAKE_PROJECT_NAME} SHARED
|
|
||||||
jni_helper.cpp
|
|
||||||
core.cpp)
|
|
||||||
target_link_libraries(${CMAKE_PROJECT_NAME})
|
|
||||||
endif ()
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
#include <jni.h>
|
|
||||||
|
|
||||||
#ifdef _LIBCLASH
|
|
||||||
#include <jni.h>
|
|
||||||
#include <string>
|
|
||||||
#include "jni_helper.h"
|
|
||||||
#include "libclash.h"
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
JNIEXPORT void JNICALL
|
|
||||||
Java_com_follow_clash_core_Core_startTun(JNIEnv *env, jobject thiz, jint fd, jobject cb) {
|
|
||||||
auto interface = new_global(cb);
|
|
||||||
startTUN(fd, interface);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
JNIEXPORT void JNICALL
|
|
||||||
Java_com_follow_clash_core_Core_stopTun(JNIEnv *env, jobject thiz) {
|
|
||||||
stopTun();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static jmethodID m_tun_interface_protect;
|
|
||||||
static jmethodID m_tun_interface_resolve_process;
|
|
||||||
|
|
||||||
|
|
||||||
static void release_jni_object_impl(void *obj) {
|
|
||||||
ATTACH_JNI();
|
|
||||||
del_global((jobject) obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void call_tun_interface_protect_impl(void *tun_interface, int fd) {
|
|
||||||
ATTACH_JNI();
|
|
||||||
env->CallVoidMethod((jobject) tun_interface,
|
|
||||||
(jmethodID) m_tun_interface_protect,
|
|
||||||
(jint) fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char*
|
|
||||||
call_tun_interface_resolve_process_impl(void *tun_interface, int protocol,
|
|
||||||
const char *source,
|
|
||||||
const char *target,
|
|
||||||
int uid) {
|
|
||||||
ATTACH_JNI();
|
|
||||||
jstring packageName = (jstring)env->CallObjectMethod((jobject) tun_interface,
|
|
||||||
(jmethodID) m_tun_interface_resolve_process,
|
|
||||||
(jint) protocol,
|
|
||||||
(jstring) new_string(source),
|
|
||||||
(jstring) new_string(target),
|
|
||||||
(jint) uid);
|
|
||||||
return get_string(packageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
JNIEXPORT jint JNICALL
|
|
||||||
JNI_OnLoad(JavaVM *vm, void *reserved) {
|
|
||||||
JNIEnv *env = nullptr;
|
|
||||||
if (vm->GetEnv((void **) &env, JNI_VERSION_1_6) != JNI_OK) {
|
|
||||||
return JNI_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
initialize_jni(vm, env);
|
|
||||||
|
|
||||||
jclass c_tun_interface = find_class("com/follow/clash/core/TunInterface");
|
|
||||||
|
|
||||||
m_tun_interface_protect = find_method(c_tun_interface, "protect", "(I)V");
|
|
||||||
m_tun_interface_resolve_process = find_method(c_tun_interface, "resolverProcess",
|
|
||||||
"(ILjava/lang/String;Ljava/lang/String;I)Ljava/lang/String;");
|
|
||||||
|
|
||||||
registerCallbacks(&call_tun_interface_protect_impl,
|
|
||||||
&call_tun_interface_resolve_process_impl,
|
|
||||||
&release_jni_object_impl);
|
|
||||||
return JNI_VERSION_1_6;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
JNIEXPORT void JNICALL
|
|
||||||
Java_com_follow_clash_core_Core_stopTun(JNIEnv *env, jobject thiz) {
|
|
||||||
|
|
||||||
}
|
|
||||||
extern "C"
|
|
||||||
JNIEXPORT void JNICALL
|
|
||||||
Java_com_follow_clash_core_Core_startTun(JNIEnv *env, jobject thiz, jint fd, jobject cb) {
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
#include "jni_helper.h"
|
|
||||||
|
|
||||||
#include <malloc.h>
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
static JavaVM *global_vm;
|
|
||||||
|
|
||||||
static jclass c_string;
|
|
||||||
static jmethodID m_new_string;
|
|
||||||
static jmethodID m_get_bytes;
|
|
||||||
|
|
||||||
void initialize_jni(JavaVM *vm, JNIEnv *env) {
|
|
||||||
global_vm = vm;
|
|
||||||
|
|
||||||
c_string = (jclass) new_global(find_class("java/lang/String"));
|
|
||||||
m_new_string = find_method(c_string, "<init>", "([B)V");
|
|
||||||
m_get_bytes = find_method(c_string, "getBytes", "()[B");
|
|
||||||
}
|
|
||||||
|
|
||||||
JavaVM *global_java_vm() {
|
|
||||||
return global_vm;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *jni_get_string(JNIEnv *env, jstring str) {
|
|
||||||
auto array = (jbyteArray) env->CallObjectMethod(str, m_get_bytes);
|
|
||||||
int length = env->GetArrayLength(array);
|
|
||||||
char *content = (char *) malloc(length + 1);
|
|
||||||
env->GetByteArrayRegion(array, 0, length, (jbyte *) content);
|
|
||||||
content[length] = 0;
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
jstring jni_new_string(JNIEnv *env, const char *str) {
|
|
||||||
auto length = (int) strlen(str);
|
|
||||||
jbyteArray array = env->NewByteArray(length);
|
|
||||||
env->SetByteArrayRegion(array, 0, length, (const jbyte *) str);
|
|
||||||
return (jstring) env->NewObject(c_string, m_new_string, array);
|
|
||||||
}
|
|
||||||
|
|
||||||
int jni_catch_exception(JNIEnv *env) {
|
|
||||||
int result = env->ExceptionCheck();
|
|
||||||
if (result) {
|
|
||||||
env->ExceptionDescribe();
|
|
||||||
env->ExceptionClear();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void jni_attach_thread(struct scoped_jni *jni) {
|
|
||||||
JavaVM *vm = global_java_vm();
|
|
||||||
if (vm->GetEnv((void **) &jni->env, JNI_VERSION_1_6) == JNI_OK) {
|
|
||||||
jni->require_release = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (vm->AttachCurrentThread(&jni->env, nullptr) != JNI_OK) {
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
jni->require_release = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void jni_detach_thread(struct scoped_jni *jni) {
|
|
||||||
JavaVM *vm = global_java_vm();
|
|
||||||
if (jni->require_release) {
|
|
||||||
vm->DetachCurrentThread();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void release_string(char **str) {
|
|
||||||
free(*str);
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <jni.h>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <malloc.h>
|
|
||||||
|
|
||||||
struct scoped_jni {
|
|
||||||
JNIEnv *env;
|
|
||||||
int require_release;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern void initialize_jni(JavaVM *vm, JNIEnv *env);
|
|
||||||
|
|
||||||
extern jstring jni_new_string(JNIEnv *env, const char *str);
|
|
||||||
|
|
||||||
extern char *jni_get_string(JNIEnv *env, jstring str);
|
|
||||||
|
|
||||||
extern int jni_catch_exception(JNIEnv *env);
|
|
||||||
|
|
||||||
extern void jni_attach_thread(struct scoped_jni *jni);
|
|
||||||
|
|
||||||
extern void jni_detach_thread(struct scoped_jni *env);
|
|
||||||
|
|
||||||
extern void release_string(char **str);
|
|
||||||
|
|
||||||
#define ATTACH_JNI() __attribute__((unused, cleanup(jni_detach_thread))) \
|
|
||||||
struct scoped_jni _jni; \
|
|
||||||
jni_attach_thread(&_jni); \
|
|
||||||
JNIEnv *env = _jni.env
|
|
||||||
|
|
||||||
#define scoped_string __attribute__((cleanup(release_string))) char*
|
|
||||||
|
|
||||||
#define find_class(name) env->FindClass(name)
|
|
||||||
#define find_method(cls, name, signature) env->GetMethodID(cls, name, signature)
|
|
||||||
#define new_global(obj) env->NewGlobalRef(obj)
|
|
||||||
#define del_global(obj) env->DeleteGlobalRef(obj)
|
|
||||||
#define get_string(jstr) jni_get_string(env, jstr)
|
|
||||||
#define new_string(cstr) jni_new_string(env, cstr)
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package com.follow.clash.core
|
|
||||||
|
|
||||||
import java.net.InetAddress
|
|
||||||
import java.net.InetSocketAddress
|
|
||||||
import java.net.URL
|
|
||||||
|
|
||||||
data object Core {
|
|
||||||
private external fun startTun(
|
|
||||||
fd: Int,
|
|
||||||
cb: TunInterface
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun parseInetSocketAddress(address: String): InetSocketAddress {
|
|
||||||
val url = URL("https://$address")
|
|
||||||
|
|
||||||
return InetSocketAddress(InetAddress.getByName(url.host), url.port)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun startTun(
|
|
||||||
fd: Int,
|
|
||||||
protect: (Int) -> Boolean,
|
|
||||||
resolverProcess: (protocol: Int, source: InetSocketAddress, target: InetSocketAddress, uid: Int) -> String
|
|
||||||
) {
|
|
||||||
startTun(fd, object : TunInterface {
|
|
||||||
override fun protect(fd: Int) {
|
|
||||||
protect(fd)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun resolverProcess(
|
|
||||||
protocol: Int,
|
|
||||||
source: String,
|
|
||||||
target: String,
|
|
||||||
uid: Int
|
|
||||||
): String {
|
|
||||||
return resolverProcess(
|
|
||||||
protocol,
|
|
||||||
parseInetSocketAddress(source),
|
|
||||||
parseInetSocketAddress(target),
|
|
||||||
uid,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
external fun stopTun()
|
|
||||||
|
|
||||||
init {
|
|
||||||
System.loadLibrary("core")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.follow.clash.core
|
|
||||||
|
|
||||||
import androidx.annotation.Keep
|
|
||||||
|
|
||||||
@Keep
|
|
||||||
interface TunInterface {
|
|
||||||
fun protect(fd: Int)
|
|
||||||
fun resolverProcess(protocol: Int, source: String, target: String, uid: Int): String
|
|
||||||
}
|
|
||||||
@@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx4G
|
|||||||
android.useAndroidX=true
|
android.useAndroidX=true
|
||||||
android.enableJetifier=true
|
android.enableJetifier=true
|
||||||
kotlin_version=1.9.22
|
kotlin_version=1.9.22
|
||||||
agp_version=8.9.1
|
agp_version=8.2.1
|
||||||
|
|||||||
@@ -2,5 +2,5 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
|
||||||
|
|
||||||
|
|||||||
@@ -24,4 +24,3 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
include ":app"
|
include ":app"
|
||||||
include ':core'
|
|
||||||
|
|||||||
64639
assets/data/GeoSite.dat
BIN
assets/images/app_icon.ico
Normal file
|
After Width: | Height: | Size: 9.4 KiB |
|
Before Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 9.5 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 7.0 KiB |
BIN
assets/images/launch_icon.png
Normal file
|
After Width: | Height: | Size: 118 KiB |
@@ -5,7 +5,6 @@ targets:
|
|||||||
options:
|
options:
|
||||||
build_extensions:
|
build_extensions:
|
||||||
'^lib/models/{{}}.dart': 'lib/models/generated/{{}}.g.dart'
|
'^lib/models/{{}}.dart': 'lib/models/generated/{{}}.g.dart'
|
||||||
'^lib/providers/{{}}.dart': 'lib/providers/generated/{{}}.g.dart'
|
|
||||||
freezed:
|
freezed:
|
||||||
options:
|
options:
|
||||||
build_extensions:
|
build_extensions:
|
||||||
|
|||||||
177
core/action.go
@@ -1,177 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Action struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
Method Method `json:"method"`
|
|
||||||
Data interface{} `json:"data"`
|
|
||||||
DefaultValue interface{} `json:"default-value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ActionResult struct {
|
|
||||||
Id string `json:"id"`
|
|
||||||
Method Method `json:"method"`
|
|
||||||
Data interface{} `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (result ActionResult) Json() ([]byte, error) {
|
|
||||||
data, err := json.Marshal(result)
|
|
||||||
return data, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (action Action) getResult(data interface{}) []byte {
|
|
||||||
resultAction := ActionResult{
|
|
||||||
Id: action.Id,
|
|
||||||
Method: action.Method,
|
|
||||||
Data: data,
|
|
||||||
}
|
|
||||||
res, _ := resultAction.Json()
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleAction(action *Action, result func(data interface{})) {
|
|
||||||
switch action.Method {
|
|
||||||
case initClashMethod:
|
|
||||||
paramsString := action.Data.(string)
|
|
||||||
result(handleInitClash(paramsString))
|
|
||||||
return
|
|
||||||
case getIsInitMethod:
|
|
||||||
result(handleGetIsInit())
|
|
||||||
return
|
|
||||||
case forceGcMethod:
|
|
||||||
handleForceGc()
|
|
||||||
result(true)
|
|
||||||
return
|
|
||||||
case shutdownMethod:
|
|
||||||
result(handleShutdown())
|
|
||||||
return
|
|
||||||
case validateConfigMethod:
|
|
||||||
data := []byte(action.Data.(string))
|
|
||||||
result(handleValidateConfig(data))
|
|
||||||
return
|
|
||||||
case updateConfigMethod:
|
|
||||||
data := []byte(action.Data.(string))
|
|
||||||
result(handleUpdateConfig(data))
|
|
||||||
return
|
|
||||||
case getProxiesMethod:
|
|
||||||
result(handleGetProxies())
|
|
||||||
return
|
|
||||||
case changeProxyMethod:
|
|
||||||
data := action.Data.(string)
|
|
||||||
handleChangeProxy(data, func(value string) {
|
|
||||||
result(value)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
case getTrafficMethod:
|
|
||||||
result(handleGetTraffic())
|
|
||||||
return
|
|
||||||
case getTotalTrafficMethod:
|
|
||||||
result(handleGetTotalTraffic())
|
|
||||||
return
|
|
||||||
case resetTrafficMethod:
|
|
||||||
handleResetTraffic()
|
|
||||||
result(true)
|
|
||||||
return
|
|
||||||
case asyncTestDelayMethod:
|
|
||||||
data := action.Data.(string)
|
|
||||||
handleAsyncTestDelay(data, func(value string) {
|
|
||||||
result(value)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
case getConnectionsMethod:
|
|
||||||
result(handleGetConnections())
|
|
||||||
return
|
|
||||||
case closeConnectionsMethod:
|
|
||||||
result(handleCloseConnections())
|
|
||||||
return
|
|
||||||
case closeConnectionMethod:
|
|
||||||
id := action.Data.(string)
|
|
||||||
result(handleCloseConnection(id))
|
|
||||||
return
|
|
||||||
case getExternalProvidersMethod:
|
|
||||||
result(handleGetExternalProviders())
|
|
||||||
return
|
|
||||||
case getExternalProviderMethod:
|
|
||||||
externalProviderName := action.Data.(string)
|
|
||||||
result(handleGetExternalProvider(externalProviderName))
|
|
||||||
case updateGeoDataMethod:
|
|
||||||
paramsString := action.Data.(string)
|
|
||||||
var params = map[string]string{}
|
|
||||||
err := json.Unmarshal([]byte(paramsString), ¶ms)
|
|
||||||
if err != nil {
|
|
||||||
result(err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
geoType := params["geo-type"]
|
|
||||||
geoName := params["geo-name"]
|
|
||||||
handleUpdateGeoData(geoType, geoName, func(value string) {
|
|
||||||
result(value)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
case updateExternalProviderMethod:
|
|
||||||
providerName := action.Data.(string)
|
|
||||||
handleUpdateExternalProvider(providerName, func(value string) {
|
|
||||||
result(value)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
case sideLoadExternalProviderMethod:
|
|
||||||
paramsString := action.Data.(string)
|
|
||||||
var params = map[string]string{}
|
|
||||||
err := json.Unmarshal([]byte(paramsString), ¶ms)
|
|
||||||
if err != nil {
|
|
||||||
result(err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
providerName := params["providerName"]
|
|
||||||
data := params["data"]
|
|
||||||
handleSideLoadExternalProvider(providerName, []byte(data), func(value string) {
|
|
||||||
result(value)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
case startLogMethod:
|
|
||||||
handleStartLog()
|
|
||||||
result(true)
|
|
||||||
return
|
|
||||||
case stopLogMethod:
|
|
||||||
handleStopLog()
|
|
||||||
result(true)
|
|
||||||
return
|
|
||||||
case startListenerMethod:
|
|
||||||
result(handleStartListener())
|
|
||||||
return
|
|
||||||
case stopListenerMethod:
|
|
||||||
result(handleStopListener())
|
|
||||||
return
|
|
||||||
case getCountryCodeMethod:
|
|
||||||
ip := action.Data.(string)
|
|
||||||
handleGetCountryCode(ip, func(value string) {
|
|
||||||
result(value)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
case getMemoryMethod:
|
|
||||||
handleGetMemory(func(value string) {
|
|
||||||
result(value)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
case getProfileMethod:
|
|
||||||
profileId := action.Data.(string)
|
|
||||||
handleGetMemory(func(value string) {
|
|
||||||
result(handleGetProfile(profileId))
|
|
||||||
})
|
|
||||||
return
|
|
||||||
case setStateMethod:
|
|
||||||
data := action.Data.(string)
|
|
||||||
handleSetState(data)
|
|
||||||
result(true)
|
|
||||||
default:
|
|
||||||
handle := nextHandle(action, result)
|
|
||||||
if handle {
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
result(action.DefaultValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||