Compare commits
74 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9cd80bcb3 | ||
|
|
a77b3a35e8 | ||
|
|
2d2708d7bd | ||
|
|
ef5f6dbd59 | ||
|
|
b6c7b15e3e | ||
|
|
de9c5ba9cc | ||
|
|
2aae00cf68 | ||
|
|
68be2d34a1 | ||
|
|
7895ccf720 | ||
|
|
e92900dbbd | ||
|
|
eada271c49 | ||
|
|
5dda2854be | ||
|
|
5184ed6fc7 | ||
|
|
4e679f776e | ||
|
|
96328f66e9 | ||
|
|
3eb14ab8a1 | ||
|
|
c6266b7917 | ||
|
|
6c27f2e2f1 | ||
|
|
e04a0094b1 | ||
|
|
683e6a58ea | ||
|
|
b340feeb49 | ||
|
|
6a39b7ef5a | ||
|
|
35f89fea90 | ||
|
|
58acd9c1ab | ||
|
|
ef97ef40a1 | ||
|
|
9cb75f4814 | ||
|
|
375c4e0884 | ||
|
|
ece8a48181 | ||
|
|
4b32a096dd | ||
|
|
04d6a928eb | ||
|
|
22e71ec6e1 | ||
|
|
6f1b07e26b | ||
|
|
1e3ab1c717 | ||
|
|
3a43dc2fe9 | ||
|
|
c94f64cf78 | ||
|
|
25764fc4d3 | ||
|
|
649dbb9886 | ||
|
|
e1dd616d74 | ||
|
|
c91d78b63f | ||
|
|
82767325e5 | ||
|
|
3f0f7f051b | ||
|
|
15c64327db | ||
|
|
09e35eb5dd | ||
|
|
77c4935106 | ||
|
|
e6da643186 | ||
|
|
61bd4e4549 | ||
|
|
a5f4d12748 | ||
|
|
9dc67f31a3 | ||
|
|
846ec9728f | ||
|
|
6e5f1b8e5f | ||
|
|
aca4a3e979 | ||
|
|
3783c3c650 | ||
|
|
01aed99002 | ||
|
|
9aec1e75e4 | ||
|
|
5dfb95a22d | ||
|
|
0f8cfa20b2 | ||
|
|
3933fd9d9e | ||
|
|
b7400f2ce8 | ||
|
|
d0ec580932 | ||
|
|
6bc0be9876 | ||
|
|
38221bcd10 | ||
|
|
bee2f8aa4f | ||
|
|
6cfcaa4edc | ||
|
|
3fdc69edd5 | ||
|
|
ed7ade0d72 | ||
|
|
621ddefc65 | ||
|
|
6de89d7de4 | ||
|
|
c36df8cb4a | ||
|
|
530817b268 | ||
|
|
721dd20251 | ||
|
|
f2aa8851ae | ||
|
|
ec2890cab2 | ||
|
|
ca946c1b06 | ||
|
|
3bc3172723 |
58
.github/release_template.md
vendored
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<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>
|
||||||
242
.github/workflows/build.yaml
vendored
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
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
|
||||||
|
- platform: windows
|
||||||
|
os: windows-11-arm
|
||||||
|
arch: arm64
|
||||||
|
- platform: linux
|
||||||
|
os: ubuntu-24.04-arm
|
||||||
|
arch: arm64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Setup rust
|
||||||
|
if: startsWith(matrix.os, 'windows-11-arm')
|
||||||
|
run: |
|
||||||
|
Invoke-WebRequest -Uri "https://win.rustup.rs/aarch64" -OutFile rustup-init.exe
|
||||||
|
.\rustup-init.exe -y --default-toolchain stable
|
||||||
|
$cargoPath = "$env:USERPROFILE\.cargo\bin"
|
||||||
|
Add-Content $env:GITHUB_PATH $cargoPath
|
||||||
|
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- 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: '1.24.0'
|
||||||
|
cache-dependency-path: |
|
||||||
|
core/go.sum
|
||||||
|
|
||||||
|
- name: Setup Flutter
|
||||||
|
uses: subosito/flutter-action@v2
|
||||||
|
with:
|
||||||
|
channel: ${{ (startsWith(matrix.os, 'windows-11-arm') || startsWith(matrix.os, 'ubuntu-24.04-arm')) && 'master' || '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/
|
||||||
|
|
||||||
138
.github/workflows/build.yml
vendored
@@ -1,138 +0,0 @@
|
|||||||
name: build
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
|
|
||||||
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: Setup Mingw64
|
|
||||||
if: startsWith(matrix.platform,'windows')
|
|
||||||
uses: msys2/setup-msys2@v2
|
|
||||||
with:
|
|
||||||
msystem: mingw64
|
|
||||||
install: mingw-w64-x86_64-gcc
|
|
||||||
update: true
|
|
||||||
|
|
||||||
|
|
||||||
- name: Set Mingw64 Env
|
|
||||||
if: startsWith(matrix.platform,'windows')
|
|
||||||
run: |
|
|
||||||
echo "${{ runner.temp }}\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
|
||||||
|
|
||||||
- name: Check Matrix
|
|
||||||
run: |
|
|
||||||
echo "Running on ${{ matrix.os }}"
|
|
||||||
echo "Arch: ${{ runner.arch }}"
|
|
||||||
gcc --version
|
|
||||||
|
|
||||||
- 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: ${{ !contains(github.ref, '+') }}
|
|
||||||
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,9 +5,11 @@
|
|||||||
*.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
|
||||||
|
|||||||
2
.gitmodules
vendored
@@ -6,3 +6,5 @@
|
|||||||
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
|
branch = FlClash
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
824
CHANGELOG.md
Normal file
@@ -0,0 +1,824 @@
|
|||||||
|
## 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
|
||||||
10
Makefile
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
android_arm64:
|
||||||
|
dart ./setup.dart android --arch arm64
|
||||||
|
macos_arm64:
|
||||||
|
dart ./setup.dart macos --arch arm64
|
||||||
|
android_app:
|
||||||
|
dart ./setup.dart android
|
||||||
|
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,13 +6,9 @@
|
|||||||
|
|
||||||
## FlClash
|
## FlClash
|
||||||
|
|
||||||
<p style="text-align: left;">
|
[](https://github.com/chen08209/FlClash/releases/)[](https://github.com/chen08209/FlClash/releases/)[](LICENSE)
|
||||||
<img alt="stars" src="https://img.shields.io/github/stars/chen08209/FlClash?style=flat-square&logo=github"/>
|
|
||||||
<img alt="downloads" src="https://img.shields.io/github/downloads/chen08209/FlClash/total"/>
|
[](https://t.me/FlClash)
|
||||||
<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.
|
||||||
|
|
||||||
@@ -38,9 +34,32 @@ on Mobile:
|
|||||||
|
|
||||||
✨ Support subscription link, Dark mode
|
✨ Support subscription link, Dark mode
|
||||||
|
|
||||||
## Contact
|
## Use
|
||||||
|
|
||||||
[Telegram](https://t.me/+G-veVtwBOl4wODc1)
|
### Linux
|
||||||
|
|
||||||
|
⚠️ 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
|
||||||
|
|
||||||
@@ -74,7 +93,7 @@ on Mobile:
|
|||||||
3. Run build script
|
3. Run build script
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dart .\setup.dart
|
dart .\setup.dart windows --arch <arm64 | amd64>
|
||||||
```
|
```
|
||||||
|
|
||||||
- linux
|
- linux
|
||||||
@@ -84,7 +103,7 @@ on Mobile:
|
|||||||
2. Run build script
|
2. Run build script
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dart .\setup.dart
|
dart .\setup.dart linux --arch <arm64 | amd64>
|
||||||
```
|
```
|
||||||
|
|
||||||
- macOS
|
- macOS
|
||||||
@@ -94,11 +113,8 @@ on Mobile:
|
|||||||
2. Run build script
|
2. Run build script
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dart .\setup.dart
|
dart .\setup.dart macos --arch <arm64 | amd64>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Star
|
## Star
|
||||||
|
|
||||||
|
|||||||
@@ -6,13 +6,9 @@
|
|||||||
|
|
||||||
## FlClash
|
## FlClash
|
||||||
|
|
||||||
<p style="text-align: left;">
|
[](https://github.com/chen08209/FlClash/releases/)[](https://github.com/chen08209/FlClash/releases/)[](LICENSE)
|
||||||
<img alt="stars" src="https://img.shields.io/github/stars/chen08209/FlClash?style=flat-square&logo=github"/>
|
|
||||||
<img alt="downloads" src="https://img.shields.io/github/downloads/chen08209/FlClash/total"/>
|
[](https://t.me/FlClash)
|
||||||
<a href="LICENSE">
|
|
||||||
<img alt="license" src="https://img.shields.io/github/license/chen08209/FlClash"/>
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
基于ClashMeta的多平台代理客户端,简单易用,开源无广告。
|
基于ClashMeta的多平台代理客户端,简单易用,开源无广告。
|
||||||
|
|
||||||
@@ -38,9 +34,32 @@ on Mobile:
|
|||||||
|
|
||||||
✨ 支持一键导入订阅, 深色模式
|
✨ 支持一键导入订阅, 深色模式
|
||||||
|
|
||||||
## Contact
|
## Use
|
||||||
|
|
||||||
[Telegram](https://t.me/+G-veVtwBOl4wODc1)
|
### Linux
|
||||||
|
|
||||||
|
⚠️ 使用前请确保安装以下依赖
|
||||||
|
|
||||||
|
```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
|
||||||
|
|
||||||
@@ -74,7 +93,7 @@ on Mobile:
|
|||||||
3. 运行构建脚本
|
3. 运行构建脚本
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dart .\setup.dart
|
dart .\setup.dart windows --arch <arm64 | amd64>
|
||||||
```
|
```
|
||||||
|
|
||||||
- linux
|
- linux
|
||||||
@@ -84,7 +103,7 @@ on Mobile:
|
|||||||
2. 运行构建脚本
|
2. 运行构建脚本
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dart .\setup.dart
|
dart .\setup.dart linux --arch <arm64 | amd64>
|
||||||
```
|
```
|
||||||
|
|
||||||
- macOS
|
- macOS
|
||||||
@@ -94,7 +113,7 @@ on Mobile:
|
|||||||
2. 运行构建脚本
|
2. 运行构建脚本
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dart .\setup.dart
|
dart .\setup.dart macos --arch <arm64 | amd64>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Star History
|
## Star History
|
||||||
|
|||||||
@@ -1,29 +1 @@
|
|||||||
# 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,5 +1,3 @@
|
|||||||
import com.android.build.gradle.tasks.MergeSourceSetFolders
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "com.android.application"
|
id "com.android.application"
|
||||||
id "kotlin-android"
|
id "kotlin-android"
|
||||||
@@ -33,23 +31,24 @@ def isRelease = defStoreFile.exists() && defStorePassword != null && defKeyAlias
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
namespace "com.follow.clash"
|
namespace "com.follow.clash"
|
||||||
compileSdkVersion 34
|
compileSdk 35
|
||||||
ndkVersion "25.1.8937393"
|
ndkVersion = "28.0.13004108"
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_17
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
targetCompatibility JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = '1.8'
|
jvmTarget = '17'
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@@ -63,7 +62,7 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.follow.clash"
|
applicationId "com.follow.clash"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 34
|
targetSdkVersion 35
|
||||||
versionCode flutterVersionCode.toInteger()
|
versionCode flutterVersionCode.toInteger()
|
||||||
versionName flutterVersionName
|
versionName flutterVersionName
|
||||||
}
|
}
|
||||||
@@ -74,10 +73,9 @@ android {
|
|||||||
applicationIdSuffix '.debug'
|
applicationIdSuffix '.debug'
|
||||||
}
|
}
|
||||||
release {
|
release {
|
||||||
minifyEnabled true
|
if (isRelease) {
|
||||||
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"
|
||||||
@@ -85,28 +83,15 @@ 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'
|
implementation 'com.google.code.gson:gson:2.10.1'
|
||||||
}
|
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,13 +1,17 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
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 android:label="FlClash Debug" tools:replace="android:label">
|
<application
|
||||||
|
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"
|
||||||
</service>
|
tools:targetApi="24" />
|
||||||
</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,18 +14,17 @@
|
|||||||
<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_SPECIAL_USE"
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
||||||
tools:ignore="SystemPermissionTypo" />
|
|
||||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
|
<uses-permission
|
||||||
|
android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||||
tools:ignore="QueryAllPackagesPermission" />
|
tools:ignore="QueryAllPackagesPermission" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="${applicationName}"
|
android:name=".FlClashApplication"
|
||||||
|
android:hardwareAccelerated="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:networkSecurityConfig="@xml/network_security_config"
|
android:label="FlClash">
|
||||||
android:extractNativeLibs="true"
|
|
||||||
android:label="FlClash"
|
|
||||||
tools:targetApi="n">
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.follow.clash.MainActivity"
|
android:name="com.follow.clash.MainActivity"
|
||||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||||
@@ -55,29 +54,43 @@
|
|||||||
<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="true" />-->
|
android:value="false" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".TempActivity"
|
android:name=".TempActivity"
|
||||||
android:theme="@style/TransparentTheme" />
|
android:exported="true"
|
||||||
|
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/icon"
|
android:icon="@drawable/ic_stat_name"
|
||||||
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>
|
||||||
@@ -85,14 +98,49 @@
|
|||||||
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="specialUse"
|
android:foregroundServiceType="dataSync"
|
||||||
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: 72 KiB After Width: | Height: | Size: 12 KiB |
112
android/app/src/main/kotlin/com/follow/clash/FilesProvider.kt
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
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,10 +1,9 @@
|
|||||||
package com.follow.clash
|
package com.follow.clash
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import com.follow.clash.plugins.AppPlugin
|
import com.follow.clash.plugins.AppPlugin
|
||||||
import com.follow.clash.plugins.ProxyPlugin
|
|
||||||
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.FlutterInjector
|
||||||
import io.flutter.embedding.engine.FlutterEngine
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
import io.flutter.embedding.engine.dart.DartExecutor
|
import io.flutter.embedding.engine.dart.DartExecutor
|
||||||
@@ -19,8 +18,7 @@ enum class RunState {
|
|||||||
|
|
||||||
|
|
||||||
object GlobalState {
|
object GlobalState {
|
||||||
|
val runLock = ReentrantLock()
|
||||||
private val lock = ReentrantLock()
|
|
||||||
|
|
||||||
val runState: MutableLiveData<RunState> = MutableLiveData<RunState>(RunState.STOP)
|
val runState: MutableLiveData<RunState> = MutableLiveData<RunState>(RunState.STOP)
|
||||||
var flutterEngine: FlutterEngine? = null
|
var flutterEngine: FlutterEngine? = null
|
||||||
@@ -31,30 +29,77 @@ object GlobalState {
|
|||||||
return currentEngine?.plugins?.get(AppPlugin::class.java) as AppPlugin?
|
return currentEngine?.plugins?.get(AppPlugin::class.java) as AppPlugin?
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCurrentTitlePlugin(): TilePlugin? {
|
suspend fun getText(text: String): String {
|
||||||
|
return getCurrentAppPlugin()?.getText(text) ?: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getCurrentTilePlugin(): TilePlugin? {
|
||||||
val currentEngine = if (flutterEngine != null) flutterEngine else serviceEngine
|
val currentEngine = if (flutterEngine != null) flutterEngine else serviceEngine
|
||||||
return currentEngine?.plugins?.get(TilePlugin::class.java) as TilePlugin?
|
return currentEngine?.plugins?.get(TilePlugin::class.java) as TilePlugin?
|
||||||
}
|
}
|
||||||
|
|
||||||
fun destroyServiceEngine() {
|
fun getCurrentVPNPlugin(): VpnPlugin? {
|
||||||
serviceEngine?.destroy()
|
return serviceEngine?.plugins?.get(VpnPlugin::class.java) as VpnPlugin?
|
||||||
serviceEngine = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun initServiceEngine(context: Context) {
|
fun handleToggle() {
|
||||||
if (serviceEngine != null) return
|
val starting = handleStart()
|
||||||
lock.withLock {
|
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()
|
destroyServiceEngine()
|
||||||
serviceEngine = FlutterEngine(context)
|
}
|
||||||
serviceEngine?.plugins?.add(ProxyPlugin())
|
}
|
||||||
|
|
||||||
|
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(AppPlugin())
|
||||||
serviceEngine?.plugins?.add(TilePlugin())
|
serviceEngine?.plugins?.add(TilePlugin())
|
||||||
val vpnService = DartExecutor.DartEntrypoint(
|
val vpnService = DartExecutor.DartEntrypoint(
|
||||||
FlutterInjector.instance().flutterLoader().findAppBundlePath(),
|
FlutterInjector.instance().flutterLoader().findAppBundlePath(),
|
||||||
"vpnService"
|
"_service"
|
||||||
)
|
)
|
||||||
serviceEngine?.dartExecutor?.executeDartEntrypoint(
|
serviceEngine?.dartExecutor?.executeDartEntrypoint(
|
||||||
vpnService,
|
vpnService,
|
||||||
|
if (flutterEngine == null) listOf("quick") else null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
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.ProxyPlugin
|
import com.follow.clash.plugins.ServicePlugin
|
||||||
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) {
|
||||||
super.configureFlutterEngine(flutterEngine)
|
super.configureFlutterEngine(flutterEngine)
|
||||||
flutterEngine.plugins.add(AppPlugin())
|
flutterEngine.plugins.add(AppPlugin())
|
||||||
flutterEngine.plugins.add(ProxyPlugin())
|
flutterEngine.plugins.add(ServicePlugin)
|
||||||
flutterEngine.plugins.add(TilePlugin())
|
flutterEngine.plugins.add(TilePlugin())
|
||||||
GlobalState.flutterEngine = flutterEngine
|
GlobalState.flutterEngine = flutterEngine
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,24 @@ 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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package com.follow.clash.extensions
|
|
||||||
|
|
||||||
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 java.net.URL
|
|
||||||
import androidx.core.graphics.drawable.toBitmap
|
|
||||||
import com.follow.clash.models.Metadata
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import java.io.ByteArrayOutputStream
|
|
||||||
import java.net.InetAddress
|
|
||||||
import java.net.InetSocketAddress
|
|
||||||
|
|
||||||
|
|
||||||
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 String.getInetSocketAddress(): InetSocketAddress {
|
|
||||||
val url = URL("https://$this")
|
|
||||||
return InetSocketAddress(InetAddress.getByName(url.host), url.port)
|
|
||||||
}
|
|
||||||
196
android/app/src/main/kotlin/com/follow/clash/extensions/Ext.kt
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
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()
|
||||||
|
}
|
||||||
@@ -3,5 +3,6 @@ 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,7 +1,7 @@
|
|||||||
package com.follow.clash.models
|
package com.follow.clash.models
|
||||||
|
|
||||||
data class Process(
|
data class Process(
|
||||||
val id: Int,
|
val id: String,
|
||||||
val metadata: Metadata,
|
val metadata: Metadata,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,34 @@
|
|||||||
package com.follow.clash.models
|
package com.follow.clash.models
|
||||||
|
|
||||||
|
import java.net.InetAddress
|
||||||
|
|
||||||
enum class AccessControlMode {
|
enum class AccessControlMode {
|
||||||
acceptSelected,
|
acceptSelected, rejectSelected,
|
||||||
rejectSelected,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data class AccessControl(
|
data class AccessControl(
|
||||||
|
val enable: Boolean,
|
||||||
val mode: AccessControlMode,
|
val mode: AccessControlMode,
|
||||||
val acceptList: List<String>,
|
val acceptList: List<String>,
|
||||||
val rejectList: List<String>,
|
val rejectList: List<String>,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class Props(
|
data class CIDR(val address: InetAddress, val prefixLength: Int)
|
||||||
val accessControl: AccessControl?,
|
|
||||||
val allowBypass: Boolean?,
|
data class VpnOptions(
|
||||||
val systemProxy: Boolean?,
|
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,
|
||||||
|
)
|
||||||
@@ -3,20 +3,30 @@ 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.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.ConnectivityManager
|
import android.net.VpnService
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.ContextCompat.getSystemService
|
import androidx.core.content.ContextCompat.getSystemService
|
||||||
import androidx.core.content.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.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.Package
|
import com.follow.clash.models.Package
|
||||||
import com.follow.clash.models.Process
|
|
||||||
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
|
||||||
@@ -28,31 +38,106 @@ 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.net.InetSocketAddress
|
import java.io.File
|
||||||
|
import java.lang.ref.WeakReference
|
||||||
|
import java.util.zip.ZipFile
|
||||||
|
|
||||||
class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware {
|
class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware {
|
||||||
|
|
||||||
private var activity: Activity? = null
|
private var activityRef: WeakReference<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 connectivity: ConnectivityManager? = null
|
private var vpnCallBack: (() -> Unit)? = 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)
|
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) {
|
||||||
@@ -61,31 +146,38 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun tip(message: String?) {
|
private fun tip(message: String?) {
|
||||||
if(GlobalState.flutterEngine == null){
|
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) {
|
override fun onMethodCall(call: MethodCall, result: Result) {
|
||||||
when (call.method) {
|
when (call.method) {
|
||||||
"moveTaskToBack" -> {
|
"moveTaskToBack" -> {
|
||||||
activity?.moveTaskToBack(true)
|
activityRef?.get()?.moveTaskToBack(true)
|
||||||
result.success(true);
|
result.success(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
"updateExcludeFromRecents" -> {
|
"updateExcludeFromRecents" -> {
|
||||||
val value = call.argument<Boolean>("value")
|
val value = call.argument<Boolean>("value")
|
||||||
updateExcludeFromRecents(value)
|
updateExcludeFromRecents(value)
|
||||||
result.success(true);
|
result.success(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
"initShortcuts" -> {
|
||||||
|
initShortcuts(call.arguments as String)
|
||||||
|
result.success(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
"getPackages" -> {
|
"getPackages" -> {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
result.success(getPackages())
|
result.success(getPackagesToJson())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
"getChinaPackageNames" -> {
|
||||||
|
scope.launch {
|
||||||
|
result.success(getChinaPackageNames())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +196,7 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware
|
|||||||
}
|
}
|
||||||
if (iconMap["default"] == null) {
|
if (iconMap["default"] == null) {
|
||||||
iconMap["default"] =
|
iconMap["default"] =
|
||||||
context?.packageManager?.defaultActivityIcon?.getBase64()
|
FlClashApplication.getAppContext().packageManager?.defaultActivityIcon?.getBase64()
|
||||||
}
|
}
|
||||||
result.success(iconMap["default"])
|
result.success(iconMap["default"])
|
||||||
return@launch
|
return@launch
|
||||||
@@ -112,72 +204,67 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"resolverProcess" -> {
|
|
||||||
val data = call.argument<String>("data")
|
|
||||||
val process =
|
|
||||||
if (data != null) Gson().fromJson(
|
|
||||||
data,
|
|
||||||
Process::class.java
|
|
||||||
) else null
|
|
||||||
val metadata = process?.metadata
|
|
||||||
val protocol = metadata?.getProtocol()
|
|
||||||
if (protocol == null) {
|
|
||||||
result.success(null)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
scope.launch {
|
|
||||||
withContext(Dispatchers.Default) {
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
|
||||||
result.success(null)
|
|
||||||
return@withContext
|
|
||||||
}
|
|
||||||
if (context == null) {
|
|
||||||
result.success(null)
|
|
||||||
return@withContext
|
|
||||||
}
|
|
||||||
if (connectivity == null) {
|
|
||||||
connectivity = context!!.getSystemService<ConnectivityManager>()
|
|
||||||
}
|
|
||||||
val src = InetSocketAddress(metadata.sourceIP, metadata.sourcePort)
|
|
||||||
val dst = InetSocketAddress(
|
|
||||||
metadata.destinationIP.ifEmpty { metadata.host },
|
|
||||||
metadata.destinationPort
|
|
||||||
)
|
|
||||||
val uid = try {
|
|
||||||
connectivity?.getConnectionOwnerUid(protocol, src, dst)
|
|
||||||
} catch (_: Exception) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
if (uid == null || uid == -1) {
|
|
||||||
result.success(null)
|
|
||||||
return@withContext
|
|
||||||
}
|
|
||||||
val packages = context?.packageManager?.getPackagesForUid(uid)
|
|
||||||
result.success(packages?.first())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"tip" -> {
|
"tip" -> {
|
||||||
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?) {
|
private fun updateExcludeFromRecents(value: Boolean?) {
|
||||||
if (context == null) return
|
val am = getSystemService(FlClashApplication.getAppContext(), ActivityManager::class.java)
|
||||||
val am = getSystemService(context!!, ActivityManager::class.java)
|
|
||||||
val task = am?.appTasks?.firstOrNull {
|
val task = am?.appTasks?.firstOrNull {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
it.taskInfo.taskId == activity?.taskId
|
it.taskInfo.taskId == activityRef?.get()?.taskId
|
||||||
} else {
|
} else {
|
||||||
it.taskInfo.id == activity?.taskId
|
it.taskInfo.id == activityRef?.get()?.taskId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +276,7 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getPackageIcon(packageName: String): String? {
|
private suspend fun getPackageIcon(packageName: String): String? {
|
||||||
val packageManager = context?.packageManager
|
val packageManager = FlClashApplication.getAppContext().packageManager
|
||||||
if (iconMap[packageName] == null) {
|
if (iconMap[packageName] == null) {
|
||||||
iconMap[packageName] = try {
|
iconMap[packageName] = try {
|
||||||
packageManager?.getApplicationIcon(packageName)?.getBase64()
|
packageManager?.getApplicationIcon(packageName)?.getBase64()
|
||||||
@@ -201,44 +288,184 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware
|
|||||||
return iconMap[packageName]
|
return iconMap[packageName]
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getPackages(): String {
|
private fun getPackages(): List<Package> {
|
||||||
return withContext(Dispatchers.Default) {
|
val packageManager = FlClashApplication.getAppContext().packageManager
|
||||||
val packageManager = context?.packageManager
|
if (packages.isNotEmpty()) return packages
|
||||||
val packages: List<Package>? =
|
packageManager?.getInstalledPackages(PackageManager.GET_META_DATA or PackageManager.GET_PERMISSIONS)
|
||||||
packageManager?.getInstalledPackages(PackageManager.GET_META_DATA)?.filter {
|
?.filter {
|
||||||
it.packageName != context?.packageName
|
it.packageName != FlClashApplication.getAppContext().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 requestGc() {
|
fun requestVpnPermission(callBack: () -> Unit) {
|
||||||
channel.invokeMethod("gc", null)
|
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) {
|
||||||
activity = binding.activity;
|
activityRef = WeakReference(binding.activity)
|
||||||
|
binding.addActivityResultListener(::onActivityResult)
|
||||||
|
binding.addRequestPermissionsResultListener(::onRequestPermissionsResultListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDetachedFromActivityForConfigChanges() {
|
override fun onDetachedFromActivityForConfigChanges() {
|
||||||
activity = null
|
activityRef = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
|
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
|
||||||
activity = binding.activity;
|
activityRef = WeakReference(binding.activity)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDetachedFromActivity() {
|
override fun onDetachedFromActivity() {
|
||||||
channel.invokeMethod("exit", null)
|
channel.invokeMethod("exit", null)
|
||||||
activity = null
|
activityRef = 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,213 +0,0 @@
|
|||||||
package com.follow.clash.plugins
|
|
||||||
|
|
||||||
import android.Manifest
|
|
||||||
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
|
|
||||||
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.Props
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class ProxyPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware {
|
|
||||||
|
|
||||||
private lateinit var flutterMethodChannel: MethodChannel
|
|
||||||
|
|
||||||
val VPN_PERMISSION_REQUEST_CODE = 1001
|
|
||||||
val NOTIFICATION_PERMISSION_REQUEST_CODE = 1002
|
|
||||||
|
|
||||||
private var activity: Activity? = null
|
|
||||||
private var context: Context? = null
|
|
||||||
private var flClashVpnService: FlClashVpnService? = null
|
|
||||||
private var port: Int = 7890
|
|
||||||
private var props: Props? = null
|
|
||||||
private var isBlockNotification: Boolean = false
|
|
||||||
private var isStart: Boolean = false
|
|
||||||
|
|
||||||
private val connection = object : ServiceConnection {
|
|
||||||
override fun onServiceConnected(className: ComponentName, service: IBinder) {
|
|
||||||
val binder = service as FlClashVpnService.LocalBinder
|
|
||||||
flClashVpnService = binder.getService()
|
|
||||||
if (isStart) {
|
|
||||||
startVpn()
|
|
||||||
} else {
|
|
||||||
flClashVpnService?.initServiceEngine()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onServiceDisconnected(arg: ComponentName) {
|
|
||||||
flClashVpnService = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
"initService" -> {
|
|
||||||
isStart = false
|
|
||||||
initService()
|
|
||||||
requestNotificationsPermission()
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
"startProxy" -> {
|
|
||||||
isStart = true
|
|
||||||
port = call.argument<Int>("port")!!
|
|
||||||
val args = call.argument<String>("args")
|
|
||||||
props =
|
|
||||||
if (args != null) Gson().fromJson(args, Props::class.java) else null
|
|
||||||
startVpn()
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"startForeground" -> {
|
|
||||||
val title = call.argument<String>("title") as String
|
|
||||||
val content = call.argument<String>("content") as String
|
|
||||||
startForeground(title, content)
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
result.notImplemented()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun initService() {
|
|
||||||
val intent = VpnService.prepare(context)
|
|
||||||
if (intent != null) {
|
|
||||||
activity?.startActivityForResult(intent, VPN_PERMISSION_REQUEST_CODE)
|
|
||||||
} else {
|
|
||||||
if (flClashVpnService != null) {
|
|
||||||
flClashVpnService!!.initServiceEngine()
|
|
||||||
} else {
|
|
||||||
bindService()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun startVpn() {
|
|
||||||
if (flClashVpnService == null) {
|
|
||||||
bindService()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (GlobalState.runState.value == RunState.START) return
|
|
||||||
GlobalState.runState.value = RunState.START
|
|
||||||
flutterMethodChannel.invokeMethod("started", flClashVpnService?.start(port, props))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun stopVpn() {
|
|
||||||
if (GlobalState.runState.value == RunState.STOP) return
|
|
||||||
GlobalState.runState.value = RunState.STOP
|
|
||||||
flClashVpnService?.stop()
|
|
||||||
GlobalState.destroyServiceEngine()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun startForeground(title: String, content: String) {
|
|
||||||
if (GlobalState.runState.value != RunState.START) return
|
|
||||||
flClashVpnService?.startForeground(title, content)
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
isBlockNotification = true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun requestNotificationsPermission() {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
||||||
val permission = context?.let {
|
|
||||||
ContextCompat.checkSelfPermission(
|
|
||||||
it,
|
|
||||||
Manifest.permission.POST_NOTIFICATIONS
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (permission != PackageManager.PERMISSION_GRANTED) {
|
|
||||||
if (isBlockNotification) return
|
|
||||||
if (activity == null) return
|
|
||||||
ActivityCompat.requestPermissions(
|
|
||||||
activity!!,
|
|
||||||
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
|
|
||||||
NOTIFICATION_PERMISSION_REQUEST_CODE
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDetachedFromActivityForConfigChanges() {
|
|
||||||
activity = null
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
|
|
||||||
activity = binding.activity
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDetachedFromActivity() {
|
|
||||||
activity = null
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun bindService() {
|
|
||||||
val intent = Intent(context, FlClashVpnService::class.java)
|
|
||||||
context?.bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
|
|
||||||
package com.follow.clash.plugins
|
package com.follow.clash.plugins
|
||||||
|
|
||||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
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(private val onStart: (() -> Unit)? = null, private val onStop: (() -> Unit)? = null) : FlutterPlugin,
|
class TilePlugin : FlutterPlugin, MethodChannel.MethodCallHandler {
|
||||||
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)
|
||||||
@@ -20,13 +19,11 @@ class TilePlugin(private val onStart: (() -> Unit)? = null, private val onStop:
|
|||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
||||||
|
|||||||
@@ -0,0 +1,266 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.follow.clash.services
|
package com.follow.clash.services
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.IBinder
|
|
||||||
import android.service.quicksettings.Tile
|
import android.service.quicksettings.Tile
|
||||||
import android.service.quicksettings.TileService
|
import android.service.quicksettings.TileService
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
@@ -37,6 +37,7 @@ 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 or Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
|
||||||
@@ -65,19 +66,7 @@ class FlClashTileService : TileService() {
|
|||||||
override fun onClick() {
|
override fun onClick() {
|
||||||
super.onClick()
|
super.onClick()
|
||||||
activityTransfer()
|
activityTransfer()
|
||||||
if (GlobalState.runState.value == RunState.STOP) {
|
GlobalState.handleToggle()
|
||||||
GlobalState.runState.value = RunState.PENDING
|
|
||||||
val titlePlugin = GlobalState.getCurrentTitlePlugin()
|
|
||||||
if (titlePlugin != null) {
|
|
||||||
titlePlugin.handleStart()
|
|
||||||
} else {
|
|
||||||
GlobalState.initServiceEngine(applicationContext)
|
|
||||||
}
|
|
||||||
} else if (GlobalState.runState.value == RunState.START) {
|
|
||||||
GlobalState.runState.value = RunState.PENDING
|
|
||||||
GlobalState.getCurrentTitlePlugin()?.handleStop()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
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_SPECIAL_USE
|
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
|
||||||
import android.net.ProxyInfo
|
import android.net.ProxyInfo
|
||||||
import android.net.VpnService
|
import android.net.VpnService
|
||||||
import android.os.Binder
|
import android.os.Binder
|
||||||
@@ -13,138 +14,173 @@ import android.os.Build
|
|||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.Parcel
|
import android.os.Parcel
|
||||||
import android.os.RemoteException
|
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.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.Props
|
import com.follow.clash.models.VpnOptions
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Deferred
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
|
||||||
class FlClashVpnService : VpnService() {
|
class FlClashVpnService : VpnService(), BaseServiceInterface {
|
||||||
private val CHANNEL = "FlClash"
|
|
||||||
|
|
||||||
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 onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
initServiceEngine()
|
GlobalState.initServiceEngine()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun start(port: Int, props: Props?): Int? {
|
override fun start(options: VpnOptions): Int {
|
||||||
return with(Builder()) {
|
return with(Builder()) {
|
||||||
addAddress("172.16.0.1", 30)
|
if (options.ipv4Address.isNotEmpty()) {
|
||||||
setMtu(9000)
|
val cidr = options.ipv4Address.toCIDR()
|
||||||
addRoute("0.0.0.0", 0)
|
addAddress(cidr.address, cidr.prefixLength)
|
||||||
props?.accessControl?.let { accessControl ->
|
val routeAddress = options.getIpv4RouteAddress()
|
||||||
when (accessControl.mode) {
|
if (routeAddress.isNotEmpty()) {
|
||||||
AccessControlMode.acceptSelected -> {
|
try {
|
||||||
(accessControl.acceptList + packageName).forEach {
|
routeAddress.forEach { i ->
|
||||||
addAllowedApplication(it)
|
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)
|
||||||
|
options.accessControl.let { accessControl ->
|
||||||
|
if (accessControl.enable) {
|
||||||
|
when (accessControl.mode) {
|
||||||
|
AccessControlMode.acceptSelected -> {
|
||||||
|
(accessControl.acceptList + packageName).forEach {
|
||||||
|
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 (props?.allowBypass == true) {
|
if (options.allowBypass) {
|
||||||
allowBypass()
|
allowBypass()
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && props?.systemProxy == true) {
|
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",
|
||||||
port,
|
options.port,
|
||||||
passList
|
options.bypassDomain
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
establish()?.detachFd()
|
establish()?.detachFd()
|
||||||
|
?: throw NullPointerException("Establish VPN rejected by system")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
override fun stop() {
|
||||||
stopSelf()
|
stopSelf()
|
||||||
stopForeground()
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val notificationBuilder: NotificationCompat.Builder by lazy {
|
private val CHANNEL = "FlClash"
|
||||||
val intent = Intent(this, MainActivity::class.java)
|
|
||||||
|
|
||||||
val pendingIntent = if (Build.VERSION.SDK_INT >= 31) {
|
private val notificationId: Int = 1
|
||||||
PendingIntent.getActivity(
|
|
||||||
this,
|
private val notificationBuilderDeferred: Deferred<NotificationCompat.Builder> by lazy {
|
||||||
0,
|
CoroutineScope(Dispatchers.Main).async {
|
||||||
intent,
|
val stopText = GlobalState.getText("stop")
|
||||||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
val intent = Intent(this@FlClashVpnService, MainActivity::class.java)
|
||||||
)
|
|
||||||
} else {
|
val pendingIntent = if (Build.VERSION.SDK_INT >= 31) {
|
||||||
PendingIntent.getActivity(
|
PendingIntent.getActivity(
|
||||||
this,
|
this@FlClashVpnService,
|
||||||
0,
|
0,
|
||||||
intent,
|
intent,
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT
|
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
||||||
)
|
)
|
||||||
}
|
} else {
|
||||||
with(NotificationCompat.Builder(this, CHANNEL)) {
|
PendingIntent.getActivity(
|
||||||
setSmallIcon(R.drawable.ic_stat_name)
|
this@FlClashVpnService,
|
||||||
setContentTitle("FlClash")
|
0,
|
||||||
setContentIntent(pendingIntent)
|
intent,
|
||||||
setCategory(NotificationCompat.CATEGORY_SERVICE)
|
PendingIntent.FLAG_UPDATE_CURRENT
|
||||||
priority = NotificationCompat.PRIORITY_MIN
|
)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
}
|
||||||
foregroundServiceBehavior = FOREGROUND_SERVICE_IMMEDIATE
|
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
setOngoing(true)
|
|
||||||
setShowWhen(false)
|
|
||||||
setOnlyAlertOnce(true)
|
|
||||||
setAutoCancel(true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun initServiceEngine() {
|
private suspend fun getNotificationBuilder(): NotificationCompat.Builder {
|
||||||
GlobalState.initServiceEngine(applicationContext)
|
return notificationBuilderDeferred.await()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTrimMemory(level: Int) {
|
@SuppressLint("ForegroundServiceType")
|
||||||
super.onTrimMemory(level)
|
override suspend fun startForeground(title: String, content: String) {
|
||||||
GlobalState.getCurrentAppPlugin()?.requestGc()
|
|
||||||
}
|
|
||||||
|
|
||||||
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 manager = getSystemService(NotificationManager::class.java)
|
val manager = getSystemService(NotificationManager::class.java)
|
||||||
var channel = manager?.getNotificationChannel(CHANNEL)
|
var channel = manager?.getNotificationChannel(CHANNEL)
|
||||||
@@ -155,18 +191,24 @@ class FlClashVpnService : VpnService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val notification =
|
val notification =
|
||||||
notificationBuilder.setContentTitle(title).setContentText(content).build()
|
getNotificationBuilder()
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
.setContentTitle(title)
|
||||||
startForeground(notificationId, notification, FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
|
.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 {
|
} else {
|
||||||
startForeground(notificationId, notification)
|
startForeground(notificationId, notification)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopForeground() {
|
override fun onTrimMemory(level: Int) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
super.onTrimMemory(level)
|
||||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
GlobalState.getCurrentVPNPlugin()?.requestGc()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val binder = LocalBinder()
|
private val binder = LocalBinder()
|
||||||
@@ -179,7 +221,7 @@ class FlClashVpnService : VpnService() {
|
|||||||
val isSuccess = super.onTransact(code, data, reply, flags)
|
val isSuccess = super.onTransact(code, data, reply, flags)
|
||||||
if (!isSuccess) {
|
if (!isSuccess) {
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
GlobalState.getCurrentTitlePlugin()?.handleStop()
|
GlobalState.getCurrentTilePlugin()?.handleStop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return isSuccess
|
return isSuccess
|
||||||
@@ -189,7 +231,6 @@ class FlClashVpnService : VpnService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onBind(intent: Intent): IBinder {
|
override fun onBind(intent: Intent): IBinder {
|
||||||
return binder
|
return binder
|
||||||
}
|
}
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 763 B After Width: | Height: | Size: 618 B |
|
Before Width: | Height: | Size: 520 B After Width: | Height: | Size: 423 B |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 803 B |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 1.6 KiB |
25
android/app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<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>
|
||||||
|
Before 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="@mipmap/ic_launcher_foreground"/>
|
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||||
<monochrome android:drawable="@mipmap/ic_launcher_foreground" />
|
<monochrome android:drawable="@drawable/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="@mipmap/ic_launcher_foreground"/>
|
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||||
<monochrome android:drawable="@mipmap/ic_launcher_foreground" />
|
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
</adaptive-icon>
|
</adaptive-icon>
|
||||||
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 886 B |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 7.1 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">@mipmap/ic_launcher_foreground</item>
|
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="s">@drawable/ic_launcher_foreground</item>
|
||||||
<item name="postSplashScreenTheme">@style/NormalTheme</item>
|
<item name="postSplashScreenTheme">@style/NormalTheme</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -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">@mipmap/ic_launcher_foreground</item>
|
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="s">@drawable/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">#EFEFEF</color>
|
<color name="ic_launcher_background">#FAFAFA</color>
|
||||||
</resources>
|
</resources>
|
||||||
6
android/app/src/main/res/xml/file_paths.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<paths>
|
||||||
|
<files-path
|
||||||
|
name="files"
|
||||||
|
path="."/>
|
||||||
|
</paths>
|
||||||
|
|
||||||
@@ -24,6 +24,7 @@ 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
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/build
|
||||||
65
android/core/build.gradle.kts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
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 = "28.0.13004108"
|
||||||
|
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val copyNativeLibs by tasks.register<Copy>("copyNativeLibs") {
|
||||||
|
doFirst {
|
||||||
|
delete("src/main/jniLibs")
|
||||||
|
}
|
||||||
|
from("../../libclash/android")
|
||||||
|
into("src/main/jniLibs")
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEvaluate {
|
||||||
|
tasks.named("preBuild") {
|
||||||
|
dependsOn(copyNativeLibs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("androidx.core:core-ktx:1.16.0")
|
||||||
|
}
|
||||||
21
android/core/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# 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
|
||||||
4
android/core/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
</manifest>
|
||||||
45
android/core/src/main/cpp/CMakeLists.txt
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.22.1)
|
||||||
|
|
||||||
|
project("core")
|
||||||
|
|
||||||
|
message("CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR}")
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
message("LIB_CLASH_PATH ${LIB_CLASH_PATH}")
|
||||||
|
if (EXISTS ${LIB_CLASH_PATH})
|
||||||
|
message("Found libclash.so for ABI ${ANDROID_ABI}")
|
||||||
|
add_compile_definitions(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 ()
|
||||||
|
message("Not found libclash.so for ABI ${ANDROID_ABI}")
|
||||||
|
add_library(${CMAKE_PROJECT_NAME} SHARED
|
||||||
|
jni_helper.cpp
|
||||||
|
core.cpp)
|
||||||
|
target_link_libraries(${CMAKE_PROJECT_NAME})
|
||||||
|
endif ()
|
||||||
75
android/core/src/main/cpp/core.cpp
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
70
android/core/src/main/cpp/jni_helper.cpp
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#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);
|
||||||
|
}
|
||||||
39
android/core/src/main/cpp/jni_helper.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#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)
|
||||||
50
android/core/src/main/java/com/follow/clash/core/Core.kt
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
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.2.1
|
agp_version=8.9.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.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip
|
||||||
|
|
||||||
|
|||||||
@@ -24,3 +24,4 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
include ":app"
|
include ":app"
|
||||||
|
include ':core'
|
||||||
|
|||||||
64257
assets/data/GeoSite.dat
BIN
assets/fonts/Icons.ttf
Normal file
BIN
assets/fonts/JetBrainsMono-Regular.ttf
Normal file
BIN
assets/fonts/Twemoji.Mozilla.ttf
Normal file
|
Before Width: | Height: | Size: 9.4 KiB |
BIN
assets/images/avatars/arue.jpg
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
assets/images/avatars/june2.jpg
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
assets/images/icon.ico
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
assets/images/icon.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
assets/images/icon_black.ico
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
assets/images/icon_black.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
assets/images/icon_white.ico
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
assets/images/icon_white.png
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 118 KiB |
@@ -5,6 +5,7 @@ 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
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
77
core/android_bride.go
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
//go:build android && cgo
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
typedef void (*release_object_func)(void *obj);
|
||||||
|
|
||||||
|
typedef void (*protect_func)(void *tun_interface, int fd);
|
||||||
|
|
||||||
|
typedef const char* (*resolve_process_func)(void *tun_interface, int protocol, const char *source, const char *target, int uid);
|
||||||
|
|
||||||
|
static void protect(protect_func fn, void *tun_interface, int fd) {
|
||||||
|
if (fn) {
|
||||||
|
fn(tun_interface, fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* resolve_process(resolve_process_func fn, void *tun_interface, int protocol, const char *source, const char *target, int uid) {
|
||||||
|
if (fn) {
|
||||||
|
return fn(tun_interface, protocol, source, target, uid);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void release_object(release_object_func fn, void *obj) {
|
||||||
|
if (fn) {
|
||||||
|
return fn(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
globalCallbacks struct {
|
||||||
|
releaseObjectFunc C.release_object_func
|
||||||
|
protectFunc C.protect_func
|
||||||
|
resolveProcessFunc C.resolve_process_func
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func protect(callback unsafe.Pointer, fd int) {
|
||||||
|
if globalCallbacks.protectFunc != nil {
|
||||||
|
C.protect(globalCallbacks.protectFunc, callback, C.int(fd))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func resolveProcess(callback unsafe.Pointer, protocol int, source, target string, uid int) string {
|
||||||
|
if globalCallbacks.resolveProcessFunc == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
s := C.CString(source)
|
||||||
|
defer C.free(unsafe.Pointer(s))
|
||||||
|
t := C.CString(target)
|
||||||
|
defer C.free(unsafe.Pointer(t))
|
||||||
|
res := C.resolve_process(globalCallbacks.resolveProcessFunc, callback, C.int(protocol), s, t, C.int(uid))
|
||||||
|
defer C.free(unsafe.Pointer(res))
|
||||||
|
return C.GoString(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func releaseObject(callback unsafe.Pointer) {
|
||||||
|
if globalCallbacks.releaseObjectFunc == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
C.release_object(globalCallbacks.releaseObjectFunc, callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
//export registerCallbacks
|
||||||
|
func registerCallbacks(markSocketFunc C.protect_func, resolveProcessFunc C.resolve_process_func, releaseObjectFunc C.release_object_func) {
|
||||||
|
globalCallbacks.protectFunc = markSocketFunc
|
||||||
|
globalCallbacks.resolveProcessFunc = resolveProcessFunc
|
||||||
|
globalCallbacks.releaseObjectFunc = releaseObjectFunc
|
||||||
|
}
|
||||||
527
core/common.go
@@ -1,125 +1,59 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "C"
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"github.com/metacubex/mihomo/adapter"
|
"github.com/metacubex/mihomo/adapter"
|
||||||
"github.com/metacubex/mihomo/adapter/inbound"
|
"github.com/metacubex/mihomo/adapter/inbound"
|
||||||
"github.com/metacubex/mihomo/adapter/outboundgroup"
|
"github.com/metacubex/mihomo/adapter/outboundgroup"
|
||||||
ap "github.com/metacubex/mihomo/adapter/provider"
|
"github.com/metacubex/mihomo/adapter/provider"
|
||||||
|
"github.com/metacubex/mihomo/common/batch"
|
||||||
"github.com/metacubex/mihomo/component/dialer"
|
"github.com/metacubex/mihomo/component/dialer"
|
||||||
"github.com/metacubex/mihomo/component/resolver"
|
"github.com/metacubex/mihomo/component/resolver"
|
||||||
"github.com/metacubex/mihomo/config"
|
"github.com/metacubex/mihomo/config"
|
||||||
"github.com/metacubex/mihomo/constant"
|
"github.com/metacubex/mihomo/constant"
|
||||||
|
"github.com/metacubex/mihomo/constant/features"
|
||||||
|
cp "github.com/metacubex/mihomo/constant/provider"
|
||||||
"github.com/metacubex/mihomo/hub"
|
"github.com/metacubex/mihomo/hub"
|
||||||
"github.com/metacubex/mihomo/hub/executor"
|
|
||||||
"github.com/metacubex/mihomo/hub/route"
|
"github.com/metacubex/mihomo/hub/route"
|
||||||
"github.com/metacubex/mihomo/listener"
|
"github.com/metacubex/mihomo/listener"
|
||||||
"github.com/metacubex/mihomo/log"
|
"github.com/metacubex/mihomo/log"
|
||||||
|
rp "github.com/metacubex/mihomo/rules/provider"
|
||||||
"github.com/metacubex/mihomo/tunnel"
|
"github.com/metacubex/mihomo/tunnel"
|
||||||
|
"github.com/samber/lo"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type healthCheckSchema struct {
|
func splitByMultipleSeparators(s string) interface{} {
|
||||||
Enable bool `provider:"enable"`
|
isSeparator := func(r rune) bool {
|
||||||
URL string `provider:"url"`
|
return r == ',' || r == ' ' || r == ';'
|
||||||
Interval int `provider:"interval"`
|
|
||||||
TestTimeout int `provider:"timeout,omitempty"`
|
|
||||||
Lazy bool `provider:"lazy,omitempty"`
|
|
||||||
ExpectedStatus string `provider:"expected-status,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type proxyProviderSchema struct {
|
|
||||||
Type string `provider:"type"`
|
|
||||||
Path string `provider:"path,omitempty"`
|
|
||||||
URL string `provider:"url,omitempty"`
|
|
||||||
Proxy string `provider:"proxy,omitempty"`
|
|
||||||
Interval int `provider:"interval,omitempty"`
|
|
||||||
Filter string `provider:"filter,omitempty"`
|
|
||||||
ExcludeFilter string `provider:"exclude-filter,omitempty"`
|
|
||||||
ExcludeType string `provider:"exclude-type,omitempty"`
|
|
||||||
DialerProxy string `provider:"dialer-proxy,omitempty"`
|
|
||||||
|
|
||||||
HealthCheck healthCheckSchema `provider:"health-check,omitempty"`
|
|
||||||
Override ap.OverrideSchema `provider:"override,omitempty"`
|
|
||||||
Header map[string][]string `provider:"header,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ruleProviderSchema struct {
|
|
||||||
Type string `provider:"type"`
|
|
||||||
Behavior string `provider:"behavior"`
|
|
||||||
Path string `provider:"path,omitempty"`
|
|
||||||
URL string `provider:"url,omitempty"`
|
|
||||||
Proxy string `provider:"proxy,omitempty"`
|
|
||||||
Format string `provider:"format,omitempty"`
|
|
||||||
Interval int `provider:"interval,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConfigExtendedParams struct {
|
|
||||||
IsPatch bool `json:"is-patch"`
|
|
||||||
IsCompatible bool `json:"is-compatible"`
|
|
||||||
SelectedMap map[string]string `json:"selected-map"`
|
|
||||||
TestURL *string `json:"test-url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GenerateConfigParams struct {
|
|
||||||
ProfilePath *string `json:"profile-path"`
|
|
||||||
Config config.RawConfig `json:"config" `
|
|
||||||
Params ConfigExtendedParams `json:"params"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ChangeProxyParams struct {
|
|
||||||
GroupName *string `json:"group-name"`
|
|
||||||
ProxyName *string `json:"proxy-name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TestDelayParams struct {
|
|
||||||
ProxyName string `json:"proxy-name"`
|
|
||||||
Timeout int64 `json:"timeout"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProcessMapItem struct {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
Value string `json:"value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ExternalProvider struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
VehicleType string `json:"vehicle-type"`
|
|
||||||
UpdateAt time.Time `json:"update-at"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func restartExecutable(execPath string) {
|
|
||||||
var err error
|
|
||||||
executor.Shutdown()
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
cmd := exec.Command(execPath, os.Args[1:]...)
|
|
||||||
log.Infoln("restarting: %q %q", execPath, os.Args[1:])
|
|
||||||
cmd.Stdin = os.Stdin
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
err = cmd.Start()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln("restarting: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infoln("restarting: %q %q", execPath, os.Args[1:])
|
parts := strings.FieldsFunc(s, isSeparator)
|
||||||
err = syscall.Exec(execPath, os.Args, os.Environ())
|
if len(parts) > 1 {
|
||||||
if err != nil {
|
return parts
|
||||||
log.Fatalln("restarting: %s", err)
|
|
||||||
}
|
}
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
version = 0
|
||||||
|
isRunning = false
|
||||||
|
runLock sync.Mutex
|
||||||
|
ips = []string{"ipwho.is", "api.ip.sb", "ipapi.co", "ipinfo.io"}
|
||||||
|
b, _ = batch.New[bool](context.Background(), batch.WithConcurrencyNum[bool](50))
|
||||||
|
)
|
||||||
|
|
||||||
|
type ExternalProviders []ExternalProvider
|
||||||
|
|
||||||
|
func (a ExternalProviders) Len() int { return len(a) }
|
||||||
|
func (a ExternalProviders) Less(i, j int) bool { return a[i].Name < a[j].Name }
|
||||||
|
func (a ExternalProviders) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
|
|
||||||
func readFile(path string) ([]byte, error) {
|
func readFile(path string) ([]byte, error) {
|
||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -132,187 +66,155 @@ func readFile(path string) ([]byte, error) {
|
|||||||
return data, err
|
return data, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeFile(path string) error {
|
func getProfilePath(id string) string {
|
||||||
absPath, err := filepath.Abs(path)
|
return filepath.Join(constant.Path.HomeDir(), "profiles", id+".yaml")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = os.Remove(absPath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRawConfigWithPath(path *string) *config.RawConfig {
|
func getProfileProvidersPath(id string) string {
|
||||||
if path == nil {
|
return filepath.Join(constant.Path.HomeDir(), "providers", id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRawConfigWithId(id string) *config.RawConfig {
|
||||||
|
path := getProfilePath(id)
|
||||||
|
bytes, err := readFile(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln("profile is not exist")
|
||||||
return config.DefaultRawConfig()
|
return config.DefaultRawConfig()
|
||||||
} else {
|
}
|
||||||
bytes, err := readFile(*path)
|
prof, err := config.UnmarshalRawConfig(bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("getProfile readFile error %v", err)
|
log.Errorln("unmarshalRawConfig error %v", err)
|
||||||
return config.DefaultRawConfig()
|
return config.DefaultRawConfig()
|
||||||
|
}
|
||||||
|
for _, mapping := range prof.ProxyProvider {
|
||||||
|
value, exist := mapping["path"].(string)
|
||||||
|
if !exist {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
prof, err := config.UnmarshalRawConfig(bytes)
|
mapping["path"] = filepath.Join(getProfileProvidersPath(id), value)
|
||||||
if err != nil {
|
}
|
||||||
log.Errorln("getProfile UnmarshalRawConfig error %v", err)
|
for _, mapping := range prof.RuleProvider {
|
||||||
return config.DefaultRawConfig()
|
value, exist := mapping["path"].(string)
|
||||||
|
if !exist {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
return prof
|
mapping["path"] = filepath.Join(getProfileProvidersPath(id), value)
|
||||||
|
}
|
||||||
|
return prof
|
||||||
|
}
|
||||||
|
|
||||||
|
func getExternalProvidersRaw() map[string]cp.Provider {
|
||||||
|
eps := make(map[string]cp.Provider)
|
||||||
|
for n, p := range tunnel.Providers() {
|
||||||
|
if p.VehicleType() != cp.Compatible {
|
||||||
|
eps[n] = p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for n, p := range tunnel.RuleProviders() {
|
||||||
|
if p.VehicleType() != cp.Compatible {
|
||||||
|
eps[n] = p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return eps
|
||||||
|
}
|
||||||
|
|
||||||
|
func toExternalProvider(p cp.Provider) (*ExternalProvider, error) {
|
||||||
|
switch p.(type) {
|
||||||
|
case *provider.ProxySetProvider:
|
||||||
|
psp := p.(*provider.ProxySetProvider)
|
||||||
|
return &ExternalProvider{
|
||||||
|
Name: psp.Name(),
|
||||||
|
Type: psp.Type().String(),
|
||||||
|
VehicleType: psp.VehicleType().String(),
|
||||||
|
Count: psp.Count(),
|
||||||
|
UpdateAt: psp.UpdatedAt(),
|
||||||
|
Path: psp.Vehicle().Path(),
|
||||||
|
SubscriptionInfo: psp.GetSubscriptionInfo(),
|
||||||
|
}, nil
|
||||||
|
case *rp.RuleSetProvider:
|
||||||
|
rsp := p.(*rp.RuleSetProvider)
|
||||||
|
return &ExternalProvider{
|
||||||
|
Name: rsp.Name(),
|
||||||
|
Type: rsp.Type().String(),
|
||||||
|
VehicleType: rsp.VehicleType().String(),
|
||||||
|
Count: rsp.Count(),
|
||||||
|
UpdateAt: rsp.UpdatedAt(),
|
||||||
|
Path: rsp.Vehicle().Path(),
|
||||||
|
}, nil
|
||||||
|
default:
|
||||||
|
return nil, errors.New("not external provider")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func decorationConfig(profilePath *string, cfg config.RawConfig) *config.RawConfig {
|
func sideUpdateExternalProvider(p cp.Provider, bytes []byte) error {
|
||||||
prof := getRawConfigWithPath(profilePath)
|
switch p.(type) {
|
||||||
|
case *provider.ProxySetProvider:
|
||||||
|
psp := p.(*provider.ProxySetProvider)
|
||||||
|
_, _, err := psp.SideUpdate(bytes)
|
||||||
|
if err == nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
case rp.RuleSetProvider:
|
||||||
|
rsp := p.(*rp.RuleSetProvider)
|
||||||
|
_, _, err := rsp.SideUpdate(bytes)
|
||||||
|
if err == nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
return errors.New("not external provider")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func decorationConfig(profileId string, cfg config.RawConfig) *config.RawConfig {
|
||||||
|
prof := getRawConfigWithId(profileId)
|
||||||
overwriteConfig(prof, cfg)
|
overwriteConfig(prof, cfg)
|
||||||
return prof
|
return prof
|
||||||
}
|
}
|
||||||
|
|
||||||
func Reduce[T any, U any](s []T, initVal U, f func(U, T) U) U {
|
func attachHosts(hosts, patchHosts map[string]any) {
|
||||||
for _, v := range s {
|
for k, v := range patchHosts {
|
||||||
initVal = f(initVal, v)
|
if str, ok := v.(string); ok {
|
||||||
}
|
hosts[k] = splitByMultipleSeparators(str)
|
||||||
return initVal
|
|
||||||
}
|
|
||||||
|
|
||||||
func Map[T, U any](slice []T, fn func(T) U) []U {
|
|
||||||
result := make([]U, len(slice))
|
|
||||||
for i, v := range slice {
|
|
||||||
result[i] = fn(v)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func replaceFromMap(s string, m map[string]string) string {
|
|
||||||
for k, v := range m {
|
|
||||||
s = strings.ReplaceAll(s, k, v)
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeDuplicateFromSlice[T any](slice []T) []T {
|
|
||||||
result := make([]T, 0)
|
|
||||||
seen := make(map[any]struct{})
|
|
||||||
for _, value := range slice {
|
|
||||||
if _, ok := seen[value]; !ok {
|
|
||||||
result = append(result, value)
|
|
||||||
seen[value] = struct{}{}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateProxyGroupAndRule(proxyGroup *[]map[string]any, rule *[]string) {
|
func updatePatchDns(dns config.RawDNS) {
|
||||||
var replacements = map[string]string{}
|
for pair := dns.NameServerPolicy.Oldest(); pair != nil; pair = pair.Next() {
|
||||||
var selectArr []map[string]any
|
if str, ok := pair.Value.(string); ok {
|
||||||
var urlTestArr []map[string]any
|
dns.NameServerPolicy.Set(pair.Key, splitByMultipleSeparators(str))
|
||||||
var fallbackArr []map[string]any
|
}
|
||||||
for _, group := range *proxyGroup {
|
}
|
||||||
switch group["type"] {
|
}
|
||||||
case "select":
|
|
||||||
selectArr = append(selectArr, group)
|
func trimArr(arr []string) (r []string) {
|
||||||
replacements[group["name"].(string)] = "Proxy"
|
for _, e := range arr {
|
||||||
break
|
r = append(r, strings.Trim(e, " "))
|
||||||
case "url-test":
|
}
|
||||||
urlTestArr = append(urlTestArr, group)
|
return
|
||||||
replacements[group["name"].(string)] = "Auto"
|
}
|
||||||
break
|
|
||||||
case "fallback":
|
func overrideRules(rules, patchRules []string) []string {
|
||||||
fallbackArr = append(fallbackArr, group)
|
target := ""
|
||||||
replacements[group["name"].(string)] = "Fallback"
|
for _, line := range rules {
|
||||||
break
|
rule := trimArr(strings.Split(line, ","))
|
||||||
default:
|
if len(rule) != 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.EqualFold(rule[0], "MATCH") {
|
||||||
|
target = rule[1]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if target == "" {
|
||||||
ProxyProxies := Reduce(selectArr, []string{}, func(res []string, cur map[string]any) []string {
|
return rules
|
||||||
if cur["proxies"] == nil {
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
for _, proxyName := range cur["proxies"].([]interface{}) {
|
|
||||||
if str, ok := proxyName.(string); ok {
|
|
||||||
str = replaceFromMap(str, replacements)
|
|
||||||
if str != "Proxy" {
|
|
||||||
res = append(res, str)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
})
|
|
||||||
|
|
||||||
ProxyProxies = removeDuplicateFromSlice(ProxyProxies)
|
|
||||||
|
|
||||||
AutoProxies := Reduce(urlTestArr, []string{}, func(res []string, cur map[string]any) []string {
|
|
||||||
if cur["proxies"] == nil {
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
for _, proxyName := range cur["proxies"].([]interface{}) {
|
|
||||||
if str, ok := proxyName.(string); ok {
|
|
||||||
str = replaceFromMap(str, replacements)
|
|
||||||
if str != "Auto" {
|
|
||||||
res = append(res, str)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
})
|
|
||||||
|
|
||||||
AutoProxies = removeDuplicateFromSlice(AutoProxies)
|
|
||||||
|
|
||||||
FallbackProxies := Reduce(fallbackArr, []string{}, func(res []string, cur map[string]any) []string {
|
|
||||||
if cur["proxies"] == nil {
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
for _, proxyName := range cur["proxies"].([]interface{}) {
|
|
||||||
if str, ok := proxyName.(string); ok {
|
|
||||||
str = replaceFromMap(str, replacements)
|
|
||||||
if str != "Fallback" {
|
|
||||||
res = append(res, str)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
})
|
|
||||||
|
|
||||||
FallbackProxies = removeDuplicateFromSlice(FallbackProxies)
|
|
||||||
|
|
||||||
var computedProxyGroup []map[string]any
|
|
||||||
|
|
||||||
if len(ProxyProxies) > 0 {
|
|
||||||
computedProxyGroup = append(computedProxyGroup,
|
|
||||||
map[string]any{
|
|
||||||
"name": "Proxy",
|
|
||||||
"type": "select",
|
|
||||||
"proxies": ProxyProxies,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
rulesExt := lo.Map(ips, func(ip string, _ int) string {
|
||||||
if len(AutoProxies) > 0 {
|
return fmt.Sprintf("DOMAIN,%s,%s", ip, target)
|
||||||
computedProxyGroup = append(computedProxyGroup,
|
|
||||||
map[string]any{
|
|
||||||
"name": "Auto",
|
|
||||||
"type": "url-test",
|
|
||||||
"proxies": AutoProxies,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(FallbackProxies) > 0 {
|
|
||||||
computedProxyGroup = append(computedProxyGroup,
|
|
||||||
map[string]any{
|
|
||||||
"name": "Fallback",
|
|
||||||
"type": "fallback",
|
|
||||||
"proxies": FallbackProxies,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
computedRule := Map(*rule, func(value string) string {
|
|
||||||
return replaceFromMap(value, replacements)
|
|
||||||
})
|
})
|
||||||
|
return append(append(rulesExt, patchRules...), rules...)
|
||||||
*proxyGroup = computedProxyGroup
|
|
||||||
*rule = computedRule
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func overwriteConfig(targetConfig *config.RawConfig, patchConfig config.RawConfig) {
|
func overwriteConfig(targetConfig *config.RawConfig, patchConfig config.RawConfig) {
|
||||||
@@ -322,11 +224,11 @@ func overwriteConfig(targetConfig *config.RawConfig, patchConfig config.RawConfi
|
|||||||
targetConfig.ExternalUIURL = ""
|
targetConfig.ExternalUIURL = ""
|
||||||
targetConfig.TCPConcurrent = patchConfig.TCPConcurrent
|
targetConfig.TCPConcurrent = patchConfig.TCPConcurrent
|
||||||
targetConfig.UnifiedDelay = patchConfig.UnifiedDelay
|
targetConfig.UnifiedDelay = patchConfig.UnifiedDelay
|
||||||
//targetConfig.GeodataMode = false
|
|
||||||
targetConfig.IPv6 = patchConfig.IPv6
|
targetConfig.IPv6 = patchConfig.IPv6
|
||||||
targetConfig.LogLevel = patchConfig.LogLevel
|
targetConfig.LogLevel = patchConfig.LogLevel
|
||||||
targetConfig.Port = 0
|
targetConfig.Port = 0
|
||||||
targetConfig.SocksPort = 0
|
targetConfig.SocksPort = 0
|
||||||
|
targetConfig.KeepAliveInterval = patchConfig.KeepAliveInterval
|
||||||
targetConfig.MixedPort = patchConfig.MixedPort
|
targetConfig.MixedPort = patchConfig.MixedPort
|
||||||
targetConfig.FindProcessMode = patchConfig.FindProcessMode
|
targetConfig.FindProcessMode = patchConfig.FindProcessMode
|
||||||
targetConfig.AllowLan = patchConfig.AllowLan
|
targetConfig.AllowLan = patchConfig.AllowLan
|
||||||
@@ -335,52 +237,94 @@ func overwriteConfig(targetConfig *config.RawConfig, patchConfig config.RawConfi
|
|||||||
targetConfig.Tun.Device = patchConfig.Tun.Device
|
targetConfig.Tun.Device = patchConfig.Tun.Device
|
||||||
targetConfig.Tun.DNSHijack = patchConfig.Tun.DNSHijack
|
targetConfig.Tun.DNSHijack = patchConfig.Tun.DNSHijack
|
||||||
targetConfig.Tun.Stack = patchConfig.Tun.Stack
|
targetConfig.Tun.Stack = patchConfig.Tun.Stack
|
||||||
|
targetConfig.Tun.RouteAddress = patchConfig.Tun.RouteAddress
|
||||||
targetConfig.GeodataLoader = patchConfig.GeodataLoader
|
targetConfig.GeodataLoader = patchConfig.GeodataLoader
|
||||||
targetConfig.Profile.StoreSelected = false
|
targetConfig.Profile.StoreSelected = false
|
||||||
targetConfig.GeoXUrl = patchConfig.GeoXUrl
|
targetConfig.GeoXUrl = patchConfig.GeoXUrl
|
||||||
targetConfig.GlobalUA = patchConfig.GlobalUA
|
targetConfig.GlobalUA = patchConfig.GlobalUA
|
||||||
if targetConfig.DNS.Enable == false {
|
if configParams.TestURL != nil {
|
||||||
targetConfig.DNS = patchConfig.DNS
|
constant.DefaultTestURL = *configParams.TestURL
|
||||||
}
|
}
|
||||||
//if runtime.GOOS == "android" {
|
for idx := range targetConfig.ProxyGroup {
|
||||||
// targetConfig.DNS.NameServer = append(targetConfig.DNS.NameServer, "dhcp://"+dns.SystemDNSPlaceholder)
|
targetConfig.ProxyGroup[idx]["url"] = ""
|
||||||
//} else if runtime.GOOS == "windows" {
|
}
|
||||||
// targetConfig.DNS.NameServer = append(targetConfig.DNS.NameServer, dns.SystemDNSPlaceholder)
|
attachHosts(targetConfig.Hosts, patchConfig.Hosts)
|
||||||
//}
|
if configParams.OverrideDns {
|
||||||
if configParams.IsCompatible == false {
|
updatePatchDns(patchConfig.DNS)
|
||||||
targetConfig.ProxyProvider = make(map[string]map[string]any)
|
targetConfig.DNS = patchConfig.DNS
|
||||||
targetConfig.RuleProvider = make(map[string]map[string]any)
|
} else {
|
||||||
generateProxyGroupAndRule(&targetConfig.ProxyGroup, &targetConfig.Rule)
|
if targetConfig.DNS.Enable == false {
|
||||||
|
targetConfig.DNS.Enable = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if configParams.OverrideRule {
|
||||||
|
targetConfig.Rule = overrideRules(patchConfig.Rule, []string{})
|
||||||
|
} else {
|
||||||
|
targetConfig.Rule = overrideRules(targetConfig.Rule, patchConfig.Rule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func patchConfig(general *config.General) {
|
func patchConfig() {
|
||||||
log.Infoln("[Apply] patch")
|
log.Infoln("[Apply] patch")
|
||||||
route.ReStartServer(general.ExternalController)
|
general := currentConfig.General
|
||||||
listener.SetAllowLan(general.AllowLan)
|
controller := currentConfig.Controller
|
||||||
inbound.SetSkipAuthPrefixes(general.SkipAuthPrefixes)
|
tls := currentConfig.TLS
|
||||||
inbound.SetAllowedIPs(general.LanAllowedIPs)
|
|
||||||
inbound.SetDisAllowedIPs(general.LanDisAllowedIPs)
|
|
||||||
listener.SetBindAddress(general.BindAddress)
|
|
||||||
tunnel.SetSniffing(general.Sniffing)
|
tunnel.SetSniffing(general.Sniffing)
|
||||||
tunnel.SetFindProcessMode(general.FindProcessMode)
|
tunnel.SetFindProcessMode(general.FindProcessMode)
|
||||||
dialer.SetTcpConcurrent(general.TCPConcurrent)
|
dialer.SetTcpConcurrent(general.TCPConcurrent)
|
||||||
dialer.DefaultInterface.Store(general.Interface)
|
dialer.DefaultInterface.Store(general.Interface)
|
||||||
adapter.UnifiedDelay.Store(general.UnifiedDelay)
|
adapter.UnifiedDelay.Store(general.UnifiedDelay)
|
||||||
|
tunnel.SetMode(general.Mode)
|
||||||
|
log.SetLevel(general.LogLevel)
|
||||||
|
resolver.DisableIPv6 = !general.IPv6
|
||||||
|
|
||||||
|
route.ReCreateServer(&route.Config{
|
||||||
|
Addr: controller.ExternalController,
|
||||||
|
TLSAddr: controller.ExternalControllerTLS,
|
||||||
|
UnixAddr: controller.ExternalControllerUnix,
|
||||||
|
PipeAddr: controller.ExternalControllerPipe,
|
||||||
|
Secret: controller.Secret,
|
||||||
|
Certificate: tls.Certificate,
|
||||||
|
PrivateKey: tls.PrivateKey,
|
||||||
|
DohServer: controller.ExternalDohServer,
|
||||||
|
IsDebug: false,
|
||||||
|
Cors: route.Cors{
|
||||||
|
AllowOrigins: controller.Cors.AllowOrigins,
|
||||||
|
AllowPrivateNetwork: controller.Cors.AllowPrivateNetwork,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateListeners(force bool) {
|
||||||
|
if !isRunning {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
general := currentConfig.General
|
||||||
|
listeners := currentConfig.Listeners
|
||||||
|
if force == true {
|
||||||
|
stopListeners()
|
||||||
|
}
|
||||||
|
listener.PatchInboundListeners(listeners, tunnel.Tunnel, true)
|
||||||
|
listener.SetAllowLan(general.AllowLan)
|
||||||
|
inbound.SetSkipAuthPrefixes(general.SkipAuthPrefixes)
|
||||||
|
inbound.SetAllowedIPs(general.LanAllowedIPs)
|
||||||
|
inbound.SetDisAllowedIPs(general.LanDisAllowedIPs)
|
||||||
|
listener.SetBindAddress(general.BindAddress)
|
||||||
listener.ReCreateHTTP(general.Port, tunnel.Tunnel)
|
listener.ReCreateHTTP(general.Port, tunnel.Tunnel)
|
||||||
listener.ReCreateSocks(general.SocksPort, tunnel.Tunnel)
|
listener.ReCreateSocks(general.SocksPort, tunnel.Tunnel)
|
||||||
listener.ReCreateRedir(general.RedirPort, tunnel.Tunnel)
|
listener.ReCreateRedir(general.RedirPort, tunnel.Tunnel)
|
||||||
listener.ReCreateAutoRedir(general.EBpf.AutoRedir, tunnel.Tunnel)
|
|
||||||
listener.ReCreateTProxy(general.TProxyPort, tunnel.Tunnel)
|
listener.ReCreateTProxy(general.TProxyPort, tunnel.Tunnel)
|
||||||
listener.ReCreateTun(general.Tun, tunnel.Tunnel)
|
|
||||||
listener.ReCreateMixed(general.MixedPort, tunnel.Tunnel)
|
listener.ReCreateMixed(general.MixedPort, tunnel.Tunnel)
|
||||||
listener.ReCreateShadowSocks(general.ShadowSocksConfig, tunnel.Tunnel)
|
listener.ReCreateShadowSocks(general.ShadowSocksConfig, tunnel.Tunnel)
|
||||||
listener.ReCreateVmess(general.VmessConfig, tunnel.Tunnel)
|
listener.ReCreateVmess(general.VmessConfig, tunnel.Tunnel)
|
||||||
listener.ReCreateTuic(general.TuicServer, tunnel.Tunnel)
|
listener.ReCreateTuic(general.TuicServer, tunnel.Tunnel)
|
||||||
tunnel.SetMode(general.Mode)
|
if !features.Android {
|
||||||
log.SetLevel(general.LogLevel)
|
listener.ReCreateTun(general.Tun, tunnel.Tunnel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
resolver.DisableIPv6 = !general.IPv6
|
func stopListeners() {
|
||||||
|
listener.StopListener()
|
||||||
}
|
}
|
||||||
|
|
||||||
func patchSelectGroup() {
|
func patchSelectGroup() {
|
||||||
@@ -408,23 +352,20 @@ func patchSelectGroup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var applyLock sync.Mutex
|
func applyConfig(rawConfig *config.RawConfig) error {
|
||||||
|
runLock.Lock()
|
||||||
func applyConfig() {
|
defer runLock.Unlock()
|
||||||
applyLock.Lock()
|
var err error
|
||||||
defer applyLock.Unlock()
|
currentConfig, err = config.ParseRawConfig(rawConfig)
|
||||||
cfg, err := config.ParseRawConfig(currentConfig)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cfg, _ = config.ParseRawConfig(config.DefaultRawConfig())
|
currentConfig, _ = config.ParseRawConfig(config.DefaultRawConfig())
|
||||||
}
|
|
||||||
if configParams.TestURL != nil {
|
|
||||||
constant.DefaultTestURL = *configParams.TestURL
|
|
||||||
}
|
}
|
||||||
if configParams.IsPatch {
|
if configParams.IsPatch {
|
||||||
patchConfig(cfg.General)
|
patchConfig()
|
||||||
} else {
|
} else {
|
||||||
runtime.GC()
|
hub.ApplyConfig(currentConfig)
|
||||||
hub.UltraApplyConfig(cfg, true)
|
|
||||||
patchSelectGroup()
|
patchSelectGroup()
|
||||||
}
|
}
|
||||||
|
updateListeners(false)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
112
core/constant.go
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/metacubex/mihomo/adapter/provider"
|
||||||
|
"github.com/metacubex/mihomo/config"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type InitParams struct {
|
||||||
|
HomeDir string `json:"home-dir"`
|
||||||
|
Version int `json:"version"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ConfigExtendedParams struct {
|
||||||
|
IsPatch bool `json:"is-patch"`
|
||||||
|
IsCompatible bool `json:"is-compatible"`
|
||||||
|
SelectedMap map[string]string `json:"selected-map"`
|
||||||
|
TestURL *string `json:"test-url"`
|
||||||
|
OverrideDns bool `json:"override-dns"`
|
||||||
|
OverrideRule bool `json:"override-rule"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GenerateConfigParams struct {
|
||||||
|
ProfileId string `json:"profile-id"`
|
||||||
|
Config config.RawConfig `json:"config" `
|
||||||
|
Params ConfigExtendedParams `json:"params"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ChangeProxyParams struct {
|
||||||
|
GroupName *string `json:"group-name"`
|
||||||
|
ProxyName *string `json:"proxy-name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestDelayParams struct {
|
||||||
|
ProxyName string `json:"proxy-name"`
|
||||||
|
TestUrl string `json:"test-url"`
|
||||||
|
Timeout int64 `json:"timeout"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ExternalProvider struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
VehicleType string `json:"vehicle-type"`
|
||||||
|
Count int `json:"count"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
UpdateAt time.Time `json:"update-at"`
|
||||||
|
SubscriptionInfo *provider.SubscriptionInfo `json:"subscription-info"`
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
messageMethod Method = "message"
|
||||||
|
initClashMethod Method = "initClash"
|
||||||
|
getIsInitMethod Method = "getIsInit"
|
||||||
|
forceGcMethod Method = "forceGc"
|
||||||
|
shutdownMethod Method = "shutdown"
|
||||||
|
validateConfigMethod Method = "validateConfig"
|
||||||
|
updateConfigMethod Method = "updateConfig"
|
||||||
|
getProxiesMethod Method = "getProxies"
|
||||||
|
changeProxyMethod Method = "changeProxy"
|
||||||
|
getTrafficMethod Method = "getTraffic"
|
||||||
|
getTotalTrafficMethod Method = "getTotalTraffic"
|
||||||
|
resetTrafficMethod Method = "resetTraffic"
|
||||||
|
asyncTestDelayMethod Method = "asyncTestDelay"
|
||||||
|
getConnectionsMethod Method = "getConnections"
|
||||||
|
closeConnectionsMethod Method = "closeConnections"
|
||||||
|
closeConnectionMethod Method = "closeConnection"
|
||||||
|
getExternalProvidersMethod Method = "getExternalProviders"
|
||||||
|
getExternalProviderMethod Method = "getExternalProvider"
|
||||||
|
getCountryCodeMethod Method = "getCountryCode"
|
||||||
|
getMemoryMethod Method = "getMemory"
|
||||||
|
updateGeoDataMethod Method = "updateGeoData"
|
||||||
|
updateExternalProviderMethod Method = "updateExternalProvider"
|
||||||
|
sideLoadExternalProviderMethod Method = "sideLoadExternalProvider"
|
||||||
|
startLogMethod Method = "startLog"
|
||||||
|
stopLogMethod Method = "stopLog"
|
||||||
|
startListenerMethod Method = "startListener"
|
||||||
|
stopListenerMethod Method = "stopListener"
|
||||||
|
updateDnsMethod Method = "updateDns"
|
||||||
|
setStateMethod Method = "setState"
|
||||||
|
getAndroidVpnOptionsMethod Method = "getAndroidVpnOptions"
|
||||||
|
getRunTimeMethod Method = "getRunTime"
|
||||||
|
getCurrentProfileNameMethod Method = "getCurrentProfileName"
|
||||||
|
getProfileMethod Method = "getProfile"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Method string
|
||||||
|
|
||||||
|
type MessageType string
|
||||||
|
|
||||||
|
type Delay struct {
|
||||||
|
Url string `json:"url"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Value int32 `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Message struct {
|
||||||
|
Type MessageType `json:"type"`
|
||||||
|
Data interface{} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
LogMessage MessageType = "log"
|
||||||
|
DelayMessage MessageType = "delay"
|
||||||
|
RequestMessage MessageType = "request"
|
||||||
|
LoadedMessage MessageType = "loaded"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (message *Message) Json() (string, error) {
|
||||||
|
data, err := json.Marshal(message)
|
||||||
|
return string(data), err
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
//go:build cgo
|
||||||
|
|
||||||
package dart_bridge
|
package dart_bridge
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||