mirror of
https://github.com/wgtunnel/android.git
synced 2026-07-03 14:07:49 +02:00
Compare commits
72 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| feec7f0ffc | |||
| b63c6a9b73 | |||
| 46975607c4 | |||
| 0c7bcb5453 | |||
| 599bf9c9e0 | |||
| 03345bdf86 | |||
| b07e604003 | |||
| c8b3af4857 | |||
| 0a3447c63d | |||
| 7f3297db79 | |||
| aa33aebd2f | |||
| 53b1d03ca8 | |||
| 53f72850e2 | |||
| b8deb7b644 | |||
| d5a3090782 | |||
| 063cbf3ea6 | |||
| 4a45387efd | |||
| fa064ef3a6 | |||
| 3f8894a566 | |||
| 6d77ef878d | |||
| a05f11739d | |||
| fe519be5cc | |||
| ab0f67c897 | |||
| a5639cd129 | |||
| babbab051f | |||
| 2e984e8b6f | |||
| 044e6da7f5 | |||
| 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 | |||
| 969e9dfe03 | |||
| aeb590db8c | |||
| 312062aa36 | |||
| 287732dfb8 | |||
| dca72a70e8 | |||
| 1c6543554f | |||
| 8c01f5bea4 | |||
| dd9f329721 | |||
| f30c48a90a | |||
| 4707d3eb95 | |||
| cedc2db326 | |||
| 256e3f7951 | |||
| 9e797b24d6 | |||
| f2b9eb526e | |||
| abb29607d3 | |||
| f6d7cbc032 | |||
| 9304d79775 | |||
| 4d18decbf7 | |||
| 76186c092f | |||
| c90a7bbaf5 |
+45
-43
@@ -1,4 +1,7 @@
|
||||
name: build
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
@@ -12,6 +15,14 @@ on:
|
||||
- prerelease
|
||||
- nightly
|
||||
- release
|
||||
flavor:
|
||||
type: choice
|
||||
description: "Product flavor"
|
||||
required: true
|
||||
default: fdroid
|
||||
options:
|
||||
- fdroid
|
||||
- standalone
|
||||
secrets:
|
||||
SIGNING_KEY_ALIAS:
|
||||
required: false
|
||||
@@ -30,6 +41,11 @@ on:
|
||||
description: "Build type"
|
||||
required: true
|
||||
default: debug
|
||||
flavor:
|
||||
type: string
|
||||
description: "Product flavor"
|
||||
required: false
|
||||
default: fdroid
|
||||
secrets:
|
||||
SIGNING_KEY_ALIAS:
|
||||
required: false
|
||||
@@ -41,6 +57,7 @@ on:
|
||||
required: false
|
||||
KEYSTORE:
|
||||
required: false
|
||||
|
||||
env:
|
||||
UPLOAD_DIR_ANDROID: android_artifacts
|
||||
|
||||
@@ -48,15 +65,17 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
SIGNING_KEY_ALIAS: ${{ secrets.ANDROID_SIGNING_KEY_ALIAS }}
|
||||
SIGNING_KEY_PASSWORD: ${{ secrets.ANDROID_SIGNING_KEY_PASSWORD }}
|
||||
SIGNING_STORE_PASSWORD: ${{ secrets.ANDROID_SIGNING_STORE_PASSWORD }}
|
||||
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/
|
||||
outputs:
|
||||
UPLOAD_DIR_ANDROID: ${{ env.UPLOAD_DIR_ANDROID }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
@@ -65,61 +84,44 @@ jobs:
|
||||
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.ANDROID_KEYSTORE }}
|
||||
|
||||
# create keystore path for gradle to read
|
||||
encodedString: ${{ secrets.KEYSTORE }}
|
||||
- name: Create keystore path env var
|
||||
if: ${{ inputs.build_type != 'debug' }}
|
||||
run: |
|
||||
store_path=${{ env.KEY_STORE_LOCATION }}${{ env.KEY_STORE_FILE }}
|
||||
echo "KEY_STORE_PATH=$store_path" >> $GITHUB_ENV
|
||||
|
||||
- name: Create service_account.json
|
||||
if: ${{ inputs.build_type != 'debug' }}
|
||||
id: createServiceAccount
|
||||
run: echo '${{ secrets.ANDROID_SERVICE_ACCOUNT_JSON }}' > service_account.json
|
||||
|
||||
- name: Build Fdroid Release APK
|
||||
if: ${{ inputs.build_type == 'release' }}
|
||||
run: ./gradlew :app:assembleFdroidRelease --info
|
||||
|
||||
- name: Build Fdroid Prerelease APK
|
||||
if: ${{ inputs.build_type == 'prerelease' }}
|
||||
run: ./gradlew :app:assembleFdroidPrerelease --info
|
||||
|
||||
- name: Build Fdroid Nightly APK
|
||||
if: ${{ inputs.build_type == 'nightly' }}
|
||||
run: ./gradlew :app:assembleFdroidNightly --info
|
||||
|
||||
- name: Build Debug APK
|
||||
if: ${{ inputs.build_type == 'debug' }}
|
||||
run: ./gradlew :app:assembleFdroidDebug --stacktrace
|
||||
|
||||
# bump versionCode for nightly and prerelease builds
|
||||
- name: Commit and push versionCode changes
|
||||
if: ${{ inputs.build_type == 'nightly' || inputs.build_type == 'prerelease' }}
|
||||
- name: Build APK
|
||||
run: |
|
||||
git config --global user.name 'GitHub Actions'
|
||||
git config --global user.email 'actions@github.com'
|
||||
git add versionCode.txt
|
||||
git commit -m "Automated build update"
|
||||
|
||||
flavor=${{ inputs.flavor }}
|
||||
build_type=${{ inputs.build_type }}
|
||||
case $build_type in
|
||||
"release")
|
||||
./gradlew :app:assemble${flavor^}Release --info
|
||||
;;
|
||||
"prerelease")
|
||||
./gradlew :app:assemble${flavor^}Prerelease --info
|
||||
;;
|
||||
"nightly")
|
||||
./gradlew :app:assemble${flavor^}Nightly --info
|
||||
;;
|
||||
"debug")
|
||||
./gradlew :app:assemble${flavor^}Debug --stacktrace
|
||||
;;
|
||||
esac
|
||||
- name: Get release apk path
|
||||
id: apk-path
|
||||
run: echo "path=$(find . -regex '^.*/build/outputs/apk/fdroid/${{ inputs.build_type }}/.*\.apk$' -type f | head -1 | tail -c+2)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Upload release apk
|
||||
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 APK
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ env.UPLOAD_DIR_ANDROID }}
|
||||
path: ${{github.workspace}}/${{ steps.apk-path.outputs.path }}
|
||||
name: android_artifacts_${{ inputs.flavor }}
|
||||
path: app/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/wgtunnel-${{ inputs.flavor }}${{ inputs.flavor == 'fdroid' && '-release' || '' }}-*.apk
|
||||
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
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
+74
-103
@@ -1,13 +1,17 @@
|
||||
name: publish
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "4 3 * * *"
|
||||
push:
|
||||
tags:
|
||||
- '[0-9]*.[0-9]*.[0-9]*'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
track:
|
||||
type: choice
|
||||
description: "Google play release track"
|
||||
description: "Google Play release track"
|
||||
options:
|
||||
- none
|
||||
- internal
|
||||
@@ -22,80 +26,69 @@ on:
|
||||
options:
|
||||
- none
|
||||
- prerelease
|
||||
- nightly
|
||||
- release
|
||||
default: release
|
||||
required: true
|
||||
tag_name:
|
||||
description: "Tag name for release"
|
||||
required: false
|
||||
default: nightly
|
||||
default: 1.1.1
|
||||
flavor:
|
||||
type: choice
|
||||
description: "Product flavor"
|
||||
required: true
|
||||
default: standalone
|
||||
options:
|
||||
- fdroid
|
||||
- standalone
|
||||
workflow_call:
|
||||
env:
|
||||
UPLOAD_DIR_ANDROID: android_artifacts
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
inputs:
|
||||
flavor:
|
||||
type: string
|
||||
description: "Product flavor"
|
||||
required: false
|
||||
default: standalone
|
||||
|
||||
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 # This fetches all history so we can check commits
|
||||
|
||||
- name: Check for new commits
|
||||
id: check
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
||||
run: |
|
||||
# This script checks for commits newer than 23 hours ago
|
||||
NEW_COMMITS=$(git rev-list --count --after="$(date -Iseconds -d '23 hours ago')" ${{ github.sha }})
|
||||
echo "new_commits=$NEW_COMMITS" >> $GITHUB_OUTPUT
|
||||
|
||||
build:
|
||||
if: ${{ inputs.release_type != 'none' }}
|
||||
build-fdroid:
|
||||
if: ${{ github.event_name == 'push' || inputs.release_type == 'release' || inputs.flavor == 'fdroid' }}
|
||||
uses: ./.github/workflows/build.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
build_type: ${{ inputs.release_type == '' && 'nightly' || inputs.release_type }}
|
||||
build_type: ${{ github.event_name == 'push' && 'release' || inputs.release_type }}
|
||||
flavor: fdroid
|
||||
|
||||
build-standalone:
|
||||
if: ${{ github.event_name == 'push' || inputs.release_type == 'release' || inputs.release_type == 'prerelease' || inputs.flavor == 'standalone' }}
|
||||
uses: ./.github/workflows/build.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
build_type: ${{ github.event_name == 'push' && 'release' || inputs.release_type }}
|
||||
flavor: standalone
|
||||
|
||||
publish:
|
||||
needs:
|
||||
- check_commits
|
||||
- build
|
||||
if: ${{ needs.check_commits.outputs.has_new_commits > 0 && inputs.release_type != 'none' }}
|
||||
- build-standalone
|
||||
name: publish-github
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
GH_USER: ${{ secrets.PAT_USERNAME }}
|
||||
# GH needed for gh cli
|
||||
GH_TOKEN: ${{ secrets.PAT }}
|
||||
GH_REPO: ${{ github.repository }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event_name == 'push' && github.ref || 'main' }}
|
||||
- name: Install system dependencies
|
||||
run: |
|
||||
sudo apt update && sudo apt install -y gh apksigner
|
||||
|
||||
# update latest tag
|
||||
- name: Set latest tag
|
||||
uses: rickstaa/action-create-tag@v1
|
||||
id: tag_creation
|
||||
with:
|
||||
tag: "latest" # or any tag name you wish to use
|
||||
tag: "latest"
|
||||
message: "Automated tag for HEAD commit"
|
||||
force_push_tag: true
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
tag_exists_error: false
|
||||
|
||||
- name: Get latest release
|
||||
id: latest_release
|
||||
uses: kaliber5/action-get-release@v1
|
||||
@@ -108,22 +101,9 @@ jobs:
|
||||
uses: requarks/changelog-action@v1
|
||||
with:
|
||||
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"
|
||||
writeToFile: false # we won't write to file, just output
|
||||
|
||||
- name: Get version code
|
||||
if: ${{ inputs.release_type == 'release' }}
|
||||
run: |
|
||||
version_code=$(grep "VERSION_CODE" buildSrc/src/main/kotlin/Constants.kt | awk '{print $5}' | tr -d '\n')
|
||||
echo "VERSION_CODE=$version_code" >> $GITHUB_ENV
|
||||
|
||||
- name: Push changes
|
||||
if: ${{ inputs.release_type == '' || inputs.release_type == 'nightly' || inputs.release_type == 'prerelease' }}
|
||||
uses: ad-m/github-push-action@master
|
||||
with:
|
||||
github_token: ${{ secrets.PAT }}
|
||||
branch: ${{ github.ref }}
|
||||
writeToFile: false
|
||||
|
||||
- name: Make download dir
|
||||
run: mkdir ${{ github.workspace }}/temp
|
||||
@@ -131,53 +111,43 @@ jobs:
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: ${{ env.UPLOAD_DIR_ANDROID }}
|
||||
pattern: android_artifacts_*
|
||||
path: ${{ github.workspace }}/temp
|
||||
|
||||
# Setup TAG_NAME, which is used as a general "name"
|
||||
- if: github.event_name == 'workflow_dispatch'
|
||||
run: echo "TAG_NAME=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV
|
||||
- if: github.event_name == 'schedule'
|
||||
run: echo "TAG_NAME=nightly" >> $GITHUB_ENV
|
||||
merge-multiple: true
|
||||
|
||||
- name: Set version release notes
|
||||
if: ${{ inputs.release_type == 'release' }}
|
||||
if: ${{ github.event_name == 'push' || inputs.release_type == 'release' }}
|
||||
run: |
|
||||
RELEASE_NOTES="$(cat ${{ github.workspace }}/fastlane/metadata/android/en-US/changelogs/${{ env.VERSION_CODE }}.txt)"
|
||||
VERSION_NAME=$(grep "const val VERSION_NAME" buildSrc/src/main/kotlin/Constants.kt | awk -F'"' '{print $2}')
|
||||
RELEASE_NOTES="$(cat ${{ github.workspace }}/fastlane/metadata/android/en-US/changelogs/${VERSION_NAME}.txt || echo "No changelog found for ${VERSION_NAME}")"
|
||||
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
|
||||
echo "$RELEASE_NOTES" >> $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
|
||||
gh release delete nightly --yes || true
|
||||
git push origin :nightly || true
|
||||
|
||||
- name: On prerelease release notes
|
||||
if: ${{ inputs.release_type == 'prerelease' }}
|
||||
if: ${{ github.event_name != 'push' && inputs.release_type == 'prerelease' }}
|
||||
run: |
|
||||
echo "RELEASE_NOTES=Testing version of app for specific feature." >> $GITHUB_ENV
|
||||
gh release delete ${{ github.event.inputs.tag_name }} --yes || true
|
||||
|
||||
- name: Get checksum
|
||||
id: checksum
|
||||
run: |
|
||||
file_path=$(find ${{ github.workspace }}/temp -type f -iname "*.apk" | tail -n1)
|
||||
echo "checksum=$(apksigner verify -print-certs $file_path | grep -Po "(?<=SHA-256 digest:) .*" | tr -d "[:blank:]")" >> $GITHUB_OUTPUT
|
||||
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 Release with Fastlane changelog notes
|
||||
- name: Create Release
|
||||
id: create_release
|
||||
uses: softprops/action-gh-release@v2
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
body: |
|
||||
${{ env.RELEASE_NOTES }}
|
||||
|
||||
SHA-256 fingerprint for the 4096-bit signing certificate:
|
||||
SHA-256 fingerprints for the 4096-bit signing certificate:
|
||||
```sh
|
||||
${{ steps.checksum.outputs.checksum }}
|
||||
```
|
||||
@@ -189,40 +159,40 @@ jobs:
|
||||
|
||||
### Changelog
|
||||
${{ steps.changelog.outputs.changes }}
|
||||
tag_name: ${{ env.TAG_NAME }}
|
||||
name: ${{ env.TAG_NAME }}
|
||||
tag_name: ${{ github.event_name == 'push' && github.ref_name || github.event.inputs.tag_name }}
|
||||
name: ${{ github.event_name == 'push' && github.ref_name || github.event.inputs.tag_name }}
|
||||
draft: false
|
||||
prerelease: ${{ inputs.release_type == 'prerelease' || inputs.release_type == '' || inputs.release_type == 'nightly' }}
|
||||
make_latest: ${{ inputs.release_type == 'release' }}
|
||||
prerelease: ${{ github.event_name != 'push' && inputs.release_type == 'prerelease' }}
|
||||
make_latest: ${{ github.event_name == 'push' || inputs.release_type == 'release' }}
|
||||
files: |
|
||||
${{ github.workspace }}/temp/*
|
||||
${{ github.workspace }}/temp/**/*.apk
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
publish-fdroid:
|
||||
publish-fdroid-public:
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- build
|
||||
if: inputs.release_type == 'release'
|
||||
- build-fdroid
|
||||
if: ${{ github.event_name == 'push' || inputs.release_type == 'release' }}
|
||||
steps:
|
||||
- name: Dispatch update for fdroid repo
|
||||
uses: peter-evans/repository-dispatch@v3
|
||||
with:
|
||||
token: ${{ secrets.PAT }}
|
||||
repository: zaneschepke/fdroid
|
||||
repository: wgtunnel/fdroid
|
||||
event-type: fdroid-update
|
||||
|
||||
publish-play:
|
||||
if: ${{ inputs.track != 'none' && inputs.track != '' }}
|
||||
if: ${{ github.event_name == 'push' || inputs.track != 'none' }}
|
||||
name: Publish to Google Play
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
env:
|
||||
SIGNING_KEY_ALIAS: ${{ secrets.ANDROID_SIGNING_KEY_ALIAS }}
|
||||
SIGNING_KEY_PASSWORD: ${{ secrets.ANDROID_SIGNING_KEY_PASSWORD }}
|
||||
SIGNING_STORE_PASSWORD: ${{ secrets.ANDROID_SIGNING_STORE_PASSWORD }}
|
||||
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/
|
||||
GH_USER: ${{ secrets.PAT_USERNAME }}
|
||||
GH_TOKEN: ${{ secrets.PAT }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -244,7 +214,7 @@ jobs:
|
||||
with:
|
||||
fileName: ${{ env.KEY_STORE_FILE }}
|
||||
fileDir: ${{ env.KEY_STORE_LOCATION }}
|
||||
encodedString: ${{ secrets.ANDROID_KEYSTORE }}
|
||||
encodedString: ${{ secrets.KEYSTORE }}
|
||||
|
||||
# create keystore path for gradle to read
|
||||
- name: Create keystore path env var
|
||||
@@ -263,5 +233,6 @@ jobs:
|
||||
bundler-cache: true
|
||||
|
||||
- name: Distribute app to Prod track 🚀
|
||||
run: (cd ${{ github.workspace }} && bundle install && bundle exec fastlane ${{ inputs.track }})
|
||||
|
||||
run: |
|
||||
track=${{ github.event_name == 'push' && 'production' || inputs.track }}
|
||||
(cd ${{ github.workspace }} && bundle install && bundle exec fastlane $track)
|
||||
+1
-1
@@ -70,5 +70,5 @@ lint/tmp/
|
||||
app/release/output.json
|
||||
.idea/codeStyles/
|
||||
# where we keep our signing secrets locally
|
||||
app/signing.properties
|
||||
/.kotlin/
|
||||
/app/keystore/
|
||||
|
||||
+2
-1
@@ -1,2 +1,3 @@
|
||||
/build
|
||||
/release
|
||||
/release
|
||||
/src/main/assets/licenses.json
|
||||
|
||||
+68
-81
@@ -6,35 +6,17 @@ plugins {
|
||||
alias(libs.plugins.ksp)
|
||||
alias(libs.plugins.compose.compiler)
|
||||
alias(libs.plugins.grgit)
|
||||
alias(libs.plugins.licensee)
|
||||
}
|
||||
|
||||
val versionFile = file("$rootDir/versionCode.txt")
|
||||
|
||||
val versionCodeIncrement =
|
||||
with(getBuildTaskName().lowercase()) {
|
||||
when {
|
||||
this.contains(Constants.NIGHTLY) || this.contains(Constants.PRERELEASE) -> {
|
||||
if (versionFile.exists()) {
|
||||
versionFile.readText().trim().toInt() + 1
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = Constants.APP_ID
|
||||
compileSdk = Constants.TARGET_SDK
|
||||
|
||||
androidResources { generateLocaleConfig = true }
|
||||
|
||||
// reproducibility
|
||||
dependenciesInfo {
|
||||
// Disables dependency metadata when building APKs.
|
||||
includeInApk = false
|
||||
// Disables dependency metadata when building Android App Bundles.
|
||||
includeInBundle = false
|
||||
}
|
||||
|
||||
@@ -42,14 +24,12 @@ android {
|
||||
applicationId = Constants.APP_ID
|
||||
minSdk = Constants.MIN_SDK
|
||||
targetSdk = Constants.TARGET_SDK
|
||||
versionCode = Constants.VERSION_CODE + versionCodeIncrement
|
||||
versionName = determineVersionName()
|
||||
versionCode = computeVersionCode()
|
||||
versionName = computeVersionName()
|
||||
|
||||
ksp { arg("room.schemaLocation", "$projectDir/schemas") }
|
||||
|
||||
sourceSets {
|
||||
getByName("debug").assets.srcDirs(files("$projectDir/schemas")) // Room
|
||||
}
|
||||
sourceSets { getByName("debug").assets.srcDirs(files("$projectDir/schemas")) }
|
||||
|
||||
buildConfigField(
|
||||
"String[]",
|
||||
@@ -63,15 +43,18 @@ android {
|
||||
|
||||
signingConfigs {
|
||||
create(Constants.RELEASE) {
|
||||
storeFile = getStoreFile()
|
||||
storePassword = getSigningProperty(Constants.STORE_PASS_VAR)
|
||||
keyAlias = getSigningProperty(Constants.KEY_ALIAS_VAR)
|
||||
keyPassword = getSigningProperty(Constants.KEY_PASS_VAR)
|
||||
storeFile = file(System.getenv("KEY_STORE_PATH") ?: "keystore/android_keystore.jks")
|
||||
storePassword =
|
||||
LocalProperties.get("SIGNING_STORE_PASSWORD")
|
||||
?: System.getenv("SIGNING_STORE_PASSWORD")
|
||||
keyAlias =
|
||||
LocalProperties.get("SIGNING_KEY_ALIAS") ?: System.getenv("SIGNING_KEY_ALIAS")
|
||||
keyPassword =
|
||||
LocalProperties.get("SIGNING_KEY_PASSWORD") ?: System.getenv("SIGNING_KEY_PASSWORD")
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
// don't strip
|
||||
packaging.jniLibs.keepDebugSymbols.addAll(
|
||||
listOf("libwg-go.so", "libwg-quick.so", "libwg.so")
|
||||
)
|
||||
@@ -87,6 +70,7 @@ android {
|
||||
signingConfig = signingConfigs.getByName(Constants.RELEASE)
|
||||
resValue("string", "provider", "\"${Constants.APP_NAME}.provider\"")
|
||||
}
|
||||
|
||||
debug {
|
||||
applicationIdSuffix = ".debug"
|
||||
resValue("string", "app_name", "WG Tunnel - Debug")
|
||||
@@ -107,31 +91,28 @@ android {
|
||||
resValue("string", "app_name", "WG Tunnel - Nightly")
|
||||
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.nightly\"")
|
||||
}
|
||||
|
||||
applicationVariants.all {
|
||||
val variant = this
|
||||
variant.outputs
|
||||
.map { it as com.android.build.gradle.internal.api.BaseVariantOutputImpl }
|
||||
.forEach { output ->
|
||||
val outputFileName =
|
||||
"${Constants.APP_NAME}-${variant.flavorName}-" +
|
||||
"${variant.buildType.name}-${variant.versionName}.apk"
|
||||
output.outputFileName = outputFileName
|
||||
}
|
||||
}
|
||||
}
|
||||
flavorDimensions.add(Constants.TYPE)
|
||||
|
||||
flavorDimensions.add("type")
|
||||
productFlavors {
|
||||
create("fdroid") {
|
||||
dimension = Constants.TYPE
|
||||
proguardFile("fdroid-rules.pro")
|
||||
dimension = "type"
|
||||
buildConfigField("String", "FLAVOR", "\"fdroid\"")
|
||||
}
|
||||
create("google") {
|
||||
dimension = "type"
|
||||
buildConfigField("String", "FLAVOR", "\"google\"")
|
||||
}
|
||||
create("standalone") {
|
||||
dimension = "type"
|
||||
buildConfigField("String", "FLAVOR", "\"standalone\"")
|
||||
}
|
||||
create("general") { dimension = Constants.TYPE }
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
isCoreLibraryDesugaringEnabled = true
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
isCoreLibraryDesugaringEnabled = true
|
||||
}
|
||||
kotlinOptions { jvmTarget = Constants.JVM_TARGET }
|
||||
buildFeatures {
|
||||
@@ -139,6 +120,26 @@ android {
|
||||
buildConfig = true
|
||||
}
|
||||
packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" } }
|
||||
|
||||
licensee {
|
||||
Constants.allowedLicenses.forEach { allow(it) }
|
||||
Constants.allowedLicenseUrls.forEach { allowUrl(it) }
|
||||
}
|
||||
|
||||
applicationVariants.all {
|
||||
val variant = this
|
||||
variant.outputs
|
||||
.map { it as com.android.build.gradle.internal.api.BaseVariantOutputImpl }
|
||||
.forEach { output ->
|
||||
val outputFileName =
|
||||
if (variant.flavorName == "fdroid" && variant.buildType.name == "release") {
|
||||
"${Constants.APP_NAME}-fdroid-release-${variant.versionName}.apk"
|
||||
} else {
|
||||
"${Constants.APP_NAME}-${variant.flavorName}-v${variant.versionName}.apk"
|
||||
}
|
||||
output.outputFileName = outputFileName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -147,8 +148,6 @@ dependencies {
|
||||
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||
|
||||
// helpers for implementing LifecycleOwner in a Service
|
||||
implementation(libs.androidx.lifecycle.service)
|
||||
implementation(libs.androidx.activity.compose)
|
||||
implementation(platform(libs.androidx.compose.bom))
|
||||
@@ -160,7 +159,6 @@ dependencies {
|
||||
implementation(libs.material)
|
||||
implementation(libs.androidx.storage)
|
||||
|
||||
// test
|
||||
testImplementation(libs.junit)
|
||||
testImplementation(libs.androidx.junit)
|
||||
androidTestImplementation(libs.androidx.junit)
|
||||
@@ -171,83 +169,72 @@ dependencies {
|
||||
debugImplementation(libs.androidx.compose.ui.tooling)
|
||||
debugImplementation(libs.androidx.compose.manifest)
|
||||
|
||||
// tunnel
|
||||
implementation(libs.tunnel)
|
||||
implementation(libs.amneziawg.android)
|
||||
coreLibraryDesugaring(libs.desugar.jdk.libs)
|
||||
|
||||
// logging
|
||||
implementation(libs.timber)
|
||||
|
||||
// compose navigation
|
||||
implementation(libs.androidx.navigation.compose)
|
||||
implementation(libs.androidx.hilt.navigation.compose)
|
||||
|
||||
// hilt
|
||||
implementation(libs.hilt.android)
|
||||
ksp(libs.hilt.android.compiler)
|
||||
ksp(libs.androidx.hilt.compiler)
|
||||
|
||||
// accompanist
|
||||
implementation(libs.accompanist.permissions)
|
||||
implementation(libs.accompanist.drawablepainter)
|
||||
|
||||
// storage
|
||||
implementation(libs.androidx.room.runtime)
|
||||
ksp(libs.androidx.room.compiler)
|
||||
implementation(libs.androidx.room.ktx)
|
||||
implementation(libs.androidx.datastore.preferences)
|
||||
|
||||
// lifecycle
|
||||
implementation(libs.lifecycle.runtime.compose)
|
||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||
implementation(libs.androidx.lifecycle.process)
|
||||
|
||||
// serialization
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
|
||||
// ui
|
||||
implementation(libs.zxing.android.embedded)
|
||||
|
||||
implementation(libs.material.icons.extended)
|
||||
|
||||
// bio
|
||||
implementation(libs.androidx.biometric.ktx)
|
||||
implementation(libs.pin.lock.compose)
|
||||
|
||||
// shortcuts
|
||||
implementation(libs.androidx.core)
|
||||
|
||||
// splash
|
||||
implementation(libs.androidx.core.splashscreen)
|
||||
|
||||
// worker
|
||||
implementation(libs.androidx.work.runtime)
|
||||
implementation(libs.androidx.hilt.work)
|
||||
|
||||
implementation(libs.qrose)
|
||||
implementation(libs.semver4j)
|
||||
|
||||
implementation(libs.ktor.client.core)
|
||||
implementation(libs.ktor.client.okhttp)
|
||||
implementation(libs.ktor.client.cio)
|
||||
implementation(libs.ktor.client.content.negotiation)
|
||||
implementation(libs.ktor.serialization.kotlinx.json)
|
||||
implementation(libs.slf4j.android)
|
||||
}
|
||||
|
||||
fun determineVersionName(): String {
|
||||
return with(getBuildTaskName().lowercase()) {
|
||||
when {
|
||||
contains(Constants.NIGHTLY) || contains(Constants.PRERELEASE) ->
|
||||
Constants.VERSION_NAME + "-${grgitService.service.get().grgit.head().abbreviatedId}"
|
||||
else -> Constants.VERSION_NAME
|
||||
}
|
||||
tasks.register<Copy>("copyLicenseeJsonToAssets") {
|
||||
dependsOn("licensee")
|
||||
val outputAssets = layout.projectDirectory.dir("src/main/assets")
|
||||
from(layout.buildDirectory.file("reports/licensee/androidFdroidRelease/artifacts.json")) {
|
||||
rename("artifacts.json", "licenses.json")
|
||||
}
|
||||
into(outputAssets)
|
||||
}
|
||||
|
||||
val incrementVersionCode by
|
||||
tasks.registering {
|
||||
doLast {
|
||||
val versionFile = file("$rootDir/versionCode.txt")
|
||||
if (versionFile.exists()) {
|
||||
versionFile.writeText(versionCodeIncrement.toString())
|
||||
println("Incremented versionCode to $versionCodeIncrement")
|
||||
}
|
||||
}
|
||||
}
|
||||
tasks.named("preBuild") { dependsOn("copyLicenseeJsonToAssets") }
|
||||
|
||||
// https://gist.github.com/obfusk/61046e09cee352ae6dd109911534b12e#fix-proposed-by-linsui-disable-baseline-profiles
|
||||
tasks.whenTaskAdded {
|
||||
if (name.startsWith("assemble") && !name.lowercase().contains("debug")) {
|
||||
dependsOn(incrementVersionCode)
|
||||
if (name.contains("ArtProfile")) {
|
||||
enabled = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,9 +155,7 @@
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"tableName": "TunnelConfig",
|
||||
@@ -227,21 +225,18 @@
|
||||
"fieldPath": "pingInterval",
|
||||
"columnName": "ping_interval",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false,
|
||||
"defaultValue": "null"
|
||||
},
|
||||
{
|
||||
"fieldPath": "pingCooldown",
|
||||
"columnName": "ping_cooldown",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false,
|
||||
"defaultValue": "null"
|
||||
},
|
||||
{
|
||||
"fieldPath": "pingIp",
|
||||
"columnName": "ping_ip",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false,
|
||||
"defaultValue": "null"
|
||||
},
|
||||
{
|
||||
@@ -275,11 +270,9 @@
|
||||
"orders": [],
|
||||
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_TunnelConfig_name` ON `${TABLE_NAME}` (`name`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": []
|
||||
]
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ae51793c4d09ea3194ecd26f0606f35c')"
|
||||
|
||||
@@ -0,0 +1,295 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 17,
|
||||
"identityHash": "380d82359c99933cc9ce783347c4ec31",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "Settings",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_tunnel_enabled` INTEGER NOT NULL, `is_tunnel_on_mobile_data_enabled` INTEGER NOT NULL, `trusted_network_ssids` TEXT NOT NULL, `is_always_on_vpn_enabled` INTEGER NOT NULL, `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_wifi_enabled` INTEGER NOT NULL DEFAULT false, `is_kernel_enabled` INTEGER NOT NULL DEFAULT false, `is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT false, `is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT false, `is_ping_enabled` INTEGER NOT NULL DEFAULT false, `is_amnezia_enabled` INTEGER NOT NULL DEFAULT false, `is_wildcards_enabled` INTEGER NOT NULL DEFAULT false, `is_stop_on_no_internet_enabled` INTEGER NOT NULL DEFAULT false, `is_vpn_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `is_kernel_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `is_lan_on_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_disable_kill_switch_on_trusted_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT false, `split_tunnel_apps` TEXT NOT NULL DEFAULT '', `wifi_detection_method` INTEGER NOT NULL DEFAULT 0)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isAutoTunnelEnabled",
|
||||
"columnName": "is_tunnel_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnMobileDataEnabled",
|
||||
"columnName": "is_tunnel_on_mobile_data_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "trustedNetworkSSIDs",
|
||||
"columnName": "trusted_network_ssids",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isAlwaysOnVpnEnabled",
|
||||
"columnName": "is_always_on_vpn_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnEthernetEnabled",
|
||||
"columnName": "is_tunnel_on_ethernet_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isShortcutsEnabled",
|
||||
"columnName": "is_shortcuts_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnWifiEnabled",
|
||||
"columnName": "is_tunnel_on_wifi_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isKernelEnabled",
|
||||
"columnName": "is_kernel_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isRestoreOnBootEnabled",
|
||||
"columnName": "is_restore_on_boot_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isMultiTunnelEnabled",
|
||||
"columnName": "is_multi_tunnel_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isPingEnabled",
|
||||
"columnName": "is_ping_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isAmneziaEnabled",
|
||||
"columnName": "is_amnezia_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isWildcardsEnabled",
|
||||
"columnName": "is_wildcards_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isStopOnNoInternetEnabled",
|
||||
"columnName": "is_stop_on_no_internet_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isVpnKillSwitchEnabled",
|
||||
"columnName": "is_vpn_kill_switch_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isKernelKillSwitchEnabled",
|
||||
"columnName": "is_kernel_kill_switch_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isLanOnKillSwitchEnabled",
|
||||
"columnName": "is_lan_on_kill_switch_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "debounceDelaySeconds",
|
||||
"columnName": "debounce_delay_seconds",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "3"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isDisableKillSwitchOnTrustedEnabled",
|
||||
"columnName": "is_disable_kill_switch_on_trusted_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnUnsecureEnabled",
|
||||
"columnName": "is_tunnel_on_unsecure_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "splitTunnelApps",
|
||||
"columnName": "split_tunnel_apps",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true,
|
||||
"defaultValue": "''"
|
||||
},
|
||||
{
|
||||
"fieldPath": "wifiDetectionMethod",
|
||||
"columnName": "wifi_detection_method",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tableName": "TunnelConfig",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `wg_quick` TEXT NOT NULL, `tunnel_networks` TEXT NOT NULL DEFAULT '', `is_mobile_data_tunnel` INTEGER NOT NULL DEFAULT false, `is_primary_tunnel` INTEGER NOT NULL DEFAULT false, `am_quick` TEXT NOT NULL DEFAULT '', `is_Active` INTEGER NOT NULL DEFAULT false, `is_ping_enabled` INTEGER NOT NULL DEFAULT false, `ping_interval` INTEGER DEFAULT null, `ping_cooldown` INTEGER DEFAULT null, `ping_ip` TEXT DEFAULT null, `is_ethernet_tunnel` INTEGER NOT NULL DEFAULT false, `is_ipv4_preferred` INTEGER NOT NULL DEFAULT true)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "wgQuick",
|
||||
"columnName": "wg_quick",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "tunnelNetworks",
|
||||
"columnName": "tunnel_networks",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true,
|
||||
"defaultValue": "''"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isMobileDataTunnel",
|
||||
"columnName": "is_mobile_data_tunnel",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isPrimaryTunnel",
|
||||
"columnName": "is_primary_tunnel",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "amQuick",
|
||||
"columnName": "am_quick",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true,
|
||||
"defaultValue": "''"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isActive",
|
||||
"columnName": "is_Active",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isPingEnabled",
|
||||
"columnName": "is_ping_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "pingInterval",
|
||||
"columnName": "ping_interval",
|
||||
"affinity": "INTEGER",
|
||||
"defaultValue": "null"
|
||||
},
|
||||
{
|
||||
"fieldPath": "pingCooldown",
|
||||
"columnName": "ping_cooldown",
|
||||
"affinity": "INTEGER",
|
||||
"defaultValue": "null"
|
||||
},
|
||||
{
|
||||
"fieldPath": "pingIp",
|
||||
"columnName": "ping_ip",
|
||||
"affinity": "TEXT",
|
||||
"defaultValue": "null"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isEthernetTunnel",
|
||||
"columnName": "is_ethernet_tunnel",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isIpv4Preferred",
|
||||
"columnName": "is_ipv4_preferred",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "true"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_TunnelConfig_name",
|
||||
"unique": true,
|
||||
"columnNames": [
|
||||
"name"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_TunnelConfig_name` ON `${TABLE_NAME}` (`name`)"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '380d82359c99933cc9ce783347c4ec31')"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- Permissions specific to full -->
|
||||
<!--updater-->
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
</manifest>
|
||||
@@ -2,7 +2,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
|
||||
<!--foreground service exempt android 14-->
|
||||
@@ -16,7 +16,6 @@
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
<!--start service on boot permission-->
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<!--android tv support-->
|
||||
|
||||
<permission
|
||||
android:name="${applicationId}.permission.CONTROL_TUNNELS"
|
||||
@@ -53,7 +52,7 @@
|
||||
<application
|
||||
android:name=".WireGuardAutoTunnel"
|
||||
android:allowBackup="false"
|
||||
android:banner="@drawable/ic_banner"
|
||||
android:banner="@mipmap/ic_banner"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
@@ -63,10 +62,13 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.App.Start"
|
||||
tools:targetApi="tiramisu">
|
||||
<activity
|
||||
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
||||
android:screenOrientation="portrait"
|
||||
tools:replace="screenOrientation" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:banner="@mipmap/ic_banner"
|
||||
android:windowSoftInputMode="adjustNothing"
|
||||
android:theme="@style/Theme.WireguardAutoTunnel"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden"
|
||||
@@ -80,10 +82,6 @@
|
||||
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
||||
android:screenOrientation="portrait"
|
||||
tools:replace="screenOrientation" />
|
||||
|
||||
<activity
|
||||
android:name=".core.shortcut.ShortcutsActivity"
|
||||
@@ -168,14 +166,11 @@
|
||||
<receiver
|
||||
android:name=".core.broadcast.RestartReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="false"
|
||||
android:directBootAware="true">
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SCREEN_ON" />
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.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" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
@@ -22,33 +21,14 @@ import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.consumeWindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.imePadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Bolt
|
||||
import androidx.compose.material.icons.rounded.Home
|
||||
import androidx.compose.material.icons.rounded.QuestionMark
|
||||
import androidx.compose.material.icons.rounded.Settings
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SnackbarData
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.navigation.compose.NavHost
|
||||
@@ -58,22 +38,22 @@ import androidx.navigation.compose.rememberNavController
|
||||
import androidx.navigation.toRoute
|
||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||
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.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.VpnDeniedDialog
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.CustomBottomNavbar
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.DynamicTopAppBar
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.currentNavBackStackEntryAsNavBarState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.CustomSnackBar
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.BottomNavbar
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.DynamicTopAppBar
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.currentNavBackStackEntryAsNavBarState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.AutoTunnelScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.advanced.AutoTunnelAdvancedScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.detection.WifiDetectionMethodScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.LocationDisclosureScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
||||
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.scanner.ScannerScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel.SplitTunnelScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.TunnelOptionsScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.pin.PinLockScreen
|
||||
@@ -82,12 +62,12 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.settings.advanced.Settings
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.AppearanceScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.display.DisplayScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.language.LanguageScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.LocationDisclosureScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.killswitch.KillSwitchScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.logs.LogsScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.SupportScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.license.LicenseScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.WireguardAutoTunnelTheme
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.goFromRoot
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
@@ -125,8 +105,10 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
setContent {
|
||||
val isTv = isRunningOnTv()
|
||||
val appUiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||
val appViewState by viewModel.appViewState.collectAsStateWithLifecycle()
|
||||
val tunnelError by viewModel.tunnelManager.errorEvents.collectAsStateWithLifecycle(null)
|
||||
|
||||
val navController = rememberNavController()
|
||||
val backStackEntry by navController.currentBackStackEntryAsState()
|
||||
@@ -136,6 +118,7 @@ class MainActivity : AppCompatActivity() {
|
||||
backStackEntry,
|
||||
viewModel,
|
||||
appUiState,
|
||||
appViewState,
|
||||
)
|
||||
val snackbar = remember { SnackbarHostState() }
|
||||
var showVpnPermissionDialog by remember { mutableStateOf(false) }
|
||||
@@ -150,6 +133,7 @@ class MainActivity : AppCompatActivity() {
|
||||
vpnPermissionDenied = true
|
||||
} else {
|
||||
vpnPermissionDenied = false
|
||||
showVpnPermissionDialog = false
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -167,6 +151,15 @@ class MainActivity : AppCompatActivity() {
|
||||
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) {
|
||||
LaunchedEffect(isConfigChanged) {
|
||||
if (isConfigChanged) {
|
||||
@@ -182,21 +175,6 @@ class MainActivity : AppCompatActivity() {
|
||||
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) {
|
||||
if (popBackStack) {
|
||||
navController.popBackStack()
|
||||
@@ -218,153 +196,130 @@ class MainActivity : AppCompatActivity() {
|
||||
batteryActivity.launch(
|
||||
Intent().apply {
|
||||
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
||||
data = Uri.parse("package:${this@MainActivity.packageName}")
|
||||
data = "package:${this@MainActivity.packageName}".toUri()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CompositionLocalProvider(LocalNavController provides navController) {
|
||||
WireguardAutoTunnelTheme(theme = appUiState.appState.theme) {
|
||||
VpnDeniedDialog(
|
||||
showVpnPermissionDialog,
|
||||
onDismiss = { showVpnPermissionDialog = false },
|
||||
)
|
||||
CompositionLocalProvider(LocalIsAndroidTV provides isTv) {
|
||||
CompositionLocalProvider(LocalNavController provides navController) {
|
||||
WireguardAutoTunnelTheme(theme = appUiState.appState.theme) {
|
||||
VpnDeniedDialog(
|
||||
showVpnPermissionDialog,
|
||||
onDismiss = {
|
||||
showVpnPermissionDialog = false
|
||||
vpnPermissionDenied = false
|
||||
},
|
||||
)
|
||||
|
||||
Scaffold(
|
||||
modifier =
|
||||
Modifier.pointerInput(Unit) {
|
||||
detectTapGestures {
|
||||
viewModel.handleEvent(AppEvent.SetSelectedTunnel(null))
|
||||
Scaffold(
|
||||
modifier =
|
||||
Modifier.pointerInput(Unit) {
|
||||
detectTapGestures {
|
||||
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
||||
}
|
||||
},
|
||||
snackbarHost = {
|
||||
SnackbarHost(snackbar) { snackbarData: SnackbarData ->
|
||||
CustomSnackBar(
|
||||
snackbarData.visuals.message,
|
||||
isRtl = false,
|
||||
containerColor =
|
||||
MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp),
|
||||
)
|
||||
}
|
||||
},
|
||||
snackbarHost = {
|
||||
SnackbarHost(snackbar) { snackbarData: SnackbarData ->
|
||||
CustomSnackBar(
|
||||
snackbarData.visuals.message,
|
||||
isRtl = false,
|
||||
containerColor =
|
||||
MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp),
|
||||
)
|
||||
}
|
||||
},
|
||||
topBar = { DynamicTopAppBar(navBarState) },
|
||||
bottomBar = {
|
||||
AnimatedVisibility(
|
||||
visible = navBarState.showBottom,
|
||||
enter = slideInVertically(initialOffsetY = { it }),
|
||||
exit = slideOutVertically(targetOffsetY = { it }),
|
||||
topBar = { DynamicTopAppBar(navBarState) },
|
||||
bottomBar = {
|
||||
AnimatedVisibility(
|
||||
visible = navBarState.showBottom,
|
||||
enter = slideInVertically(initialOffsetY = { it }),
|
||||
exit = slideOutVertically(targetOffsetY = { it }),
|
||||
) {
|
||||
BottomNavbar(appUiState = appUiState)
|
||||
}
|
||||
},
|
||||
) { padding ->
|
||||
Box(
|
||||
modifier =
|
||||
Modifier.fillMaxSize()
|
||||
.background(MaterialTheme.colorScheme.surface)
|
||||
.padding(padding)
|
||||
.consumeWindowInsets(padding)
|
||||
.imePadding()
|
||||
) {
|
||||
CustomBottomNavbar(
|
||||
listOf(
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.tunnels),
|
||||
route = Route.Main,
|
||||
icon = Icons.Rounded.Home,
|
||||
onClick = { navController.goFromRoot(Route.Main) },
|
||||
),
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.auto_tunnel),
|
||||
route = Route.AutoTunnel,
|
||||
icon = Icons.Rounded.Bolt,
|
||||
onClick = {
|
||||
val route =
|
||||
if (
|
||||
appUiState.appState
|
||||
.isLocationDisclosureShown
|
||||
)
|
||||
Route.AutoTunnel
|
||||
else Route.LocationDisclosure
|
||||
navController.goFromRoot(route)
|
||||
},
|
||||
active = appUiState.isAutoTunnelActive,
|
||||
),
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.settings),
|
||||
route = Route.Settings,
|
||||
icon = Icons.Rounded.Settings,
|
||||
onClick = { navController.goFromRoot(Route.Settings) },
|
||||
),
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.support),
|
||||
route = Route.Support,
|
||||
icon = Icons.Rounded.QuestionMark,
|
||||
onClick = { navController.goFromRoot(Route.Support) },
|
||||
),
|
||||
),
|
||||
navBarState = navBarState,
|
||||
)
|
||||
}
|
||||
},
|
||||
) { padding ->
|
||||
Box(
|
||||
modifier =
|
||||
Modifier.fillMaxSize()
|
||||
.background(MaterialTheme.colorScheme.surface)
|
||||
.padding(padding)
|
||||
.consumeWindowInsets(padding)
|
||||
.imePadding()
|
||||
) {
|
||||
NavHost(
|
||||
navController,
|
||||
startDestination =
|
||||
(if (appUiState.appState.isPinLockEnabled) Route.Lock
|
||||
else Route.Main),
|
||||
) {
|
||||
composable<Route.Main> {
|
||||
MainScreen(appUiState, appViewState, viewModel)
|
||||
}
|
||||
composable<Route.Settings> {
|
||||
SettingsScreen(appUiState, appViewState, viewModel)
|
||||
}
|
||||
composable<Route.SettingsAdvanced> {
|
||||
SettingsAdvancedScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.LocationDisclosure> {
|
||||
LocationDisclosureScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.AutoTunnel> {
|
||||
AutoTunnelScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Appearance> { AppearanceScreen() }
|
||||
composable<Route.Language> { LanguageScreen(appUiState, viewModel) }
|
||||
composable<Route.Display> { DisplayScreen(appUiState, viewModel) }
|
||||
composable<Route.Support> { SupportScreen() }
|
||||
composable<Route.AutoTunnelAdvanced> {
|
||||
AutoTunnelAdvancedScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Logs> { LogsScreen(appViewState, viewModel) }
|
||||
composable<Route.Config> { backStack ->
|
||||
val args = backStack.toRoute<Route.Config>()
|
||||
val config = appUiState.tunnels.firstOrNull { it.id == args.id }
|
||||
ConfigScreen(config, viewModel)
|
||||
}
|
||||
composable<Route.TunnelOptions> { backStack ->
|
||||
val args = backStack.toRoute<Route.TunnelOptions>()
|
||||
appUiState.tunnels
|
||||
.firstOrNull { it.id == args.id }
|
||||
?.let { config ->
|
||||
TunnelOptionsScreen(config, appUiState, viewModel)
|
||||
}
|
||||
}
|
||||
composable<Route.Lock> { PinLockScreen(viewModel) }
|
||||
composable<Route.Scanner> { ScannerScreen(viewModel) }
|
||||
composable<Route.KillSwitch> {
|
||||
KillSwitchScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.SplitTunnel> { SplitTunnelScreen(viewModel) }
|
||||
composable<Route.TunnelAutoTunnel> { backStack ->
|
||||
val args = backStack.toRoute<Route.TunnelOptions>()
|
||||
appUiState.tunnels
|
||||
.firstOrNull { it.id == args.id }
|
||||
?.let {
|
||||
TunnelAutoTunnelScreen(
|
||||
it,
|
||||
appUiState.appSettings,
|
||||
viewModel,
|
||||
)
|
||||
}
|
||||
NavHost(
|
||||
navController,
|
||||
startDestination =
|
||||
(if (appUiState.appState.isPinLockEnabled) Route.Lock
|
||||
else Route.Main),
|
||||
) {
|
||||
composable<Route.Main> {
|
||||
MainScreen(appUiState, appViewState, viewModel)
|
||||
}
|
||||
composable<Route.Settings> {
|
||||
SettingsScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.SettingsAdvanced> {
|
||||
SettingsAdvancedScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.LocationDisclosure> {
|
||||
LocationDisclosureScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.AutoTunnel> {
|
||||
AutoTunnelScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Appearance> { AppearanceScreen() }
|
||||
composable<Route.Language> {
|
||||
LanguageScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Display> {
|
||||
DisplayScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Support> {
|
||||
SupportScreen(appViewModel = viewModel)
|
||||
}
|
||||
composable<Route.License> { LicenseScreen() }
|
||||
composable<Route.AutoTunnelAdvanced> {
|
||||
AutoTunnelAdvancedScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.WifiDetectionMethod> {
|
||||
WifiDetectionMethodScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Logs> { LogsScreen(appViewState, viewModel) }
|
||||
composable<Route.Config> { backStack ->
|
||||
val args = backStack.toRoute<Route.Config>()
|
||||
val config =
|
||||
appUiState.tunnels.firstOrNull { it.id == args.id }
|
||||
ConfigScreen(config, viewModel)
|
||||
}
|
||||
composable<Route.TunnelOptions> { backStack ->
|
||||
val args = backStack.toRoute<Route.TunnelOptions>()
|
||||
appUiState.tunnels
|
||||
.firstOrNull { it.id == args.id }
|
||||
?.let { config ->
|
||||
TunnelOptionsScreen(config, viewModel, appViewState)
|
||||
}
|
||||
}
|
||||
composable<Route.Lock> { PinLockScreen(viewModel) }
|
||||
composable<Route.KillSwitch> {
|
||||
KillSwitchScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.SplitTunnel> { SplitTunnelScreen(viewModel) }
|
||||
composable<Route.TunnelAutoTunnel> { backStack ->
|
||||
val args = backStack.toRoute<Route.TunnelOptions>()
|
||||
appUiState.tunnels
|
||||
.firstOrNull { it.id == args.id }
|
||||
?.let {
|
||||
TunnelAutoTunnelScreen(
|
||||
it,
|
||||
appUiState.appSettings,
|
||||
viewModel,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -3,12 +3,12 @@ package com.zaneschepke.wireguardautotunnel.core.broadcast
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.zaneschepke.logcatter.LogReader
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
@@ -26,18 +26,20 @@ class RestartReceiver : BroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var tunnelManager: TunnelManager
|
||||
|
||||
@Inject lateinit var logReader: LogReader
|
||||
|
||||
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
Timber.d("RestartReceiver triggered with action: ${intent.action}")
|
||||
// screen on for Android TV only to help with sleep shutdowns
|
||||
if (intent.action == Intent.ACTION_SCREEN_ON && !context.isRunningOnTv()) return
|
||||
serviceManager.updateTunnelTile()
|
||||
serviceManager.updateAutoTunnelTile()
|
||||
applicationScope.launch(ioDispatcher) {
|
||||
val settings = appDataRepository.settings.get()
|
||||
if (settings.isRestoreOnBootEnabled) {
|
||||
if (settings.isAutoTunnelEnabled && !serviceManager.autoTunnelActive.value) {
|
||||
if (
|
||||
settings.isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null
|
||||
) {
|
||||
Timber.d("Starting auto-tunnel on boot/update")
|
||||
serviceManager.startAutoTunnel()
|
||||
} else {
|
||||
@@ -47,6 +49,7 @@ class RestartReceiver : BroadcastReceiver() {
|
||||
} else {
|
||||
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
|
||||
|
||||
import android.app.Service
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.ServiceConnection
|
||||
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.di.ApplicationScope
|
||||
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.requestTunnelTileServiceStateUpdate
|
||||
import jakarta.inject.Inject
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@@ -37,23 +37,37 @@ constructor(
|
||||
|
||||
private val autoTunnelMutex = Mutex()
|
||||
|
||||
private val _autoTunnelActive = MutableStateFlow(false)
|
||||
val autoTunnelActive = _autoTunnelActive.asStateFlow()
|
||||
private val _tunnelService = MutableStateFlow<TunnelForegroundService?>(null)
|
||||
private val _autoTunnelService = MutableStateFlow<AutoTunnelService?>(null)
|
||||
val autoTunnelService = _autoTunnelService.asStateFlow()
|
||||
|
||||
var autoTunnelService = CompletableDeferred<AutoTunnelService>()
|
||||
var backgroundService = CompletableDeferred<TunnelForegroundService>()
|
||||
|
||||
private fun <T : Service> startService(cls: Class<T>, background: Boolean) {
|
||||
runCatching {
|
||||
val intent = Intent(context, cls)
|
||||
if (background) {
|
||||
context.startForegroundService(intent)
|
||||
} else {
|
||||
context.startService(intent)
|
||||
}
|
||||
private val tunnelServiceConnection =
|
||||
object : ServiceConnection {
|
||||
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
||||
val binder = service as? TunnelForegroundService.LocalBinder
|
||||
_tunnelService.value = binder?.service
|
||||
Timber.d("TunnelForegroundService connected")
|
||||
}
|
||||
.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 {
|
||||
return VpnService.prepare(context) == null
|
||||
@@ -63,20 +77,13 @@ constructor(
|
||||
autoTunnelMutex.withLock {
|
||||
val settings = appDataRepository.settings.get()
|
||||
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = true))
|
||||
if (autoTunnelService.isCompleted) {
|
||||
_autoTunnelActive.update { true }
|
||||
return
|
||||
if (_autoTunnelService.value != null) return
|
||||
withContext(ioDispatcher) {
|
||||
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 {
|
||||
val settings = appDataRepository.settings.get()
|
||||
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = false))
|
||||
if (!autoTunnelService.isCompleted) return
|
||||
runCatching {
|
||||
val service = autoTunnelService.await()
|
||||
service.stop()
|
||||
_autoTunnelActive.update { false }
|
||||
autoTunnelService = CompletableDeferred()
|
||||
if (_autoTunnelService.value == null) return
|
||||
_autoTunnelService.value?.let { service ->
|
||||
service.stop()
|
||||
try {
|
||||
context.unbindService(autoTunnelServiceConnection)
|
||||
} finally {
|
||||
_tunnelService.value = null
|
||||
}
|
||||
.onFailure { Timber.e(it) }
|
||||
}
|
||||
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
||||
}
|
||||
}
|
||||
|
||||
fun startTunnelForegroundService() {
|
||||
if (backgroundService.isCompleted) return
|
||||
runCatching {
|
||||
backgroundService = CompletableDeferred()
|
||||
startService(
|
||||
TunnelForegroundService::class.java,
|
||||
!WireGuardAutoTunnel.isForeground(),
|
||||
)
|
||||
suspend fun startTunnelForegroundService() {
|
||||
if (_tunnelService.value != null) return
|
||||
withContext(ioDispatcher) {
|
||||
applicationScope.launch(ioDispatcher) {
|
||||
val intent = Intent(context, TunnelForegroundService::class.java)
|
||||
context.startForegroundService(intent)
|
||||
context.bindService(intent, tunnelServiceConnection, Context.BIND_AUTO_CREATE)
|
||||
}
|
||||
.onFailure { Timber.e(it) }
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun stopTunnelForegroundService() {
|
||||
if (!backgroundService.isCompleted) return
|
||||
runCatching {
|
||||
val service = backgroundService.await()
|
||||
service.stop()
|
||||
backgroundService = CompletableDeferred()
|
||||
fun stopTunnelForegroundService() {
|
||||
_tunnelService.value?.let { service ->
|
||||
service.stop()
|
||||
try {
|
||||
context.unbindService(tunnelServiceConnection)
|
||||
} finally {
|
||||
_tunnelService.value = null
|
||||
}
|
||||
.onFailure { Timber.e(it) }
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleAutoTunnel() {
|
||||
applicationScope.launch(ioDispatcher) {
|
||||
if (_autoTunnelActive.value) stopAutoTunnel() else startAutoTunnel()
|
||||
if (_autoTunnelService.value != null) stopAutoTunnel() else startAutoTunnel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,4 +139,12 @@ constructor(
|
||||
fun updateTunnelTile() {
|
||||
context.requestTunnelTileServiceStateUpdate()
|
||||
}
|
||||
|
||||
fun handleTunnelServiceDestroy() {
|
||||
_tunnelService.update { null }
|
||||
}
|
||||
|
||||
fun handleAutoTunnelServiceDestroy() {
|
||||
_autoTunnelService.update { null }
|
||||
}
|
||||
}
|
||||
|
||||
+15
-9
@@ -2,6 +2,7 @@ package com.zaneschepke.wireguardautotunnel.core.service
|
||||
|
||||
import android.app.Notification
|
||||
import android.content.Intent
|
||||
import android.os.Binder
|
||||
import android.os.IBinder
|
||||
import androidx.core.app.ServiceCompat
|
||||
import androidx.lifecycle.LifecycleService
|
||||
@@ -13,9 +14,9 @@ import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
||||
import com.zaneschepke.wireguardautotunnel.core.notification.WireGuardNotification
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||
@@ -23,7 +24,6 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.distinctByKeys
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.NonCancellable
|
||||
@@ -64,9 +64,12 @@ class TunnelForegroundService : LifecycleService() {
|
||||
|
||||
private val jobsMutex = Mutex()
|
||||
|
||||
class LocalBinder(val service: TunnelForegroundService) : Binder()
|
||||
|
||||
private val binder = LocalBinder(this)
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
serviceManager.backgroundService.complete(this)
|
||||
ServiceCompat.startForeground(
|
||||
this@TunnelForegroundService,
|
||||
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)
|
||||
return null
|
||||
return binder
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
super.onStartCommand(intent, flags, startId)
|
||||
serviceManager.backgroundService.complete(this)
|
||||
ServiceCompat.startForeground(
|
||||
this@TunnelForegroundService,
|
||||
NotificationManager.VPN_NOTIFICATION_ID,
|
||||
@@ -163,8 +165,12 @@ class TunnelForegroundService : LifecycleService() {
|
||||
} else {
|
||||
pingJobs[tun]?.cancel() // Cancel any stale job
|
||||
if (tun.isPingEnabled) {
|
||||
pingJobs[tun] = startPingJob(tun)
|
||||
Timber.d("Started ping job for ${tun.tunName}")
|
||||
if (tun.isStaticallyConfigured()) {
|
||||
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() {
|
||||
serviceManager.backgroundService = CompletableDeferred()
|
||||
serviceManager.handleTunnelServiceDestroy()
|
||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
+51
-17
@@ -1,6 +1,7 @@
|
||||
package com.zaneschepke.wireguardautotunnel.core.service.autotunnel
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Binder
|
||||
import android.os.IBinder
|
||||
import android.os.PowerManager
|
||||
import androidx.core.app.ServiceCompat
|
||||
@@ -14,12 +15,12 @@ import com.zaneschepke.wireguardautotunnel.core.notification.WireGuardNotificati
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.KillSwitchEvent
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.AutoTunnelState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.NetworkState
|
||||
@@ -28,11 +29,11 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
@@ -68,26 +69,32 @@ class AutoTunnelService : LifecycleService() {
|
||||
|
||||
private var killSwitchJob: Job? = null
|
||||
|
||||
class LocalBinder(val service: AutoTunnelService) : Binder()
|
||||
|
||||
private val binder = LocalBinder(this)
|
||||
|
||||
private var isServiceRunning = false
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
serviceManager.autoTunnelService.complete(this)
|
||||
launchWatcherNotification()
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent): IBinder? {
|
||||
override fun onBind(intent: Intent): IBinder {
|
||||
super.onBind(intent)
|
||||
return null
|
||||
return binder
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
super.onStartCommand(intent, flags, startId)
|
||||
Timber.d("onStartCommand executed with startId: $startId")
|
||||
serviceManager.autoTunnelService.complete(this)
|
||||
start()
|
||||
return START_STICKY
|
||||
}
|
||||
|
||||
fun start() {
|
||||
if (isServiceRunning) return
|
||||
isServiceRunning = true
|
||||
kotlin
|
||||
.runCatching {
|
||||
launchWatcherNotification()
|
||||
@@ -100,12 +107,13 @@ class AutoTunnelService : LifecycleService() {
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
isServiceRunning = false
|
||||
wakeLock?.let { if (it.isHeld) it.release() }
|
||||
stopSelf()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
serviceManager.autoTunnelService = CompletableDeferred()
|
||||
serviceManager.handleAutoTunnelServiceDestroy()
|
||||
restoreVpnKillSwitch()
|
||||
super.onDestroy()
|
||||
}
|
||||
@@ -259,18 +267,44 @@ class AutoTunnelService : LifecycleService() {
|
||||
lifecycleScope.launch(ioDispatcher) {
|
||||
Timber.i("Starting auto-tunnel network event watcher")
|
||||
val settings = appDataRepository.get().settings.get()
|
||||
Timber.d("Starting with debounce delay of: ${settings.debounceDelaySeconds} seconds")
|
||||
|
||||
var reevaluationJob: Job? = null
|
||||
|
||||
autoTunnelStateFlow.debounce(settings.debounceDelayMillis()).collect { watcherState ->
|
||||
if (watcherState == defaultState) return@collect
|
||||
Timber.d("New auto tunnel state emitted ${watcherState.networkState}")
|
||||
when (val event = watcherState.asAutoTunnelEvent()) {
|
||||
is AutoTunnelEvent.Start ->
|
||||
(event.tunnelConf ?: appDataRepository.get().getPrimaryOrFirstTunnel())
|
||||
?.let { tunnelManager.startTunnel(it) }
|
||||
// TODO improve this to target specific tunnels to better support multi-tunnel
|
||||
is AutoTunnelEvent.Stop -> tunnelManager.stopTunnel()
|
||||
AutoTunnelEvent.DoNothing -> Timber.i("Auto-tunneling: no condition met")
|
||||
reevaluationJob?.cancel()
|
||||
handleAutoTunnelEvent(watcherState)
|
||||
|
||||
// schedule one-time re-evaluation
|
||||
reevaluationJob = launch {
|
||||
delay(REEVALUATE_CHECK_DELAY)
|
||||
if (watcherState != defaultState) {
|
||||
Timber.d("Re-evaluating auto-tunnel state..")
|
||||
handleAutoTunnelEvent(watcherState)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun handleAutoTunnelEvent(watcherState: AutoTunnelState) {
|
||||
Timber.i("Auto-tunnel settings: ${watcherState.settings.toAutoTunnelStateString()}")
|
||||
Timber.i("Auto-tunnel network state: ${watcherState.networkState}")
|
||||
when (
|
||||
val event =
|
||||
watcherState.asAutoTunnelEvent().also {
|
||||
Timber.i("Auto-tunnel event: ${it.javaClass.simpleName}")
|
||||
}
|
||||
) {
|
||||
is AutoTunnelEvent.Start ->
|
||||
(event.tunnelConf ?: appDataRepository.get().getPrimaryOrFirstTunnel())?.let {
|
||||
tunnelManager.startTunnel(it)
|
||||
}
|
||||
is AutoTunnelEvent.Stop -> tunnelManager.stopTunnel()
|
||||
AutoTunnelEvent.DoNothing -> Timber.i("Auto-tunneling: nothing to do")
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val REEVALUATE_CHECK_DELAY = 5_000L
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -38,8 +38,8 @@ class AutoTunnelControlTile : TileService(), LifecycleOwner {
|
||||
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
||||
Timber.d("Start listening called for auto tunnel tile")
|
||||
lifecycleScope.launch {
|
||||
serviceManager.autoTunnelActive.collect {
|
||||
if (it) return@collect setActive()
|
||||
serviceManager.autoTunnelService.collect {
|
||||
if (it != null) return@collect setActive()
|
||||
setInactive()
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ class AutoTunnelControlTile : TileService(), LifecycleOwner {
|
||||
super.onClick()
|
||||
unlockAndRun {
|
||||
lifecycleScope.launch {
|
||||
if (serviceManager.autoTunnelActive.value) {
|
||||
if (serviceManager.autoTunnelService.value != null) {
|
||||
serviceManager.stopAutoTunnel()
|
||||
setInactive()
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||
|
||||
import com.wireguard.android.backend.BackendException
|
||||
import com.wireguard.android.backend.Tunnel
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendError
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendError
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.concurrent.thread
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
@@ -31,6 +27,10 @@ abstract class BaseTunnel(
|
||||
private val serviceManager: ServiceManager,
|
||||
) : 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 tunThreads = ConcurrentHashMap<Int, Thread>()
|
||||
override val activeTunnels = activeTuns.asStateFlow()
|
||||
@@ -45,37 +45,34 @@ abstract class BaseTunnel(
|
||||
|
||||
abstract fun stopBackend(tunnel: TunnelConf)
|
||||
|
||||
override suspend fun clearError(tunnelConf: TunnelConf) =
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
||||
|
||||
override fun hasVpnPermission(): Boolean {
|
||||
return serviceManager.hasVpnPermission()
|
||||
}
|
||||
|
||||
protected suspend fun updateTunnelStatus(
|
||||
tunnelConf: TunnelConf,
|
||||
state: TunnelStatus? = null,
|
||||
status: TunnelStatus? = null,
|
||||
stats: TunnelStatistics? = null,
|
||||
) {
|
||||
tunStatusMutex.withLock {
|
||||
activeTuns.update { current ->
|
||||
val originalConf = current.getKeyById(tunnelConf.id) ?: tunnelConf
|
||||
val existingState = current.getValueById(tunnelConf.id) ?: TunnelState()
|
||||
val newState = state ?: existingState.status
|
||||
activeTuns.update { currentTuns ->
|
||||
val originalConf = currentTuns.getKeyById(tunnelConf.id) ?: tunnelConf
|
||||
val existingState = currentTuns.getValueById(tunnelConf.id) ?: TunnelState()
|
||||
val newState = status ?: existingState.status
|
||||
if (newState == TunnelStatus.Down) {
|
||||
Timber.d("Removing tunnel ${tunnelConf.id} from activeTunnels as state is DOWN")
|
||||
cleanUpTunThread(tunnelConf)
|
||||
current - originalConf
|
||||
currentTuns - originalConf
|
||||
} else if (existingState.status == newState && stats == null) {
|
||||
Timber.d("Skipping redundant state update for ${tunnelConf.id}: $newState")
|
||||
current
|
||||
currentTuns
|
||||
} else {
|
||||
val updated =
|
||||
existingState.copy(
|
||||
status = newState,
|
||||
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()
|
||||
tunMutex.withLock {
|
||||
tunThreads[tunnelConf.id] = thread {
|
||||
runCatching {
|
||||
runBlocking {
|
||||
try {
|
||||
Timber.d("Starting tunnel ${tunnelConf.id}...")
|
||||
startTunnelInner(tunnelConf)
|
||||
Timber.d("Started complete for tunnel ${tunnelConf.name}...")
|
||||
} catch (e: BackendError) {
|
||||
Timber.e(e, "Failed to start tunnel ${tunnelConf.name} userspace")
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Error(e))
|
||||
} catch (e: InterruptedException) {
|
||||
Timber.w(
|
||||
"Tunnel start has been interrupted as ${tunnelConf.name} failed to start"
|
||||
)
|
||||
}
|
||||
}
|
||||
try {
|
||||
runBlocking {
|
||||
Timber.d("Starting tunnel ${tunnelConf.id}...")
|
||||
startTunnelInner(tunnelConf)
|
||||
Timber.d("Started complete for tunnel ${tunnelConf.name}...")
|
||||
}
|
||||
.onFailure { Timber.w("Tunnel start has been interrupted") }
|
||||
} catch (e: InterruptedException) {
|
||||
Timber.w(
|
||||
"Tunnel start has been interrupted as ${tunnelConf.name} failed to start"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,11 +138,10 @@ abstract class BaseTunnel(
|
||||
Timber.d("Started for tun ${tunnelConf.id}...")
|
||||
saveTunnelActiveState(tunnelConf, true)
|
||||
serviceManager.startTunnelForegroundService()
|
||||
} catch (e: BackendException) {
|
||||
} catch (e: BackendError) {
|
||||
Timber.e(e, "Failed to start backend for ${tunnelConf.name}")
|
||||
val backendError = e.toBackendError()
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Error(backendError))
|
||||
throw backendError
|
||||
_errorEvents.emit(tunnelConf to e)
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,26 +153,27 @@ abstract class BaseTunnel(
|
||||
override suspend fun stopTunnel(tunnelConf: TunnelConf?, reason: TunnelStatus.StopReason) {
|
||||
if (tunnelConf == null) return stopActiveTunnels()
|
||||
tunMutex.withLock {
|
||||
try {
|
||||
if (activeTuns.isStarting(tunnelConf.id))
|
||||
return handleStuckStartingTunnelShutdown(tunnelConf)
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Stopping(reason))
|
||||
stopTunnelInner(tunnelConf)
|
||||
} catch (e: BackendError) {
|
||||
Timber.e(e, "Failed to stop tunnel ${tunnelConf.id}")
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Error(e))
|
||||
}
|
||||
if (activeTuns.isStarting(tunnelConf.id))
|
||||
return handleStuckStartingTunnelShutdown(tunnelConf)
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Stopping(reason))
|
||||
stopTunnelInner(tunnelConf)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun stopTunnelInner(tunnelConf: TunnelConf) {
|
||||
val tunnel = activeTuns.findTunnel(tunnelConf.id) ?: return
|
||||
stopBackend(tunnel)
|
||||
saveTunnelActiveState(tunnelConf, false)
|
||||
removeActiveTunnel(tunnel)
|
||||
try {
|
||||
val tunnel = activeTuns.findTunnel(tunnelConf.id) ?: return
|
||||
stopBackend(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())
|
||||
serviceManager.stopTunnelForegroundService()
|
||||
}
|
||||
@@ -193,15 +184,15 @@ abstract class BaseTunnel(
|
||||
tunThreads[tunnel.id]?.let {
|
||||
if (it.state != Thread.State.TERMINATED) {
|
||||
it.interrupt()
|
||||
updateTunnelStatus(tunnel, TunnelStatus.Down)
|
||||
} else {
|
||||
Timber.d("Thread already terminated")
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Failed to stop tunnel thread for ${tunnel.name}")
|
||||
} finally {
|
||||
updateTunnelStatus(tunnel, TunnelStatus.Down)
|
||||
}
|
||||
cleanUpTunThread(tunnel)
|
||||
}
|
||||
|
||||
private fun cleanUpTunThread(tunnel: TunnelConf) {
|
||||
@@ -221,7 +212,7 @@ abstract class BaseTunnel(
|
||||
bouncingTunnelIds[tunnelConf.id] = reason
|
||||
try {
|
||||
stopTunnel(tunnelConf, reason)
|
||||
delay(300L)
|
||||
delay(BOUNCE_DELAY)
|
||||
startTunnel(tunnelConf)
|
||||
} finally {
|
||||
bouncingTunnelIds.remove(tunnelConf.id)
|
||||
@@ -235,4 +226,8 @@ abstract class BaseTunnel(
|
||||
|
||||
override suspend fun runningTunnelNames(): Set<String> =
|
||||
activeTuns.value.keys.map { it.tunName }.toSet()
|
||||
|
||||
companion object {
|
||||
const val BOUNCE_DELAY = 300L
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ import com.wireguard.android.backend.BackendException
|
||||
import com.wireguard.android.backend.Tunnel
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.WireGuardStatistics
|
||||
|
||||
@@ -4,9 +4,10 @@ import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.di.Kernel
|
||||
import com.zaneschepke.wireguardautotunnel.di.Userspace
|
||||
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.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
@@ -15,6 +16,7 @@ import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
@@ -62,6 +64,9 @@ constructor(
|
||||
initialValue = emptyMap(),
|
||||
)
|
||||
|
||||
override val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
||||
get() = tunnelProviderFlow.value.errorEvents
|
||||
|
||||
override val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason> =
|
||||
tunnelProviderFlow.value.bouncingTunnelIds
|
||||
|
||||
@@ -69,10 +74,6 @@ constructor(
|
||||
return userspaceTunnel.hasVpnPermission()
|
||||
}
|
||||
|
||||
override suspend fun clearError(tunnelConf: TunnelConf) {
|
||||
tunnelProviderFlow.value.clearError(tunnelConf)
|
||||
}
|
||||
|
||||
override suspend fun updateTunnelStatistics(tunnel: TunnelConf) {
|
||||
tunnelProviderFlow.value.updateTunnelStatistics(tunnel)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||
|
||||
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.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
interface TunnelProvider {
|
||||
@@ -46,11 +48,11 @@ interface TunnelProvider {
|
||||
|
||||
val activeTunnels: StateFlow<Map<TunnelConf, TunnelState>>
|
||||
|
||||
val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
||||
|
||||
val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason>
|
||||
|
||||
fun hasVpnPermission(): Boolean
|
||||
|
||||
suspend fun clearError(tunnelConf: TunnelConf)
|
||||
|
||||
suspend fun updateTunnelStatistics(tunnel: TunnelConf)
|
||||
}
|
||||
|
||||
+4
-3
@@ -2,9 +2,9 @@ package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.AmneziaStatistics
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||
@@ -50,8 +50,9 @@ constructor(
|
||||
} catch (e: BackendException) {
|
||||
Timber.e(e, "Failed to stop tunnel ${tunnel.id}")
|
||||
throw e.toBackendError()
|
||||
} finally {
|
||||
handlePreviouslyEnabledVpnKillSwitch()
|
||||
}
|
||||
handlePreviouslyEnabledVpnKillSwitch()
|
||||
}
|
||||
|
||||
// stop vpn kill switch if we need to resolve DNS for peer endpoints
|
||||
@@ -69,7 +70,7 @@ constructor(
|
||||
// restore vpn kill switch if needed
|
||||
private fun handlePreviouslyEnabledVpnKillSwitch() {
|
||||
// let auto tunnel handle this if it is active
|
||||
if (!serviceManager.autoTunnelActive.value) {
|
||||
if (serviceManager.autoTunnelService.value == null) {
|
||||
previousBackendState?.let { (state, lanEnabled) ->
|
||||
Timber.d("Restoring kill switch configuration")
|
||||
val lan = if (lanEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS else emptyList()
|
||||
|
||||
@@ -57,7 +57,7 @@ constructor(
|
||||
withContext(ioDispatcher) {
|
||||
Timber.i("Service worker started")
|
||||
with(appDataRepository.settings.get()) {
|
||||
if (isAutoTunnelEnabled && !serviceManager.autoTunnelActive.value)
|
||||
if (isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null)
|
||||
return@with serviceManager.startAutoTunnel()
|
||||
if (tunnelManager.activeTunnels.value.isEmpty())
|
||||
tunnelManager.restorePreviousState()
|
||||
|
||||
@@ -8,12 +8,12 @@ import androidx.room.TypeConverters
|
||||
import androidx.room.migration.AutoMigrationSpec
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.TunnelConfig
|
||||
|
||||
@Database(
|
||||
entities = [Settings::class, TunnelConfig::class],
|
||||
version = 16,
|
||||
version = 17,
|
||||
autoMigrations =
|
||||
[
|
||||
AutoMigration(from = 1, to = 2),
|
||||
@@ -31,10 +31,11 @@ import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||
AutoMigration(from = 13, to = 14),
|
||||
AutoMigration(from = 14, to = 15),
|
||||
AutoMigration(from = 15, to = 16),
|
||||
AutoMigration(from = 16, to = 17, spec = WifiDetectionMigration::class),
|
||||
],
|
||||
exportSchema = true,
|
||||
)
|
||||
@TypeConverters(DatabaseListConverters::class)
|
||||
@TypeConverters(DatabaseConverters::class)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun settingDao(): SettingsDao
|
||||
|
||||
@@ -47,3 +48,6 @@ class RemoveLegacySettingColumnsMigration : AutoMigrationSpec
|
||||
|
||||
@DeleteColumn(tableName = "Settings", columnName = "is_auto_tunnel_paused")
|
||||
class RemoveTunnelPauseMigration : AutoMigrationSpec
|
||||
|
||||
@DeleteColumn(tableName = "Settings", columnName = "is_wifi_by_shell_enabled")
|
||||
class WifiDetectionMigration : AutoMigrationSpec
|
||||
|
||||
@@ -25,7 +25,7 @@ class DataStoreManager(
|
||||
val locationDisclosureShown = booleanPreferencesKey("LOCATION_DISCLOSURE_SHOWN")
|
||||
val batteryDisableShown = booleanPreferencesKey("BATTERY_OPTIMIZE_DISABLE_SHOWN")
|
||||
val pinLockEnabled = booleanPreferencesKey("PIN_LOCK_ENABLED")
|
||||
val tunnelStatsExpanded = booleanPreferencesKey("TUNNEL_STATS_EXPANDED")
|
||||
val expandedTunnelIds = stringPreferencesKey("EXPANDED_TUNNEL_IDS")
|
||||
val isLocalLogsEnabled = booleanPreferencesKey("LOCAL_LOGS_ENABLED")
|
||||
val locale = stringPreferencesKey("LOCALE")
|
||||
val theme = stringPreferencesKey("THEME")
|
||||
|
||||
@@ -7,7 +7,6 @@ import timber.log.Timber
|
||||
class DatabaseCallback : RoomDatabase.Callback() {
|
||||
override fun onCreate(db: SupportSQLiteDatabase) =
|
||||
db.run {
|
||||
// Notice non-ui thread is here
|
||||
beginTransaction()
|
||||
try {
|
||||
execSQL(Queries.createDefaultSettings())
|
||||
|
||||
+8
-1
@@ -1,9 +1,10 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class DatabaseListConverters {
|
||||
class DatabaseConverters {
|
||||
@TypeConverter
|
||||
fun listToString(value: MutableList<String>): String {
|
||||
return Json.encodeToString(value)
|
||||
@@ -20,4 +21,10 @@ class DatabaseListConverters {
|
||||
Json.decodeFromString<MutableList<String>>(json)
|
||||
}
|
||||
}
|
||||
|
||||
@TypeConverter fun fromStatus(status: Settings.WifiDetectionMethod): Int = status.value
|
||||
|
||||
@TypeConverter
|
||||
fun toStatus(value: Int): Settings.WifiDetectionMethod =
|
||||
Settings.WifiDetectionMethod.fromValue(value)
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
|
||||
@@ -5,7 +5,7 @@ import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.TunnelConfig
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.TunnelConfigs
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.entity
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Asset(
|
||||
val name: String,
|
||||
@SerialName("browser_download_url") val browserDownloadUrl: String,
|
||||
)
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.entity
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||
|
||||
data class GeneralState(
|
||||
val isLocationDisclosureShown: Boolean = LOCATION_DISCLOSURE_SHOWN_DEFAULT,
|
||||
val isBatteryOptimizationDisableShown: Boolean = BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT,
|
||||
val isPinLockEnabled: Boolean = PIN_LOCK_ENABLED_DEFAULT,
|
||||
val expandedTunnelIds: List<Int> = emptyList(),
|
||||
val isLocalLogsEnabled: Boolean = IS_LOGS_ENABLED_DEFAULT,
|
||||
val isRemoteControlEnabled: Boolean = IS_REMOTE_CONTROL_ENABLED,
|
||||
val remoteKey: String? = null,
|
||||
val locale: String? = null,
|
||||
val theme: Theme = Theme.AUTOMATIC,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
const val LOCATION_DISCLOSURE_SHOWN_DEFAULT = false
|
||||
const val BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT = false
|
||||
const val PIN_LOCK_ENABLED_DEFAULT = false
|
||||
const val IS_LOGS_ENABLED_DEFAULT = false
|
||||
const val IS_REMOTE_CONTROL_ENABLED = false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.entity
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class GitHubRelease(
|
||||
@SerialName("tag_name") val tagName: String,
|
||||
val name: String?,
|
||||
val body: String?,
|
||||
val assets: List<Asset>,
|
||||
)
|
||||
+15
-56
@@ -1,9 +1,8 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.model
|
||||
package com.zaneschepke.wireguardautotunnel.data.entity
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppSettings
|
||||
|
||||
@Entity
|
||||
data class Settings(
|
||||
@@ -32,8 +31,6 @@ data class Settings(
|
||||
val isAmneziaEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_wildcards_enabled", defaultValue = "false")
|
||||
val isWildcardsEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_wifi_by_shell_enabled", defaultValue = "false")
|
||||
val isWifiNameByShellEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_stop_on_no_internet_enabled", defaultValue = "false")
|
||||
val isStopOnNoInternetEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_vpn_kill_switch_enabled", defaultValue = "false")
|
||||
@@ -46,61 +43,23 @@ data class Settings(
|
||||
val debounceDelaySeconds: Int = 3,
|
||||
@ColumnInfo(name = "is_disable_kill_switch_on_trusted_enabled", defaultValue = "false")
|
||||
val isDisableKillSwitchOnTrustedEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_tunnel_on_unsecure_enabled", defaultValue = "false")
|
||||
val isTunnelOnUnsecureEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "split_tunnel_apps", defaultValue = "")
|
||||
val splitTunnelApps: MutableList<String> = mutableListOf(),
|
||||
@ColumnInfo(name = "wifi_detection_method", defaultValue = "0")
|
||||
val wifiDetectionMethod: WifiDetectionMethod = WifiDetectionMethod.fromValue(0),
|
||||
) {
|
||||
|
||||
fun toAppSettings(): AppSettings {
|
||||
return AppSettings(
|
||||
id,
|
||||
isAutoTunnelEnabled,
|
||||
isTunnelOnMobileDataEnabled,
|
||||
trustedNetworkSSIDs,
|
||||
isAlwaysOnVpnEnabled,
|
||||
isTunnelOnEthernetEnabled,
|
||||
isShortcutsEnabled,
|
||||
isTunnelOnWifiEnabled,
|
||||
isKernelEnabled,
|
||||
isRestoreOnBootEnabled,
|
||||
isMultiTunnelEnabled,
|
||||
isPingEnabled,
|
||||
isAmneziaEnabled,
|
||||
isWildcardsEnabled,
|
||||
isWifiNameByShellEnabled,
|
||||
isStopOnNoInternetEnabled,
|
||||
isVpnKillSwitchEnabled,
|
||||
isKernelKillSwitchEnabled,
|
||||
isLanOnKillSwitchEnabled,
|
||||
debounceDelaySeconds,
|
||||
isDisableKillSwitchOnTrustedEnabled,
|
||||
)
|
||||
}
|
||||
enum class WifiDetectionMethod(val value: Int) {
|
||||
DEFAULT(0),
|
||||
LEGACY(1),
|
||||
ROOT(2),
|
||||
SHIZUKU(3);
|
||||
|
||||
companion object {
|
||||
fun from(appSettings: AppSettings): Settings {
|
||||
return with(appSettings) {
|
||||
Settings(
|
||||
id,
|
||||
isAutoTunnelEnabled,
|
||||
isTunnelOnMobileDataEnabled,
|
||||
trustedNetworkSSIDs.toMutableList(),
|
||||
isAlwaysOnVpnEnabled,
|
||||
isTunnelOnEthernetEnabled,
|
||||
isShortcutsEnabled,
|
||||
isTunnelOnWifiEnabled,
|
||||
isKernelEnabled,
|
||||
isRestoreOnBootEnabled,
|
||||
isMultiTunnelEnabled,
|
||||
isPingEnabled,
|
||||
isAmneziaEnabled,
|
||||
isWildcardsEnabled,
|
||||
isWifiNameByShellEnabled,
|
||||
isStopOnNoInternetEnabled,
|
||||
isVpnKillSwitchEnabled,
|
||||
isKernelKillSwitchEnabled,
|
||||
isLanOnKillSwitchEnabled,
|
||||
debounceDelaySeconds,
|
||||
isDisableKillSwitchOnTrustedEnabled,
|
||||
)
|
||||
}
|
||||
companion object {
|
||||
fun fromValue(value: Int): WifiDetectionMethod =
|
||||
entries.find { it.value == value } ?: DEFAULT
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-43
@@ -1,10 +1,9 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.model
|
||||
package com.zaneschepke.wireguardautotunnel.data.entity
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
|
||||
@Entity(indices = [Index(value = ["name"], unique = true)])
|
||||
data class TunnelConfig(
|
||||
@@ -30,48 +29,7 @@ data class TunnelConfig(
|
||||
var isIpv4Preferred: Boolean = true,
|
||||
) {
|
||||
|
||||
fun toTunnel(): TunnelConf {
|
||||
return TunnelConf(
|
||||
id,
|
||||
name,
|
||||
wgQuick,
|
||||
tunnelNetworks,
|
||||
isMobileDataTunnel,
|
||||
isPrimaryTunnel,
|
||||
amQuick,
|
||||
isActive,
|
||||
isPingEnabled,
|
||||
pingInterval,
|
||||
pingCooldown,
|
||||
pingIp,
|
||||
isEthernetTunnel,
|
||||
isIpv4Preferred,
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val AM_QUICK_DEFAULT = ""
|
||||
|
||||
fun from(tunnelConf: TunnelConf): TunnelConfig {
|
||||
return with(tunnelConf) {
|
||||
return TunnelConfig(
|
||||
id,
|
||||
tunName,
|
||||
wgQuick,
|
||||
tunnelNetworks.toMutableList(),
|
||||
isMobileDataTunnel,
|
||||
isPrimaryTunnel,
|
||||
amQuick,
|
||||
isActive,
|
||||
isPingEnabled,
|
||||
pingInterval,
|
||||
pingCooldown,
|
||||
pingIp,
|
||||
isEthernetTunnel,
|
||||
isIpv4Preferred,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.mapper
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.GeneralState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppState
|
||||
|
||||
object GeneralStateMapper {
|
||||
fun toAppState(generalState: GeneralState): AppState =
|
||||
with(generalState) {
|
||||
AppState(
|
||||
isLocationDisclosureShown,
|
||||
isBatteryOptimizationDisableShown,
|
||||
isPinLockEnabled,
|
||||
expandedTunnelIds,
|
||||
isLocalLogsEnabled,
|
||||
isRemoteControlEnabled,
|
||||
remoteKey,
|
||||
locale,
|
||||
theme,
|
||||
)
|
||||
}
|
||||
|
||||
fun toGeneralState(appState: AppState): GeneralState {
|
||||
return with(appState) {
|
||||
GeneralState(
|
||||
isLocationDisclosureShown,
|
||||
isBatteryOptimizationDisableShown,
|
||||
isPinLockEnabled,
|
||||
expandedTunnelIds,
|
||||
isLocalLogsEnabled,
|
||||
isRemoteControlEnabled,
|
||||
remoteKey,
|
||||
locale,
|
||||
theme,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.mapper
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.GitHubRelease
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppUpdate
|
||||
import kotlin.collections.firstOrNull
|
||||
|
||||
object GitHubReleaseMapper {
|
||||
fun toAppUpdate(gitHubRelease: GitHubRelease, newVersion: String): AppUpdate {
|
||||
with(gitHubRelease) {
|
||||
val apkAsset = assets.firstOrNull { it.name.endsWith(".apk") }
|
||||
return AppUpdate(
|
||||
version = newVersion,
|
||||
title = name ?: "Update $tagName",
|
||||
releaseNotes = body ?: "No release notes provided",
|
||||
apkUrl = apkAsset?.browserDownloadUrl,
|
||||
apkFileName = apkAsset?.name,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.mapper
|
||||
|
||||
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||
|
||||
object SettingsMapper {
|
||||
fun toAppSettings(settings: Settings): AppSettings {
|
||||
return AppSettings(
|
||||
id = settings.id,
|
||||
isAutoTunnelEnabled = settings.isAutoTunnelEnabled,
|
||||
isTunnelOnMobileDataEnabled = settings.isTunnelOnMobileDataEnabled,
|
||||
trustedNetworkSSIDs = settings.trustedNetworkSSIDs,
|
||||
isAlwaysOnVpnEnabled = settings.isAlwaysOnVpnEnabled,
|
||||
isTunnelOnEthernetEnabled = settings.isTunnelOnEthernetEnabled,
|
||||
isShortcutsEnabled = settings.isShortcutsEnabled,
|
||||
isTunnelOnWifiEnabled = settings.isTunnelOnWifiEnabled,
|
||||
isKernelEnabled = settings.isKernelEnabled,
|
||||
isRestoreOnBootEnabled = settings.isRestoreOnBootEnabled,
|
||||
isMultiTunnelEnabled = settings.isMultiTunnelEnabled,
|
||||
isPingEnabled = settings.isPingEnabled,
|
||||
isAmneziaEnabled = settings.isAmneziaEnabled,
|
||||
isWildcardsEnabled = settings.isWildcardsEnabled,
|
||||
isStopOnNoInternetEnabled = settings.isStopOnNoInternetEnabled,
|
||||
isVpnKillSwitchEnabled = settings.isVpnKillSwitchEnabled,
|
||||
isKernelKillSwitchEnabled = settings.isKernelKillSwitchEnabled,
|
||||
isLanOnKillSwitchEnabled = settings.isLanOnKillSwitchEnabled,
|
||||
debounceDelaySeconds = settings.debounceDelaySeconds,
|
||||
isDisableKillSwitchOnTrustedEnabled = settings.isDisableKillSwitchOnTrustedEnabled,
|
||||
isTunnelOnUnsecureEnabled = settings.isTunnelOnUnsecureEnabled,
|
||||
splitTunnelApps = settings.splitTunnelApps,
|
||||
wifiDetectionMethod =
|
||||
AndroidNetworkMonitor.WifiDetectionMethod.fromValue(
|
||||
settings.wifiDetectionMethod.value
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fun toSettings(appSettings: AppSettings): Settings {
|
||||
return Settings(
|
||||
id = appSettings.id,
|
||||
isAutoTunnelEnabled = appSettings.isAutoTunnelEnabled,
|
||||
isTunnelOnMobileDataEnabled = appSettings.isTunnelOnMobileDataEnabled,
|
||||
trustedNetworkSSIDs = appSettings.trustedNetworkSSIDs.toMutableList(),
|
||||
isAlwaysOnVpnEnabled = appSettings.isAlwaysOnVpnEnabled,
|
||||
isTunnelOnEthernetEnabled = appSettings.isTunnelOnEthernetEnabled,
|
||||
isShortcutsEnabled = appSettings.isShortcutsEnabled,
|
||||
isTunnelOnWifiEnabled = appSettings.isTunnelOnWifiEnabled,
|
||||
isKernelEnabled = appSettings.isKernelEnabled,
|
||||
isRestoreOnBootEnabled = appSettings.isRestoreOnBootEnabled,
|
||||
isMultiTunnelEnabled = appSettings.isMultiTunnelEnabled,
|
||||
isPingEnabled = appSettings.isPingEnabled,
|
||||
isAmneziaEnabled = appSettings.isAmneziaEnabled,
|
||||
isWildcardsEnabled = appSettings.isWildcardsEnabled,
|
||||
isStopOnNoInternetEnabled = appSettings.isStopOnNoInternetEnabled,
|
||||
isVpnKillSwitchEnabled = appSettings.isVpnKillSwitchEnabled,
|
||||
isKernelKillSwitchEnabled = appSettings.isKernelKillSwitchEnabled,
|
||||
isLanOnKillSwitchEnabled = appSettings.isLanOnKillSwitchEnabled,
|
||||
debounceDelaySeconds = appSettings.debounceDelaySeconds,
|
||||
isDisableKillSwitchOnTrustedEnabled = appSettings.isDisableKillSwitchOnTrustedEnabled,
|
||||
isTunnelOnUnsecureEnabled = appSettings.isTunnelOnUnsecureEnabled,
|
||||
splitTunnelApps = appSettings.splitTunnelApps.toMutableList(),
|
||||
wifiDetectionMethod =
|
||||
Settings.WifiDetectionMethod.fromValue(appSettings.wifiDetectionMethod.value),
|
||||
)
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.mapper
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.TunnelConfig
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
|
||||
object TunnelConfigMapper {
|
||||
fun toTunnelConf(tunnelConfig: TunnelConfig): TunnelConf {
|
||||
return with(tunnelConfig) {
|
||||
TunnelConf(
|
||||
id,
|
||||
name,
|
||||
wgQuick,
|
||||
tunnelNetworks,
|
||||
isMobileDataTunnel,
|
||||
isPrimaryTunnel,
|
||||
amQuick,
|
||||
isActive,
|
||||
isPingEnabled,
|
||||
pingInterval,
|
||||
pingCooldown,
|
||||
pingIp,
|
||||
isEthernetTunnel,
|
||||
isIpv4Preferred,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun toTunnelConfig(tunnelConf: TunnelConf): TunnelConfig {
|
||||
return with(tunnelConf) {
|
||||
TunnelConfig(
|
||||
id,
|
||||
tunName,
|
||||
wgQuick,
|
||||
tunnelNetworks.toMutableList(),
|
||||
isMobileDataTunnel,
|
||||
isPrimaryTunnel,
|
||||
amQuick,
|
||||
isActive,
|
||||
isPingEnabled,
|
||||
pingInterval,
|
||||
pingCooldown,
|
||||
pingIp,
|
||||
isEthernetTunnel,
|
||||
isIpv4Preferred,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.model
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||
|
||||
data class GeneralState(
|
||||
val isLocationDisclosureShown: Boolean = LOCATION_DISCLOSURE_SHOWN_DEFAULT,
|
||||
val isBatteryOptimizationDisableShown: Boolean = BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT,
|
||||
val isPinLockEnabled: Boolean = PIN_LOCK_ENABLED_DEFAULT,
|
||||
val isTunnelStatsExpanded: Boolean = IS_TUNNEL_STATS_EXPANDED,
|
||||
val isLocalLogsEnabled: Boolean = IS_LOGS_ENABLED_DEFAULT,
|
||||
val isRemoteControlEnabled: Boolean = IS_REMOTE_CONTROL_ENABLED,
|
||||
val remoteKey: String? = null,
|
||||
val locale: String? = null,
|
||||
val theme: Theme = Theme.AUTOMATIC,
|
||||
) {
|
||||
|
||||
fun toAppState(): AppState =
|
||||
AppState(
|
||||
isLocationDisclosureShown,
|
||||
isBatteryOptimizationDisableShown,
|
||||
isPinLockEnabled,
|
||||
isTunnelStatsExpanded,
|
||||
isLocalLogsEnabled,
|
||||
isRemoteControlEnabled,
|
||||
remoteKey,
|
||||
locale,
|
||||
theme,
|
||||
)
|
||||
|
||||
companion object {
|
||||
fun from(appState: AppState): GeneralState {
|
||||
return with(appState) {
|
||||
GeneralState(
|
||||
isLocationDisclosureShown,
|
||||
isBatteryOptimizationDisableShown,
|
||||
isPinLockEnabled,
|
||||
isTunnelStatsExpanded,
|
||||
isLocalLogsEnabled,
|
||||
isRemoteControlEnabled,
|
||||
remoteKey,
|
||||
locale,
|
||||
theme,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const val LOCATION_DISCLOSURE_SHOWN_DEFAULT = false
|
||||
const val BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT = false
|
||||
const val PIN_LOCK_ENABLED_DEFAULT = false
|
||||
const val IS_TUNNEL_STATS_EXPANDED = false
|
||||
const val IS_LOGS_ENABLED_DEFAULT = false
|
||||
const val IS_REMOTE_CONTROL_ENABLED = false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.network
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.GitHubRelease
|
||||
|
||||
interface GitHubApi {
|
||||
suspend fun getLatestRelease(owner: String, repo: String): Result<GitHubRelease>
|
||||
|
||||
suspend fun getNightlyRelease(owner: String, repo: String): Result<GitHubRelease>
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.network
|
||||
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.okhttp.OkHttp
|
||||
import io.ktor.client.plugins.HttpTimeout
|
||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
object KtorClient {
|
||||
fun create(): HttpClient {
|
||||
return HttpClient(OkHttp) {
|
||||
install(ContentNegotiation) {
|
||||
json(
|
||||
Json {
|
||||
ignoreUnknownKeys = true
|
||||
isLenient = true
|
||||
}
|
||||
)
|
||||
}
|
||||
install(HttpTimeout) {
|
||||
requestTimeoutMillis = 15000
|
||||
connectTimeoutMillis = 15000
|
||||
socketTimeoutMillis = 15000
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.network
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.GitHubRelease
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.body
|
||||
import io.ktor.client.plugins.ClientRequestException
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.http.HttpStatusCode
|
||||
|
||||
class KtorGitHubApi(private val client: HttpClient) : GitHubApi {
|
||||
override suspend fun getLatestRelease(owner: String, repo: String): Result<GitHubRelease> {
|
||||
return try {
|
||||
val response: GitHubRelease =
|
||||
client.get("https://api.github.com/repos/$owner/$repo/releases/latest").body()
|
||||
Result.success(response)
|
||||
} catch (e: ClientRequestException) {
|
||||
when (e.response.status) {
|
||||
HttpStatusCode.Forbidden -> Result.failure(Exception("Rate limit exceeded"))
|
||||
HttpStatusCode.NotFound ->
|
||||
Result.failure(Exception("Repository or release not found"))
|
||||
else -> Result.failure(e)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getNightlyRelease(owner: String, repo: String): Result<GitHubRelease> {
|
||||
return try {
|
||||
// Fetch all releases
|
||||
val releases: List<GitHubRelease> =
|
||||
client.get("https://api.github.com/repos/$owner/$repo/releases").body()
|
||||
|
||||
// Find the first release with "nightly" in the tag_name (case-insensitive)
|
||||
val nightlyRelease =
|
||||
releases.firstOrNull { release ->
|
||||
release.tagName.contains("nightly", ignoreCase = true)
|
||||
}
|
||||
|
||||
if (nightlyRelease != null) {
|
||||
Result.success(nightlyRelease)
|
||||
} else {
|
||||
Result.failure(Exception("No release with 'nightly' tag found"))
|
||||
}
|
||||
} catch (e: ClientRequestException) {
|
||||
when (e.response.status) {
|
||||
HttpStatusCode.Forbidden -> Result.failure(Exception("Rate limit exceeded"))
|
||||
HttpStatusCode.NotFound ->
|
||||
Result.failure(Exception("Repository or release not found"))
|
||||
else -> Result.failure(e)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||
|
||||
+36
-11
@@ -1,8 +1,9 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.GeneralState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppState
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.GeneralState
|
||||
import com.zaneschepke.wireguardautotunnel.data.mapper.GeneralStateMapper
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@@ -38,13 +39,36 @@ class DataStoreAppStateRepository(private val dataStoreManager: DataStoreManager
|
||||
dataStoreManager.saveToDataStore(DataStoreManager.batteryDisableShown, shown)
|
||||
}
|
||||
|
||||
override suspend fun isTunnelStatsExpanded(): Boolean {
|
||||
return dataStoreManager.getFromStore(DataStoreManager.tunnelStatsExpanded)
|
||||
?: GeneralState.IS_TUNNEL_STATS_EXPANDED
|
||||
override suspend fun setTunnelExpanded(id: Int) {
|
||||
val ids =
|
||||
dataStoreManager
|
||||
.getFromStore(DataStoreManager.expandedTunnelIds)
|
||||
?.split(",")
|
||||
?.mapNotNull { it.toIntOrNull() } ?: emptyList()
|
||||
|
||||
if (ids.contains(id)) return
|
||||
|
||||
val updatedList = ids.toMutableList().apply { add(id) }
|
||||
dataStoreManager.saveToDataStore(
|
||||
DataStoreManager.expandedTunnelIds,
|
||||
updatedList.joinToString(","),
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun setTunnelStatsExpanded(expanded: Boolean) {
|
||||
dataStoreManager.saveToDataStore(DataStoreManager.tunnelStatsExpanded, expanded)
|
||||
override suspend fun removeTunnelExpanded(id: Int) {
|
||||
val ids =
|
||||
dataStoreManager
|
||||
.getFromStore(DataStoreManager.expandedTunnelIds)
|
||||
?.split(",")
|
||||
?.mapNotNull { it.toIntOrNull() } ?: emptyList()
|
||||
|
||||
if (ids.isEmpty() || !ids.contains(id)) return
|
||||
|
||||
val updatedList = ids.toMutableList().apply { remove(id) }
|
||||
dataStoreManager.saveToDataStore(
|
||||
DataStoreManager.expandedTunnelIds,
|
||||
updatedList.joinToString(","),
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun setTheme(theme: Theme) {
|
||||
@@ -110,9 +134,10 @@ class DataStoreAppStateRepository(private val dataStoreManager: DataStoreManager
|
||||
isPinLockEnabled =
|
||||
pref[DataStoreManager.pinLockEnabled]
|
||||
?: GeneralState.PIN_LOCK_ENABLED_DEFAULT,
|
||||
isTunnelStatsExpanded =
|
||||
pref[DataStoreManager.tunnelStatsExpanded]
|
||||
?: GeneralState.IS_TUNNEL_STATS_EXPANDED,
|
||||
expandedTunnelIds =
|
||||
pref[DataStoreManager.expandedTunnelIds]?.split(",")?.mapNotNull {
|
||||
it.toIntOrNull()
|
||||
} ?: emptyList(),
|
||||
isLocalLogsEnabled =
|
||||
pref[DataStoreManager.isLocalLogsEnabled]
|
||||
?: GeneralState.IS_LOGS_ENABLED_DEFAULT,
|
||||
@@ -129,5 +154,5 @@ class DataStoreAppStateRepository(private val dataStoreManager: DataStoreManager
|
||||
}
|
||||
} ?: GeneralState()
|
||||
}
|
||||
.map { it.toAppState() }
|
||||
.map(GeneralStateMapper::toAppState)
|
||||
}
|
||||
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||
|
||||
import android.content.Context
|
||||
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
||||
import com.zaneschepke.wireguardautotunnel.data.mapper.GitHubReleaseMapper
|
||||
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppUpdate
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.UpdateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.client.statement.bodyAsChannel
|
||||
import io.ktor.http.contentLength
|
||||
import io.ktor.utils.io.ByteReadChannel
|
||||
import io.ktor.utils.io.readAvailable
|
||||
import java.io.File
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
|
||||
class GitHubUpdateRepository(
|
||||
private val gitHubApi: GitHubApi,
|
||||
private val httpClient: HttpClient,
|
||||
private val githubOwner: String,
|
||||
private val githubRepo: String,
|
||||
private val context: Context,
|
||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||
) : UpdateRepository {
|
||||
override suspend fun checkForUpdate(currentVersion: String): Result<AppUpdate?> =
|
||||
withContext(ioDispatcher) {
|
||||
Timber.i("Checking for update")
|
||||
val isNightly = BuildConfig.VERSION_NAME.contains("nightly")
|
||||
val release =
|
||||
if (isNightly) {
|
||||
gitHubApi.getNightlyRelease(githubOwner, githubRepo).onFailure(Timber::e)
|
||||
} else {
|
||||
gitHubApi.getLatestRelease(githubOwner, githubRepo).onFailure(Timber::e)
|
||||
}
|
||||
release.map { release ->
|
||||
val apkAsset =
|
||||
release.assets.find { asset ->
|
||||
asset.name.startsWith("wgtunnel-${Constants.STANDALONE_FLAVOR}-v") &&
|
||||
asset.name.endsWith(".apk")
|
||||
}
|
||||
val newVersion =
|
||||
apkAsset
|
||||
?.name
|
||||
?.removePrefix("wgtunnel-${Constants.STANDALONE_FLAVOR}-v")
|
||||
?.removeSuffix(".apk") ?: return@map null
|
||||
|
||||
Timber.i("Latest version: $newVersion, current version: $currentVersion")
|
||||
if (isNightly && newVersion != currentVersion)
|
||||
return@map GitHubReleaseMapper.toAppUpdate(release, newVersion)
|
||||
if (NumberUtils.compareVersions(newVersion, currentVersion) > 0) {
|
||||
GitHubReleaseMapper.toAppUpdate(release, newVersion)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun downloadApk(
|
||||
apkUrl: String,
|
||||
fileName: String,
|
||||
onProgress: (Float) -> Unit,
|
||||
): Result<File> =
|
||||
withContext(ioDispatcher) {
|
||||
try {
|
||||
// clean up old files
|
||||
context.getExternalFilesDir(null)?.listFiles()?.forEach { file ->
|
||||
if (file.extension == "apk") file.delete()
|
||||
}
|
||||
|
||||
val response: HttpResponse = httpClient.get(apkUrl)
|
||||
|
||||
val apkFile = File(context.getExternalFilesDir(null), fileName)
|
||||
|
||||
val channel: ByteReadChannel = response.bodyAsChannel()
|
||||
val totalBytes: Long = response.contentLength() ?: -1L
|
||||
var bytesCopied = 0L
|
||||
|
||||
apkFile.outputStream().use { output ->
|
||||
val buffer = ByteArray(8 * 1024)
|
||||
|
||||
while (!channel.isClosedForRead) {
|
||||
val bytesRead = channel.readAvailable(buffer)
|
||||
if (bytesRead <= 0) break
|
||||
output.write(buffer, 0, bytesRead)
|
||||
bytesCopied += bytesRead
|
||||
|
||||
if (totalBytes > 0) {
|
||||
val progress = bytesCopied.toFloat() / totalBytes
|
||||
onProgress(progress.coerceIn(0f, 1f))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Result.success(apkFile)
|
||||
} catch (e: Exception) {
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -1,9 +1,10 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||
import com.zaneschepke.wireguardautotunnel.data.mapper.SettingsMapper
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
@@ -16,15 +17,15 @@ class RoomSettingsRepository(
|
||||
) : AppSettingRepository {
|
||||
|
||||
override suspend fun save(appSettings: AppSettings) {
|
||||
withContext(ioDispatcher) { settingsDoa.save(Settings.from(appSettings)) }
|
||||
withContext(ioDispatcher) { settingsDoa.save(SettingsMapper.toSettings(appSettings)) }
|
||||
}
|
||||
|
||||
override val flow =
|
||||
settingsDoa.getSettingsFlow().flowOn(ioDispatcher).map { it.toAppSettings() }
|
||||
settingsDoa.getSettingsFlow().flowOn(ioDispatcher).map(SettingsMapper::toAppSettings)
|
||||
|
||||
override suspend fun get(): AppSettings {
|
||||
return withContext(ioDispatcher) {
|
||||
(settingsDoa.getAll().firstOrNull() ?: Settings()).toAppSettings()
|
||||
SettingsMapper.toAppSettings(settingsDoa.getAll().firstOrNull() ?: Settings())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+29
-13
@@ -1,9 +1,9 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||
import com.zaneschepke.wireguardautotunnel.data.mapper.TunnelConfigMapper
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
@@ -17,19 +17,25 @@ class RoomTunnelRepository(
|
||||
) : TunnelRepository {
|
||||
|
||||
override val flow =
|
||||
tunnelConfigDao.getAllFlow().flowOn(ioDispatcher).map { it.map { it.toTunnel() } }
|
||||
tunnelConfigDao.getAllFlow().flowOn(ioDispatcher).map {
|
||||
it.map(TunnelConfigMapper::toTunnelConf)
|
||||
}
|
||||
|
||||
override suspend fun getAll(): Tunnels {
|
||||
return withContext(ioDispatcher) { tunnelConfigDao.getAll().map { it.toTunnel() } }
|
||||
return withContext(ioDispatcher) {
|
||||
tunnelConfigDao.getAll().map(TunnelConfigMapper::toTunnelConf)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun save(tunnelConf: TunnelConf) {
|
||||
withContext(ioDispatcher) { tunnelConfigDao.save(TunnelConfig.from(tunnelConf)) }
|
||||
withContext(ioDispatcher) {
|
||||
tunnelConfigDao.save(TunnelConfigMapper.toTunnelConfig(tunnelConf))
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun saveAll(tunnelConfList: List<TunnelConf>) {
|
||||
withContext(ioDispatcher) {
|
||||
tunnelConfigDao.saveAll(tunnelConfList.map(TunnelConfig::from))
|
||||
tunnelConfigDao.saveAll(tunnelConfList.map(TunnelConfigMapper::toTunnelConfig))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,15 +61,21 @@ class RoomTunnelRepository(
|
||||
}
|
||||
|
||||
override suspend fun delete(tunnelConf: TunnelConf) {
|
||||
withContext(ioDispatcher) { tunnelConfigDao.delete(TunnelConfig.from(tunnelConf)) }
|
||||
withContext(ioDispatcher) {
|
||||
tunnelConfigDao.delete(TunnelConfigMapper.toTunnelConfig(tunnelConf))
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getById(id: Int): TunnelConf? {
|
||||
return withContext(ioDispatcher) { tunnelConfigDao.getById(id.toLong())?.toTunnel() }
|
||||
return withContext(ioDispatcher) {
|
||||
tunnelConfigDao.getById(id.toLong())?.let(TunnelConfigMapper::toTunnelConf)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getActive(): Tunnels {
|
||||
return withContext(ioDispatcher) { tunnelConfigDao.getActive().map { it.toTunnel() } }
|
||||
return withContext(ioDispatcher) {
|
||||
tunnelConfigDao.getActive().map(TunnelConfigMapper::toTunnelConf)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun count(): Int {
|
||||
@@ -71,22 +83,26 @@ class RoomTunnelRepository(
|
||||
}
|
||||
|
||||
override suspend fun findByTunnelName(name: String): TunnelConf? {
|
||||
return withContext(ioDispatcher) { tunnelConfigDao.getByName(name)?.toTunnel() }
|
||||
return withContext(ioDispatcher) {
|
||||
tunnelConfigDao.getByName(name)?.let(TunnelConfigMapper::toTunnelConf)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun findByTunnelNetworksName(name: String): Tunnels {
|
||||
return withContext(ioDispatcher) {
|
||||
tunnelConfigDao.findByTunnelNetworkName(name).map { it.toTunnel() }
|
||||
tunnelConfigDao.findByTunnelNetworkName(name).map(TunnelConfigMapper::toTunnelConf)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun findByMobileDataTunnel(): Tunnels {
|
||||
return withContext(ioDispatcher) {
|
||||
tunnelConfigDao.findByMobileDataTunnel().map { it.toTunnel() }
|
||||
tunnelConfigDao.findByMobileDataTunnel().map(TunnelConfigMapper::toTunnelConf)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun findPrimary(): Tunnels {
|
||||
return withContext(ioDispatcher) { tunnelConfigDao.findByPrimary().map { it.toTunnel() } }
|
||||
return withContext(ioDispatcher) {
|
||||
tunnelConfigDao.findByPrimary().map(TunnelConfigMapper::toTunnelConf)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,19 +8,25 @@ import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
||||
import com.zaneschepke.wireguardautotunnel.data.DatabaseCallback
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
||||
import com.zaneschepke.wireguardautotunnel.data.network.KtorClient
|
||||
import com.zaneschepke.wireguardautotunnel.data.network.KtorGitHubApi
|
||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRoomRepository
|
||||
import com.zaneschepke.wireguardautotunnel.data.repository.DataStoreAppStateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.data.repository.GitHubUpdateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.data.repository.RoomSettingsRepository
|
||||
import com.zaneschepke.wireguardautotunnel.data.repository.RoomTunnelRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.UpdateRepository
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import io.ktor.client.HttpClient
|
||||
import javax.inject.Singleton
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
|
||||
@@ -94,4 +100,34 @@ class RepositoryModule {
|
||||
): AppDataRepository {
|
||||
return AppDataRoomRepository(settingsRepository, tunnelRepository, appStateRepository)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideHttpClient(): HttpClient {
|
||||
return KtorClient.create()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideGitHubApi(client: HttpClient): GitHubApi {
|
||||
return KtorGitHubApi(client)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideUpdateRepository(
|
||||
gitHubApi: GitHubApi,
|
||||
client: HttpClient,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
@ApplicationContext context: Context,
|
||||
): UpdateRepository {
|
||||
return GitHubUpdateRepository(
|
||||
gitHubApi,
|
||||
client,
|
||||
"wgtunnel",
|
||||
"wgtunnel",
|
||||
context,
|
||||
ioDispatcher,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,9 +113,11 @@ class TunnelModule {
|
||||
@ApplicationContext context: Context,
|
||||
settingsRepository: AppSettingRepository,
|
||||
): NetworkMonitor {
|
||||
return AndroidNetworkMonitor(context) {
|
||||
runBlocking { settingsRepository.get().isWifiNameByShellEnabled }
|
||||
}
|
||||
val method = runBlocking { settingsRepository.get().wifiDetectionMethod }
|
||||
return AndroidNetworkMonitor(
|
||||
context,
|
||||
AndroidNetworkMonitor.WifiDetectionMethod.fromValue(method.value),
|
||||
)
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.enums
|
||||
|
||||
enum class ConfigType {
|
||||
AMNEZIA,
|
||||
AM,
|
||||
WG,
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.enums
|
||||
|
||||
sealed class TunnelStatus {
|
||||
data class Error(val error: BackendError) : TunnelStatus()
|
||||
|
||||
data object Up : TunnelStatus()
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.events
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
|
||||
sealed class AutoTunnelEvent {
|
||||
data class Start(val tunnelConf: TunnelConf? = null) : AutoTunnelEvent()
|
||||
|
||||
+19
-2
@@ -1,4 +1,6 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.entity
|
||||
package com.zaneschepke.wireguardautotunnel.domain.model
|
||||
|
||||
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
||||
|
||||
data class AppSettings(
|
||||
val id: Int = 0,
|
||||
@@ -15,15 +17,30 @@ data class AppSettings(
|
||||
val isPingEnabled: Boolean = false,
|
||||
val isAmneziaEnabled: Boolean = false,
|
||||
val isWildcardsEnabled: Boolean = false,
|
||||
val isWifiNameByShellEnabled: Boolean = false,
|
||||
val isStopOnNoInternetEnabled: Boolean = false,
|
||||
val isVpnKillSwitchEnabled: Boolean = false,
|
||||
val isKernelKillSwitchEnabled: Boolean = false,
|
||||
val isLanOnKillSwitchEnabled: Boolean = false,
|
||||
val debounceDelaySeconds: Int = 3,
|
||||
val isDisableKillSwitchOnTrustedEnabled: Boolean = false,
|
||||
val isTunnelOnUnsecureEnabled: Boolean = false,
|
||||
val splitTunnelApps: List<String> = emptyList(),
|
||||
val wifiDetectionMethod: AndroidNetworkMonitor.WifiDetectionMethod =
|
||||
AndroidNetworkMonitor.WifiDetectionMethod.DEFAULT,
|
||||
) {
|
||||
fun debounceDelayMillis(): Long {
|
||||
return debounceDelaySeconds * 1000L
|
||||
}
|
||||
|
||||
fun toAutoTunnelStateString(): String {
|
||||
return """
|
||||
TunnelOnWifi: $isTunnelOnWifiEnabled
|
||||
TunnelOnMobileData: $isTunnelOnMobileDataEnabled
|
||||
TunnelOnEthernet: $isTunnelOnEthernetEnabled
|
||||
Wildcards: $isWildcardsEnabled
|
||||
StopOnNoInternet: $isStopOnNoInternetEnabled
|
||||
Trusted Networks: $trustedNetworkSSIDs
|
||||
"""
|
||||
.trimIndent()
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.entity
|
||||
package com.zaneschepke.wireguardautotunnel.domain.model
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||
|
||||
@@ -6,7 +6,7 @@ data class AppState(
|
||||
val isLocationDisclosureShown: Boolean,
|
||||
val isBatteryOptimizationDisableShown: Boolean,
|
||||
val isPinLockEnabled: Boolean,
|
||||
val isTunnelStatsExpanded: Boolean,
|
||||
val expandedTunnelIds: List<Int>,
|
||||
val isLocalLogsEnabled: Boolean,
|
||||
val isRemoteControlEnabled: Boolean,
|
||||
val remoteKey: String?,
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.model
|
||||
|
||||
data class AppUpdate(
|
||||
val version: String,
|
||||
val title: String,
|
||||
val releaseNotes: String,
|
||||
val apkUrl: String?,
|
||||
val apkFileName: String?,
|
||||
)
|
||||
+5
-4
@@ -1,4 +1,4 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.entity
|
||||
package com.zaneschepke.wireguardautotunnel.domain.model
|
||||
|
||||
import com.wireguard.android.backend.Tunnel
|
||||
import com.wireguard.config.Config
|
||||
@@ -26,7 +26,6 @@ data class TunnelConf(
|
||||
val pingIp: String? = null,
|
||||
val isEthernetTunnel: Boolean = false,
|
||||
val isIpv4Preferred: Boolean = true,
|
||||
val useCache: Boolean = false,
|
||||
@Transient private var stateChangeCallback: ((Any) -> Unit)? = null,
|
||||
) : Tunnel, org.amnezia.awg.backend.Tunnel {
|
||||
|
||||
@@ -60,6 +59,10 @@ data class TunnelConf(
|
||||
return result
|
||||
}
|
||||
|
||||
fun isStaticallyConfigured(): Boolean {
|
||||
return toAmConfig().peers.all { it.endpoint.get().host.isValidIpv4orIpv6Address() }
|
||||
}
|
||||
|
||||
fun copyWithCallback(
|
||||
id: Int = this.id,
|
||||
tunName: String = this.tunName,
|
||||
@@ -107,8 +110,6 @@ data class TunnelConf(
|
||||
|
||||
override fun isIpv4ResolutionPreferred(): Boolean = isIpv4Preferred
|
||||
|
||||
override fun useCache(): Boolean = useCache
|
||||
|
||||
override fun onStateChange(newState: org.amnezia.awg.backend.Tunnel.State) {
|
||||
stateChangeCallback?.invoke(newState)
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
|
||||
interface AppDataRepository {
|
||||
suspend fun getPrimaryOrFirstTunnel(): TunnelConf?
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface AppSettingRepository {
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@@ -17,9 +17,9 @@ interface AppStateRepository {
|
||||
|
||||
suspend fun setBatteryOptimizationDisableShown(shown: Boolean)
|
||||
|
||||
suspend fun isTunnelStatsExpanded(): Boolean
|
||||
suspend fun setTunnelExpanded(id: Int)
|
||||
|
||||
suspend fun setTunnelStatsExpanded(expanded: Boolean)
|
||||
suspend fun removeTunnelExpanded(id: Int)
|
||||
|
||||
suspend fun setTheme(theme: Theme)
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppUpdate
|
||||
import java.io.File
|
||||
|
||||
interface UpdateRepository {
|
||||
suspend fun checkForUpdate(currentVersion: String): Result<AppUpdate?>
|
||||
|
||||
suspend fun downloadApk(
|
||||
apkUrl: String,
|
||||
fileName: String,
|
||||
onProgress: (Float) -> Unit,
|
||||
): Result<File>
|
||||
}
|
||||
+1
@@ -12,6 +12,7 @@ class AmneziaStatistics(private val statistics: Statistics) : TunnelStatistics()
|
||||
rxBytes = stats.rxBytes,
|
||||
txBytes = stats.txBytes,
|
||||
latestHandshakeEpochMillis = stats.latestHandshakeEpochMillis,
|
||||
resolvedEndpoint = stats.resolvedEndpoint,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -3,10 +3,10 @@ package com.zaneschepke.wireguardautotunnel.domain.state
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.allDown
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.hasActive
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.isUp
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.KillSwitchEvent
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isMatchingToWildcardList
|
||||
|
||||
data class AutoTunnelState(
|
||||
@@ -16,6 +16,7 @@ data class AutoTunnelState(
|
||||
val tunnels: List<TunnelConf> = emptyList(),
|
||||
) {
|
||||
|
||||
// also need to check for Wi-Fi state as there is some overlap when they are both connected
|
||||
private fun isMobileDataActive(): Boolean {
|
||||
return !networkState.isEthernetConnected &&
|
||||
!networkState.isWifiConnected &&
|
||||
@@ -50,6 +51,7 @@ data class AutoTunnelState(
|
||||
return getTunnelWithMatchingTunnelNetwork() ?: tunnels.firstOrNull { it.isPrimaryTunnel }
|
||||
}
|
||||
|
||||
// ignore cellular state as there is overlap where it may still be active, but not prioritized
|
||||
private fun isWifiActive(): Boolean {
|
||||
return !networkState.isEthernetConnected && networkState.isWifiConnected
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ abstract class TunnelStatistics {
|
||||
val rxBytes: Long,
|
||||
val txBytes: Long,
|
||||
val latestHandshakeEpochMillis: Long,
|
||||
val resolvedEndpoint: String,
|
||||
)
|
||||
|
||||
abstract fun peerStats(peer: Key): PeerStats?
|
||||
|
||||
+1
@@ -12,6 +12,7 @@ class WireGuardStatistics(private val statistics: Statistics) : TunnelStatistics
|
||||
txBytes = peerStats.txBytes,
|
||||
rxBytes = peerStats.rxBytes,
|
||||
latestHandshakeEpochMillis = peerStats.latestHandshakeEpochMillis,
|
||||
resolvedEndpoint = peerStats.resolvedEndpoint,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ sealed class Route {
|
||||
|
||||
@Serializable data object AutoTunnelAdvanced : Route()
|
||||
|
||||
@Serializable data object WifiDetectionMethod : Route()
|
||||
|
||||
@Serializable data object LocationDisclosure : Route()
|
||||
|
||||
@Serializable data object Appearance : Route()
|
||||
@@ -29,7 +31,7 @@ sealed class Route {
|
||||
|
||||
@Serializable data object Lock : Route()
|
||||
|
||||
@Serializable data object Scanner : Route()
|
||||
@Serializable data object License : Route()
|
||||
|
||||
@Serializable data class Config(val id: Int) : Route()
|
||||
|
||||
|
||||
+37
-11
@@ -2,39 +2,65 @@ package com.zaneschepke.wireguardautotunnel.ui.common
|
||||
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.indication
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.ripple
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun ExpandingRowListItem(
|
||||
leading: @Composable () -> Unit,
|
||||
text: String,
|
||||
onHold: () -> Unit = {},
|
||||
onHold: () -> Unit,
|
||||
onClick: () -> Unit,
|
||||
onDoubleClick: () -> Unit,
|
||||
trailing: @Composable () -> Unit,
|
||||
isExpanded: Boolean,
|
||||
expanded: @Composable () -> Unit = {},
|
||||
isSelected: Boolean,
|
||||
expanded: (@Composable () -> Unit)?,
|
||||
) {
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
val haptic = LocalHapticFeedback.current
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
|
||||
Box(
|
||||
modifier =
|
||||
Modifier.animateContentSize()
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.combinedClickable(onClick = { onClick() }, onLongClick = { onHold() })
|
||||
.background(
|
||||
if (isSelected) MaterialTheme.colorScheme.primary.copy(alpha = 0.1f)
|
||||
else Color.Transparent
|
||||
)
|
||||
.then(
|
||||
if (!isTv) {
|
||||
Modifier.combinedClickable(
|
||||
interactionSource = interactionSource,
|
||||
indication = ripple(),
|
||||
onClick = onClick,
|
||||
onLongClick = {
|
||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onHold()
|
||||
},
|
||||
onDoubleClick = onDoubleClick,
|
||||
)
|
||||
} else Modifier
|
||||
)
|
||||
) {
|
||||
Column {
|
||||
Row(
|
||||
@@ -58,7 +84,7 @@ fun ExpandingRowListItem(
|
||||
}
|
||||
trailing()
|
||||
}
|
||||
if (isExpanded) expanded()
|
||||
expanded?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun SectionDivider() {
|
||||
HorizontalDivider(
|
||||
color = MaterialTheme.colorScheme.outline.copy(0.30f),
|
||||
modifier = Modifier.padding(horizontal = 12.dp),
|
||||
)
|
||||
}
|
||||
+1
-1
@@ -73,7 +73,7 @@ fun IconSurfaceButton(
|
||||
else MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
}
|
||||
Column {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
Text(title, style = MaterialTheme.typography.titleMedium)
|
||||
description?.let {
|
||||
Text(
|
||||
|
||||
+19
-15
@@ -3,21 +3,25 @@ package com.zaneschepke.wireguardautotunnel.ui.common.button.surface
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.Modifier
|
||||
|
||||
@Composable
|
||||
fun SelectionItemLabel(
|
||||
textResId: Int,
|
||||
style: androidx.compose.ui.text.TextStyle = MaterialTheme.typography.bodyMedium,
|
||||
isDescription: Boolean = false,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(textResId),
|
||||
style =
|
||||
style.copy(
|
||||
color =
|
||||
if (isDescription) MaterialTheme.colorScheme.outline
|
||||
else MaterialTheme.colorScheme.onSurface
|
||||
),
|
||||
)
|
||||
fun SelectionItemLabel(text: String, labelType: SelectionLabelType, modifier: Modifier = Modifier) {
|
||||
|
||||
val style =
|
||||
when (labelType) {
|
||||
SelectionLabelType.DESCRIPTION ->
|
||||
MaterialTheme.typography.bodySmall.copy(color = MaterialTheme.colorScheme.outline)
|
||||
SelectionLabelType.TITLE ->
|
||||
MaterialTheme.typography.bodyMedium.copy(
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
}
|
||||
|
||||
Text(text = text, style = style, modifier = modifier)
|
||||
}
|
||||
|
||||
enum class SelectionLabelType {
|
||||
DESCRIPTION,
|
||||
TITLE,
|
||||
}
|
||||
|
||||
+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) }
|
||||
}
|
||||
+44
-2
@@ -9,21 +9,23 @@ import androidx.activity.compose.ManagedActivityResultLauncher
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.runtime.Composable
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import timber.log.Timber
|
||||
|
||||
@Composable
|
||||
fun rememberFileImportLauncherForResult(
|
||||
onNoFileExplorer: () -> Unit,
|
||||
onData: (data: Uri) -> Unit,
|
||||
): ManagedActivityResultLauncher<String, Uri?> {
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
return rememberLauncherForActivityResult(
|
||||
object : ActivityResultContracts.GetContent() {
|
||||
override fun createIntent(context: Context, input: String): Intent {
|
||||
val intent =
|
||||
super.createIntent(context, input).apply {
|
||||
type =
|
||||
if (context.isRunningOnTv()) {
|
||||
if (isTv) {
|
||||
Constants.ALLOWED_TV_FILE_TYPES
|
||||
} else {
|
||||
Constants.ALL_FILE_TYPES
|
||||
@@ -63,3 +65,43 @@ fun rememberFileImportLauncherForResult(
|
||||
onData(data)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun rememberFileExportLauncherForResult(
|
||||
mimeType: String = Constants.ZIP_FILE_MIME_TYPE,
|
||||
onResult: (Uri?) -> Unit,
|
||||
): ManagedActivityResultLauncher<String, Uri?> {
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
return rememberLauncherForActivityResult(
|
||||
contract =
|
||||
object : ActivityResultContracts.CreateDocument(mimeType) {
|
||||
override fun createIntent(context: Context, input: String): Intent {
|
||||
super.createIntent(context, input)
|
||||
val intent =
|
||||
Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type =
|
||||
if (isTv) {
|
||||
Constants.ALLOWED_TV_FILE_TYPES
|
||||
} else {
|
||||
mimeType
|
||||
}
|
||||
putExtra(Intent.EXTRA_TITLE, input)
|
||||
}
|
||||
|
||||
Timber.d("Returning SAF intent for launch")
|
||||
return intent
|
||||
}
|
||||
}
|
||||
) { uri ->
|
||||
Timber.d("SAF onResult called with Uri: $uri")
|
||||
if (uri != null) {
|
||||
Timber.d(
|
||||
"Uri details: scheme=${uri.scheme}, authority=${uri.authority}, path=${uri.path}"
|
||||
)
|
||||
} else {
|
||||
Timber.d("SAF picker canceled or failed to return a Uri")
|
||||
}
|
||||
onResult(uri)
|
||||
}
|
||||
}
|
||||
|
||||
-115
@@ -1,115 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.Badge
|
||||
import androidx.compose.material3.BadgedBox
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.SilverTree
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
|
||||
@Composable
|
||||
fun BottomBarTabs(
|
||||
tabs: List<BottomNavItem>,
|
||||
selectedTabIndex: Int,
|
||||
isChildRoute: Boolean,
|
||||
onTabSelected: (BottomNavItem) -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val isRunningOnTv = remember { context.isRunningOnTv() }
|
||||
|
||||
Row(
|
||||
modifier =
|
||||
Modifier.fillMaxWidth().height(64.dp).padding(horizontal = 8.dp).padding(top = 12.dp),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
tabs.forEachIndexed { index, tab ->
|
||||
Column(
|
||||
modifier =
|
||||
Modifier.weight(1f)
|
||||
.fillMaxHeight()
|
||||
.background(Color.Transparent)
|
||||
.then(
|
||||
if (isRunningOnTv) {
|
||||
Modifier.clickable {
|
||||
if (index == selectedTabIndex && !isChildRoute) return@clickable
|
||||
tab.onClick.invoke()
|
||||
onTabSelected(tab)
|
||||
}
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
)
|
||||
.pointerInput(Unit) {
|
||||
detectTapGestures {
|
||||
if (index == selectedTabIndex && !isChildRoute)
|
||||
return@detectTapGestures
|
||||
tab.onClick.invoke()
|
||||
onTabSelected(tab)
|
||||
}
|
||||
},
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
) {
|
||||
val animatedColor by
|
||||
animateColorAsState(
|
||||
targetValue = MaterialTheme.colorScheme.primary,
|
||||
animationSpec = spring(stiffness = Spring.StiffnessLow),
|
||||
label = "animatedColor",
|
||||
)
|
||||
val color =
|
||||
if (selectedTabIndex == index) animatedColor
|
||||
else MaterialTheme.colorScheme.onSurface
|
||||
|
||||
if (tab.active) {
|
||||
BadgedBox(
|
||||
badge = {
|
||||
Badge(
|
||||
modifier = Modifier.offset(x = 8.dp, y = ((-8).dp)).size(6.dp),
|
||||
containerColor = SilverTree,
|
||||
)
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
imageVector = tab.icon,
|
||||
contentDescription = tab.name,
|
||||
tint = color,
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Icon(
|
||||
imageVector = tab.icon,
|
||||
contentDescription = tab.name,
|
||||
tint = color,
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-121
@@ -1,121 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.systemBars
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.geometry.CornerRadius
|
||||
import androidx.compose.ui.geometry.RoundRect
|
||||
import androidx.compose.ui.geometry.toRect
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Path
|
||||
import androidx.compose.ui.graphics.PathEffect
|
||||
import androidx.compose.ui.graphics.PathMeasure
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
|
||||
@Composable
|
||||
fun CustomBottomNavbar(tabs: List<BottomNavItem>, navBarState: NavBarState) {
|
||||
var selectedTabIndex by remember { mutableIntStateOf(0) }
|
||||
var isChildRoute by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(tabs) {}
|
||||
when (navBarState.route) {
|
||||
Route.Main -> {
|
||||
selectedTabIndex = 0
|
||||
isChildRoute = false
|
||||
}
|
||||
Route.AutoTunnel -> {
|
||||
selectedTabIndex = 1
|
||||
isChildRoute = false
|
||||
}
|
||||
Route.Settings -> {
|
||||
selectedTabIndex = 2
|
||||
isChildRoute = false
|
||||
}
|
||||
Route.Support -> {
|
||||
selectedTabIndex = 3
|
||||
isChildRoute = false
|
||||
}
|
||||
else -> isChildRoute = true
|
||||
}
|
||||
|
||||
val systemBars = WindowInsets.systemBars
|
||||
val bottomPadding = with(LocalDensity.current) { systemBars.getBottom(this).toDp() }
|
||||
val navHeight = 64.dp + bottomPadding
|
||||
|
||||
Box(modifier = Modifier.fillMaxWidth().height(navHeight).background(Color.Transparent)) {
|
||||
BottomBarTabs(
|
||||
tabs = tabs,
|
||||
selectedTabIndex = selectedTabIndex,
|
||||
isChildRoute = isChildRoute,
|
||||
onTabSelected = { selectedTabIndex = tabs.indexOf(it) },
|
||||
)
|
||||
|
||||
val animatedSelectedTabIndex by
|
||||
animateFloatAsState(
|
||||
targetValue = selectedTabIndex.toFloat(),
|
||||
label = "animatedSelectedTabIndex",
|
||||
animationSpec =
|
||||
spring(
|
||||
stiffness = Spring.StiffnessLow,
|
||||
dampingRatio = Spring.DampingRatioLowBouncy,
|
||||
),
|
||||
)
|
||||
|
||||
val animatedColor by
|
||||
animateColorAsState(
|
||||
targetValue = MaterialTheme.colorScheme.primary,
|
||||
label = "animatedColor",
|
||||
animationSpec = spring(stiffness = Spring.StiffnessLow),
|
||||
)
|
||||
|
||||
Canvas(modifier = Modifier.fillMaxWidth().height(navHeight)) {
|
||||
val path =
|
||||
Path().apply { addRoundRect(RoundRect(size.toRect(), CornerRadius(size.height))) }
|
||||
val length = PathMeasure().apply { setPath(path, false) }.length
|
||||
|
||||
val tabWidth = size.width / tabs.size
|
||||
drawPath(
|
||||
path,
|
||||
brush =
|
||||
Brush.horizontalGradient(
|
||||
colors =
|
||||
listOf(
|
||||
animatedColor.copy(alpha = 0f),
|
||||
animatedColor.copy(alpha = 1f),
|
||||
animatedColor.copy(alpha = 1f),
|
||||
animatedColor.copy(alpha = 0f),
|
||||
),
|
||||
startX = tabWidth * animatedSelectedTabIndex,
|
||||
endX = tabWidth * (animatedSelectedTabIndex + 1),
|
||||
),
|
||||
style =
|
||||
Stroke(
|
||||
width = 4f,
|
||||
pathEffect =
|
||||
PathEffect.dashPathEffect(intervals = floatArrayOf(length / 2, length)),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.navigation.NavHostController
|
||||
|
||||
val LocalNavController =
|
||||
compositionLocalOf<NavHostController> { error("NavController was not provided") }
|
||||
+3
-6
@@ -19,11 +19,10 @@ import androidx.compose.runtime.CompositionLocalProvider
|
||||
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.platform.LocalLayoutDirection
|
||||
import androidx.compose.ui.unit.LayoutDirection
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
|
||||
@Composable
|
||||
fun CustomSnackBar(
|
||||
@@ -31,12 +30,10 @@ fun CustomSnackBar(
|
||||
isRtl: Boolean = true,
|
||||
containerColor: Color = MaterialTheme.colorScheme.surface,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
Snackbar(
|
||||
containerColor = containerColor,
|
||||
modifier =
|
||||
Modifier.fillMaxWidth(if (context.isRunningOnTv()) 1 / 3f else 2 / 3f)
|
||||
.padding(bottom = 100.dp),
|
||||
modifier = Modifier.fillMaxWidth(if (isTv) 1 / 3f else 2 / 3f).padding(bottom = 100.dp),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
) {
|
||||
CompositionLocalProvider(
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.enums
|
||||
|
||||
enum class InterfaceActions {
|
||||
TOGGLE_AMNEZIA_VALUES,
|
||||
SET_AMNEZIA_COMPATIBILITY,
|
||||
TOGGLE_SHOW_SCRIPTS,
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.enums
|
||||
|
||||
enum class PeerActions {
|
||||
EXCLUDE_LAN
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation
|
||||
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
+8
-1
@@ -1,9 +1,12 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.navigation.NavBackStackEntry
|
||||
import androidx.navigation.NavDestination.Companion.hasRoute
|
||||
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||
import androidx.navigation.NavHostController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@@ -11,3 +14,7 @@ import kotlin.reflect.KClass
|
||||
fun <T : Route> NavBackStackEntry?.isCurrentRoute(cls: KClass<T>): Boolean {
|
||||
return this?.destination?.hierarchy?.any { it.hasRoute(route = cls) } == true
|
||||
}
|
||||
|
||||
val LocalNavController =
|
||||
compositionLocalOf<NavHostController> { error("NavController was not provided") }
|
||||
val LocalIsAndroidTV = staticCompositionLocalOf { false }
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation.components
|
||||
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Bolt
|
||||
import androidx.compose.material.icons.rounded.Home
|
||||
import androidx.compose.material.icons.rounded.QuestionMark
|
||||
import androidx.compose.material.icons.rounded.Settings
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.BottomNavItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.isCurrentRoute
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.SilverTree
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.goFromRoot
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun BottomNavbar(appUiState: AppUiState) {
|
||||
val navController = LocalNavController.current
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
|
||||
val items =
|
||||
listOf(
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.tunnels),
|
||||
route = Route.Main,
|
||||
icon = Icons.Rounded.Home,
|
||||
onClick = { navController.goFromRoot(Route.Main) },
|
||||
),
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.auto_tunnel),
|
||||
route = Route.AutoTunnel,
|
||||
icon = Icons.Rounded.Bolt,
|
||||
onClick = {
|
||||
val route =
|
||||
if (appUiState.appState.isLocationDisclosureShown) Route.AutoTunnel
|
||||
else Route.LocationDisclosure
|
||||
navController.goFromRoot(route)
|
||||
},
|
||||
active = appUiState.isAutoTunnelActive,
|
||||
),
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.settings),
|
||||
route = Route.Settings,
|
||||
icon = Icons.Rounded.Settings,
|
||||
onClick = { navController.goFromRoot(Route.Settings) },
|
||||
),
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.support),
|
||||
route = Route.Support,
|
||||
icon = Icons.Rounded.QuestionMark,
|
||||
onClick = { navController.goFromRoot(Route.Support) },
|
||||
),
|
||||
)
|
||||
// Define ripple configuration based on platform
|
||||
val rippleConfiguration =
|
||||
if (isTv) {
|
||||
RippleConfiguration()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
// Apply ripple configuration only if needed
|
||||
CompositionLocalProvider(LocalRippleConfiguration provides rippleConfiguration) {
|
||||
NavigationBar(containerColor = MaterialTheme.colorScheme.surface) {
|
||||
items.forEach { item ->
|
||||
val isSelected = navBackStackEntry.isCurrentRoute(item.route::class)
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
|
||||
NavigationBarItem(
|
||||
icon = {
|
||||
if (item.active) {
|
||||
BadgedBox(
|
||||
badge = {
|
||||
Badge(
|
||||
modifier =
|
||||
Modifier.offset(x = 8.dp, y = (-8).dp).size(6.dp),
|
||||
containerColor = SilverTree,
|
||||
)
|
||||
}
|
||||
) {
|
||||
Icon(imageVector = item.icon, contentDescription = item.name)
|
||||
}
|
||||
} else {
|
||||
Icon(imageVector = item.icon, contentDescription = item.name)
|
||||
}
|
||||
},
|
||||
onClick = { navController.goFromRoot(item.route) },
|
||||
selected = isSelected,
|
||||
enabled = true,
|
||||
label = null,
|
||||
alwaysShowLabel = false,
|
||||
colors =
|
||||
NavigationBarItemDefaults.colors(
|
||||
selectedIconColor = MaterialTheme.colorScheme.primary,
|
||||
unselectedIconColor = MaterialTheme.colorScheme.onBackground,
|
||||
indicatorColor = Color.Transparent,
|
||||
),
|
||||
interactionSource = interactionSource,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-6
@@ -1,10 +1,6 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation.components
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.animation.*
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
@@ -14,6 +10,7 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.NavBarState
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
+197
-160
@@ -1,13 +1,10 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation.components
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Add
|
||||
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.Stop
|
||||
import androidx.compose.material.icons.rounded.*
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
@@ -15,80 +12,126 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.navigation.NavBackStackEntry
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.toRoute
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.isCurrentRoute
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppViewState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.NavBarState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Brick
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.SilverTree
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
|
||||
data class NavBarState(
|
||||
val showTop: Boolean = true,
|
||||
val showBottom: Boolean = true,
|
||||
val topTitle: @Composable (() -> Unit)? = null,
|
||||
val topTrailing: @Composable (() -> Unit)? = null,
|
||||
val route: Route? = null,
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun currentNavBackStackEntryAsNavBarState(
|
||||
navController: NavController,
|
||||
backStackEntry: NavBackStackEntry?,
|
||||
viewModel: AppViewModel,
|
||||
uiState: AppUiState,
|
||||
appViewState: AppViewState,
|
||||
): State<NavBarState> {
|
||||
return produceState(initialValue = NavBarState(), key1 = backStackEntry, key2 = uiState) {
|
||||
fun isActiveSelected() =
|
||||
uiState.activeTunnels.any { active ->
|
||||
appViewState.selectedTunnels.any { it.id == active.key.id }
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ActionIconButton(icon: ImageVector, labelRes: Int, onClick: () -> Unit) {
|
||||
IconButton(onClick = onClick) {
|
||||
Icon(
|
||||
icon,
|
||||
contentDescription = stringResource(labelRes),
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun TunnelActionBar() {
|
||||
val selectedCount = appViewState.selectedTunnels.size
|
||||
val showDelete = !isActiveSelected()
|
||||
|
||||
Row {
|
||||
if (selectedCount == 0) {
|
||||
ActionIconButton(Icons.Rounded.Add, R.string.add_tunnel) {
|
||||
viewModel.handleEvent(
|
||||
AppEvent.SetBottomSheet(AppViewState.BottomSheet.IMPORT_TUNNELS)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
ActionIconButton(Icons.Rounded.SelectAll, R.string.select_all) {
|
||||
viewModel.handleEvent(AppEvent.ToggleSelectAllTunnels)
|
||||
}
|
||||
// due to permissions, and SAF issues on TV, not support less than Android 10 on
|
||||
// Android TV for file exports
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
ActionIconButton(Icons.Rounded.Download, R.string.download) {
|
||||
viewModel.handleEvent(
|
||||
AppEvent.SetBottomSheet(AppViewState.BottomSheet.EXPORT_TUNNELS)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedCount == 1) {
|
||||
ActionIconButton(Icons.Rounded.CopyAll, R.string.copy) {
|
||||
viewModel.handleEvent(AppEvent.CopySelectedTunnel)
|
||||
}
|
||||
}
|
||||
|
||||
if (showDelete) {
|
||||
ActionIconButton(Icons.Rounded.Delete, R.string.delete_tunnel) {
|
||||
viewModel.handleEvent(AppEvent.SetShowModal(AppViewState.ModalType.DELETE))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return produceState(
|
||||
initialValue = NavBarState(),
|
||||
key1 = backStackEntry,
|
||||
key2 = uiState,
|
||||
key3 = appViewState,
|
||||
) {
|
||||
value =
|
||||
when {
|
||||
backStackEntry.isCurrentRoute(Route.Main::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.tunnels)) },
|
||||
{
|
||||
IconButton(
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleBottomSheet) }
|
||||
) {
|
||||
val icon = Icons.Rounded.Add
|
||||
Icon(
|
||||
icon,
|
||||
stringResource(R.string.add_tunnel),
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
}
|
||||
},
|
||||
topTitle = { Text(stringResource(R.string.tunnels)) },
|
||||
topTrailing = { TunnelActionBar() },
|
||||
route = Route.Main,
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.AutoTunnel::class) -> {
|
||||
val (icon, label, tint) =
|
||||
if (uiState.appSettings.isAutoTunnelEnabled) {
|
||||
Triple(Icons.Rounded.Stop, R.string.stop_auto, Brick)
|
||||
} else {
|
||||
Triple(Icons.Rounded.PlayArrow, R.string.start_auto, SilverTree)
|
||||
}
|
||||
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.auto_tunnel)) },
|
||||
{
|
||||
topTitle = { Text(stringResource(R.string.auto_tunnel)) },
|
||||
topTrailing = {
|
||||
IconButton(
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnel) }
|
||||
) {
|
||||
val (icon, description, color) =
|
||||
if (uiState.appSettings.isAutoTunnelEnabled) {
|
||||
Triple(Icons.Rounded.Stop, R.string.stop_auto, Brick)
|
||||
} else {
|
||||
Triple(
|
||||
Icons.Rounded.PlayArrow,
|
||||
R.string.start_auto,
|
||||
SilverTree,
|
||||
)
|
||||
}
|
||||
Icon(
|
||||
icon,
|
||||
stringResource(description),
|
||||
tint = color,
|
||||
stringResource(label),
|
||||
tint = tint,
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
}
|
||||
@@ -96,175 +139,169 @@ fun currentNavBackStackEntryAsNavBarState(
|
||||
route = Route.AutoTunnel,
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.AutoTunnelAdvanced::class) ||
|
||||
backStackEntry.isCurrentRoute(Route.SettingsAdvanced::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.advanced_settings)) },
|
||||
route = Route.AutoTunnelAdvanced,
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.Settings::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.settings)) },
|
||||
{
|
||||
IconButton(
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleBottomSheet) }
|
||||
) {
|
||||
val icon = Icons.Rounded.Menu
|
||||
Icon(
|
||||
icon,
|
||||
stringResource(R.string.quick_actions),
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
}
|
||||
},
|
||||
route = Route.Settings,
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.KillSwitch::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.kill_switch)) },
|
||||
route = Route.KillSwitch,
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.Appearance::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.appearance)) },
|
||||
route = Route.Appearance,
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.Language::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.language)) },
|
||||
route = Route.Language,
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.Display::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.display_theme)) },
|
||||
route = Route.Display,
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Logs::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = false,
|
||||
{ Text(stringResource(R.string.logs)) },
|
||||
{
|
||||
IconButton(
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleBottomSheet) }
|
||||
) {
|
||||
val icon = Icons.Rounded.Menu
|
||||
Icon(
|
||||
icon,
|
||||
stringResource(R.string.quick_actions),
|
||||
modifier = Modifier.size(iconSize),
|
||||
topTitle = { Text(stringResource(R.string.logs)) },
|
||||
topTrailing = {
|
||||
ActionIconButton(Icons.Rounded.Menu, R.string.quick_actions) {
|
||||
viewModel.handleEvent(
|
||||
AppEvent.SetBottomSheet(AppViewState.BottomSheet.LOGS)
|
||||
)
|
||||
}
|
||||
},
|
||||
route = Route.Logs,
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.TunnelOptions::class) -> {
|
||||
val args = backStackEntry?.toRoute<Route.TunnelOptions>()
|
||||
val tunnel = uiState.tunnels.find { it.id == args?.id }
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Settings::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ tunnel?.name?.let { Text(it) } },
|
||||
{
|
||||
IconButton(
|
||||
onClick = {
|
||||
topTitle = { Text(stringResource(R.string.settings)) },
|
||||
route = Route.Settings,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Appearance::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.appearance)) },
|
||||
route = Route.Appearance,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Language::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.language)) },
|
||||
route = Route.Language,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Display::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.display_theme)) },
|
||||
route = Route.Display,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.WifiDetectionMethod::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.wifi_detection_method)) },
|
||||
route = Route.WifiDetectionMethod,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.KillSwitch::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.kill_switch)) },
|
||||
route = Route.KillSwitch,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Support::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.support)) },
|
||||
route = Route.Support,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.License::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.licenses)) },
|
||||
route = Route.License,
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.AutoTunnelAdvanced::class) ||
|
||||
backStackEntry.isCurrentRoute(Route.SettingsAdvanced::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.advanced_settings)) },
|
||||
route = Route.AutoTunnelAdvanced,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.TunnelOptions::class) -> {
|
||||
val args = backStackEntry?.toRoute<Route.TunnelOptions>()
|
||||
val tunnel = uiState.tunnels.find { it.id == args?.id }
|
||||
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { tunnel?.name?.let { Text(it) } },
|
||||
topTrailing = {
|
||||
Row {
|
||||
ActionIconButton(Icons.Rounded.QrCode2, R.string.show_qr) {
|
||||
tunnel?.id?.let {
|
||||
navController.navigate(Route.Config(id = it))
|
||||
viewModel.handleEvent(
|
||||
AppEvent.SetShowModal(AppViewState.ModalType.QR)
|
||||
)
|
||||
}
|
||||
}
|
||||
) {
|
||||
val icon = Icons.Rounded.Edit
|
||||
Icon(
|
||||
icon,
|
||||
stringResource(R.string.edit_tunnel),
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
ActionIconButton(Icons.Rounded.Edit, R.string.edit_tunnel) {
|
||||
tunnel?.id?.let { navController.navigate(Route.Config(it)) }
|
||||
}
|
||||
}
|
||||
},
|
||||
route = args?.let { Route.TunnelOptions(it.id) },
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.SplitTunnel::class) -> {
|
||||
val args = backStackEntry?.toRoute<Route.SplitTunnel>()
|
||||
val name = uiState.tunnels.find { it.id == args?.id }?.name
|
||||
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ name?.let { Text(it) } },
|
||||
{
|
||||
IconButton(
|
||||
onClick = { viewModel.handleEvent(AppEvent.InvokeScreenAction) }
|
||||
) {
|
||||
val icon = Icons.Rounded.Save
|
||||
Icon(
|
||||
icon,
|
||||
stringResource(R.string.save),
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
topTitle = { name?.let { Text(it) } },
|
||||
topTrailing = {
|
||||
ActionIconButton(Icons.Rounded.Save, R.string.save) {
|
||||
viewModel.handleEvent(AppEvent.InvokeScreenAction)
|
||||
}
|
||||
},
|
||||
route = args?.let { Route.SplitTunnel(it.id) },
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Config::class) -> {
|
||||
val args = backStackEntry?.toRoute<Route.Config>()
|
||||
val name = uiState.tunnels.find { it.id == args?.id }?.name
|
||||
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ name?.let { Text(it) } },
|
||||
{
|
||||
IconButton(
|
||||
onClick = { viewModel.handleEvent(AppEvent.InvokeScreenAction) }
|
||||
) {
|
||||
val icon = Icons.Rounded.Save
|
||||
Icon(
|
||||
icon,
|
||||
stringResource(R.string.save),
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
topTitle = { name?.let { Text(it) } },
|
||||
topTrailing = {
|
||||
ActionIconButton(Icons.Rounded.Save, R.string.save) {
|
||||
viewModel.handleEvent(AppEvent.InvokeScreenAction)
|
||||
}
|
||||
},
|
||||
route = args?.let { Route.Config(it.id) },
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.TunnelAutoTunnel::class) -> {
|
||||
val args = backStackEntry?.toRoute<Route.TunnelAutoTunnel>()
|
||||
val name = uiState.tunnels.find { it.id == args?.id }?.name
|
||||
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ name?.let { Text(it) } },
|
||||
topTitle = { name?.let { Text(it) } },
|
||||
route = args?.let { Route.TunnelAutoTunnel(it.id) },
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.Support::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.support)) },
|
||||
route = Route.Support,
|
||||
)
|
||||
}
|
||||
|
||||
else -> NavBarState(showTop = false, showBottom = false)
|
||||
}
|
||||
}
|
||||
+7
-8
@@ -8,8 +8,6 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -24,8 +22,10 @@ import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||
import com.google.accompanist.permissions.isGranted
|
||||
import com.google.accompanist.permissions.rememberPermissionState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.AdvancedSettingsItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.NetworkTunnelingItems
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.WifiTunnelingItems
|
||||
@@ -33,7 +33,6 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.Backgr
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.LocationServicesDialog
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isLocationServicesEnabled
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
|
||||
@OptIn(ExperimentalPermissionsApi::class)
|
||||
@@ -41,6 +40,7 @@ import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
fun AutoTunnelScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||
val context = LocalContext.current
|
||||
val navController = LocalNavController.current
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
val fineLocationState = rememberPermissionState(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
var currentText by remember { mutableStateOf("") }
|
||||
var isBackgroundLocationGranted by remember { mutableStateOf(true) }
|
||||
@@ -67,12 +67,11 @@ fun AutoTunnelScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) checkFineLocationGranted()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
if (context.isRunningOnTv() && Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
|
||||
if (isTv && Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
|
||||
checkFineLocationGranted()
|
||||
} else {
|
||||
val backgroundLocationState =
|
||||
rememberPermissionState(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
||||
isBackgroundLocationGranted = backgroundLocationState.status.isGranted
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,9 +108,9 @@ fun AutoTunnelScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||
{ isWifiNameReadable() },
|
||||
)
|
||||
)
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
||||
SectionDivider()
|
||||
SurfaceSelectionGroupButton(items = NetworkTunnelingItems(uiState, viewModel))
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
||||
SectionDivider()
|
||||
SurfaceSelectionGroupButton(
|
||||
items =
|
||||
listOf(
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components
|
||||
|
||||
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.SignalCellular4Bar
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -95,7 +95,7 @@ fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<Se
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnEthernet) },
|
||||
),
|
||||
SelectionItem(
|
||||
leadingIcon = Icons.Outlined.AirplanemodeActive,
|
||||
leadingIcon = Icons.Outlined.PublicOff,
|
||||
title = {
|
||||
Text(
|
||||
stringResource(R.string.stop_on_no_internet),
|
||||
|
||||
+3
-4
@@ -20,7 +20,6 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardCapitalization
|
||||
@@ -28,7 +27,7 @@ import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ClickableIconButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.textbox.CustomTextField
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
@@ -40,7 +39,7 @@ fun TrustedNetworkTextBox(
|
||||
onValueChange: (network: String) -> Unit,
|
||||
supporting: @Composable () -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
FlowRow(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
@@ -49,7 +48,7 @@ fun TrustedNetworkTextBox(
|
||||
trustedNetworks.forEach { ssid ->
|
||||
ClickableIconButton(
|
||||
onClick = {
|
||||
if (context.isRunningOnTv()) {
|
||||
if (isTv) {
|
||||
onDelete(ssid)
|
||||
}
|
||||
},
|
||||
|
||||
+70
-61
@@ -1,18 +1,9 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Code
|
||||
import androidx.compose.material.icons.outlined.Filter1
|
||||
import androidx.compose.material.icons.outlined.Security
|
||||
import androidx.compose.material.icons.outlined.VpnKeyOff
|
||||
import androidx.compose.material.icons.outlined.Wifi
|
||||
import androidx.compose.material.icons.outlined.*
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
@@ -22,19 +13,23 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
||||
import com.zaneschepke.networkmonitor.NetworkStatus
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.LearnMoreLinkLabel
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asString
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
@@ -48,7 +43,8 @@ fun WifiTunnelingItems(
|
||||
isWifiNameReadable: () -> Boolean,
|
||||
): List<SelectionItem> {
|
||||
val context = LocalContext.current
|
||||
val clipboard = LocalClipboardManager.current
|
||||
val navController = LocalNavController.current
|
||||
val clipboardHelper = rememberClipboardHelper()
|
||||
|
||||
val baseItems =
|
||||
listOf(
|
||||
@@ -71,65 +67,77 @@ fun WifiTunnelingItems(
|
||||
)
|
||||
},
|
||||
description = {
|
||||
val wifiName by
|
||||
val wifiInfo by
|
||||
remember(uiState.networkStatus) {
|
||||
derivedStateOf {
|
||||
(uiState.networkStatus as? NetworkStatus.Connected)
|
||||
?.takeIf { it.wifiConnected }
|
||||
?.wifiSsid
|
||||
.let { Pair(it?.wifiSsid, it?.securityType) }
|
||||
}
|
||||
}
|
||||
Text(
|
||||
text =
|
||||
wifiName?.let { stringResource(R.string.wifi_name_template, it) }
|
||||
?: stringResource(R.string.inactive),
|
||||
style =
|
||||
MaterialTheme.typography.bodySmall.copy(
|
||||
color = MaterialTheme.colorScheme.outline
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier =
|
||||
Modifier.clickable {
|
||||
wifiName?.let { clipboard.setText(AnnotatedString(it)) }
|
||||
},
|
||||
)
|
||||
val (wifiName, securityType) = wifiInfo
|
||||
Column {
|
||||
Text(
|
||||
text =
|
||||
wifiName?.let { stringResource(R.string.wifi_name_template, it) }
|
||||
?: stringResource(R.string.inactive),
|
||||
style =
|
||||
MaterialTheme.typography.bodySmall.copy(
|
||||
color = MaterialTheme.colorScheme.outline
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
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) },
|
||||
),
|
||||
SelectionItem(
|
||||
leadingIcon = Icons.Outlined.Code,
|
||||
title = {
|
||||
Text(
|
||||
stringResource(R.string.wifi_name_via_shell),
|
||||
style =
|
||||
MaterialTheme.typography.bodyMedium.copy(
|
||||
MaterialTheme.colorScheme.onSurface
|
||||
),
|
||||
)
|
||||
},
|
||||
description = {
|
||||
Text(
|
||||
stringResource(R.string.use_root_shell_for_wifi),
|
||||
style =
|
||||
MaterialTheme.typography.bodySmall.copy(
|
||||
MaterialTheme.colorScheme.outline
|
||||
),
|
||||
)
|
||||
},
|
||||
trailing = {
|
||||
ScaledSwitch(
|
||||
checked = uiState.appSettings.isWifiNameByShellEnabled,
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleRootShellWifi) },
|
||||
)
|
||||
},
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleRootShellWifi) },
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
return if (uiState.appSettings.isTunnelOnWifiEnabled) {
|
||||
baseItems +
|
||||
listOf(
|
||||
SelectionItem(
|
||||
leadingIcon = Icons.Outlined.WifiFind,
|
||||
title = {
|
||||
Text(
|
||||
stringResource(R.string.wifi_detection_method),
|
||||
style =
|
||||
MaterialTheme.typography.bodyMedium.copy(
|
||||
MaterialTheme.colorScheme.onSurface
|
||||
),
|
||||
)
|
||||
},
|
||||
description = {
|
||||
Text(
|
||||
stringResource(
|
||||
R.string.current_template,
|
||||
uiState.appSettings.wifiDetectionMethod.asString(context),
|
||||
),
|
||||
style =
|
||||
MaterialTheme.typography.bodySmall.copy(
|
||||
MaterialTheme.colorScheme.outline
|
||||
),
|
||||
)
|
||||
},
|
||||
trailing = {
|
||||
ForwardButton { navController.navigate(Route.WifiDetectionMethod) }
|
||||
},
|
||||
onClick = { navController.navigate(Route.WifiDetectionMethod) },
|
||||
),
|
||||
SelectionItem(
|
||||
leadingIcon = Icons.Outlined.Filter1,
|
||||
title = {
|
||||
@@ -194,7 +202,8 @@ fun WifiTunnelingItems(
|
||||
currentText = currentText,
|
||||
onSave = { ssid ->
|
||||
if (
|
||||
uiState.appSettings.isWifiNameByShellEnabled ||
|
||||
uiState.appSettings.wifiDetectionMethod ==
|
||||
AndroidNetworkMonitor.WifiDetectionMethod.ROOT ||
|
||||
isWifiNameReadable()
|
||||
) {
|
||||
viewModel.handleEvent(AppEvent.SaveTrustedSSID(ssid))
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.detection
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.IconSurfaceButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asDescriptionString
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asString
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
|
||||
@Composable
|
||||
fun WifiDetectionMethodScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||
val context = LocalContext.current
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.spacedBy(24.dp, Alignment.Top),
|
||||
modifier = Modifier.fillMaxSize().padding(top = 24.dp).padding(horizontal = 24.dp),
|
||||
) {
|
||||
enumValues<AndroidNetworkMonitor.WifiDetectionMethod>().forEach {
|
||||
val title = it.asString(context)
|
||||
val description = it.asDescriptionString(context)
|
||||
// TODO skip shizuku for now
|
||||
if (it == AndroidNetworkMonitor.WifiDetectionMethod.SHIZUKU) return@forEach
|
||||
IconSurfaceButton(
|
||||
title = title,
|
||||
onClick = { viewModel.handleEvent(AppEvent.SetDetectionMethod(it)) },
|
||||
selected = uiState.appSettings.wifiDetectionMethod == it,
|
||||
description = description,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -11,10 +11,10 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.components.AppSettingsItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.components.LocationDisclosureHeader
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.components.SkipItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components.AppSettingsItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components.LocationDisclosureHeader
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components.SkipItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.goFromRoot
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.components
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.LocationOn
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.components
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.components
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components
|
||||
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
+55
-42
@@ -5,20 +5,19 @@ import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.res.stringResource
|
||||
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.ui.Route
|
||||
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.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.TunnelImportSheet
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.TunnelList
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.UrlImportDialog
|
||||
@@ -32,9 +31,8 @@ import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
@Composable
|
||||
fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: AppViewModel) {
|
||||
val navController = LocalNavController.current
|
||||
val clipboard = LocalClipboardManager.current
|
||||
val clipboard = rememberClipboardHelper()
|
||||
|
||||
var showDeleteTunnelAlertDialog by remember { mutableStateOf(false) }
|
||||
var showUrlImportDialog by remember { mutableStateOf(false) }
|
||||
|
||||
val tunnelFileImportResultLauncher =
|
||||
@@ -49,6 +47,15 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
||||
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 =
|
||||
rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted
|
||||
->
|
||||
@@ -60,16 +67,19 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
||||
)
|
||||
return@rememberLauncherForActivityResult
|
||||
}
|
||||
navController.navigate(Route.Scanner)
|
||||
scanLauncher.launch(
|
||||
ScanOptions().setDesiredBarcodeFormats(ScanOptions.QR_CODE).setBeepEnabled(false)
|
||||
)
|
||||
}
|
||||
|
||||
if (showDeleteTunnelAlertDialog && appViewState.selectedTunnel != null) {
|
||||
if (appViewState.showModal == AppViewState.ModalType.DELETE) {
|
||||
InfoDialog(
|
||||
onDismiss = { showDeleteTunnelAlertDialog = false },
|
||||
onDismiss = {
|
||||
viewModel.handleEvent(AppEvent.SetShowModal(AppViewState.ModalType.NONE))
|
||||
},
|
||||
onAttest = {
|
||||
appViewState.selectedTunnel.let { viewModel.handleEvent(AppEvent.DeleteTunnel(it)) }
|
||||
showDeleteTunnelAlertDialog = false
|
||||
viewModel.handleEvent(AppEvent.SetSelectedTunnel(null))
|
||||
viewModel.handleEvent(AppEvent.DeleteSelectedTunnels)
|
||||
viewModel.handleEvent(AppEvent.SetShowModal(AppViewState.ModalType.NONE))
|
||||
},
|
||||
title = { Text(text = stringResource(R.string.delete_tunnel)) },
|
||||
body = { Text(text = stringResource(R.string.delete_tunnel_message)) },
|
||||
@@ -77,21 +87,35 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
||||
)
|
||||
}
|
||||
|
||||
TunnelImportSheet(
|
||||
appViewState.showBottomSheet,
|
||||
onDismiss = { viewModel.handleEvent(AppEvent.ToggleBottomSheet) },
|
||||
onFileClick = { tunnelFileImportResultLauncher.launch(Constants.ALLOWED_TV_FILE_TYPES) },
|
||||
onQrClick = { requestPermissionLauncher.launch(android.Manifest.permission.CAMERA) },
|
||||
onClipboardClick = {
|
||||
clipboard.getText()?.text?.let {
|
||||
viewModel.handleEvent(AppEvent.ImportTunnelFromClipboard(it))
|
||||
}
|
||||
},
|
||||
onManualImportClick = {
|
||||
navController.navigate(Route.Config(Constants.MANUAL_TUNNEL_CONFIG_ID))
|
||||
},
|
||||
onUrlClick = { showUrlImportDialog = true },
|
||||
)
|
||||
when (appViewState.bottomSheet) {
|
||||
AppViewState.BottomSheet.EXPORT_TUNNELS -> {
|
||||
ExportTunnelsBottomSheet(viewModel)
|
||||
}
|
||||
AppViewState.BottomSheet.IMPORT_TUNNELS -> {
|
||||
TunnelImportSheet(
|
||||
onDismiss = {
|
||||
viewModel.handleEvent(AppEvent.SetBottomSheet(AppViewState.BottomSheet.NONE))
|
||||
},
|
||||
onFileClick = {
|
||||
tunnelFileImportResultLauncher.launch(Constants.ALLOWED_TV_FILE_TYPES)
|
||||
},
|
||||
onQrClick = {
|
||||
requestPermissionLauncher.launch(android.Manifest.permission.CAMERA)
|
||||
},
|
||||
onClipboardClick = {
|
||||
clipboard.paste { result ->
|
||||
if (result != null)
|
||||
viewModel.handleEvent(AppEvent.ImportTunnelFromClipboard(result))
|
||||
}
|
||||
},
|
||||
onManualImportClick = {
|
||||
navController.navigate(Route.Config(Constants.MANUAL_TUNNEL_CONFIG_ID))
|
||||
},
|
||||
onUrlClick = { showUrlImportDialog = true },
|
||||
)
|
||||
}
|
||||
else -> Unit
|
||||
}
|
||||
|
||||
if (showUrlImportDialog) {
|
||||
UrlImportDialog(
|
||||
@@ -105,22 +129,11 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
||||
|
||||
TunnelList(
|
||||
appUiState = appUiState,
|
||||
activeTunnels = appUiState.activeTunnels,
|
||||
selectedTunnel = appViewState.selectedTunnel,
|
||||
onSetSelectedTunnel = { viewModel.handleEvent(AppEvent.SetSelectedTunnel(it)) },
|
||||
onDeleteTunnel = {
|
||||
viewModel.handleEvent(AppEvent.SetSelectedTunnel(it))
|
||||
showDeleteTunnelAlertDialog = true
|
||||
},
|
||||
selectedTunnels = appViewState.selectedTunnels,
|
||||
onToggleTunnel = { tunnel, checked ->
|
||||
if (checked) viewModel.handleEvent(AppEvent.StartTunnel(tunnel))
|
||||
else viewModel.handleEvent(AppEvent.StopTunnel(tunnel))
|
||||
},
|
||||
onExpandStats = { viewModel.handleEvent(AppEvent.ToggleTunnelStatsExpanded) },
|
||||
onCopyTunnel = {
|
||||
viewModel.handleEvent(AppEvent.CopyTunnel(it))
|
||||
viewModel.handleEvent(AppEvent.SetSelectedTunnel(null))
|
||||
},
|
||||
modifier = Modifier.fillMaxSize().padding(vertical = 24.dp).padding(horizontal = 12.dp),
|
||||
viewModel = viewModel,
|
||||
)
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.autotunnel.components.EthernetTunnelItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.autotunnel.components.MobileDataTunnelItem
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
|
||||
+2
-2
@@ -16,8 +16,8 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.TrustedNetworkTextBox
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.WildcardsLabel
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user