mirror of
https://github.com/wgtunnel/android.git
synced 2026-07-03 14:07:49 +02:00
Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d30b9a742 | |||
| 2e98878814 | |||
| 77aa2c30d7 | |||
| e773238e6b | |||
| 85316bec3f | |||
| 1935653309 | |||
| e3e24b4a06 | |||
| 7af53dcc18 | |||
| 2eb0ab0f19 | |||
| 07857a53c2 | |||
| 25fd31e252 | |||
| 0c90b33813 | |||
| e6671fd3b4 | |||
| 735e38e989 | |||
| 90698c2b17 | |||
| 245b8ee3e7 | |||
| 343554407a | |||
| b493d83730 | |||
| 53cd717340 | |||
| 76574e3dd2 | |||
| 282a752389 | |||
| 5aa9145361 | |||
| 586726c848 | |||
| af759a3909 | |||
| b467d66554 | |||
| c833e15c8f | |||
| eec1bbd2f6 |
@@ -1,4 +1,6 @@
|
|||||||
name: Build
|
name: build
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
@@ -20,7 +22,7 @@ on:
|
|||||||
default: fdroid
|
default: fdroid
|
||||||
options:
|
options:
|
||||||
- fdroid
|
- fdroid
|
||||||
- full
|
- standalone
|
||||||
secrets:
|
secrets:
|
||||||
SIGNING_KEY_ALIAS:
|
SIGNING_KEY_ALIAS:
|
||||||
required: false
|
required: false
|
||||||
@@ -94,10 +96,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
store_path=${{ env.KEY_STORE_LOCATION }}${{ env.KEY_STORE_FILE }}
|
store_path=${{ env.KEY_STORE_LOCATION }}${{ env.KEY_STORE_FILE }}
|
||||||
echo "KEY_STORE_PATH=$store_path" >> $GITHUB_ENV
|
echo "KEY_STORE_PATH=$store_path" >> $GITHUB_ENV
|
||||||
- name: Create service_account.json
|
|
||||||
if: ${{ inputs.build_type != 'debug' }}
|
|
||||||
id: createServiceAccount
|
|
||||||
run: echo '${{ secrets.SERVICE_ACCOUNT_JSON }}' > service_account.json
|
|
||||||
- name: Build APK
|
- name: Build APK
|
||||||
run: |
|
run: |
|
||||||
flavor=${{ inputs.flavor }}
|
flavor=${{ inputs.flavor }}
|
||||||
@@ -119,9 +118,10 @@ jobs:
|
|||||||
- name: Get release apk path
|
- name: Get release apk path
|
||||||
id: apk-path
|
id: apk-path
|
||||||
run: echo "path=$(find . -regex '^.*/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/.*\.apk$' -type f | head -1 | tail -c+2)" >> $GITHUB_OUTPUT
|
run: echo "path=$(find . -regex '^.*/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/.*\.apk$' -type f | head -1 | tail -c+2)" >> $GITHUB_OUTPUT
|
||||||
- name: Upload release apk
|
- name: Upload APK
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ env.UPLOAD_DIR_ANDROID }}
|
name: android_artifacts_${{ inputs.flavor }}
|
||||||
path: ${{ github.workspace }}/${{ steps.apk-path.outputs.path }}
|
path: app/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/wgtunnel-${{ inputs.flavor }}${{ inputs.flavor == 'fdroid' && '-release' || '' }}-*.apk
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
if-no-files-found: warn
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
name: nightly
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: "4 3 * * *"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check_commits:
|
||||||
|
name: Check for New Commits
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
has_new_commits: ${{ steps.check.outputs.new_commits }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Check for new commits
|
||||||
|
id: check
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.PAT }}
|
||||||
|
run: |
|
||||||
|
NEW_COMMITS=$(git rev-list --count --after="$(date -Iseconds -d '23 hours ago')" ${{ github.sha }})
|
||||||
|
echo "new_commits=$NEW_COMMITS" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
build-standalone-nightly:
|
||||||
|
uses: ./.github/workflows/build.yml
|
||||||
|
secrets: inherit
|
||||||
|
with:
|
||||||
|
build_type: "nightly"
|
||||||
|
flavor: standalone
|
||||||
|
|
||||||
|
publish:
|
||||||
|
needs:
|
||||||
|
- check_commits
|
||||||
|
- build-standalone-nightly
|
||||||
|
if: ${{ needs.check_commits.outputs.has_new_commits > 0 && inputs.release_type != 'none' }}
|
||||||
|
name: publish-nightly
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install system dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt update && sudo apt install -y gh apksigner
|
||||||
|
- name: Set latest tag
|
||||||
|
uses: rickstaa/action-create-tag@v1
|
||||||
|
id: tag_creation
|
||||||
|
with:
|
||||||
|
tag: "latest"
|
||||||
|
message: "Automated tag for HEAD commit"
|
||||||
|
force_push_tag: true
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
tag_exists_error: false
|
||||||
|
|
||||||
|
- name: Generate Changelog
|
||||||
|
id: changelog
|
||||||
|
uses: requarks/changelog-action@v1
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
toTag: "nightly"
|
||||||
|
fromTag: "latest"
|
||||||
|
writeToFile: false
|
||||||
|
|
||||||
|
- name: Make download dir
|
||||||
|
run: mkdir ${{ github.workspace }}/temp
|
||||||
|
|
||||||
|
- name: Download artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
pattern: android_artifacts_*
|
||||||
|
path: ${{ github.workspace }}/temp
|
||||||
|
|
||||||
|
- name: Set release notes
|
||||||
|
run: |
|
||||||
|
echo "RELEASE_NOTES=Nightly build for the latest development version of the app." >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Delete previous nightly version
|
||||||
|
uses: ClementTsang/delete-tag-and-release@v0.4.0
|
||||||
|
with:
|
||||||
|
tag_name: "nightly"
|
||||||
|
delete_release: true
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Get checksum
|
||||||
|
id: checksum
|
||||||
|
run: |
|
||||||
|
file_path=$(find ${{ github.workspace }}/temp -type f -iname "*.apk" | head -n 1)
|
||||||
|
if [ -z "$file_path" ]; then
|
||||||
|
echo "No APK file found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
checksum=$(apksigner verify --print-certs "$file_path" | grep -Po "(?<=SHA-256 digest:) .*" | tr -d "[:blank:]")
|
||||||
|
echo "checksum=$checksum" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Create nightly release
|
||||||
|
id: create_release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
body: |
|
||||||
|
${{ env.RELEASE_NOTES }}
|
||||||
|
|
||||||
|
SHA-256 fingerprints for the 4096-bit signing certificate:
|
||||||
|
```sh
|
||||||
|
${{ steps.checksum.outputs.checksum }}
|
||||||
|
```
|
||||||
|
|
||||||
|
To verify fingerprint:
|
||||||
|
```sh
|
||||||
|
apksigner verify --print-certs [path to APK file] | grep SHA-256
|
||||||
|
```
|
||||||
|
|
||||||
|
### Changelog
|
||||||
|
${{ steps.changelog.outputs.changes }}
|
||||||
|
tag_name: nightly
|
||||||
|
name: nightly
|
||||||
|
draft: false
|
||||||
|
prerelease: true
|
||||||
|
make_latest: false
|
||||||
|
files: |
|
||||||
|
${{ github.workspace }}/temp/**/*.apk
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
name: on-pr
|
name: on-pr
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|||||||
+100
-77
@@ -1,8 +1,9 @@
|
|||||||
name: publish
|
name: publish
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
packages: write
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
|
||||||
- cron: "4 3 * * *"
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
track:
|
track:
|
||||||
@@ -22,95 +23,60 @@ on:
|
|||||||
options:
|
options:
|
||||||
- none
|
- none
|
||||||
- prerelease
|
- prerelease
|
||||||
- nightly
|
|
||||||
- release
|
- release
|
||||||
default: release
|
default: release
|
||||||
required: true
|
required: true
|
||||||
tag_name:
|
tag_name:
|
||||||
description: "Tag name for release"
|
description: "Tag name for release"
|
||||||
required: false
|
required: false
|
||||||
default: nightly
|
default: 1.1.1
|
||||||
flavor:
|
flavor:
|
||||||
type: choice
|
type: choice
|
||||||
description: "Product flavor"
|
description: "Product flavor"
|
||||||
required: true
|
required: true
|
||||||
default: full
|
default: standalone
|
||||||
options:
|
options:
|
||||||
- fdroid
|
- fdroid
|
||||||
- full
|
- standalone
|
||||||
workflow_call:
|
workflow_call:
|
||||||
inputs:
|
inputs:
|
||||||
flavor:
|
flavor:
|
||||||
type: string
|
type: string
|
||||||
description: "Product flavor"
|
description: "Product flavor"
|
||||||
required: false
|
required: false
|
||||||
default: full
|
default: standalone
|
||||||
|
|
||||||
env:
|
|
||||||
UPLOAD_DIR_ANDROID: android_artifacts
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
packages: write
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check_commits:
|
|
||||||
name: Check for New Commits
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
outputs:
|
|
||||||
has_new_commits: ${{ steps.check.outputs.new_commits }}
|
|
||||||
steps:
|
|
||||||
- name: Checkout Repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- name: Check for new commits
|
|
||||||
id: check
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
run: |
|
|
||||||
NEW_COMMITS=$(git rev-list --count --after="$(date -Iseconds -d '23 hours ago')" ${{ github.sha }})
|
|
||||||
echo "new_commits=$NEW_COMMITS" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
build-fdroid:
|
build-fdroid:
|
||||||
if: ${{ inputs.release_type == 'release' || inputs.flavor == 'fdroid' }}
|
if: ${{ inputs.release_type == 'release' || inputs.flavor == 'fdroid' }}
|
||||||
uses: ./.github/workflows/build.yml
|
uses: ./.github/workflows/build.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
with:
|
with:
|
||||||
build_type: ${{ inputs.release_type == '' && 'nightly' || inputs.release_type }}
|
build_type: ${{ inputs.release_type }}
|
||||||
flavor: fdroid
|
flavor: fdroid
|
||||||
|
|
||||||
build-full:
|
build-standalone:
|
||||||
if: ${{ inputs.release_type == 'release' || inputs.release_type == 'nightly' || inputs.release_type == 'prerelease' || inputs.flavor == 'full' }}
|
if: ${{ inputs.release_type == 'release' || inputs.release_type == 'prerelease' || inputs.flavor == 'standalone' }}
|
||||||
uses: ./.github/workflows/build.yml
|
uses: ./.github/workflows/build.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
with:
|
with:
|
||||||
build_type: ${{ inputs.release_type == '' && 'nightly' || inputs.release_type }}
|
build_type: ${{ inputs.release_type }}
|
||||||
flavor: full
|
flavor: standalone
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
needs:
|
needs:
|
||||||
- check_commits
|
- build-standalone
|
||||||
- build-full
|
|
||||||
if: ${{ needs.check_commits.outputs.has_new_commits > 0 && inputs.release_type != 'none' }}
|
|
||||||
name: publish-github
|
name: publish-github
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
|
||||||
ref: main
|
ref: main
|
||||||
- name: Install system dependencies
|
- name: Install system dependencies
|
||||||
run: |
|
run: |
|
||||||
sudo apt update && sudo apt install -y gh apksigner
|
sudo apt update && sudo apt install -y gh apksigner
|
||||||
- name: Set TAG_NAME
|
|
||||||
run: |
|
|
||||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
|
||||||
echo "TAG_NAME=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV
|
|
||||||
elif [ "${{ github.event_name }}" = "schedule" ]; then
|
|
||||||
echo "TAG_NAME=nightly" >> $GITHUB_ENV
|
|
||||||
echo "RELEASE_TYPE=nightly" >> $GITHUB_ENV
|
|
||||||
fi
|
|
||||||
- name: Set latest tag
|
- name: Set latest tag
|
||||||
uses: rickstaa/action-create-tag@v1
|
uses: rickstaa/action-create-tag@v1
|
||||||
id: tag_creation
|
id: tag_creation
|
||||||
@@ -126,21 +92,26 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
latest: true
|
latest: true
|
||||||
|
|
||||||
- name: Generate Changelog
|
- name: Generate Changelog
|
||||||
id: changelog
|
id: changelog
|
||||||
uses: requarks/changelog-action@v1
|
uses: requarks/changelog-action@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
toTag: ${{ github.event_name == 'schedule' && 'nightly' || steps.latest_release.outputs.tag_name }}
|
toTag: ${{ steps.latest_release.outputs.tag_name }}
|
||||||
fromTag: "latest"
|
fromTag: "latest"
|
||||||
writeToFile: false
|
writeToFile: false
|
||||||
|
|
||||||
- name: Make download dir
|
- name: Make download dir
|
||||||
run: mkdir ${{ github.workspace }}/temp
|
run: mkdir ${{ github.workspace }}/temp
|
||||||
|
|
||||||
- name: Download artifacts
|
- name: Download artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ env.UPLOAD_DIR_ANDROID }}
|
pattern: android_artifacts_*
|
||||||
path: ${{ github.workspace }}/temp
|
path: ${{ github.workspace }}/temp
|
||||||
|
merge-multiple: true
|
||||||
|
|
||||||
- name: Set version release notes
|
- name: Set version release notes
|
||||||
if: ${{ inputs.release_type == 'release' }}
|
if: ${{ inputs.release_type == 'release' }}
|
||||||
run: |
|
run: |
|
||||||
@@ -150,36 +121,22 @@ jobs:
|
|||||||
echo "$RELEASE_NOTES" >> $GITHUB_ENV
|
echo "$RELEASE_NOTES" >> $GITHUB_ENV
|
||||||
echo "EOF" >> $GITHUB_ENV
|
echo "EOF" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: On nightly release notes
|
|
||||||
if: ${{ contains(env.TAG_NAME, 'nightly') }}
|
|
||||||
run: |
|
|
||||||
echo "RELEASE_NOTES=Nightly build for the latest development version of the app." >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: On prerelease release notes
|
- name: On prerelease release notes
|
||||||
if: ${{ inputs.release_type == 'prerelease' }}
|
if: ${{ inputs.release_type == 'prerelease' }}
|
||||||
run: |
|
run: |
|
||||||
echo "RELEASE_NOTES=Testing version of app for specific feature." >> $GITHUB_ENV
|
echo "RELEASE_NOTES=Testing version of app for specific feature." >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Delete previous release
|
- name: Get checksum
|
||||||
if: ${{ contains(env.TAG_NAME, 'nightly') || inputs.release_type == 'prerelease' }}
|
|
||||||
uses: ClementTsang/delete-tag-and-release@v0.3.1
|
|
||||||
with:
|
|
||||||
tag_name: ${{ env.TAG_NAME }}
|
|
||||||
delete_release: true
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Get checksums
|
|
||||||
id: checksum
|
id: checksum
|
||||||
run: |
|
run: |
|
||||||
checksums=""
|
file_path=$(find ${{ github.workspace }}/temp -type f -iname "*.apk" | head -n 1)
|
||||||
for file_path in $(find ${{ github.workspace }}/temp -type f -iname "*.apk"); do
|
if [ -z "$file_path" ]; then
|
||||||
checksum=$(apksigner verify -print-certs $file_path | grep -Po "(?<=SHA-256 digest:) .*" | tr -d "[:blank:]")
|
echo "No APK file found"
|
||||||
checksums="$checksums\n$file_path: $checksum"
|
exit 1
|
||||||
done
|
fi
|
||||||
echo "checksum<<EOF" >> $GITHUB_OUTPUT
|
checksum=$(apksigner verify --print-certs "$file_path" | grep -Po "(?<=SHA-256 digest:) .*" | tr -d "[:blank:]")
|
||||||
echo -e "$checksums" >> $GITHUB_OUTPUT
|
echo "checksum=$checksum" >> $GITHUB_OUTPUT
|
||||||
echo "EOF" >> $GITHUB_OUTPUT
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
@@ -199,12 +156,78 @@ jobs:
|
|||||||
|
|
||||||
### Changelog
|
### Changelog
|
||||||
${{ steps.changelog.outputs.changes }}
|
${{ steps.changelog.outputs.changes }}
|
||||||
tag_name: ${{ env.TAG_NAME }}
|
tag_name: ${{ github.event.inputs.tag_name }}
|
||||||
name: ${{ env.TAG_NAME }}
|
name: ${{ github.event.inputs.tag_name }}
|
||||||
draft: false
|
draft: false
|
||||||
prerelease: ${{ inputs.release_type == 'prerelease' || inputs.release_type == '' || inputs.release_type == 'nightly' }}
|
prerelease: ${{ inputs.release_type == 'prerelease' }}
|
||||||
make_latest: ${{ inputs.release_type == 'release' }}
|
make_latest: ${{ inputs.release_type == 'release' }}
|
||||||
files: |
|
files: |
|
||||||
${{ github.workspace }}/temp/*
|
${{ github.workspace }}/temp/**/*.apk
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
publish-fdroid-public:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs:
|
||||||
|
- build-fdroid
|
||||||
|
if: inputs.release_type == 'release'
|
||||||
|
steps:
|
||||||
|
- name: Dispatch update for fdroid repo
|
||||||
|
uses: peter-evans/repository-dispatch@v3
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
repository: wgtunnel/fdroid
|
||||||
|
event-type: fdroid-update
|
||||||
|
|
||||||
|
publish-play:
|
||||||
|
if: ${{ inputs.track != 'none' }}
|
||||||
|
name: Publish to Google Play
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
env:
|
||||||
|
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
|
||||||
|
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
||||||
|
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
|
||||||
|
KEY_STORE_FILE: 'android_keystore.jks'
|
||||||
|
KEY_STORE_LOCATION: ${{ github.workspace }}/app/keystore/
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Set up JDK 17
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: '17'
|
||||||
|
cache: gradle
|
||||||
|
|
||||||
|
- name: Grant execute permission for gradlew
|
||||||
|
run: chmod +x gradlew
|
||||||
|
|
||||||
|
# Here we need to decode keystore.jks from base64 string and place it
|
||||||
|
# in the folder specified in the release signing configuration
|
||||||
|
- name: Decode Keystore
|
||||||
|
id: decode_keystore
|
||||||
|
uses: timheuer/base64-to-file@v1.2
|
||||||
|
with:
|
||||||
|
fileName: ${{ env.KEY_STORE_FILE }}
|
||||||
|
fileDir: ${{ env.KEY_STORE_LOCATION }}
|
||||||
|
encodedString: ${{ secrets.KEYSTORE }}
|
||||||
|
|
||||||
|
# create keystore path for gradle to read
|
||||||
|
- name: Create keystore path env var
|
||||||
|
run: |
|
||||||
|
store_path=${{ env.KEY_STORE_LOCATION }}${{ env.KEY_STORE_FILE }}
|
||||||
|
echo "KEY_STORE_PATH=$store_path" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Create service_account.json
|
||||||
|
id: createServiceAccount
|
||||||
|
run: echo '${{ secrets.SERVICE_ACCOUNT_JSON }}' > service_account.json
|
||||||
|
|
||||||
|
- name: Deploy with fastlane
|
||||||
|
uses: ruby/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
ruby-version: '3.2' # Not needed with a .ruby-version file
|
||||||
|
bundler-cache: true
|
||||||
|
|
||||||
|
- name: Distribute app to Prod track 🚀
|
||||||
|
run: (cd ${{ github.workspace }} && bundle install && bundle exec fastlane ${{ inputs.track }})
|
||||||
@@ -103,13 +103,16 @@ android {
|
|||||||
dimension = "type"
|
dimension = "type"
|
||||||
buildConfigField("String", "FLAVOR", "\"google\"")
|
buildConfigField("String", "FLAVOR", "\"google\"")
|
||||||
}
|
}
|
||||||
create("full") { dimension = "type" }
|
create("standalone") {
|
||||||
|
dimension = "type"
|
||||||
|
buildConfigField("String", "FLAVOR", "\"standalone\"")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
|
isCoreLibraryDesugaringEnabled = true
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
isCoreLibraryDesugaringEnabled = true
|
|
||||||
}
|
}
|
||||||
kotlinOptions { jvmTarget = Constants.JVM_TARGET }
|
kotlinOptions { jvmTarget = Constants.JVM_TARGET }
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
@@ -121,7 +124,6 @@ android {
|
|||||||
licensee {
|
licensee {
|
||||||
Constants.allowedLicenses.forEach { allow(it) }
|
Constants.allowedLicenses.forEach { allow(it) }
|
||||||
allowUrl(Constants.XZING_LICENSE_URL)
|
allowUrl(Constants.XZING_LICENSE_URL)
|
||||||
allowUrl("https://rafaellins.mit-license.org/2021/")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationVariants.all {
|
applicationVariants.all {
|
||||||
@@ -195,6 +197,7 @@ dependencies {
|
|||||||
implementation(libs.kotlinx.serialization.json)
|
implementation(libs.kotlinx.serialization.json)
|
||||||
|
|
||||||
implementation(libs.zxing.android.embedded)
|
implementation(libs.zxing.android.embedded)
|
||||||
|
|
||||||
implementation(libs.material.icons.extended)
|
implementation(libs.material.icons.extended)
|
||||||
|
|
||||||
implementation(libs.androidx.biometric.ktx)
|
implementation(libs.androidx.biometric.ktx)
|
||||||
@@ -207,7 +210,7 @@ dependencies {
|
|||||||
implementation(libs.androidx.work.runtime)
|
implementation(libs.androidx.work.runtime)
|
||||||
implementation(libs.androidx.hilt.work)
|
implementation(libs.androidx.hilt.work)
|
||||||
|
|
||||||
implementation(libs.qrcode.kotlin)
|
implementation(libs.qrose)
|
||||||
implementation(libs.semver4j)
|
implementation(libs.semver4j)
|
||||||
|
|
||||||
implementation(libs.ktor.client.core)
|
implementation(libs.ktor.client.core)
|
||||||
|
|||||||
@@ -62,6 +62,10 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.App.Start"
|
android:theme="@style/Theme.App.Start"
|
||||||
tools:targetApi="tiramisu">
|
tools:targetApi="tiramisu">
|
||||||
|
<activity
|
||||||
|
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
||||||
|
android:screenOrientation="portrait"
|
||||||
|
tools:replace="screenOrientation" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
@@ -78,10 +82,6 @@
|
|||||||
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
|
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
|
||||||
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
|
||||||
android:screenOrientation="portrait"
|
|
||||||
tools:replace="screenOrientation" />
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".core.shortcut.ShortcutsActivity"
|
android:name=".core.shortcut.ShortcutsActivity"
|
||||||
@@ -166,15 +166,11 @@
|
|||||||
<receiver
|
<receiver
|
||||||
android:name=".core.broadcast.RestartReceiver"
|
android:name=".core.broadcast.RestartReceiver"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false"
|
android:exported="false">
|
||||||
android:directBootAware="true">
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.SCREEN_ON" />
|
|
||||||
<action android:name="android.intent.action.USER_PRESENT" />
|
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||||
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
|
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
|
||||||
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
|
|
||||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import androidx.compose.animation.slideOutVertically
|
|||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.gestures.detectTapGestures
|
import androidx.compose.foundation.gestures.detectTapGestures
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.material.icons.rounded.Settings
|
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
@@ -39,7 +38,6 @@ import androidx.navigation.compose.rememberNavController
|
|||||||
import androidx.navigation.toRoute
|
import androidx.navigation.toRoute
|
||||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.VpnDeniedDialog
|
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.VpnDeniedDialog
|
||||||
@@ -55,7 +53,6 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.Loca
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.autotunnel.TunnelAutoTunnelScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.autotunnel.TunnelAutoTunnelScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.ConfigScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.ConfigScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.scanner.ScannerScreen
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel.SplitTunnelScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel.SplitTunnelScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.TunnelOptionsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.TunnelOptionsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.pin.PinLockScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.pin.PinLockScreen
|
||||||
@@ -110,6 +107,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val isTv = isRunningOnTv()
|
val isTv = isRunningOnTv()
|
||||||
val appUiState by viewModel.uiState.collectAsStateWithLifecycle()
|
val appUiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||||
val appViewState by viewModel.appViewState.collectAsStateWithLifecycle()
|
val appViewState by viewModel.appViewState.collectAsStateWithLifecycle()
|
||||||
|
val tunnelError by viewModel.tunnelManager.errorEvents.collectAsStateWithLifecycle(null)
|
||||||
|
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
val backStackEntry by navController.currentBackStackEntryAsState()
|
val backStackEntry by navController.currentBackStackEntryAsState()
|
||||||
@@ -134,6 +132,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
vpnPermissionDenied = true
|
vpnPermissionDenied = true
|
||||||
} else {
|
} else {
|
||||||
vpnPermissionDenied = false
|
vpnPermissionDenied = false
|
||||||
|
showVpnPermissionDialog = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -151,6 +150,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
viewModel.handleEvent(AppEvent.SetBatteryOptimizeDisableShown)
|
viewModel.handleEvent(AppEvent.SetBatteryOptimizeDisableShown)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(tunnelError) {
|
||||||
|
if (tunnelError == null) return@LaunchedEffect
|
||||||
|
val message = tunnelError!!.second.toStringRes()
|
||||||
|
val context = this@MainActivity
|
||||||
|
snackbar.showSnackbar(
|
||||||
|
context.getString(R.string.tunnel_error_template, context.getString(message))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
with(appViewState) {
|
with(appViewState) {
|
||||||
LaunchedEffect(isConfigChanged) {
|
LaunchedEffect(isConfigChanged) {
|
||||||
if (isConfigChanged) {
|
if (isConfigChanged) {
|
||||||
@@ -166,21 +174,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
viewModel.handleEvent(AppEvent.MessageShown)
|
viewModel.handleEvent(AppEvent.MessageShown)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LaunchedEffect(appUiState.activeTunnels) {
|
|
||||||
appUiState.activeTunnels.mapNotNull { (tunnelConf, tunnelState) ->
|
|
||||||
(tunnelState.status as? TunnelStatus.Error)?.let { error ->
|
|
||||||
val message = error.error.toStringRes()
|
|
||||||
val context = this@MainActivity
|
|
||||||
snackbar.showSnackbar(
|
|
||||||
context.getString(
|
|
||||||
R.string.tunnel_error_template,
|
|
||||||
context.getString(message),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
viewModel.handleEvent(AppEvent.ClearTunnelError(tunnelConf))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LaunchedEffect(popBackStack) {
|
LaunchedEffect(popBackStack) {
|
||||||
if (popBackStack) {
|
if (popBackStack) {
|
||||||
navController.popBackStack()
|
navController.popBackStack()
|
||||||
@@ -214,7 +207,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
WireguardAutoTunnelTheme(theme = appUiState.appState.theme) {
|
WireguardAutoTunnelTheme(theme = appUiState.appState.theme) {
|
||||||
VpnDeniedDialog(
|
VpnDeniedDialog(
|
||||||
showVpnPermissionDialog,
|
showVpnPermissionDialog,
|
||||||
onDismiss = { showVpnPermissionDialog = false },
|
onDismiss = {
|
||||||
|
showVpnPermissionDialog = false
|
||||||
|
vpnPermissionDenied = false
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
@@ -300,11 +296,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
appUiState.tunnels
|
appUiState.tunnels
|
||||||
.firstOrNull { it.id == args.id }
|
.firstOrNull { it.id == args.id }
|
||||||
?.let { config ->
|
?.let { config ->
|
||||||
TunnelOptionsScreen(config, viewModel)
|
TunnelOptionsScreen(config, viewModel, appViewState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
composable<Route.Lock> { PinLockScreen(viewModel) }
|
composable<Route.Lock> { PinLockScreen(viewModel) }
|
||||||
composable<Route.Scanner> { ScannerScreen(viewModel) }
|
|
||||||
composable<Route.KillSwitch> {
|
composable<Route.KillSwitch> {
|
||||||
KillSwitchScreen(appUiState, viewModel)
|
KillSwitchScreen(appUiState, viewModel)
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-6
@@ -3,12 +3,12 @@ package com.zaneschepke.wireguardautotunnel.core.broadcast
|
|||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import com.zaneschepke.logcatter.LogReader
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
@@ -26,20 +26,20 @@ class RestartReceiver : BroadcastReceiver() {
|
|||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
@Inject lateinit var tunnelManager: TunnelManager
|
||||||
|
|
||||||
|
@Inject lateinit var logReader: LogReader
|
||||||
|
|
||||||
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
Timber.d("RestartReceiver triggered with action: ${intent.action}")
|
Timber.d("RestartReceiver triggered with action: ${intent.action}")
|
||||||
// screen on for Android TV only to help with sleep shutdowns
|
|
||||||
val isTv = context.isRunningOnTv()
|
|
||||||
if (intent.action == Intent.ACTION_SCREEN_ON && !isTv) return
|
|
||||||
if (intent.action == Intent.ACTION_USER_PRESENT && !isTv) return
|
|
||||||
serviceManager.updateTunnelTile()
|
serviceManager.updateTunnelTile()
|
||||||
serviceManager.updateAutoTunnelTile()
|
serviceManager.updateAutoTunnelTile()
|
||||||
applicationScope.launch(ioDispatcher) {
|
applicationScope.launch(ioDispatcher) {
|
||||||
val settings = appDataRepository.settings.get()
|
val settings = appDataRepository.settings.get()
|
||||||
if (settings.isRestoreOnBootEnabled) {
|
if (settings.isRestoreOnBootEnabled) {
|
||||||
if (settings.isAutoTunnelEnabled && !serviceManager.autoTunnelActive.value) {
|
if (
|
||||||
|
settings.isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null
|
||||||
|
) {
|
||||||
Timber.d("Starting auto-tunnel on boot/update")
|
Timber.d("Starting auto-tunnel on boot/update")
|
||||||
serviceManager.startAutoTunnel()
|
serviceManager.startAutoTunnel()
|
||||||
} else {
|
} else {
|
||||||
@@ -49,6 +49,7 @@ class RestartReceiver : BroadcastReceiver() {
|
|||||||
} else {
|
} else {
|
||||||
Timber.d("Restore on boot disabled, skipping")
|
Timber.d("Restore on boot disabled, skipping")
|
||||||
}
|
}
|
||||||
|
if (intent.action == Intent.ACTION_MY_PACKAGE_REPLACED) logReader.deleteAndClearLogs()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+71
-55
@@ -1,10 +1,11 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.service
|
package com.zaneschepke.wireguardautotunnel.core.service
|
||||||
|
|
||||||
import android.app.Service
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.ServiceConnection
|
||||||
import android.net.VpnService
|
import android.net.VpnService
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import android.os.IBinder
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.AutoTunnelService
|
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.AutoTunnelService
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
@@ -13,7 +14,6 @@ import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
|||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestAutoTunnelTileServiceUpdate
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestAutoTunnelTileServiceUpdate
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestTunnelTileServiceStateUpdate
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestTunnelTileServiceStateUpdate
|
||||||
import jakarta.inject.Inject
|
import jakarta.inject.Inject
|
||||||
import kotlinx.coroutines.CompletableDeferred
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
@@ -37,23 +37,37 @@ constructor(
|
|||||||
|
|
||||||
private val autoTunnelMutex = Mutex()
|
private val autoTunnelMutex = Mutex()
|
||||||
|
|
||||||
private val _autoTunnelActive = MutableStateFlow(false)
|
private val _tunnelService = MutableStateFlow<TunnelForegroundService?>(null)
|
||||||
val autoTunnelActive = _autoTunnelActive.asStateFlow()
|
private val _autoTunnelService = MutableStateFlow<AutoTunnelService?>(null)
|
||||||
|
val autoTunnelService = _autoTunnelService.asStateFlow()
|
||||||
|
|
||||||
var autoTunnelService = CompletableDeferred<AutoTunnelService>()
|
private val tunnelServiceConnection =
|
||||||
var backgroundService = CompletableDeferred<TunnelForegroundService>()
|
object : ServiceConnection {
|
||||||
|
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
||||||
private fun <T : Service> startService(cls: Class<T>, background: Boolean) {
|
val binder = service as? TunnelForegroundService.LocalBinder
|
||||||
runCatching {
|
_tunnelService.value = binder?.service
|
||||||
val intent = Intent(context, cls)
|
Timber.d("TunnelForegroundService connected")
|
||||||
if (background) {
|
|
||||||
context.startForegroundService(intent)
|
|
||||||
} else {
|
|
||||||
context.startService(intent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.onFailure { Timber.e(it) }
|
|
||||||
}
|
override fun onServiceDisconnected(name: ComponentName) {
|
||||||
|
_tunnelService.value = null
|
||||||
|
Timber.d("TunnelForegroundService disconnected")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val autoTunnelServiceConnection =
|
||||||
|
object : ServiceConnection {
|
||||||
|
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
||||||
|
val binder = service as? AutoTunnelService.LocalBinder
|
||||||
|
_autoTunnelService.value = binder?.service
|
||||||
|
Timber.d("AutoTunnelService connected")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onServiceDisconnected(name: ComponentName) {
|
||||||
|
_autoTunnelService.value = null
|
||||||
|
Timber.d("AutoTunnelService disconnected")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun hasVpnPermission(): Boolean {
|
fun hasVpnPermission(): Boolean {
|
||||||
return VpnService.prepare(context) == null
|
return VpnService.prepare(context) == null
|
||||||
@@ -63,20 +77,13 @@ constructor(
|
|||||||
autoTunnelMutex.withLock {
|
autoTunnelMutex.withLock {
|
||||||
val settings = appDataRepository.settings.get()
|
val settings = appDataRepository.settings.get()
|
||||||
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = true))
|
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = true))
|
||||||
if (autoTunnelService.isCompleted) {
|
if (_autoTunnelService.value != null) return
|
||||||
_autoTunnelActive.update { true }
|
withContext(ioDispatcher) {
|
||||||
return
|
val intent = Intent(context, AutoTunnelService::class.java)
|
||||||
|
context.startForegroundService(intent)
|
||||||
|
context.bindService(intent, autoTunnelServiceConnection, Context.BIND_AUTO_CREATE)
|
||||||
|
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
||||||
}
|
}
|
||||||
runCatching {
|
|
||||||
autoTunnelService = CompletableDeferred()
|
|
||||||
startService(AutoTunnelService::class.java, !WireGuardAutoTunnel.isForeground())
|
|
||||||
_autoTunnelActive.update { true }
|
|
||||||
}
|
|
||||||
.onFailure {
|
|
||||||
Timber.e(it)
|
|
||||||
_autoTunnelActive.update { false }
|
|
||||||
}
|
|
||||||
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,43 +91,44 @@ constructor(
|
|||||||
autoTunnelMutex.withLock {
|
autoTunnelMutex.withLock {
|
||||||
val settings = appDataRepository.settings.get()
|
val settings = appDataRepository.settings.get()
|
||||||
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = false))
|
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = false))
|
||||||
if (!autoTunnelService.isCompleted) return
|
if (_autoTunnelService.value == null) return
|
||||||
runCatching {
|
_autoTunnelService.value?.let { service ->
|
||||||
val service = autoTunnelService.await()
|
service.stop()
|
||||||
service.stop()
|
try {
|
||||||
_autoTunnelActive.update { false }
|
context.unbindService(autoTunnelServiceConnection)
|
||||||
autoTunnelService = CompletableDeferred()
|
} finally {
|
||||||
|
_tunnelService.value = null
|
||||||
}
|
}
|
||||||
.onFailure { Timber.e(it) }
|
}
|
||||||
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startTunnelForegroundService() {
|
suspend fun startTunnelForegroundService() {
|
||||||
if (backgroundService.isCompleted) return
|
if (_tunnelService.value != null) return
|
||||||
runCatching {
|
withContext(ioDispatcher) {
|
||||||
backgroundService = CompletableDeferred()
|
applicationScope.launch(ioDispatcher) {
|
||||||
startService(
|
val intent = Intent(context, TunnelForegroundService::class.java)
|
||||||
TunnelForegroundService::class.java,
|
context.startForegroundService(intent)
|
||||||
!WireGuardAutoTunnel.isForeground(),
|
context.bindService(intent, tunnelServiceConnection, Context.BIND_AUTO_CREATE)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
.onFailure { Timber.e(it) }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun stopTunnelForegroundService() {
|
fun stopTunnelForegroundService() {
|
||||||
if (!backgroundService.isCompleted) return
|
_tunnelService.value?.let { service ->
|
||||||
runCatching {
|
service.stop()
|
||||||
val service = backgroundService.await()
|
try {
|
||||||
service.stop()
|
context.unbindService(tunnelServiceConnection)
|
||||||
backgroundService = CompletableDeferred()
|
} finally {
|
||||||
|
_tunnelService.value = null
|
||||||
}
|
}
|
||||||
.onFailure { Timber.e(it) }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleAutoTunnel() {
|
fun toggleAutoTunnel() {
|
||||||
applicationScope.launch(ioDispatcher) {
|
applicationScope.launch(ioDispatcher) {
|
||||||
if (_autoTunnelActive.value) stopAutoTunnel() else startAutoTunnel()
|
if (_autoTunnelService.value != null) stopAutoTunnel() else startAutoTunnel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,4 +139,12 @@ constructor(
|
|||||||
fun updateTunnelTile() {
|
fun updateTunnelTile() {
|
||||||
context.requestTunnelTileServiceStateUpdate()
|
context.requestTunnelTileServiceStateUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun handleTunnelServiceDestroy() {
|
||||||
|
_tunnelService.update { null }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun handleAutoTunnelServiceDestroy() {
|
||||||
|
_autoTunnelService.update { null }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-8
@@ -2,6 +2,7 @@ package com.zaneschepke.wireguardautotunnel.core.service
|
|||||||
|
|
||||||
import android.app.Notification
|
import android.app.Notification
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Binder
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import androidx.core.app.ServiceCompat
|
import androidx.core.app.ServiceCompat
|
||||||
import androidx.lifecycle.LifecycleService
|
import androidx.lifecycle.LifecycleService
|
||||||
@@ -23,7 +24,6 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.distinctByKeys
|
|||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CompletableDeferred
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.NonCancellable
|
import kotlinx.coroutines.NonCancellable
|
||||||
@@ -64,9 +64,12 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
|
|
||||||
private val jobsMutex = Mutex()
|
private val jobsMutex = Mutex()
|
||||||
|
|
||||||
|
class LocalBinder(val service: TunnelForegroundService) : Binder()
|
||||||
|
|
||||||
|
private val binder = LocalBinder(this)
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
serviceManager.backgroundService.complete(this)
|
|
||||||
ServiceCompat.startForeground(
|
ServiceCompat.startForeground(
|
||||||
this@TunnelForegroundService,
|
this@TunnelForegroundService,
|
||||||
NotificationManager.VPN_NOTIFICATION_ID,
|
NotificationManager.VPN_NOTIFICATION_ID,
|
||||||
@@ -75,14 +78,13 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBind(intent: Intent): IBinder? {
|
override fun onBind(intent: Intent): IBinder {
|
||||||
super.onBind(intent)
|
super.onBind(intent)
|
||||||
return null
|
return binder
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
super.onStartCommand(intent, flags, startId)
|
super.onStartCommand(intent, flags, startId)
|
||||||
serviceManager.backgroundService.complete(this)
|
|
||||||
ServiceCompat.startForeground(
|
ServiceCompat.startForeground(
|
||||||
this@TunnelForegroundService,
|
this@TunnelForegroundService,
|
||||||
NotificationManager.VPN_NOTIFICATION_ID,
|
NotificationManager.VPN_NOTIFICATION_ID,
|
||||||
@@ -163,8 +165,12 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
} else {
|
} else {
|
||||||
pingJobs[tun]?.cancel() // Cancel any stale job
|
pingJobs[tun]?.cancel() // Cancel any stale job
|
||||||
if (tun.isPingEnabled) {
|
if (tun.isPingEnabled) {
|
||||||
pingJobs[tun] = startPingJob(tun)
|
if (tun.isStaticallyConfigured()) {
|
||||||
Timber.d("Started ping job for ${tun.tunName}")
|
Timber.d("Skipping ping for statically configured tunnel")
|
||||||
|
} else {
|
||||||
|
pingJobs[tun] = startPingJob(tun)
|
||||||
|
Timber.d("Started ping job for ${tun.tunName}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,7 +279,7 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
serviceManager.backgroundService = CompletableDeferred()
|
serviceManager.handleTunnelServiceDestroy()
|
||||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-6
@@ -1,6 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.service.autotunnel
|
package com.zaneschepke.wireguardautotunnel.core.service.autotunnel
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Binder
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import androidx.core.app.ServiceCompat
|
import androidx.core.app.ServiceCompat
|
||||||
@@ -28,7 +29,6 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
|||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Provider
|
import javax.inject.Provider
|
||||||
import kotlinx.coroutines.CompletableDeferred
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.FlowPreview
|
import kotlinx.coroutines.FlowPreview
|
||||||
@@ -68,21 +68,23 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
|
|
||||||
private var killSwitchJob: Job? = null
|
private var killSwitchJob: Job? = null
|
||||||
|
|
||||||
|
class LocalBinder(val service: AutoTunnelService) : Binder()
|
||||||
|
|
||||||
|
private val binder = LocalBinder(this)
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
serviceManager.autoTunnelService.complete(this)
|
|
||||||
launchWatcherNotification()
|
launchWatcherNotification()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBind(intent: Intent): IBinder? {
|
override fun onBind(intent: Intent): IBinder {
|
||||||
super.onBind(intent)
|
super.onBind(intent)
|
||||||
return null
|
return binder
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
super.onStartCommand(intent, flags, startId)
|
super.onStartCommand(intent, flags, startId)
|
||||||
Timber.d("onStartCommand executed with startId: $startId")
|
Timber.d("onStartCommand executed with startId: $startId")
|
||||||
serviceManager.autoTunnelService.complete(this)
|
|
||||||
start()
|
start()
|
||||||
return START_STICKY
|
return START_STICKY
|
||||||
}
|
}
|
||||||
@@ -105,7 +107,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
serviceManager.autoTunnelService = CompletableDeferred()
|
serviceManager.handleAutoTunnelServiceDestroy()
|
||||||
restoreVpnKillSwitch()
|
restoreVpnKillSwitch()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -38,8 +38,8 @@ class AutoTunnelControlTile : TileService(), LifecycleOwner {
|
|||||||
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
Timber.d("Start listening called for auto tunnel tile")
|
Timber.d("Start listening called for auto tunnel tile")
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
serviceManager.autoTunnelActive.collect {
|
serviceManager.autoTunnelService.collect {
|
||||||
if (it) return@collect setActive()
|
if (it != null) return@collect setActive()
|
||||||
setInactive()
|
setInactive()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ class AutoTunnelControlTile : TileService(), LifecycleOwner {
|
|||||||
super.onClick()
|
super.onClick()
|
||||||
unlockAndRun {
|
unlockAndRun {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
if (serviceManager.autoTunnelActive.value) {
|
if (serviceManager.autoTunnelService.value != null) {
|
||||||
serviceManager.stopAutoTunnel()
|
serviceManager.stopAutoTunnel()
|
||||||
setInactive()
|
setInactive()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
import com.wireguard.android.backend.BackendException
|
|
||||||
import com.wireguard.android.backend.Tunnel
|
import com.wireguard.android.backend.Tunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
@@ -11,14 +10,11 @@ import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
|||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendError
|
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
|
||||||
import kotlinx.coroutines.flow.update
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
@@ -31,6 +27,10 @@ abstract class BaseTunnel(
|
|||||||
private val serviceManager: ServiceManager,
|
private val serviceManager: ServiceManager,
|
||||||
) : TunnelProvider {
|
) : TunnelProvider {
|
||||||
|
|
||||||
|
private val _errorEvents =
|
||||||
|
MutableSharedFlow<Pair<TunnelConf, BackendError>>(replay = 0, extraBufferCapacity = 1)
|
||||||
|
override val errorEvents = _errorEvents.asSharedFlow()
|
||||||
|
|
||||||
private val activeTuns = MutableStateFlow<Map<TunnelConf, TunnelState>>(emptyMap())
|
private val activeTuns = MutableStateFlow<Map<TunnelConf, TunnelState>>(emptyMap())
|
||||||
private val tunThreads = ConcurrentHashMap<Int, Thread>()
|
private val tunThreads = ConcurrentHashMap<Int, Thread>()
|
||||||
override val activeTunnels = activeTuns.asStateFlow()
|
override val activeTunnels = activeTuns.asStateFlow()
|
||||||
@@ -45,37 +45,34 @@ abstract class BaseTunnel(
|
|||||||
|
|
||||||
abstract fun stopBackend(tunnel: TunnelConf)
|
abstract fun stopBackend(tunnel: TunnelConf)
|
||||||
|
|
||||||
override suspend fun clearError(tunnelConf: TunnelConf) =
|
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
|
||||||
|
|
||||||
override fun hasVpnPermission(): Boolean {
|
override fun hasVpnPermission(): Boolean {
|
||||||
return serviceManager.hasVpnPermission()
|
return serviceManager.hasVpnPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected suspend fun updateTunnelStatus(
|
protected suspend fun updateTunnelStatus(
|
||||||
tunnelConf: TunnelConf,
|
tunnelConf: TunnelConf,
|
||||||
state: TunnelStatus? = null,
|
status: TunnelStatus? = null,
|
||||||
stats: TunnelStatistics? = null,
|
stats: TunnelStatistics? = null,
|
||||||
) {
|
) {
|
||||||
tunStatusMutex.withLock {
|
tunStatusMutex.withLock {
|
||||||
activeTuns.update { current ->
|
activeTuns.update { currentTuns ->
|
||||||
val originalConf = current.getKeyById(tunnelConf.id) ?: tunnelConf
|
val originalConf = currentTuns.getKeyById(tunnelConf.id) ?: tunnelConf
|
||||||
val existingState = current.getValueById(tunnelConf.id) ?: TunnelState()
|
val existingState = currentTuns.getValueById(tunnelConf.id) ?: TunnelState()
|
||||||
val newState = state ?: existingState.status
|
val newState = status ?: existingState.status
|
||||||
if (newState == TunnelStatus.Down) {
|
if (newState == TunnelStatus.Down) {
|
||||||
Timber.d("Removing tunnel ${tunnelConf.id} from activeTunnels as state is DOWN")
|
Timber.d("Removing tunnel ${tunnelConf.id} from activeTunnels as state is DOWN")
|
||||||
cleanUpTunThread(tunnelConf)
|
cleanUpTunThread(tunnelConf)
|
||||||
current - originalConf
|
currentTuns - originalConf
|
||||||
} else if (existingState.status == newState && stats == null) {
|
} else if (existingState.status == newState && stats == null) {
|
||||||
Timber.d("Skipping redundant state update for ${tunnelConf.id}: $newState")
|
Timber.d("Skipping redundant state update for ${tunnelConf.id}: $newState")
|
||||||
current
|
currentTuns
|
||||||
} else {
|
} else {
|
||||||
val updated =
|
val updated =
|
||||||
existingState.copy(
|
existingState.copy(
|
||||||
status = newState,
|
status = newState,
|
||||||
statistics = stats ?: existingState.statistics,
|
statistics = stats ?: existingState.statistics,
|
||||||
)
|
)
|
||||||
current + (originalConf to updated)
|
currentTuns + (originalConf to updated)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,23 +114,17 @@ abstract class BaseTunnel(
|
|||||||
if (this@BaseTunnel is UserspaceTunnel) stopActiveTunnels()
|
if (this@BaseTunnel is UserspaceTunnel) stopActiveTunnels()
|
||||||
tunMutex.withLock {
|
tunMutex.withLock {
|
||||||
tunThreads[tunnelConf.id] = thread {
|
tunThreads[tunnelConf.id] = thread {
|
||||||
runCatching {
|
runBlocking {
|
||||||
runBlocking {
|
try {
|
||||||
try {
|
Timber.d("Starting tunnel ${tunnelConf.id}...")
|
||||||
Timber.d("Starting tunnel ${tunnelConf.id}...")
|
startTunnelInner(tunnelConf)
|
||||||
startTunnelInner(tunnelConf)
|
Timber.d("Started complete for tunnel ${tunnelConf.name}...")
|
||||||
Timber.d("Started complete for tunnel ${tunnelConf.name}...")
|
} catch (e: InterruptedException) {
|
||||||
} catch (e: BackendError) {
|
Timber.w(
|
||||||
Timber.e(e, "Failed to start tunnel ${tunnelConf.name} userspace")
|
"Tunnel start has been interrupted as ${tunnelConf.name} failed to start"
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Error(e))
|
)
|
||||||
} catch (e: InterruptedException) {
|
|
||||||
Timber.w(
|
|
||||||
"Tunnel start has been interrupted as ${tunnelConf.name} failed to start"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.onFailure { Timber.w("Tunnel start has been interrupted") }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,11 +138,10 @@ abstract class BaseTunnel(
|
|||||||
Timber.d("Started for tun ${tunnelConf.id}...")
|
Timber.d("Started for tun ${tunnelConf.id}...")
|
||||||
saveTunnelActiveState(tunnelConf, true)
|
saveTunnelActiveState(tunnelConf, true)
|
||||||
serviceManager.startTunnelForegroundService()
|
serviceManager.startTunnelForegroundService()
|
||||||
} catch (e: BackendException) {
|
} catch (e: BackendError) {
|
||||||
Timber.e(e, "Failed to start backend for ${tunnelConf.name}")
|
Timber.e(e, "Failed to start backend for ${tunnelConf.name}")
|
||||||
val backendError = e.toBackendError()
|
_errorEvents.emit(tunnelConf to e)
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Error(backendError))
|
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
||||||
throw backendError
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,26 +153,27 @@ abstract class BaseTunnel(
|
|||||||
override suspend fun stopTunnel(tunnelConf: TunnelConf?, reason: TunnelStatus.StopReason) {
|
override suspend fun stopTunnel(tunnelConf: TunnelConf?, reason: TunnelStatus.StopReason) {
|
||||||
if (tunnelConf == null) return stopActiveTunnels()
|
if (tunnelConf == null) return stopActiveTunnels()
|
||||||
tunMutex.withLock {
|
tunMutex.withLock {
|
||||||
try {
|
if (activeTuns.isStarting(tunnelConf.id))
|
||||||
if (activeTuns.isStarting(tunnelConf.id))
|
return handleStuckStartingTunnelShutdown(tunnelConf)
|
||||||
return handleStuckStartingTunnelShutdown(tunnelConf)
|
updateTunnelStatus(tunnelConf, TunnelStatus.Stopping(reason))
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Stopping(reason))
|
stopTunnelInner(tunnelConf)
|
||||||
stopTunnelInner(tunnelConf)
|
|
||||||
} catch (e: BackendError) {
|
|
||||||
Timber.e(e, "Failed to stop tunnel ${tunnelConf.id}")
|
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Error(e))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun stopTunnelInner(tunnelConf: TunnelConf) {
|
private suspend fun stopTunnelInner(tunnelConf: TunnelConf) {
|
||||||
val tunnel = activeTuns.findTunnel(tunnelConf.id) ?: return
|
try {
|
||||||
stopBackend(tunnel)
|
val tunnel = activeTuns.findTunnel(tunnelConf.id) ?: return
|
||||||
saveTunnelActiveState(tunnelConf, false)
|
stopBackend(tunnel)
|
||||||
removeActiveTunnel(tunnel)
|
saveTunnelActiveState(tunnelConf, false)
|
||||||
|
removeActiveTunnel(tunnel)
|
||||||
|
} catch (e: BackendError) {
|
||||||
|
Timber.e(e, "Failed to stop tunnel ${tunnelConf.id}")
|
||||||
|
_errorEvents.emit(tunnelConf to e)
|
||||||
|
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun handleServiceStateOnChange() {
|
private fun handleServiceStateOnChange() {
|
||||||
if (activeTuns.value.isEmpty() && bouncingTunnelIds.isEmpty())
|
if (activeTuns.value.isEmpty() && bouncingTunnelIds.isEmpty())
|
||||||
serviceManager.stopTunnelForegroundService()
|
serviceManager.stopTunnelForegroundService()
|
||||||
}
|
}
|
||||||
@@ -193,15 +184,15 @@ abstract class BaseTunnel(
|
|||||||
tunThreads[tunnel.id]?.let {
|
tunThreads[tunnel.id]?.let {
|
||||||
if (it.state != Thread.State.TERMINATED) {
|
if (it.state != Thread.State.TERMINATED) {
|
||||||
it.interrupt()
|
it.interrupt()
|
||||||
updateTunnelStatus(tunnel, TunnelStatus.Down)
|
|
||||||
} else {
|
} else {
|
||||||
Timber.d("Thread already terminated")
|
Timber.d("Thread already terminated")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "Failed to stop tunnel thread for ${tunnel.name}")
|
Timber.e(e, "Failed to stop tunnel thread for ${tunnel.name}")
|
||||||
|
} finally {
|
||||||
|
updateTunnelStatus(tunnel, TunnelStatus.Down)
|
||||||
}
|
}
|
||||||
cleanUpTunThread(tunnel)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cleanUpTunThread(tunnel: TunnelConf) {
|
private fun cleanUpTunThread(tunnel: TunnelConf) {
|
||||||
@@ -221,7 +212,7 @@ abstract class BaseTunnel(
|
|||||||
bouncingTunnelIds[tunnelConf.id] = reason
|
bouncingTunnelIds[tunnelConf.id] = reason
|
||||||
try {
|
try {
|
||||||
stopTunnel(tunnelConf, reason)
|
stopTunnel(tunnelConf, reason)
|
||||||
delay(300L)
|
delay(BOUNCE_DELAY)
|
||||||
startTunnel(tunnelConf)
|
startTunnel(tunnelConf)
|
||||||
} finally {
|
} finally {
|
||||||
bouncingTunnelIds.remove(tunnelConf.id)
|
bouncingTunnelIds.remove(tunnelConf.id)
|
||||||
@@ -235,4 +226,8 @@ abstract class BaseTunnel(
|
|||||||
|
|
||||||
override suspend fun runningTunnelNames(): Set<String> =
|
override suspend fun runningTunnelNames(): Set<String> =
|
||||||
activeTuns.value.keys.map { it.tunName }.toSet()
|
activeTuns.value.keys.map { it.tunName }.toSet()
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val BOUNCE_DELAY = 300L
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|||||||
import com.zaneschepke.wireguardautotunnel.di.Kernel
|
import com.zaneschepke.wireguardautotunnel.di.Kernel
|
||||||
import com.zaneschepke.wireguardautotunnel.di.Userspace
|
import com.zaneschepke.wireguardautotunnel.di.Userspace
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendError
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
@@ -15,6 +16,7 @@ import kotlinx.coroutines.CoroutineDispatcher
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.filterNotNull
|
import kotlinx.coroutines.flow.filterNotNull
|
||||||
import kotlinx.coroutines.flow.flatMapLatest
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
@@ -62,6 +64,9 @@ constructor(
|
|||||||
initialValue = emptyMap(),
|
initialValue = emptyMap(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
override val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
||||||
|
get() = tunnelProviderFlow.value.errorEvents
|
||||||
|
|
||||||
override val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason> =
|
override val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason> =
|
||||||
tunnelProviderFlow.value.bouncingTunnelIds
|
tunnelProviderFlow.value.bouncingTunnelIds
|
||||||
|
|
||||||
@@ -69,10 +74,6 @@ constructor(
|
|||||||
return userspaceTunnel.hasVpnPermission()
|
return userspaceTunnel.hasVpnPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun clearError(tunnelConf: TunnelConf) {
|
|
||||||
tunnelProviderFlow.value.clearError(tunnelConf)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun updateTunnelStatistics(tunnel: TunnelConf) {
|
override suspend fun updateTunnelStatistics(tunnel: TunnelConf) {
|
||||||
tunnelProviderFlow.value.updateTunnelStatistics(tunnel)
|
tunnelProviderFlow.value.updateTunnelStatistics(tunnel)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendError
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
|
||||||
interface TunnelProvider {
|
interface TunnelProvider {
|
||||||
@@ -46,11 +48,11 @@ interface TunnelProvider {
|
|||||||
|
|
||||||
val activeTunnels: StateFlow<Map<TunnelConf, TunnelState>>
|
val activeTunnels: StateFlow<Map<TunnelConf, TunnelState>>
|
||||||
|
|
||||||
|
val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
||||||
|
|
||||||
val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason>
|
val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason>
|
||||||
|
|
||||||
fun hasVpnPermission(): Boolean
|
fun hasVpnPermission(): Boolean
|
||||||
|
|
||||||
suspend fun clearError(tunnelConf: TunnelConf)
|
|
||||||
|
|
||||||
suspend fun updateTunnelStatistics(tunnel: TunnelConf)
|
suspend fun updateTunnelStatistics(tunnel: TunnelConf)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -50,8 +50,9 @@ constructor(
|
|||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
Timber.e(e, "Failed to stop tunnel ${tunnel.id}")
|
Timber.e(e, "Failed to stop tunnel ${tunnel.id}")
|
||||||
throw e.toBackendError()
|
throw e.toBackendError()
|
||||||
|
} finally {
|
||||||
|
handlePreviouslyEnabledVpnKillSwitch()
|
||||||
}
|
}
|
||||||
handlePreviouslyEnabledVpnKillSwitch()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop vpn kill switch if we need to resolve DNS for peer endpoints
|
// stop vpn kill switch if we need to resolve DNS for peer endpoints
|
||||||
@@ -69,7 +70,7 @@ constructor(
|
|||||||
// restore vpn kill switch if needed
|
// restore vpn kill switch if needed
|
||||||
private fun handlePreviouslyEnabledVpnKillSwitch() {
|
private fun handlePreviouslyEnabledVpnKillSwitch() {
|
||||||
// let auto tunnel handle this if it is active
|
// let auto tunnel handle this if it is active
|
||||||
if (!serviceManager.autoTunnelActive.value) {
|
if (serviceManager.autoTunnelService.value == null) {
|
||||||
previousBackendState?.let { (state, lanEnabled) ->
|
previousBackendState?.let { (state, lanEnabled) ->
|
||||||
Timber.d("Restoring kill switch configuration")
|
Timber.d("Restoring kill switch configuration")
|
||||||
val lan = if (lanEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS else emptyList()
|
val lan = if (lanEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS else emptyList()
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ constructor(
|
|||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
Timber.i("Service worker started")
|
Timber.i("Service worker started")
|
||||||
with(appDataRepository.settings.get()) {
|
with(appDataRepository.settings.get()) {
|
||||||
if (isAutoTunnelEnabled && !serviceManager.autoTunnelActive.value)
|
if (isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null)
|
||||||
return@with serviceManager.startAutoTunnel()
|
return@with serviceManager.startAutoTunnel()
|
||||||
if (tunnelManager.activeTunnels.value.isEmpty())
|
if (tunnelManager.activeTunnels.value.isEmpty())
|
||||||
tunnelManager.restorePreviousState()
|
tunnelManager.restorePreviousState()
|
||||||
|
|||||||
@@ -60,6 +60,10 @@ data class TunnelConf(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isStaticallyConfigured(): Boolean {
|
||||||
|
return toAmConfig().peers.all { it.endpoint.get().host.isValidIpv4orIpv6Address() }
|
||||||
|
}
|
||||||
|
|
||||||
fun copyWithCallback(
|
fun copyWithCallback(
|
||||||
id: Int = this.id,
|
id: Int = this.id,
|
||||||
tunName: String = this.tunName,
|
tunName: String = this.tunName,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.enums
|
package com.zaneschepke.wireguardautotunnel.domain.enums
|
||||||
|
|
||||||
enum class ConfigType {
|
enum class ConfigType {
|
||||||
AMNEZIA,
|
AM,
|
||||||
WG,
|
WG,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.enums
|
package com.zaneschepke.wireguardautotunnel.domain.enums
|
||||||
|
|
||||||
sealed class TunnelStatus {
|
sealed class TunnelStatus {
|
||||||
data class Error(val error: BackendError) : TunnelStatus()
|
|
||||||
|
|
||||||
data object Up : TunnelStatus()
|
data object Up : TunnelStatus()
|
||||||
|
|
||||||
|
|||||||
+1
@@ -12,6 +12,7 @@ class AmneziaStatistics(private val statistics: Statistics) : TunnelStatistics()
|
|||||||
rxBytes = stats.rxBytes,
|
rxBytes = stats.rxBytes,
|
||||||
txBytes = stats.txBytes,
|
txBytes = stats.txBytes,
|
||||||
latestHandshakeEpochMillis = stats.latestHandshakeEpochMillis,
|
latestHandshakeEpochMillis = stats.latestHandshakeEpochMillis,
|
||||||
|
resolvedEndpoint = stats.resolvedEndpoint,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ abstract class TunnelStatistics {
|
|||||||
val rxBytes: Long,
|
val rxBytes: Long,
|
||||||
val txBytes: Long,
|
val txBytes: Long,
|
||||||
val latestHandshakeEpochMillis: Long,
|
val latestHandshakeEpochMillis: Long,
|
||||||
|
val resolvedEndpoint: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
abstract fun peerStats(peer: Key): PeerStats?
|
abstract fun peerStats(peer: Key): PeerStats?
|
||||||
|
|||||||
+1
@@ -12,6 +12,7 @@ class WireGuardStatistics(private val statistics: Statistics) : TunnelStatistics
|
|||||||
txBytes = peerStats.txBytes,
|
txBytes = peerStats.txBytes,
|
||||||
rxBytes = peerStats.rxBytes,
|
rxBytes = peerStats.rxBytes,
|
||||||
latestHandshakeEpochMillis = peerStats.latestHandshakeEpochMillis,
|
latestHandshakeEpochMillis = peerStats.latestHandshakeEpochMillis,
|
||||||
|
resolvedEndpoint = peerStats.rosolvedEndpoint,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ sealed class Route {
|
|||||||
|
|
||||||
@Serializable data object Lock : Route()
|
@Serializable data object Lock : Route()
|
||||||
|
|
||||||
@Serializable data object Scanner : Route()
|
|
||||||
|
|
||||||
@Serializable data object License : Route()
|
@Serializable data object License : Route()
|
||||||
|
|
||||||
@Serializable data class Config(val id: Int) : Route()
|
@Serializable data class Config(val id: Int) : Route()
|
||||||
|
|||||||
+15
-23
@@ -2,22 +2,21 @@ package com.zaneschepke.wireguardautotunnel.ui.common
|
|||||||
|
|
||||||
import androidx.compose.animation.animateContentSize
|
import androidx.compose.animation.animateContentSize
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.combinedClickable
|
import androidx.compose.foundation.combinedClickable
|
||||||
import androidx.compose.foundation.indication
|
import androidx.compose.foundation.indication
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.interaction.PressInteraction
|
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.ripple
|
import androidx.compose.material3.ripple
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
@@ -44,32 +43,25 @@ fun ExpandingRowListItem(
|
|||||||
modifier =
|
modifier =
|
||||||
Modifier.animateContentSize()
|
Modifier.animateContentSize()
|
||||||
.clip(RoundedCornerShape(8.dp))
|
.clip(RoundedCornerShape(8.dp))
|
||||||
|
.background(
|
||||||
|
if (isSelected) MaterialTheme.colorScheme.primary.copy(alpha = 0.1f)
|
||||||
|
else Color.Transparent
|
||||||
|
)
|
||||||
.then(
|
.then(
|
||||||
if (!isTv) {
|
if (!isTv) {
|
||||||
Modifier.combinedClickable(
|
Modifier.combinedClickable(
|
||||||
onClick = onClick,
|
interactionSource = interactionSource,
|
||||||
onLongClick = {
|
indication = ripple(),
|
||||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
onClick = onClick,
|
||||||
onHold()
|
onLongClick = {
|
||||||
},
|
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
onDoubleClick = onDoubleClick,
|
onHold()
|
||||||
)
|
},
|
||||||
.indication(
|
onDoubleClick = onDoubleClick,
|
||||||
interactionSource = interactionSource,
|
)
|
||||||
indication = ripple(),
|
|
||||||
)
|
|
||||||
} else Modifier
|
} else Modifier
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
LaunchedEffect(isSelected) {
|
|
||||||
if (isSelected) {
|
|
||||||
interactionSource.emit(PressInteraction.Press(Offset.Zero))
|
|
||||||
} else {
|
|
||||||
interactionSource.emit(
|
|
||||||
PressInteraction.Release(PressInteraction.Press(Offset.Zero))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Column {
|
Column {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),
|
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),
|
||||||
|
|||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.common.functions
|
||||||
|
|
||||||
|
import android.content.ClipData
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.ui.platform.ClipEntry
|
||||||
|
import androidx.compose.ui.platform.Clipboard
|
||||||
|
import androidx.compose.ui.platform.LocalClipboard
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class ClipboardHelper(
|
||||||
|
private val clipboard: Clipboard,
|
||||||
|
private val coroutineScope: CoroutineScope,
|
||||||
|
private val dispatcher: CoroutineDispatcher = Dispatchers.Main,
|
||||||
|
) {
|
||||||
|
fun copy(text: String, label: String = "") {
|
||||||
|
coroutineScope.launch(dispatcher) {
|
||||||
|
val clipData = ClipData.newPlainText(label, text)
|
||||||
|
clipboard.setClipEntry(ClipEntry(clipData))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun paste(onResult: (String?) -> Unit) {
|
||||||
|
coroutineScope.launch(dispatcher) {
|
||||||
|
val entry = clipboard.getClipEntry()
|
||||||
|
val text = entry?.clipData?.getItemAt(0)?.text?.toString()
|
||||||
|
onResult(text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun rememberClipboardHelper(
|
||||||
|
coroutineScope: CoroutineScope = rememberCoroutineScope()
|
||||||
|
): ClipboardHelper {
|
||||||
|
val clipboard = LocalClipboard.current
|
||||||
|
return remember(clipboard, coroutineScope) { ClipboardHelper(clipboard, coroutineScope) }
|
||||||
|
}
|
||||||
+12
-12
@@ -4,16 +4,7 @@ import android.os.Build
|
|||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.rounded.Add
|
import androidx.compose.material.icons.rounded.*
|
||||||
import androidx.compose.material.icons.rounded.CopyAll
|
|
||||||
import androidx.compose.material.icons.rounded.Delete
|
|
||||||
import androidx.compose.material.icons.rounded.Download
|
|
||||||
import androidx.compose.material.icons.rounded.Edit
|
|
||||||
import androidx.compose.material.icons.rounded.Menu
|
|
||||||
import androidx.compose.material.icons.rounded.PlayArrow
|
|
||||||
import androidx.compose.material.icons.rounded.Save
|
|
||||||
import androidx.compose.material.icons.rounded.SelectAll
|
|
||||||
import androidx.compose.material.icons.rounded.Stop
|
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@@ -240,8 +231,17 @@ fun currentNavBackStackEntryAsNavBarState(
|
|||||||
showBottom = true,
|
showBottom = true,
|
||||||
topTitle = { tunnel?.name?.let { Text(it) } },
|
topTitle = { tunnel?.name?.let { Text(it) } },
|
||||||
topTrailing = {
|
topTrailing = {
|
||||||
ActionIconButton(Icons.Rounded.Edit, R.string.edit_tunnel) {
|
Row {
|
||||||
tunnel?.id?.let { navController.navigate(Route.Config(it)) }
|
ActionIconButton(Icons.Rounded.QrCode2, R.string.show_qr) {
|
||||||
|
tunnel?.id?.let {
|
||||||
|
viewModel.handleEvent(
|
||||||
|
AppEvent.SetShowModal(AppViewState.ModalType.QR)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ActionIconButton(Icons.Rounded.Edit, R.string.edit_tunnel) {
|
||||||
|
tunnel?.id?.let { navController.navigate(Route.Config(it)) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
route = args?.let { Route.TunnelOptions(it.id) },
|
route = args?.let { Route.TunnelOptions(it.id) },
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components
|
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components
|
||||||
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.AirplanemodeActive
|
import androidx.compose.material.icons.outlined.PublicOff
|
||||||
import androidx.compose.material.icons.outlined.SettingsEthernet
|
import androidx.compose.material.icons.outlined.SettingsEthernet
|
||||||
import androidx.compose.material.icons.outlined.SignalCellular4Bar
|
import androidx.compose.material.icons.outlined.SignalCellular4Bar
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@@ -95,7 +95,7 @@ fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<Se
|
|||||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnEthernet) },
|
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnEthernet) },
|
||||||
),
|
),
|
||||||
SelectionItem(
|
SelectionItem(
|
||||||
leadingIcon = Icons.Outlined.AirplanemodeActive,
|
leadingIcon = Icons.Outlined.PublicOff,
|
||||||
title = {
|
title = {
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.stop_on_no_internet),
|
stringResource(R.string.stop_on_no_internet),
|
||||||
|
|||||||
+31
-20
@@ -22,16 +22,15 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.networkmonitor.NetworkStatus
|
import com.zaneschepke.networkmonitor.NetworkStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.LearnMoreLinkLabel
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.LearnMoreLinkLabel
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||||
@@ -48,7 +47,7 @@ fun WifiTunnelingItems(
|
|||||||
isWifiNameReadable: () -> Boolean,
|
isWifiNameReadable: () -> Boolean,
|
||||||
): List<SelectionItem> {
|
): List<SelectionItem> {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val clipboard = LocalClipboardManager.current
|
val clipboardHelper = rememberClipboardHelper()
|
||||||
|
|
||||||
val baseItems =
|
val baseItems =
|
||||||
listOf(
|
listOf(
|
||||||
@@ -71,29 +70,41 @@ fun WifiTunnelingItems(
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
description = {
|
description = {
|
||||||
val wifiName by
|
val wifiInfo by
|
||||||
remember(uiState.networkStatus) {
|
remember(uiState.networkStatus) {
|
||||||
derivedStateOf {
|
derivedStateOf {
|
||||||
(uiState.networkStatus as? NetworkStatus.Connected)
|
(uiState.networkStatus as? NetworkStatus.Connected)
|
||||||
?.takeIf { it.wifiConnected }
|
?.takeIf { it.wifiConnected }
|
||||||
?.wifiSsid
|
.let { Pair(it?.wifiSsid, it?.securityType) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Text(
|
val (wifiName, securityType) = wifiInfo
|
||||||
text =
|
Column {
|
||||||
wifiName?.let { stringResource(R.string.wifi_name_template, it) }
|
Text(
|
||||||
?: stringResource(R.string.inactive),
|
text =
|
||||||
style =
|
wifiName?.let { stringResource(R.string.wifi_name_template, it) }
|
||||||
MaterialTheme.typography.bodySmall.copy(
|
?: stringResource(R.string.inactive),
|
||||||
color = MaterialTheme.colorScheme.outline
|
style =
|
||||||
),
|
MaterialTheme.typography.bodySmall.copy(
|
||||||
maxLines = 1,
|
color = MaterialTheme.colorScheme.outline
|
||||||
overflow = TextOverflow.Ellipsis,
|
),
|
||||||
modifier =
|
maxLines = 1,
|
||||||
Modifier.clickable {
|
overflow = TextOverflow.Ellipsis,
|
||||||
wifiName?.let { clipboard.setText(AnnotatedString(it)) }
|
modifier =
|
||||||
},
|
Modifier.clickable { wifiName?.let { clipboardHelper.copy(it) } },
|
||||||
)
|
)
|
||||||
|
securityType?.let {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.security_template, it.name),
|
||||||
|
style =
|
||||||
|
MaterialTheme.typography.bodySmall.copy(
|
||||||
|
color = MaterialTheme.colorScheme.outline
|
||||||
|
),
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnWifi) },
|
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnWifi) },
|
||||||
),
|
),
|
||||||
|
|||||||
+19
-5
@@ -7,12 +7,14 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.journeyapps.barcodescanner.ScanContract
|
||||||
|
import com.journeyapps.barcodescanner.ScanOptions
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileImportLauncherForResult
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileImportLauncherForResult
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ExportTunnelsBottomSheet
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ExportTunnelsBottomSheet
|
||||||
@@ -29,7 +31,7 @@ import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
|||||||
@Composable
|
@Composable
|
||||||
fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: AppViewModel) {
|
fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: AppViewModel) {
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val clipboard = LocalClipboardManager.current
|
val clipboard = rememberClipboardHelper()
|
||||||
|
|
||||||
var showUrlImportDialog by remember { mutableStateOf(false) }
|
var showUrlImportDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
@@ -45,6 +47,17 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
|||||||
onData = { data -> viewModel.handleEvent(AppEvent.ImportTunnelFromFile(data)) },
|
onData = { data -> viewModel.handleEvent(AppEvent.ImportTunnelFromFile(data)) },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val scanLauncher =
|
||||||
|
rememberLauncherForActivityResult(
|
||||||
|
contract = ScanContract(),
|
||||||
|
onResult = { result ->
|
||||||
|
{
|
||||||
|
if (result != null && result.contents.isNotEmpty())
|
||||||
|
viewModel.handleEvent(AppEvent.ImportTunnelFromQrCode(result.contents))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
val requestPermissionLauncher =
|
val requestPermissionLauncher =
|
||||||
rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted
|
rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted
|
||||||
->
|
->
|
||||||
@@ -56,7 +69,7 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
|||||||
)
|
)
|
||||||
return@rememberLauncherForActivityResult
|
return@rememberLauncherForActivityResult
|
||||||
}
|
}
|
||||||
navController.navigate(Route.Scanner)
|
scanLauncher.launch(ScanOptions().setDesiredBarcodeFormats(ScanOptions.QR_CODE))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appViewState.showModal == AppViewState.ModalType.DELETE) {
|
if (appViewState.showModal == AppViewState.ModalType.DELETE) {
|
||||||
@@ -90,8 +103,9 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
|||||||
requestPermissionLauncher.launch(android.Manifest.permission.CAMERA)
|
requestPermissionLauncher.launch(android.Manifest.permission.CAMERA)
|
||||||
},
|
},
|
||||||
onClipboardClick = {
|
onClipboardClick = {
|
||||||
clipboard.getText()?.text?.let {
|
clipboard.paste { result ->
|
||||||
viewModel.handleEvent(AppEvent.ImportTunnelFromClipboard(it))
|
if (result != null)
|
||||||
|
viewModel.handleEvent(AppEvent.ImportTunnelFromClipboard(result))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onManualImportClick = {
|
onManualImportClick = {
|
||||||
|
|||||||
+1
-1
@@ -93,7 +93,7 @@ fun ExportTunnelsBottomSheet(viewModel: AppViewModel) {
|
|||||||
ExportOptionRow(
|
ExportOptionRow(
|
||||||
label = stringResource(R.string.export_tunnels_amnezia),
|
label = stringResource(R.string.export_tunnels_amnezia),
|
||||||
onClick = {
|
onClick = {
|
||||||
exportConfigType = ConfigType.AMNEZIA
|
exportConfigType = ConfigType.AM
|
||||||
if (!isAuthorized && !isTv) {
|
if (!isAuthorized && !isTv) {
|
||||||
showAuthPrompt = true
|
showAuthPrompt = true
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+18
-4
@@ -7,6 +7,7 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.overscroll
|
import androidx.compose.foundation.overscroll
|
||||||
|
import androidx.compose.foundation.rememberOverscrollEffect
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@@ -18,6 +19,7 @@ import com.zaneschepke.wireguardautotunnel.core.tunnel.getValueById
|
|||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||||
@@ -35,12 +37,19 @@ fun TunnelList(
|
|||||||
onToggleTunnel: (TunnelConf, Boolean) -> Unit,
|
onToggleTunnel: (TunnelConf, Boolean) -> Unit,
|
||||||
viewModel: AppViewModel,
|
viewModel: AppViewModel,
|
||||||
) {
|
) {
|
||||||
|
val isTv = LocalIsAndroidTV.current
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val collator = Collator.getInstance(Locale.getDefault())
|
val collator = Collator.getInstance(Locale.getDefault())
|
||||||
val sortedTunnels =
|
val sortedTunnels =
|
||||||
remember(appUiState.tunnels) {
|
remember(appUiState.tunnels) {
|
||||||
appUiState.tunnels.sortedWith(compareBy(collator) { it.tunName })
|
appUiState.tunnels.sortedWith(
|
||||||
|
compareBy(
|
||||||
|
// primary tunnel first
|
||||||
|
{ !it.isPrimaryTunnel },
|
||||||
|
{ collator.compare(it.tunName, "") },
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
@@ -49,7 +58,7 @@ fun TunnelList(
|
|||||||
modifier =
|
modifier =
|
||||||
modifier
|
modifier
|
||||||
.pointerInput(Unit) { if (appUiState.tunnels.isEmpty()) return@pointerInput }
|
.pointerInput(Unit) { if (appUiState.tunnels.isEmpty()) return@pointerInput }
|
||||||
.overscroll(ScrollableDefaults.overscrollEffect()),
|
.overscroll(rememberOverscrollEffect()),
|
||||||
state = rememberLazyListState(0, appUiState.tunnels.count()),
|
state = rememberLazyListState(0, appUiState.tunnels.count()),
|
||||||
userScrollEnabled = true,
|
userScrollEnabled = true,
|
||||||
reverseLayout = false,
|
reverseLayout = false,
|
||||||
@@ -71,8 +80,12 @@ fun TunnelList(
|
|||||||
tunnel = tunnel,
|
tunnel = tunnel,
|
||||||
tunnelState = tunnelState,
|
tunnelState = tunnelState,
|
||||||
onClick = {
|
onClick = {
|
||||||
navController.navigate(Route.TunnelOptions(tunnel.id))
|
if (selectedTunnels.isNotEmpty() && !isTv) {
|
||||||
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
viewModel.handleEvent(AppEvent.ToggleSelectedTunnel(tunnel))
|
||||||
|
} else {
|
||||||
|
navController.navigate(Route.TunnelOptions(tunnel.id))
|
||||||
|
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onDoubleClick = {
|
onDoubleClick = {
|
||||||
viewModel.handleEvent(AppEvent.ToggleTunnelStatsExpanded(tunnel.id))
|
viewModel.handleEvent(AppEvent.ToggleTunnelStatsExpanded(tunnel.id))
|
||||||
@@ -81,6 +94,7 @@ fun TunnelList(
|
|||||||
viewModel.handleEvent(AppEvent.ToggleSelectedTunnel(it))
|
viewModel.handleEvent(AppEvent.ToggleSelectedTunnel(it))
|
||||||
},
|
},
|
||||||
onSwitchClick = { checked -> onToggleTunnel(tunnel, checked) },
|
onSwitchClick = { checked -> onToggleTunnel(tunnel, checked) },
|
||||||
|
isTv = isTv,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -26,7 +26,6 @@ import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
|||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.ExpandingRowListItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.ExpandingRowListItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asColor
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asColor
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -40,9 +39,8 @@ fun TunnelRowItem(
|
|||||||
onDoubleClick: () -> Unit,
|
onDoubleClick: () -> Unit,
|
||||||
onToggleSelectedTunnel: (TunnelConf) -> Unit,
|
onToggleSelectedTunnel: (TunnelConf) -> Unit,
|
||||||
onSwitchClick: (Boolean) -> Unit,
|
onSwitchClick: (Boolean) -> Unit,
|
||||||
|
isTv: Boolean,
|
||||||
) {
|
) {
|
||||||
val isTv = LocalIsAndroidTV.current
|
|
||||||
|
|
||||||
val leadingIconColor =
|
val leadingIconColor =
|
||||||
remember(state) {
|
remember(state) {
|
||||||
if (state.status.isUp()) tunnelState.statistics.asColor() else Color.Gray
|
if (state.status.isUp()) tunnelState.statistics.asColor() else Color.Gray
|
||||||
|
|||||||
+67
-23
@@ -8,6 +8,9 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.derivedStateOf
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
@@ -21,49 +24,90 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.toThreeDecimalPlaceSt
|
|||||||
@Composable
|
@Composable
|
||||||
fun TunnelStatisticsRow(statistics: TunnelStatistics?, tunnelConf: TunnelConf) {
|
fun TunnelStatisticsRow(statistics: TunnelStatistics?, tunnelConf: TunnelConf) {
|
||||||
val config = TunnelConf.configFromAmQuick(tunnelConf.wgQuick)
|
val config = TunnelConf.configFromAmQuick(tunnelConf.wgQuick)
|
||||||
config.peers.forEach { peer ->
|
Column(
|
||||||
Row(
|
modifier = Modifier.fillMaxWidth().padding(start = 45.dp, bottom = 10.dp, end = 10.dp),
|
||||||
modifier = Modifier.fillMaxWidth().padding(end = 10.dp, bottom = 10.dp, start = 45.dp),
|
verticalArrangement = Arrangement.spacedBy(10.dp, Alignment.CenterVertically),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
horizontalAlignment = Alignment.Start,
|
||||||
horizontalArrangement = Arrangement.spacedBy(5.dp, Alignment.Start),
|
) {
|
||||||
) {
|
config.peers.forEach { peer ->
|
||||||
val peerId = peer.publicKey.toBase64().subSequence(0, 3).toString() + "***"
|
val peerId = remember { peer.publicKey.toBase64().subSequence(0, 3).toString() + "***" }
|
||||||
val peerRx = statistics?.peerStats(peer.publicKey)?.rxBytes ?: 0
|
val endpoint =
|
||||||
val peerTx = statistics?.peerStats(peer.publicKey)?.txBytes ?: 0
|
remember(statistics) { statistics?.peerStats(peer.publicKey)?.resolvedEndpoint }
|
||||||
val peerTxMB = NumberUtils.bytesToMB(peerTx).toThreeDecimalPlaceString()
|
val peerRxMB by
|
||||||
val peerRxMB = NumberUtils.bytesToMB(peerRx).toThreeDecimalPlaceString()
|
remember(statistics) {
|
||||||
val handshake =
|
derivedStateOf {
|
||||||
statistics?.peerStats(peer.publicKey)?.latestHandshakeEpochMillis?.let {
|
statistics
|
||||||
if (it == 0L) {
|
?.peerStats(peer.publicKey)
|
||||||
stringResource(R.string.never)
|
?.rxBytes
|
||||||
} else {
|
?.let { NumberUtils.bytesToMB(it) }
|
||||||
"${NumberUtils.getSecondsBetweenTimestampAndNow(it)} ${stringResource(R.string.sec)}"
|
?.toThreeDecimalPlaceString()
|
||||||
}
|
}
|
||||||
} ?: stringResource(R.string.never)
|
}
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
val peerTxMB by
|
||||||
|
remember(statistics) {
|
||||||
|
derivedStateOf {
|
||||||
|
statistics
|
||||||
|
?.peerStats(peer.publicKey)
|
||||||
|
?.txBytes
|
||||||
|
?.let { NumberUtils.bytesToMB(it) }
|
||||||
|
?.toThreeDecimalPlaceString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val handshake by
|
||||||
|
remember(statistics) {
|
||||||
|
derivedStateOf {
|
||||||
|
statistics?.peerStats(peer.publicKey)?.latestHandshakeEpochMillis?.let {
|
||||||
|
if (it == 0L) {
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
"${NumberUtils.getSecondsBetweenTimestampAndNow(it)}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start),
|
||||||
|
) {
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.peer).lowercase() + ": $peerId",
|
stringResource(R.string.peer).lowercase() + ": $peerId",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
"tx: $peerTxMB MB",
|
stringResource(R.string.handshake) +
|
||||||
|
": ${if(handshake == null) stringResource(R.string.never) else handshake + " " + stringResource(R.string.sec)}",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start),
|
||||||
|
) {
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.handshake) + ": $handshake",
|
"rx: ${peerRxMB ?: 0.00} MB",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
"rx: $peerRxMB MB",
|
"tx: ${peerTxMB ?: 0.00} MB",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if (endpoint != null) {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
"endpoint: $endpoint",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.outline,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-7
@@ -16,16 +16,15 @@ import androidx.compose.material3.OutlinedTextField
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
|
||||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||||
import androidx.compose.ui.text.input.VisualTransformation
|
import androidx.compose.ui.text.input.VisualTransformation
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationTextBox
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationTextBox
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.InterfaceProxy
|
import com.zaneschepke.wireguardautotunnel.ui.state.InterfaceProxy
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -38,7 +37,7 @@ fun InterfaceFields(
|
|||||||
onInterfaceChange: (InterfaceProxy) -> Unit,
|
onInterfaceChange: (InterfaceProxy) -> Unit,
|
||||||
) {
|
) {
|
||||||
val keyboardController = LocalSoftwareKeyboardController.current
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
val clipboardManager = LocalClipboardManager.current
|
val clipboardManager = rememberClipboardHelper()
|
||||||
val keyboardActions = KeyboardActions(onDone = { keyboardController?.hide() })
|
val keyboardActions = KeyboardActions(onDone = { keyboardController?.hide() })
|
||||||
val keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done)
|
val keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done)
|
||||||
|
|
||||||
@@ -53,8 +52,9 @@ fun InterfaceFields(
|
|||||||
if (isAuthenticated) VisualTransformation.None else PasswordVisualTransformation(),
|
if (isAuthenticated) VisualTransformation.None else PasswordVisualTransformation(),
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
IconButton(
|
IconButton(
|
||||||
enabled = isAuthenticated,
|
enabled = true,
|
||||||
onClick = {
|
onClick = {
|
||||||
|
if (!isAuthenticated) return@IconButton showAuthPrompt()
|
||||||
val keypair = com.wireguard.crypto.KeyPair()
|
val keypair = com.wireguard.crypto.KeyPair()
|
||||||
onInterfaceChange(
|
onInterfaceChange(
|
||||||
interfaceState.copy(
|
interfaceState.copy(
|
||||||
@@ -88,9 +88,7 @@ fun InterfaceFields(
|
|||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
IconButton(
|
IconButton(onClick = { clipboardManager.copy(interfaceState.publicKey) }) {
|
||||||
onClick = { clipboardManager.setText(AnnotatedString(interfaceState.publicKey)) }
|
|
||||||
) {
|
|
||||||
Icon(Icons.Rounded.ContentCopy, stringResource(R.string.copy_public_key))
|
Icon(Icons.Rounded.ContentCopy, stringResource(R.string.copy_public_key))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main.scanner
|
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.DisposableEffect
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.viewinterop.AndroidView
|
|
||||||
import com.journeyapps.barcodescanner.CompoundBarcodeView
|
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun ScannerScreen(viewModel: AppViewModel) {
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
val barcodeView = remember {
|
|
||||||
CompoundBarcodeView(context).apply {
|
|
||||||
this.initializeFromIntent((context as Activity).intent)
|
|
||||||
this.setStatusText("")
|
|
||||||
this.decodeSingle { result ->
|
|
||||||
result.text?.let { barCodeOrQr ->
|
|
||||||
viewModel.handleEvent(AppEvent.ImportTunnelFromQrCode(barCodeOrQr))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AndroidView(factory = { barcodeView })
|
|
||||||
DisposableEffect(Unit) {
|
|
||||||
barcodeView.resume()
|
|
||||||
onDispose { barcodeView.pause() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+15
-17
@@ -1,12 +1,15 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel
|
||||||
|
|
||||||
import androidx.compose.animation.Crossfade
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.animation.core.tween
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
@@ -34,21 +37,16 @@ fun SplitTunnelScreen(
|
|||||||
appViewModel.handleEvent(AppEvent.PopBackStack(true))
|
appViewModel.handleEvent(AppEvent.PopBackStack(true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (uiState.loading) {
|
||||||
Crossfade(
|
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||||
targetState = uiState.loading,
|
CircularProgressIndicator(modifier = Modifier.size(30.dp), strokeWidth = 5.dp)
|
||||||
animationSpec = tween(200),
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
) { isLoading ->
|
|
||||||
if (isLoading) {
|
|
||||||
SplitTunnelSkeleton()
|
|
||||||
} else {
|
|
||||||
SplitTunnelContent(
|
|
||||||
uiState = uiState,
|
|
||||||
onSplitOptionChange = viewModel::updateSplitOption,
|
|
||||||
onAppSelectionToggle = viewModel::toggleAppSelection,
|
|
||||||
onQueryChange = viewModel::onSearchQuery,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
SplitTunnelContent(
|
||||||
|
uiState = uiState,
|
||||||
|
onSplitOptionChange = viewModel::updateSplitOption,
|
||||||
|
onAppSelectionToggle = viewModel::toggleAppSelection,
|
||||||
|
onQueryChange = viewModel::onSearchQuery,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-92
@@ -1,92 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel
|
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.layout.width
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.animation.ShimmerEffect
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun SplitTunnelSkeleton() {
|
|
||||||
val shimmerBrush = ShimmerEffect()
|
|
||||||
|
|
||||||
Column(
|
|
||||||
verticalArrangement = Arrangement.spacedBy(24.dp, Alignment.CenterVertically),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(top = 24.dp),
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp).height(45.dp),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
|
||||||
) {
|
|
||||||
repeat(3) {
|
|
||||||
Box(
|
|
||||||
modifier =
|
|
||||||
Modifier.weight(1f)
|
|
||||||
.height(45.dp)
|
|
||||||
.clip(RoundedCornerShape(8.dp))
|
|
||||||
.background(shimmerBrush)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp).height(45.dp),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier =
|
|
||||||
Modifier.height(45.dp)
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clip(RoundedCornerShape(8.dp))
|
|
||||||
.background(shimmerBrush)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
LazyColumn(
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.Top,
|
|
||||||
contentPadding = PaddingValues(top = 10.dp),
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
) {
|
|
||||||
items(20) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp, vertical = 8.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier =
|
|
||||||
Modifier.size(iconSize).clip(CircleShape).background(shimmerBrush)
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(16.dp))
|
|
||||||
Box(
|
|
||||||
modifier =
|
|
||||||
Modifier.height(20.dp)
|
|
||||||
.weight(1f)
|
|
||||||
.clip(RoundedCornerShape(4.dp))
|
|
||||||
.background(shimmerBrush)
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(16.dp))
|
|
||||||
Box(modifier = Modifier.size(24.dp).clip(CircleShape).background(shimmerBrush))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+5
-6
@@ -18,7 +18,6 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
|||||||
import java.text.Collator
|
import java.text.Collator
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
@@ -50,7 +49,6 @@ constructor(
|
|||||||
tunnelId?.let { loadInitialState(it) }
|
tunnelId?.let { loadInitialState(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO improve this loading experience
|
|
||||||
private fun loadInitialState(tunnelId: Int) =
|
private fun loadInitialState(tunnelId: Int) =
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val tunnel = tunnelRepository.getById(tunnelId) ?: return@launch
|
val tunnel = tunnelRepository.getById(tunnelId) ?: return@launch
|
||||||
@@ -66,7 +64,7 @@ constructor(
|
|||||||
|
|
||||||
val installedPackages = packages.map { it.packageName }.toSet()
|
val installedPackages = packages.map { it.packageName }.toSet()
|
||||||
|
|
||||||
// remove uninstalled apps
|
// Remove uninstalled apps
|
||||||
proxyInterface.includedApplications.retainAll { it in installedPackages }
|
proxyInterface.includedApplications.retainAll { it in installedPackages }
|
||||||
proxyInterface.excludedApplications.retainAll { it in installedPackages }
|
proxyInterface.excludedApplications.retainAll { it in installedPackages }
|
||||||
|
|
||||||
@@ -98,12 +96,13 @@ constructor(
|
|||||||
selected,
|
selected,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.sortedWith(compareBy(collator) { it.first.name })
|
.sortedWith(
|
||||||
|
compareByDescending<Pair<TunnelApp, Boolean>> { it.second }
|
||||||
|
.thenBy(collator) { it.first.name }
|
||||||
|
)
|
||||||
|
|
||||||
allTunneledApps = tunneledApps
|
allTunneledApps = tunneledApps
|
||||||
|
|
||||||
delay(500)
|
|
||||||
|
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
SplitTunnelUiState(
|
SplitTunnelUiState(
|
||||||
loading = false,
|
loading = false,
|
||||||
|
|||||||
+37
-2
@@ -6,18 +6,53 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.*
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.*
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.AuthorizationPromptWrapper
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppViewState
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TunnelOptionsScreen(tunnelConf: TunnelConf, viewModel: AppViewModel) {
|
fun TunnelOptionsScreen(
|
||||||
|
tunnelConf: TunnelConf,
|
||||||
|
viewModel: AppViewModel,
|
||||||
|
appViewState: AppViewState,
|
||||||
|
) {
|
||||||
|
val isTv = LocalIsAndroidTV.current
|
||||||
|
|
||||||
|
var showAuthPrompt by remember { mutableStateOf(!isTv) }
|
||||||
|
var isAuthorized by remember { mutableStateOf(isTv) }
|
||||||
|
|
||||||
|
if (appViewState.showModal == AppViewState.ModalType.QR) {
|
||||||
|
|
||||||
|
// Show authorization prompt if needed
|
||||||
|
if (showAuthPrompt) {
|
||||||
|
AuthorizationPromptWrapper(
|
||||||
|
onDismiss = { showAuthPrompt = false },
|
||||||
|
onSuccess = {
|
||||||
|
showAuthPrompt = false
|
||||||
|
isAuthorized = true
|
||||||
|
},
|
||||||
|
viewModel = viewModel,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (isAuthorized) {
|
||||||
|
QrCodeDialog(
|
||||||
|
tunnelConf = tunnelConf,
|
||||||
|
onDismiss = {
|
||||||
|
viewModel.handleEvent(AppEvent.SetShowModal(AppViewState.ModalType.NONE))
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.Start,
|
horizontalAlignment = Alignment.Start,
|
||||||
|
|||||||
+190
@@ -0,0 +1,190 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.Image
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.outlined.Check
|
||||||
|
import androidx.compose.material.icons.outlined.VpnKey
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.MultiChoiceSegmentedButtonRow
|
||||||
|
import androidx.compose.material3.SegmentedButton
|
||||||
|
import androidx.compose.material3.SegmentedButtonDefaults
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.window.DialogProperties
|
||||||
|
import com.zaneschepke.wireguardautotunnel.MainActivity
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.ConfigType
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.setScreenBrightness
|
||||||
|
import io.github.alexzhirkevich.qrose.options.QrBallShape
|
||||||
|
import io.github.alexzhirkevich.qrose.options.QrBrush
|
||||||
|
import io.github.alexzhirkevich.qrose.options.QrErrorCorrectionLevel
|
||||||
|
import io.github.alexzhirkevich.qrose.options.QrFrameShape
|
||||||
|
import io.github.alexzhirkevich.qrose.options.QrOptions
|
||||||
|
import io.github.alexzhirkevich.qrose.options.QrPixelShape
|
||||||
|
import io.github.alexzhirkevich.qrose.options.circle
|
||||||
|
import io.github.alexzhirkevich.qrose.options.roundCorners
|
||||||
|
import io.github.alexzhirkevich.qrose.options.solid
|
||||||
|
import io.github.alexzhirkevich.qrose.rememberQrCodePainter
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun QrCodeDialog(tunnelConf: TunnelConf, onDismiss: () -> Unit) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val activity = context as? MainActivity
|
||||||
|
|
||||||
|
// Handle screen brightness
|
||||||
|
DisposableEffect(Unit) {
|
||||||
|
activity?.setScreenBrightness(1.0f)
|
||||||
|
onDispose { activity?.setScreenBrightness(-1f) }
|
||||||
|
}
|
||||||
|
|
||||||
|
QrCodeAlertDialog(tunnelConf = tunnelConf, onDismiss = onDismiss)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun QrCodeAlertDialog(tunnelConf: TunnelConf, onDismiss: () -> Unit) {
|
||||||
|
Surface(color = Color.White, tonalElevation = 0.dp) {
|
||||||
|
AlertDialog(
|
||||||
|
containerColor = Color.White,
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text(stringResource(R.string.done), color = MaterialTheme.colorScheme.surface)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
text = tunnelConf.name,
|
||||||
|
color = Color.Black,
|
||||||
|
style = MaterialTheme.typography.titleLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
text = { QrCodeContent(tunnelConf = tunnelConf) },
|
||||||
|
properties = DialogProperties(usePlatformDefaultWidth = true),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun QrCodeContent(tunnelConf: TunnelConf) {
|
||||||
|
var selectedOption by remember { mutableStateOf(ConfigType.WG) }
|
||||||
|
val qrCodeText =
|
||||||
|
when (selectedOption) {
|
||||||
|
ConfigType.AM -> tunnelConf.toAmConfig().toAwgQuickString(true)
|
||||||
|
ConfigType.WG -> tunnelConf.toWgConfig().toWgQuickString(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp, Alignment.Top),
|
||||||
|
) {
|
||||||
|
val qrCodePainter = rememberQrCodePainter(data = qrCodeText, options = createQrOptions())
|
||||||
|
Image(
|
||||||
|
painter = qrCodePainter,
|
||||||
|
contentDescription = stringResource(R.string.show_qr),
|
||||||
|
modifier =
|
||||||
|
Modifier.size(300.dp)
|
||||||
|
.align(Alignment.CenterHorizontally)
|
||||||
|
.padding(16.dp)
|
||||||
|
.background(Color.White),
|
||||||
|
)
|
||||||
|
ConfigTypeSelector(
|
||||||
|
selectedOption = selectedOption,
|
||||||
|
onOptionSelected = { selectedOption = it },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ConfigTypeSelector(selectedOption: ConfigType, onOptionSelected: (ConfigType) -> Unit) {
|
||||||
|
MultiChoiceSegmentedButtonRow(modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp)) {
|
||||||
|
ConfigType.entries.sortedDescending().forEachIndexed { index, entry ->
|
||||||
|
val isActive = selectedOption == entry
|
||||||
|
val typeName =
|
||||||
|
stringResource(
|
||||||
|
when (entry) {
|
||||||
|
ConfigType.AM -> R.string.amnezia
|
||||||
|
ConfigType.WG -> R.string.wireguard
|
||||||
|
}
|
||||||
|
)
|
||||||
|
SegmentedButton(
|
||||||
|
shape =
|
||||||
|
SegmentedButtonDefaults.itemShape(
|
||||||
|
index = index,
|
||||||
|
count = ConfigType.entries.size,
|
||||||
|
baseShape = RoundedCornerShape(8.dp),
|
||||||
|
),
|
||||||
|
icon = {
|
||||||
|
SegmentedButtonDefaults.Icon(
|
||||||
|
active = isActive,
|
||||||
|
activeContent = {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.Check,
|
||||||
|
contentDescription = stringResource(R.string.select),
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.size(SegmentedButtonDefaults.IconSize),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.VpnKey,
|
||||||
|
contentDescription = typeName,
|
||||||
|
tint = Color.Black,
|
||||||
|
modifier = Modifier.size(SegmentedButtonDefaults.IconSize),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
colors =
|
||||||
|
SegmentedButtonDefaults.colors()
|
||||||
|
.copy(
|
||||||
|
activeContainerColor = Color.White,
|
||||||
|
inactiveContainerColor = Color.White,
|
||||||
|
),
|
||||||
|
onCheckedChange = { onOptionSelected(entry) },
|
||||||
|
checked = isActive,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = typeName,
|
||||||
|
color = Color.Black,
|
||||||
|
style = MaterialTheme.typography.labelMedium,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createQrOptions(): QrOptions = QrOptions {
|
||||||
|
shapes {
|
||||||
|
darkPixel = QrPixelShape.circle()
|
||||||
|
ball = QrBallShape.circle()
|
||||||
|
frame = QrFrameShape.roundCorners(0.2f)
|
||||||
|
}
|
||||||
|
colors {
|
||||||
|
dark = QrBrush.solid(Color.Black)
|
||||||
|
frame = QrBrush.solid(Color.Black)
|
||||||
|
ball = QrBrush.solid(Color.Black)
|
||||||
|
}
|
||||||
|
errorCorrectionLevel = QrErrorCorrectionLevel.Medium
|
||||||
|
}
|
||||||
+3
-5
@@ -8,20 +8,19 @@ import androidx.compose.material3.MaterialTheme
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun RemoteControlItem(uiState: AppUiState, viewModel: AppViewModel): SelectionItem {
|
fun RemoteControlItem(uiState: AppUiState, viewModel: AppViewModel): SelectionItem {
|
||||||
val clipboardManager = LocalClipboardManager.current
|
val clipboardManager = rememberClipboardHelper()
|
||||||
|
|
||||||
return SelectionItem(
|
return SelectionItem(
|
||||||
leadingIcon = Icons.Filled.SmartToy,
|
leadingIcon = Icons.Filled.SmartToy,
|
||||||
@@ -42,8 +41,7 @@ fun RemoteControlItem(uiState: AppUiState, viewModel: AppViewModel): SelectionIt
|
|||||||
),
|
),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
modifier =
|
modifier = Modifier.clickable { clipboardManager.copy(key) },
|
||||||
Modifier.clickable { clipboardManager.setText(AnnotatedString(key)) },
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-20
@@ -23,25 +23,21 @@ fun DisplayScreen(appUiState: AppUiState, viewModel: AppViewModel) {
|
|||||||
verticalArrangement = Arrangement.spacedBy(24.dp, Alignment.Top),
|
verticalArrangement = Arrangement.spacedBy(24.dp, Alignment.Top),
|
||||||
modifier = Modifier.fillMaxSize().padding(top = 24.dp).padding(horizontal = 24.dp),
|
modifier = Modifier.fillMaxSize().padding(top = 24.dp).padding(horizontal = 24.dp),
|
||||||
) {
|
) {
|
||||||
IconSurfaceButton(
|
enumValues<Theme>().forEach {
|
||||||
title = stringResource(R.string.automatic),
|
val title =
|
||||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.AUTOMATIC)) },
|
when (it) {
|
||||||
selected = appUiState.appState.theme == Theme.AUTOMATIC,
|
Theme.DARK -> stringResource(R.string.dark)
|
||||||
)
|
Theme.LIGHT -> stringResource(R.string.light)
|
||||||
IconSurfaceButton(
|
Theme.AUTOMATIC -> stringResource(R.string.automatic)
|
||||||
title = stringResource(R.string.light),
|
Theme.DYNAMIC -> stringResource(R.string.dynamic)
|
||||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.LIGHT)) },
|
Theme.DARKER -> stringResource(R.string.darker)
|
||||||
selected = appUiState.appState.theme == Theme.LIGHT,
|
Theme.AMOLED -> stringResource(R.string.amoled)
|
||||||
)
|
}
|
||||||
IconSurfaceButton(
|
IconSurfaceButton(
|
||||||
title = stringResource(R.string.dark),
|
title = title,
|
||||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.DARK)) },
|
onClick = { viewModel.handleEvent(AppEvent.SetTheme(it)) },
|
||||||
selected = appUiState.appState.theme == Theme.DARK,
|
selected = appUiState.appState.theme == it,
|
||||||
)
|
)
|
||||||
IconSurfaceButton(
|
}
|
||||||
title = stringResource(R.string.dynamic),
|
|
||||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.DYNAMIC)) },
|
|
||||||
selected = appUiState.appState.theme == Theme.DYNAMIC,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -11,17 +11,16 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.zaneschepke.logcatter.model.LogMessage
|
import com.zaneschepke.logcatter.model.LogMessage
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.text.LogTypeLabel
|
import com.zaneschepke.wireguardautotunnel.ui.common.text.LogTypeLabel
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LogItem(log: LogMessage) {
|
fun LogItem(log: LogMessage) {
|
||||||
val clipboardManager = LocalClipboardManager.current
|
val clipboardManager = rememberClipboardHelper()
|
||||||
val fontSize = 10.sp
|
val fontSize = 10.sp
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
@@ -32,7 +31,7 @@ fun LogItem(log: LogMessage) {
|
|||||||
.clickable(
|
.clickable(
|
||||||
interactionSource = remember { MutableInteractionSource() },
|
interactionSource = remember { MutableInteractionSource() },
|
||||||
indication = null,
|
indication = null,
|
||||||
onClick = { clipboardManager.setText(AnnotatedString(log.toString())) },
|
onClick = { clipboardManager.copy(log.toString()) },
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
Text(text = log.tag, modifier = Modifier.fillMaxSize(0.3f), fontSize = fontSize)
|
Text(text = log.tag, modifier = Modifier.fillMaxSize(0.3f), fontSize = fontSize)
|
||||||
|
|||||||
+9
-3
@@ -23,6 +23,7 @@ import com.zaneschepke.wireguardautotunnel.ui.common.label.GroupLabel
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.ContactSupportOptions
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.ContactSupportOptions
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.GeneralSupportOptions
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.GeneralSupportOptions
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.UpdateSection
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.UpdateSection
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.canInstallPackages
|
import com.zaneschepke.wireguardautotunnel.util.extensions.canInstallPackages
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestInstallPackagesPermission
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestInstallPackagesPermission
|
||||||
@@ -54,7 +55,7 @@ fun SupportScreen(viewModel: SupportViewModel = hiltViewModel(), appViewModel: A
|
|||||||
InfoDialog(
|
InfoDialog(
|
||||||
onDismiss = { viewModel.handleUpdateShown() },
|
onDismiss = { viewModel.handleUpdateShown() },
|
||||||
onAttest = {
|
onAttest = {
|
||||||
if (BuildConfig.FLAVOR != "full") {
|
if (BuildConfig.FLAVOR != Constants.STANDALONE_FLAVOR) {
|
||||||
uiState.appUpdate?.apkUrl?.let { context.openWebUrl(it) }
|
uiState.appUpdate?.apkUrl?.let { context.openWebUrl(it) }
|
||||||
return@InfoDialog
|
return@InfoDialog
|
||||||
}
|
}
|
||||||
@@ -86,7 +87,8 @@ fun SupportScreen(viewModel: SupportViewModel = hiltViewModel(), appViewModel: A
|
|||||||
},
|
},
|
||||||
confirmText = {
|
confirmText = {
|
||||||
Text(
|
Text(
|
||||||
if (BuildConfig.FLAVOR != "full") stringResource(R.string.download)
|
if (BuildConfig.FLAVOR != Constants.STANDALONE_FLAVOR)
|
||||||
|
stringResource(R.string.download)
|
||||||
else stringResource(R.string.download_and_install)
|
else stringResource(R.string.download_and_install)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -121,7 +123,11 @@ fun SupportScreen(viewModel: SupportViewModel = hiltViewModel(), appViewModel: A
|
|||||||
)
|
)
|
||||||
UpdateSection(
|
UpdateSection(
|
||||||
onUpdateCheck = {
|
onUpdateCheck = {
|
||||||
if (BuildConfig.DEBUG || BuildConfig.VERSION_NAME.contains("beta"))
|
if (
|
||||||
|
BuildConfig.DEBUG ||
|
||||||
|
BuildConfig.VERSION_NAME.contains("beta") ||
|
||||||
|
BuildConfig.FLAVOR == Constants.GOOGLE_PLAY_FLAVOR
|
||||||
|
)
|
||||||
return@UpdateSection context.showToast(R.string.update_check_unsupported)
|
return@UpdateSection context.showToast(R.string.update_check_unsupported)
|
||||||
context.showToast(R.string.checking_for_update)
|
context.showToast(R.string.checking_for_update)
|
||||||
viewModel.handleUpdateCheck()
|
viewModel.handleUpdateCheck()
|
||||||
|
|||||||
+1
-1
@@ -85,7 +85,7 @@ fun ContactSupportOptions(context: android.content.Context) {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if (BuildConfig.FLAVOR == Constants.FDROID_FLAVOR) {
|
if (BuildConfig.FLAVOR != Constants.GOOGLE_PLAY_FLAVOR) {
|
||||||
add(
|
add(
|
||||||
SelectionItem(
|
SelectionItem(
|
||||||
leadingIcon = Icons.Filled.Favorite,
|
leadingIcon = Icons.Filled.Favorite,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ data class AppViewState(
|
|||||||
NONE,
|
NONE,
|
||||||
DELETE,
|
DELETE,
|
||||||
INFO,
|
INFO,
|
||||||
|
QR,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class BottomSheet {
|
enum class BottomSheet {
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ val Plantation = Color(0xFF264A49)
|
|||||||
val Shark = Color(0xFF21272A)
|
val Shark = Color(0xFF21272A)
|
||||||
val BalticSea = Color(0xFF1C1B1F)
|
val BalticSea = Color(0xFF1C1B1F)
|
||||||
|
|
||||||
|
// amoled
|
||||||
|
val ElectricTeal = Color(0xFF4DD0E1)
|
||||||
|
|
||||||
// Status colors
|
// Status colors
|
||||||
val SilverTree = Color(0xFF6DB58B)
|
val SilverTree = Color(0xFF6DB58B)
|
||||||
val Brick = Color(0xFFCE4257)
|
val Brick = Color(0xFFCE4257)
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ enum class Theme {
|
|||||||
AUTOMATIC,
|
AUTOMATIC,
|
||||||
LIGHT,
|
LIGHT,
|
||||||
DARK,
|
DARK,
|
||||||
|
DARKER,
|
||||||
|
AMOLED,
|
||||||
DYNAMIC,
|
DYNAMIC,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +61,18 @@ fun WireguardAutoTunnelTheme(theme: Theme = Theme.AUTOMATIC, content: @Composabl
|
|||||||
isDark = true
|
isDark = true
|
||||||
DarkColorScheme
|
DarkColorScheme
|
||||||
}
|
}
|
||||||
|
Theme.DARKER -> {
|
||||||
|
isDark = true
|
||||||
|
DarkColorScheme.copy(surface = BalticSea, background = BalticSea)
|
||||||
|
}
|
||||||
|
Theme.AMOLED -> {
|
||||||
|
isDark = true
|
||||||
|
DarkColorScheme.copy(
|
||||||
|
surface = Color.Black,
|
||||||
|
background = Color.Black,
|
||||||
|
primary = ElectricTeal,
|
||||||
|
)
|
||||||
|
}
|
||||||
Theme.LIGHT -> {
|
Theme.LIGHT -> {
|
||||||
isDark = false
|
isDark = false
|
||||||
LightColorScheme
|
LightColorScheme
|
||||||
|
|||||||
@@ -35,5 +35,7 @@ object Constants {
|
|||||||
const val QR_CODE_NAME_PROPERTY = "# Name ="
|
const val QR_CODE_NAME_PROPERTY = "# Name ="
|
||||||
|
|
||||||
const val FDROID_FLAVOR = "fdroid"
|
const val FDROID_FLAVOR = "fdroid"
|
||||||
|
const val GOOGLE_PLAY_FLAVOR = "google"
|
||||||
|
const val STANDALONE_FLAVOR = "standalone"
|
||||||
const val RELEASE = "release"
|
const val RELEASE = "release"
|
||||||
}
|
}
|
||||||
|
|||||||
+23
@@ -1,6 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.util.extensions
|
package com.zaneschepke.wireguardautotunnel.util.extensions
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
|
import android.app.Activity
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Context.POWER_SERVICE
|
import android.content.Context.POWER_SERVICE
|
||||||
@@ -17,6 +18,9 @@ import android.widget.Toast
|
|||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
import androidx.core.location.LocationManagerCompat
|
import androidx.core.location.LocationManagerCompat
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
|
import androidx.core.view.WindowCompat
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import androidx.core.view.WindowInsetsControllerCompat
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.tile.AutoTunnelControlTile
|
import com.zaneschepke.wireguardautotunnel.core.service.tile.AutoTunnelControlTile
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.tile.TunnelControlTile
|
import com.zaneschepke.wireguardautotunnel.core.service.tile.TunnelControlTile
|
||||||
@@ -225,3 +229,22 @@ fun Context.installApk(apkFile: File) {
|
|||||||
}
|
}
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Activity.setScreenBrightness(brightness: Float) {
|
||||||
|
window.attributes = window.attributes.apply { screenBrightness = brightness }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Activity.enableImmersiveMode() {
|
||||||
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
|
val controller = WindowCompat.getInsetsController(window, window.decorView)
|
||||||
|
controller.systemBarsBehavior =
|
||||||
|
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
|
controller.hide(WindowInsetsCompat.Type.systemBars())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Activity.disableImmersiveMode() {
|
||||||
|
WindowCompat.setDecorFitsSystemWindows(window, true)
|
||||||
|
val controller = WindowCompat.getInsetsController(window, window.decorView)
|
||||||
|
controller.show(WindowInsetsCompat.Type.systemBars())
|
||||||
|
window.statusBarColor = android.graphics.Color.TRANSPARENT
|
||||||
|
}
|
||||||
|
|||||||
+19
-4
@@ -1,14 +1,29 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.util.extensions
|
package com.zaneschepke.wireguardautotunnel.util.extensions
|
||||||
|
|
||||||
import java.util.regex.Pattern
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
val hasNumberInParentheses = """^(.+?)\((\d+)\)$""".toRegex()
|
val hasNumberInParentheses = """^(.+?)\((\d+)\)$""".toRegex()
|
||||||
|
|
||||||
fun String.isValidIpv4orIpv6Address(): Boolean {
|
fun String.isValidIpv4orIpv6Address(): Boolean {
|
||||||
val ipv4Pattern = Pattern.compile("^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\$")
|
val sanitized = removeSurrounding("[", "]")
|
||||||
val ipv6Pattern = Pattern.compile("^([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\$")
|
val ipv6Pattern =
|
||||||
return ipv4Pattern.matcher(this).matches() || ipv6Pattern.matcher(this).matches()
|
Regex(
|
||||||
|
"(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:)" +
|
||||||
|
"{1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]" +
|
||||||
|
"{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:" +
|
||||||
|
"[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4})" +
|
||||||
|
"{1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}" +
|
||||||
|
":((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]" +
|
||||||
|
"{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}" +
|
||||||
|
"[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:)" +
|
||||||
|
"{1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))"
|
||||||
|
)
|
||||||
|
val ipv4Pattern =
|
||||||
|
Regex(
|
||||||
|
"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}" +
|
||||||
|
"(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
|
||||||
|
)
|
||||||
|
return ipv4Pattern.matches(sanitized) || ipv6Pattern.matches(sanitized)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.hasNumberInParentheses(): Boolean {
|
fun String.hasNumberInParentheses(): Boolean {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ constructor(
|
|||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||||
@MainDispatcher private val mainDispatcher: CoroutineDispatcher,
|
@MainDispatcher private val mainDispatcher: CoroutineDispatcher,
|
||||||
@AppShell private val rootShell: Provider<RootShell>,
|
@AppShell private val rootShell: Provider<RootShell>,
|
||||||
private val tunnelManager: TunnelManager,
|
val tunnelManager: TunnelManager,
|
||||||
private val serviceManager: ServiceManager,
|
private val serviceManager: ServiceManager,
|
||||||
private val logReader: LogReader,
|
private val logReader: LogReader,
|
||||||
private val fileUtils: FileUtils,
|
private val fileUtils: FileUtils,
|
||||||
@@ -86,7 +86,7 @@ constructor(
|
|||||||
appDataRepository.tunnels.flow,
|
appDataRepository.tunnels.flow,
|
||||||
appDataRepository.appState.flow,
|
appDataRepository.appState.flow,
|
||||||
tunnelManager.activeTunnels,
|
tunnelManager.activeTunnels,
|
||||||
serviceManager.autoTunnelActive,
|
serviceManager.autoTunnelService.map { it != null },
|
||||||
networkMonitor.networkStatusFlow,
|
networkMonitor.networkStatusFlow,
|
||||||
) { array ->
|
) { array ->
|
||||||
val settings = array[0] as AppSettings
|
val settings = array[0] as AppSettings
|
||||||
@@ -206,7 +206,6 @@ constructor(
|
|||||||
is AppEvent.ShowMessage -> handleShowMessage(event.message)
|
is AppEvent.ShowMessage -> handleShowMessage(event.message)
|
||||||
is AppEvent.PopBackStack ->
|
is AppEvent.PopBackStack ->
|
||||||
_appViewState.update { it.copy(popBackStack = event.pop) }
|
_appViewState.update { it.copy(popBackStack = event.pop) }
|
||||||
is AppEvent.ClearTunnelError -> tunnelManager.clearError(event.tunnel)
|
|
||||||
AppEvent.ToggleRemoteControl -> handleToggleRemoteControl(state.appState)
|
AppEvent.ToggleRemoteControl -> handleToggleRemoteControl(state.appState)
|
||||||
AppEvent.ClearSelectedTunnels -> clearSelectedTunnels()
|
AppEvent.ClearSelectedTunnels -> clearSelectedTunnels()
|
||||||
is AppEvent.SetShowModal ->
|
is AppEvent.SetShowModal ->
|
||||||
@@ -265,6 +264,9 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleTunnelErrors() =
|
||||||
|
viewModelScope.launch { tunnelManager.errorEvents.collect { errorEvent -> } }
|
||||||
|
|
||||||
private suspend fun handleAppReadyCheck(tunnels: List<TunnelConf>) {
|
private suspend fun handleAppReadyCheck(tunnels: List<TunnelConf>) {
|
||||||
if (tunnels.size == appDataRepository.tunnels.count()) {
|
if (tunnels.size == appDataRepository.tunnels.count()) {
|
||||||
_appViewState.update { it.copy(isAppReady = true) }
|
_appViewState.update { it.copy(isAppReady = true) }
|
||||||
@@ -398,6 +400,7 @@ constructor(
|
|||||||
|
|
||||||
private suspend fun handleClipboardImport(config: String, tunnels: List<TunnelConf>) {
|
private suspend fun handleClipboardImport(config: String, tunnels: List<TunnelConf>) {
|
||||||
runCatching {
|
runCatching {
|
||||||
|
Timber.d("Config: $config")
|
||||||
val amConfig = TunnelConf.configFromAmQuick(config)
|
val amConfig = TunnelConf.configFromAmQuick(config)
|
||||||
val tunnelConf = TunnelConf.tunnelConfigFromAmConfig(amConfig)
|
val tunnelConf = TunnelConf.tunnelConfigFromAmConfig(amConfig)
|
||||||
saveTunnel(
|
saveTunnel(
|
||||||
@@ -686,7 +689,7 @@ constructor(
|
|||||||
if (tunnels.isEmpty()) return
|
if (tunnels.isEmpty()) return
|
||||||
val (files, shareFileName) =
|
val (files, shareFileName) =
|
||||||
when (configType) {
|
when (configType) {
|
||||||
ConfigType.AMNEZIA -> {
|
ConfigType.AM -> {
|
||||||
val amFiles = fileUtils.createAmFiles(tunnels)
|
val amFiles = fileUtils.createAmFiles(tunnels)
|
||||||
if (amFiles.isEmpty()) {
|
if (amFiles.isEmpty()) {
|
||||||
throw IOException("No valid Amnezia config files created")
|
throw IOException("No valid Amnezia config files created")
|
||||||
|
|||||||
@@ -106,8 +106,6 @@ sealed class AppEvent {
|
|||||||
|
|
||||||
data class ShowMessage(val message: StringValue) : AppEvent()
|
data class ShowMessage(val message: StringValue) : AppEvent()
|
||||||
|
|
||||||
data class ClearTunnelError(val tunnel: TunnelConf) : AppEvent()
|
|
||||||
|
|
||||||
data class PopBackStack(val pop: Boolean) : AppEvent()
|
data class PopBackStack(val pop: Boolean) : AppEvent()
|
||||||
|
|
||||||
data class SetBottomSheet(val showSheet: AppViewState.BottomSheet) : AppEvent()
|
data class SetBottomSheet(val showSheet: AppViewState.BottomSheet) : AppEvent()
|
||||||
|
|||||||
@@ -221,6 +221,7 @@
|
|||||||
<string name="wifi_name_template">Active: %1$s</string>
|
<string name="wifi_name_template">Active: %1$s</string>
|
||||||
<string name="remote_key_template">Key: %1$s</string>
|
<string name="remote_key_template">Key: %1$s</string>
|
||||||
<string name="version_template">Version: %1$s</string>
|
<string name="version_template">Version: %1$s</string>
|
||||||
|
<string name="security_template">Security: %1$s</string>
|
||||||
<string name="flavor_template">Flavor: %1$s</string>
|
<string name="flavor_template">Flavor: %1$s</string>
|
||||||
<string name="config_error">config error</string>
|
<string name="config_error">config error</string>
|
||||||
<string name="dns_resolve_error">dns resolution error</string>
|
<string name="dns_resolve_error">dns resolution error</string>
|
||||||
@@ -255,4 +256,10 @@
|
|||||||
<string name="allow">Allow</string>
|
<string name="allow">Allow</string>
|
||||||
<string name="licenses">Licenses</string>
|
<string name="licenses">Licenses</string>
|
||||||
<string name="update_check_unsupported">Update check not supported this build type.</string>
|
<string name="update_check_unsupported">Update check not supported this build type.</string>
|
||||||
|
<string name="darker">Darker</string>
|
||||||
|
<string name="amoled">AMOLED</string>
|
||||||
|
<string name="show_qr">Show QR</string>
|
||||||
|
<string name="amnezia">Amnezia</string>
|
||||||
|
<string name="wireguard">WireGuard</string>
|
||||||
|
<string name="done">Done</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
<item name="android:colorPrimary">@color/background</item>
|
<item name="android:colorPrimary">@color/background</item>
|
||||||
<item name="android:windowAllowReturnTransitionOverlap">true</item>
|
<item name="android:windowAllowReturnTransitionOverlap">true</item>
|
||||||
<item name="android:windowAllowEnterTransitionOverlap">true</item>
|
<item name="android:windowAllowEnterTransitionOverlap">true</item>
|
||||||
|
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||||
|
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="Theme.App.Start" parent="@style/Theme.SplashScreen">
|
<style name="Theme.App.Start" parent="@style/Theme.SplashScreen">
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
object Constants {
|
object Constants {
|
||||||
const val VERSION_NAME = "3.8.3"
|
const val VERSION_NAME = "3.9.0"
|
||||||
const val JVM_TARGET = "17"
|
const val JVM_TARGET = "17"
|
||||||
const val VERSION_CODE = 38300
|
const val VERSION_CODE = 38900
|
||||||
const val TARGET_SDK = 35
|
const val TARGET_SDK = 35
|
||||||
const val MIN_SDK = 26
|
const val MIN_SDK = 26
|
||||||
const val APP_ID = "com.zaneschepke.wireguardautotunnel"
|
const val APP_ID = "com.zaneschepke.wireguardautotunnel"
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ fun Project.computeVersionName(): String {
|
|||||||
// Bump minor for pre-release
|
// Bump minor for pre-release
|
||||||
val preReleaseVersion = Semver.of(
|
val preReleaseVersion = Semver.of(
|
||||||
baseVersion.major,
|
baseVersion.major,
|
||||||
baseVersion.minor + 1,
|
baseVersion.minor,
|
||||||
0
|
0 + 1,
|
||||||
)
|
)
|
||||||
"${preReleaseVersion}-beta+git.${getGitCommitHash()}"
|
"${preReleaseVersion}-beta+git.${getGitCommitHash()}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
What's new:
|
||||||
|
- Fix Android TV Banners
|
||||||
|
- Add multi-select for tunnels
|
||||||
|
- Add in-app update checker
|
||||||
|
- Add license screen
|
||||||
|
- Various bug fixes
|
||||||
+12
-11
@@ -1,12 +1,12 @@
|
|||||||
[versions]
|
[versions]
|
||||||
accompanist = "0.37.2"
|
accompanist = "0.37.3"
|
||||||
activityCompose = "1.10.1"
|
activityCompose = "1.10.1"
|
||||||
amneziawgAndroid = "1.3.8"
|
amneziawgAndroid = "1.4.0"
|
||||||
androidx-junit = "1.2.1"
|
androidx-junit = "1.2.1"
|
||||||
appcompat = "1.7.0"
|
appcompat = "1.7.0"
|
||||||
biometricKtx = "1.2.0-alpha05"
|
biometricKtx = "1.2.0-alpha05"
|
||||||
coreKtx = "1.16.0"
|
coreKtx = "1.16.0"
|
||||||
datastorePreferences = "1.1.4"
|
datastorePreferences = "1.2.0-alpha01"
|
||||||
desugar_jdk_libs = "2.1.5"
|
desugar_jdk_libs = "2.1.5"
|
||||||
espressoCore = "3.6.1"
|
espressoCore = "3.6.1"
|
||||||
hiltAndroid = "2.56.2"
|
hiltAndroid = "2.56.2"
|
||||||
@@ -18,18 +18,19 @@ lifecycle-runtime-compose = "2.8.7"
|
|||||||
material3 = "1.3.2"
|
material3 = "1.3.2"
|
||||||
navigationCompose = "2.8.9"
|
navigationCompose = "2.8.9"
|
||||||
pinLockCompose = "1.0.4"
|
pinLockCompose = "1.0.4"
|
||||||
qrcodeKotlin = "4.4.1"
|
qrose = "1.0.1"
|
||||||
roomVersion = "2.7.0"
|
roomVersion = "2.7.1"
|
||||||
semver4j = "3.1.0"
|
semver4j = "3.1.0"
|
||||||
slf4jAndroid = "1.7.36"
|
slf4jAndroid = "1.7.36"
|
||||||
timber = "5.0.1"
|
timber = "5.0.1"
|
||||||
tunnel = "1.2.14"
|
tunnel = "1.3.0"
|
||||||
androidGradlePlugin = "8.9.2"
|
androidGradlePlugin = "8.9.2"
|
||||||
kotlin = "2.1.20"
|
kotlin = "2.1.20"
|
||||||
ksp = "2.1.20-2.0.0"
|
ksp = "2.1.20-2.0.0"
|
||||||
composeBom = "2025.04.00"
|
composeBom = "2025.04.01"
|
||||||
compose = "1.7.8"
|
compose = "1.8.0"
|
||||||
workRuntimeKtxVersion = "2.10.0"
|
icons = "1.7.8"
|
||||||
|
workRuntimeKtxVersion = "2.10.1"
|
||||||
zxingAndroidEmbedded = "4.3.0"
|
zxingAndroidEmbedded = "4.3.0"
|
||||||
coreSplashscreen = "1.0.1"
|
coreSplashscreen = "1.0.1"
|
||||||
gradlePlugins-grgit = "5.3.0"
|
gradlePlugins-grgit = "5.3.0"
|
||||||
@@ -95,10 +96,10 @@ ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktorCli
|
|||||||
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktorClientCore" }
|
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktorClientCore" }
|
||||||
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktorClientCore" }
|
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktorClientCore" }
|
||||||
lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle-runtime-compose" }
|
lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle-runtime-compose" }
|
||||||
material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "compose" }
|
material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "icons" }
|
||||||
|
|
||||||
pin-lock-compose = { module = "com.zaneschepke:pin_lock_compose", version.ref = "pinLockCompose" }
|
pin-lock-compose = { module = "com.zaneschepke:pin_lock_compose", version.ref = "pinLockCompose" }
|
||||||
qrcode-kotlin = { module = "io.github.g0dkar:qrcode-kotlin", version.ref = "qrcodeKotlin" }
|
qrose = { module = "io.github.alexzhirkevich:qrose", version.ref = "qrose" }
|
||||||
semver4j = { module = "com.vdurmont:semver4j", version.ref = "semver4j" }
|
semver4j = { module = "com.vdurmont:semver4j", version.ref = "semver4j" }
|
||||||
slf4j-android = { module = "org.slf4j:slf4j-android", version.ref = "slf4jAndroid" }
|
slf4j-android = { module = "org.slf4j:slf4j-android", version.ref = "slf4jAndroid" }
|
||||||
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
|
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
|
||||||
|
|||||||
+34
-8
@@ -12,6 +12,7 @@ import android.net.NetworkRequest
|
|||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import com.wireguard.android.util.RootShell
|
import com.wireguard.android.util.RootShell
|
||||||
|
import java.util.Collections
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.channels.awaitClose
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
@@ -45,10 +46,18 @@ class AndroidNetworkMonitor(
|
|||||||
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||||
|
|
||||||
@get:Synchronized @set:Synchronized var currentSsid: String? = null
|
@get:Synchronized @set:Synchronized var currentSsid: String? = null
|
||||||
|
@get:Synchronized @set:Synchronized var securityType: WifiSecurityType? = null
|
||||||
|
|
||||||
@get:Synchronized @set:Synchronized var wifiConnected = false
|
@get:Synchronized @set:Synchronized var wifiConnected = false
|
||||||
|
|
||||||
data class WifiState(val connected: Boolean = false, val ssid: String? = null)
|
// Track active Wi-Fi networks and last active network ID
|
||||||
|
private val activeNetworks = Collections.synchronizedSet(mutableSetOf<Network>())
|
||||||
|
|
||||||
|
data class WifiState(
|
||||||
|
val connected: Boolean = false,
|
||||||
|
val ssid: String? = null,
|
||||||
|
val securityType: WifiSecurityType? = null,
|
||||||
|
)
|
||||||
|
|
||||||
data class TransportState(val connected: Boolean = false)
|
data class TransportState(val connected: Boolean = false)
|
||||||
|
|
||||||
@@ -72,15 +81,15 @@ class AndroidNetworkMonitor(
|
|||||||
|
|
||||||
suspend fun handleUnknownWifi() {
|
suspend fun handleUnknownWifi() {
|
||||||
val newSsid = getWifiSsid()
|
val newSsid = getWifiSsid()
|
||||||
|
val securityType = wifiManager?.getCurrentSecurityType()
|
||||||
// Only update if new SSID is valid; preserve existing valid SSID otherwise
|
// Only update if new SSID is valid; preserve existing valid SSID otherwise
|
||||||
if (newSsid != null && newSsid != WifiManager.UNKNOWN_SSID) {
|
if (newSsid != null && newSsid != WifiManager.UNKNOWN_SSID) {
|
||||||
currentSsid = newSsid
|
currentSsid = newSsid
|
||||||
trySend(WifiState(connected = wifiConnected, ssid = currentSsid))
|
trySend(WifiState(wifiConnected, currentSsid, securityType))
|
||||||
} else if (currentSsid == null || currentSsid == WifiManager.UNKNOWN_SSID) {
|
} else if (currentSsid == null || currentSsid == WifiManager.UNKNOWN_SSID) {
|
||||||
currentSsid = newSsid
|
currentSsid = newSsid
|
||||||
trySend(WifiState(connected = wifiConnected, ssid = currentSsid))
|
trySend(WifiState(wifiConnected, currentSsid, securityType))
|
||||||
}
|
}
|
||||||
Timber.d("handleUnknownWifi: currentSsid=$currentSsid")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val locationPermissionReceiver =
|
val locationPermissionReceiver =
|
||||||
@@ -139,18 +148,34 @@ class AndroidNetworkMonitor(
|
|||||||
object : ConnectivityManager.NetworkCallback() {
|
object : ConnectivityManager.NetworkCallback() {
|
||||||
override fun onAvailable(network: Network) {
|
override fun onAvailable(network: Network) {
|
||||||
Timber.d("Wi-Fi onAvailable: network=$network")
|
Timber.d("Wi-Fi onAvailable: network=$network")
|
||||||
|
activeNetworks.add(network)
|
||||||
launch {
|
launch {
|
||||||
currentSsid = getWifiSsid()
|
currentSsid = getWifiSsid()
|
||||||
|
securityType = wifiManager?.getCurrentSecurityType()
|
||||||
wifiConnected = true
|
wifiConnected = true
|
||||||
trySend(WifiState(connected = true, ssid = currentSsid))
|
trySend(
|
||||||
|
WifiState(
|
||||||
|
connected = true,
|
||||||
|
ssid = currentSsid,
|
||||||
|
securityType = securityType,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLost(network: Network) {
|
override fun onLost(network: Network) {
|
||||||
Timber.d("Wi-Fi onLost: network=$network")
|
Timber.d("Wi-Fi onLost: network=$network")
|
||||||
currentSsid = null
|
activeNetworks.remove(network)
|
||||||
wifiConnected = false
|
if (activeNetworks.isEmpty()) {
|
||||||
trySend(WifiState(connected = false, ssid = null))
|
Timber.d(
|
||||||
|
"All Wi-Fi networks disconnected, clearing currentSsid and wifiConnected"
|
||||||
|
)
|
||||||
|
currentSsid = null
|
||||||
|
wifiConnected = false
|
||||||
|
trySend(WifiState(connected = false, ssid = null, securityType = null))
|
||||||
|
} else {
|
||||||
|
Timber.d("Wi-Fi onLost, but still connected to other networks, ignoring")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,6 +253,7 @@ class AndroidNetworkMonitor(
|
|||||||
if (hasAnyConnection) {
|
if (hasAnyConnection) {
|
||||||
NetworkStatus.Connected(
|
NetworkStatus.Connected(
|
||||||
wifiSsid = wifi.ssid,
|
wifiSsid = wifi.ssid,
|
||||||
|
securityType = wifi.securityType,
|
||||||
wifiConnected = wifi.connected,
|
wifiConnected = wifi.connected,
|
||||||
cellularConnected = cellular.connected,
|
cellularConnected = cellular.connected,
|
||||||
ethernetConnected = ethernet.connected,
|
ethernetConnected = ethernet.connected,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.zaneschepke.networkmonitor
|
package com.zaneschepke.networkmonitor
|
||||||
|
|
||||||
|
import android.net.wifi.WifiManager
|
||||||
|
import android.os.Build
|
||||||
import com.wireguard.android.util.RootShell
|
import com.wireguard.android.util.RootShell
|
||||||
|
|
||||||
fun RootShell.getCurrentWifiName(): String? {
|
fun RootShell.getCurrentWifiName(): String? {
|
||||||
@@ -10,3 +12,12 @@ fun RootShell.getCurrentWifiName(): String? {
|
|||||||
)
|
)
|
||||||
return response.firstOrNull()
|
return response.firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
fun WifiManager.getCurrentSecurityType(): WifiSecurityType? {
|
||||||
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
WifiSecurityType.from(connectionInfo.currentSecurityType)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ sealed class NetworkStatus {
|
|||||||
|
|
||||||
data class Connected(
|
data class Connected(
|
||||||
val wifiSsid: String? = null,
|
val wifiSsid: String? = null,
|
||||||
|
val securityType: WifiSecurityType? = null,
|
||||||
override val wifiConnected: Boolean = false,
|
override val wifiConnected: Boolean = false,
|
||||||
override val ethernetConnected: Boolean = false,
|
override val ethernetConnected: Boolean = false,
|
||||||
override val cellularConnected: Boolean = false,
|
override val cellularConnected: Boolean = false,
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.zaneschepke.networkmonitor
|
||||||
|
|
||||||
|
import android.net.wifi.WifiInfo
|
||||||
|
|
||||||
|
enum class WifiSecurityType {
|
||||||
|
UNKNOWN,
|
||||||
|
OPEN,
|
||||||
|
WEP,
|
||||||
|
WPA2, // WPA and WPA2
|
||||||
|
WPA3, // WPA3-Personal (SAE)
|
||||||
|
OWE,
|
||||||
|
WAPI, // All WAPI_PSK and WAPI_CERT
|
||||||
|
EAP, // All EAP (covers both WPA3 and others)
|
||||||
|
PASSPOINT, // All Passpoint versions
|
||||||
|
DPP;
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun from(securityType: Int): WifiSecurityType {
|
||||||
|
return when (securityType) {
|
||||||
|
WifiInfo.SECURITY_TYPE_OPEN -> OPEN
|
||||||
|
WifiInfo.SECURITY_TYPE_WEP -> WEP
|
||||||
|
WifiInfo.SECURITY_TYPE_PSK -> WPA2
|
||||||
|
WifiInfo.SECURITY_TYPE_EAP -> EAP
|
||||||
|
WifiInfo.SECURITY_TYPE_SAE -> WPA3
|
||||||
|
WifiInfo.SECURITY_TYPE_OWE -> OWE
|
||||||
|
WifiInfo.SECURITY_TYPE_WAPI_PSK,
|
||||||
|
WifiInfo.SECURITY_TYPE_WAPI_CERT -> WAPI
|
||||||
|
WifiInfo.SECURITY_TYPE_EAP_WPA3_ENTERPRISE -> EAP
|
||||||
|
WifiInfo.SECURITY_TYPE_EAP_WPA3_ENTERPRISE_192_BIT -> EAP
|
||||||
|
WifiInfo.SECURITY_TYPE_PASSPOINT_R1_R2,
|
||||||
|
WifiInfo.SECURITY_TYPE_PASSPOINT_R3 -> PASSPOINT
|
||||||
|
WifiInfo.SECURITY_TYPE_DPP -> DPP
|
||||||
|
WifiInfo.SECURITY_TYPE_UNKNOWN -> UNKNOWN
|
||||||
|
else -> UNKNOWN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user