mirror of
https://github.com/wgtunnel/android.git
synced 2026-07-03 14:07:49 +02:00
Compare commits
64 Commits
fix-nightly
..
3.9.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| d3d70ab2e7 | |||
| 9b2d4a3fb5 | |||
| d7741c37c5 | |||
| 6046e4131f | |||
| 4b2d2d20db | |||
| a09501aaf5 | |||
| d46a0653f1 | |||
| 49ee2431c2 | |||
| dfcc022257 | |||
| bc08069a64 | |||
| fb97adca4f | |||
| 41540db9b7 |
+45
-43
@@ -1,4 +1,7 @@
|
|||||||
name: build
|
name: build
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
@@ -12,6 +15,14 @@ on:
|
|||||||
- prerelease
|
- prerelease
|
||||||
- nightly
|
- nightly
|
||||||
- release
|
- release
|
||||||
|
flavor:
|
||||||
|
type: choice
|
||||||
|
description: "Product flavor"
|
||||||
|
required: true
|
||||||
|
default: fdroid
|
||||||
|
options:
|
||||||
|
- fdroid
|
||||||
|
- standalone
|
||||||
secrets:
|
secrets:
|
||||||
SIGNING_KEY_ALIAS:
|
SIGNING_KEY_ALIAS:
|
||||||
required: false
|
required: false
|
||||||
@@ -30,6 +41,11 @@ on:
|
|||||||
description: "Build type"
|
description: "Build type"
|
||||||
required: true
|
required: true
|
||||||
default: debug
|
default: debug
|
||||||
|
flavor:
|
||||||
|
type: string
|
||||||
|
description: "Product flavor"
|
||||||
|
required: false
|
||||||
|
default: fdroid
|
||||||
secrets:
|
secrets:
|
||||||
SIGNING_KEY_ALIAS:
|
SIGNING_KEY_ALIAS:
|
||||||
required: false
|
required: false
|
||||||
@@ -41,6 +57,7 @@ on:
|
|||||||
required: false
|
required: false
|
||||||
KEYSTORE:
|
KEYSTORE:
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
env:
|
env:
|
||||||
UPLOAD_DIR_ANDROID: android_artifacts
|
UPLOAD_DIR_ANDROID: android_artifacts
|
||||||
|
|
||||||
@@ -48,15 +65,17 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
SIGNING_KEY_ALIAS: ${{ secrets.ANDROID_SIGNING_KEY_ALIAS }}
|
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
|
||||||
SIGNING_KEY_PASSWORD: ${{ secrets.ANDROID_SIGNING_KEY_PASSWORD }}
|
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
||||||
SIGNING_STORE_PASSWORD: ${{ secrets.ANDROID_SIGNING_STORE_PASSWORD }}
|
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
|
||||||
KEY_STORE_FILE: 'android_keystore.jks'
|
KEY_STORE_FILE: 'android_keystore.jks'
|
||||||
KEY_STORE_LOCATION: ${{ github.workspace }}/app/keystore/
|
KEY_STORE_LOCATION: ${{ github.workspace }}/app/keystore/
|
||||||
outputs:
|
outputs:
|
||||||
UPLOAD_DIR_ANDROID: ${{ env.UPLOAD_DIR_ANDROID }}
|
UPLOAD_DIR_ANDROID: ${{ env.UPLOAD_DIR_ANDROID }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
- name: Set up JDK 17
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
@@ -65,61 +84,44 @@ jobs:
|
|||||||
cache: gradle
|
cache: gradle
|
||||||
- name: Grant execute permission for gradlew
|
- name: Grant execute permission for gradlew
|
||||||
run: chmod +x 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
|
- name: Decode Keystore
|
||||||
id: decode_keystore
|
id: decode_keystore
|
||||||
uses: timheuer/base64-to-file@v1.2
|
uses: timheuer/base64-to-file@v1.2
|
||||||
with:
|
with:
|
||||||
fileName: ${{ env.KEY_STORE_FILE }}
|
fileName: ${{ env.KEY_STORE_FILE }}
|
||||||
fileDir: ${{ env.KEY_STORE_LOCATION }}
|
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
|
- name: Create keystore path env var
|
||||||
if: ${{ inputs.build_type != 'debug' }}
|
if: ${{ inputs.build_type != 'debug' }}
|
||||||
run: |
|
run: |
|
||||||
store_path=${{ env.KEY_STORE_LOCATION }}${{ env.KEY_STORE_FILE }}
|
store_path=${{ env.KEY_STORE_LOCATION }}${{ env.KEY_STORE_FILE }}
|
||||||
echo "KEY_STORE_PATH=$store_path" >> $GITHUB_ENV
|
echo "KEY_STORE_PATH=$store_path" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Create service_account.json
|
- name: Build APK
|
||||||
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' }}
|
|
||||||
run: |
|
run: |
|
||||||
git config --global user.name 'GitHub Actions'
|
flavor=${{ inputs.flavor }}
|
||||||
git config --global user.email 'actions@github.com'
|
build_type=${{ inputs.build_type }}
|
||||||
git add versionCode.txt
|
case $build_type in
|
||||||
git commit -m "Automated build update"
|
"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
|
- name: Get release apk path
|
||||||
id: 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
|
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
|
||||||
- name: Upload release apk
|
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ env.UPLOAD_DIR_ANDROID }}
|
name: android_artifacts_${{ inputs.flavor }}
|
||||||
path: ${{github.workspace}}/${{ steps.apk-path.outputs.path }}
|
path: app/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/wgtunnel-${{ inputs.flavor }}${{ inputs.flavor == 'fdroid' && '-release' || '' }}-*.apk
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
if-no-files-found: warn
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
name: nightly
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: "4 3 * * *"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check_commits:
|
||||||
|
name: Check for New Commits
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
has_new_commits: ${{ steps.check.outputs.new_commits }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Check for new commits
|
||||||
|
id: check
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.PAT }}
|
||||||
|
run: |
|
||||||
|
NEW_COMMITS=$(git rev-list --count --after="$(date -Iseconds -d '23 hours ago')" ${{ github.sha }})
|
||||||
|
echo "new_commits=$NEW_COMMITS" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
build-standalone-nightly:
|
||||||
|
uses: ./.github/workflows/build.yml
|
||||||
|
secrets: inherit
|
||||||
|
with:
|
||||||
|
build_type: "nightly"
|
||||||
|
flavor: standalone
|
||||||
|
|
||||||
|
publish:
|
||||||
|
needs:
|
||||||
|
- check_commits
|
||||||
|
- build-standalone-nightly
|
||||||
|
if: ${{ needs.check_commits.outputs.has_new_commits > 0 && inputs.release_type != 'none' }}
|
||||||
|
name: publish-nightly
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install system dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt update && sudo apt install -y gh apksigner
|
||||||
|
- name: Set latest tag
|
||||||
|
uses: rickstaa/action-create-tag@v1
|
||||||
|
id: tag_creation
|
||||||
|
with:
|
||||||
|
tag: "latest"
|
||||||
|
message: "Automated tag for HEAD commit"
|
||||||
|
force_push_tag: true
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
tag_exists_error: false
|
||||||
|
|
||||||
|
- name: Generate Changelog
|
||||||
|
id: changelog
|
||||||
|
uses: requarks/changelog-action@v1
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
toTag: "nightly"
|
||||||
|
fromTag: "latest"
|
||||||
|
writeToFile: false
|
||||||
|
|
||||||
|
- name: Make download dir
|
||||||
|
run: mkdir ${{ github.workspace }}/temp
|
||||||
|
|
||||||
|
- name: Download artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
pattern: android_artifacts_*
|
||||||
|
path: ${{ github.workspace }}/temp
|
||||||
|
|
||||||
|
- name: Set release notes
|
||||||
|
run: |
|
||||||
|
echo "RELEASE_NOTES=Nightly build for the latest development version of the app." >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Delete previous nightly version
|
||||||
|
uses: ClementTsang/delete-tag-and-release@v0.4.0
|
||||||
|
with:
|
||||||
|
tag_name: "nightly"
|
||||||
|
delete_release: true
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Get checksum
|
||||||
|
id: checksum
|
||||||
|
run: |
|
||||||
|
file_path=$(find ${{ github.workspace }}/temp -type f -iname "*.apk" | head -n 1)
|
||||||
|
if [ -z "$file_path" ]; then
|
||||||
|
echo "No APK file found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
checksum=$(apksigner verify --print-certs "$file_path" | grep -Po "(?<=SHA-256 digest:) .*" | tr -d "[:blank:]")
|
||||||
|
echo "checksum=$checksum" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Create nightly release
|
||||||
|
id: create_release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
body: |
|
||||||
|
${{ env.RELEASE_NOTES }}
|
||||||
|
|
||||||
|
SHA-256 fingerprints for the 4096-bit signing certificate:
|
||||||
|
```sh
|
||||||
|
${{ steps.checksum.outputs.checksum }}
|
||||||
|
```
|
||||||
|
|
||||||
|
To verify fingerprint:
|
||||||
|
```sh
|
||||||
|
apksigner verify --print-certs [path to APK file] | grep SHA-256
|
||||||
|
```
|
||||||
|
|
||||||
|
### Changelog
|
||||||
|
${{ steps.changelog.outputs.changes }}
|
||||||
|
tag_name: nightly
|
||||||
|
name: nightly
|
||||||
|
draft: false
|
||||||
|
prerelease: true
|
||||||
|
make_latest: false
|
||||||
|
files: |
|
||||||
|
${{ github.workspace }}/temp/**/*.apk
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
name: on-issue
|
|
||||||
|
|
||||||
on:
|
|
||||||
issues:
|
|
||||||
types: [ opened, closed, reopened ]
|
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
on-issue:
|
|
||||||
name: On new issue
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Send Telegram Message
|
|
||||||
run: |
|
|
||||||
msg_text='${{ github.actor }} updated an issue:
|
|
||||||
status: ${{ github.event.issue.state }} - #${{ github.event.issue.number }} ${{ github.event.issue.title }}
|
|
||||||
https://github.com/zaneschepke/wgtunnel/issues/${{ github.event.issue.number }}'
|
|
||||||
curl -s -X POST 'https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage' \
|
|
||||||
-d "chat_id=${{ secrets.TELEGRAM_TO }}&text=${msg_text}&message_thread_id=${{ vars.TELEGRAM_ACTIVITY_TOPIC }}"
|
|
||||||
|
|
||||||
- name: Send Matrix Message
|
|
||||||
run: |
|
|
||||||
msg_text='${{ github.actor }} updated an issue:
|
|
||||||
status: ${{ github.event.issue.state }} - #${{ github.event.issue.number }} ${{ github.event.issue.title }}
|
|
||||||
https://github.com/zaneschepke/wgtunnel/issues/${{ github.event.issue.number }}'
|
|
||||||
# Escape newlines and quotes for JSON
|
|
||||||
formatted_msg=$(echo -n "$msg_text" | sed ':a;N;$ba;s/\n/\\n/g' | sed 's/"/\\"/g')
|
|
||||||
curl -s -X POST \
|
|
||||||
-H "Authorization: Bearer ${{ secrets.MATRIX_TOKEN }}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"msgtype": "m.text",
|
|
||||||
"body": "'"$formatted_msg"'"
|
|
||||||
}' \
|
|
||||||
"https://matrix.org/_matrix/client/v3/rooms/${{ vars.MATRIX_ACTIVITY_TOPIC }}/send/m.room.message/$(date +%s)"
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
name: on-publish
|
|
||||||
|
|
||||||
on:
|
|
||||||
release:
|
|
||||||
types: [ published ]
|
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
on-publish:
|
|
||||||
name: On publish
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Send Telegram Message
|
|
||||||
run: |
|
|
||||||
msg_text='${{ github.actor }} published a new release:
|
|
||||||
Release: ${{ github.event.release.tag_name }}
|
|
||||||
${{ github.event.release.body }}
|
|
||||||
https://github.com/zaneschepke/wgtunnel/releases/tag/${{ github.event.release.tag_name }}'
|
|
||||||
curl -s -X POST 'https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage' \
|
|
||||||
-d "chat_id=${{ secrets.TELEGRAM_TO }}&text=${msg_text}&message_thread_id=${{ vars.TELEGRAM_RELEASE_TOPIC }}"
|
|
||||||
|
|
||||||
- name: Send Matrix Message
|
|
||||||
run: |
|
|
||||||
msg_text='${{ github.actor }} published a new release:
|
|
||||||
Release: ${{ github.event.release.tag_name }}
|
|
||||||
${{ github.event.release.body }}
|
|
||||||
https://github.com/zaneschepke/wgtunnel/releases/tag/${{ github.event.release.tag_name }}'
|
|
||||||
# Escape newlines and quotes for JSON
|
|
||||||
formatted_msg=$(echo -n "$msg_text" | sed ':a;N;$ba;s/\n/\\n/g' | sed 's/"/\\"/g')
|
|
||||||
curl -s -X POST \
|
|
||||||
-H "Authorization: Bearer ${{ secrets.MATRIX_TOKEN }}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"msgtype": "m.text",
|
|
||||||
"body": "'"$formatted_msg"'"
|
|
||||||
}' \
|
|
||||||
"https://matrix.org/_matrix/client/v3/rooms/${{ vars.MATRIX_RELEASE_TOPIC }}/send/m.room.message/$(date +%s)"
|
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
name: on-pr
|
name: on-pr
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
+65
-117
@@ -1,13 +1,14 @@
|
|||||||
name: publish
|
name: publish
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
packages: write
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
|
||||||
- cron: "4 3 * * *"
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
track:
|
track:
|
||||||
type: choice
|
type: choice
|
||||||
description: "Google play release track"
|
description: "Google Play release track"
|
||||||
options:
|
options:
|
||||||
- none
|
- none
|
||||||
- internal
|
- internal
|
||||||
@@ -22,90 +23,69 @@ on:
|
|||||||
options:
|
options:
|
||||||
- none
|
- none
|
||||||
- prerelease
|
- prerelease
|
||||||
- nightly
|
|
||||||
- release
|
- release
|
||||||
default: release
|
default: release
|
||||||
required: true
|
required: true
|
||||||
tag_name:
|
tag_name:
|
||||||
description: "Tag name for release"
|
description: "Tag name for release"
|
||||||
required: false
|
required: false
|
||||||
default: nightly
|
default: 1.1.1
|
||||||
|
flavor:
|
||||||
|
type: choice
|
||||||
|
description: "Product flavor"
|
||||||
|
required: true
|
||||||
|
default: standalone
|
||||||
|
options:
|
||||||
|
- fdroid
|
||||||
|
- standalone
|
||||||
workflow_call:
|
workflow_call:
|
||||||
env:
|
inputs:
|
||||||
UPLOAD_DIR_ANDROID: android_artifacts
|
flavor:
|
||||||
|
type: string
|
||||||
permissions:
|
description: "Product flavor"
|
||||||
contents: write
|
required: false
|
||||||
|
default: standalone
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check_commits:
|
|
||||||
name: Check for New Commits
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
outputs:
|
|
||||||
has_new_commits: ${{ steps.check.outputs.new_commits }}
|
|
||||||
|
|
||||||
steps:
|
build-fdroid:
|
||||||
- name: Checkout Repository
|
if: ${{ inputs.release_type == 'release' || inputs.flavor == 'fdroid' }}
|
||||||
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' }}
|
|
||||||
uses: ./.github/workflows/build.yml
|
uses: ./.github/workflows/build.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
with:
|
with:
|
||||||
build_type: ${{ inputs.release_type == '' && 'nightly' || inputs.release_type }}
|
build_type: ${{ inputs.release_type }}
|
||||||
|
flavor: fdroid
|
||||||
|
|
||||||
|
build-standalone:
|
||||||
|
if: ${{ inputs.release_type == 'release' || inputs.release_type == 'prerelease' || inputs.flavor == 'standalone' }}
|
||||||
|
uses: ./.github/workflows/build.yml
|
||||||
|
secrets: inherit
|
||||||
|
with:
|
||||||
|
build_type: ${{ inputs.release_type }}
|
||||||
|
flavor: standalone
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
needs:
|
needs:
|
||||||
- check_commits
|
- build-standalone
|
||||||
- build
|
|
||||||
if: ${{ needs.check_commits.outputs.has_new_commits > 0 && inputs.release_type != 'none' }}
|
|
||||||
name: publish-github
|
name: publish-github
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
|
||||||
GH_USER: ${{ secrets.PAT_USERNAME }}
|
|
||||||
# GH needed for gh cli
|
|
||||||
GH_TOKEN: ${{ secrets.PAT }}
|
|
||||||
GH_REPO: ${{ github.repository }}
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: main
|
||||||
- name: Install system dependencies
|
- name: Install system dependencies
|
||||||
run: |
|
run: |
|
||||||
sudo apt update && sudo apt install -y gh apksigner
|
sudo apt update && sudo apt install -y gh apksigner
|
||||||
|
|
||||||
# update latest tag
|
|
||||||
- name: Set latest tag
|
- name: Set latest tag
|
||||||
uses: rickstaa/action-create-tag@v1
|
uses: rickstaa/action-create-tag@v1
|
||||||
id: tag_creation
|
id: tag_creation
|
||||||
with:
|
with:
|
||||||
tag: "latest" # or any tag name you wish to use
|
tag: "latest"
|
||||||
message: "Automated tag for HEAD commit"
|
message: "Automated tag for HEAD commit"
|
||||||
force_push_tag: true
|
force_push_tag: true
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
tag_exists_error: false
|
tag_exists_error: false
|
||||||
|
|
||||||
- name: Create Release
|
|
||||||
uses: actions/create-release@v1
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
with:
|
|
||||||
tag_name: latest
|
|
||||||
release_name: Automated Latest tag
|
|
||||||
draft: false
|
|
||||||
prerelease: false
|
|
||||||
|
|
||||||
- name: Get latest release
|
- name: Get latest release
|
||||||
id: latest_release
|
id: latest_release
|
||||||
uses: kaliber5/action-get-release@v1
|
uses: kaliber5/action-get-release@v1
|
||||||
@@ -118,22 +98,9 @@ jobs:
|
|||||||
uses: requarks/changelog-action@v1
|
uses: requarks/changelog-action@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
toTag: ${{ github.event_name == 'schedule' && 'nightly' || steps.latest_release.outputs.tag_name }}
|
toTag: ${{ steps.latest_release.outputs.tag_name }}
|
||||||
fromTag: "latest"
|
fromTag: "latest"
|
||||||
writeToFile: false # we won't write to file, just output
|
writeToFile: false
|
||||||
|
|
||||||
- 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 }}
|
|
||||||
|
|
||||||
- name: Make download dir
|
- name: Make download dir
|
||||||
run: mkdir ${{ github.workspace }}/temp
|
run: mkdir ${{ github.workspace }}/temp
|
||||||
@@ -141,53 +108,43 @@ jobs:
|
|||||||
- name: Download artifacts
|
- name: Download artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ env.UPLOAD_DIR_ANDROID }}
|
pattern: android_artifacts_*
|
||||||
path: ${{ github.workspace }}/temp
|
path: ${{ github.workspace }}/temp
|
||||||
|
merge-multiple: true
|
||||||
# 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
|
|
||||||
|
|
||||||
- name: Set version release notes
|
- name: Set version release notes
|
||||||
if: ${{ inputs.release_type == 'release' }}
|
if: ${{ inputs.release_type == 'release' }}
|
||||||
run: |
|
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<<EOF" >> $GITHUB_ENV
|
||||||
echo "$RELEASE_NOTES" >> $GITHUB_ENV
|
echo "$RELEASE_NOTES" >> $GITHUB_ENV
|
||||||
echo "EOF" >> $GITHUB_ENV
|
echo "EOF" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: On nightly release notes
|
|
||||||
if: ${{ contains(env.TAG_NAME, 'nightly') }}
|
|
||||||
run: |
|
|
||||||
echo "RELEASE_NOTES=Nightly build for the latest development version of the app." >> $GITHUB_ENV
|
|
||||||
gh release delete nightly --yes || true
|
|
||||||
git push origin :nightly || true
|
|
||||||
|
|
||||||
- name: On prerelease release notes
|
- name: On prerelease release notes
|
||||||
if: ${{ inputs.release_type == 'prerelease' }}
|
if: ${{ inputs.release_type == 'prerelease' }}
|
||||||
run: |
|
run: |
|
||||||
echo "RELEASE_NOTES=Testing version of app for specific feature." >> $GITHUB_ENV
|
echo "RELEASE_NOTES=Testing version of app for specific feature." >> $GITHUB_ENV
|
||||||
gh release delete ${{ github.event.inputs.tag_name }} --yes || true
|
|
||||||
|
|
||||||
- name: Get checksum
|
- name: Get checksum
|
||||||
id: checksum
|
id: checksum
|
||||||
run: |
|
run: |
|
||||||
file_path=$(find ${{ github.workspace }}/temp -type f -iname "*.apk" | tail -n1)
|
file_path=$(find ${{ github.workspace }}/temp -type f -iname "*.apk" | head -n 1)
|
||||||
echo "checksum=$(apksigner verify -print-certs $file_path | grep -Po "(?<=SHA-256 digest:) .*" | tr -d "[:blank:]")" >> $GITHUB_OUTPUT
|
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
|
||||||
- name: Create Release with Fastlane changelog notes
|
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
with:
|
with:
|
||||||
body: |
|
body: |
|
||||||
${{ env.RELEASE_NOTES }}
|
${{ env.RELEASE_NOTES }}
|
||||||
|
|
||||||
SHA-256 fingerprint for the 4096-bit signing certificate:
|
SHA-256 fingerprints for the 4096-bit signing certificate:
|
||||||
```sh
|
```sh
|
||||||
${{ steps.checksum.outputs.checksum }}
|
${{ steps.checksum.outputs.checksum }}
|
||||||
```
|
```
|
||||||
@@ -199,48 +156,40 @@ jobs:
|
|||||||
|
|
||||||
### Changelog
|
### Changelog
|
||||||
${{ steps.changelog.outputs.changes }}
|
${{ steps.changelog.outputs.changes }}
|
||||||
tag_name: ${{ env.TAG_NAME }}
|
tag_name: ${{ github.event.inputs.tag_name }}
|
||||||
name: ${{ env.TAG_NAME }}
|
name: ${{ github.event.inputs.tag_name }}
|
||||||
draft: false
|
draft: false
|
||||||
prerelease: ${{ inputs.release_type == 'prerelease' || inputs.release_type == '' || inputs.release_type == 'nightly' }}
|
prerelease: ${{ inputs.release_type == 'prerelease' }}
|
||||||
make_latest: ${{ inputs.release_type == 'release' }}
|
make_latest: ${{ inputs.release_type == 'release' }}
|
||||||
files: |
|
files: |
|
||||||
${{ github.workspace }}/temp/*
|
${{ github.workspace }}/temp/**/*.apk
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
# notify socials
|
publish-fdroid-public:
|
||||||
- name: Trigger on-publish workflow
|
|
||||||
if: ${{ inputs.release_type == 'release' }}
|
|
||||||
uses: peter-evans/repository-dispatch@v3
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.PAT }}
|
|
||||||
event-type: publish-release
|
|
||||||
|
|
||||||
publish-fdroid:
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs:
|
needs:
|
||||||
- build
|
- build-fdroid
|
||||||
if: inputs.release_type == 'release'
|
if: inputs.release_type == 'release'
|
||||||
steps:
|
steps:
|
||||||
- name: Dispatch update for fdroid repo
|
- name: Dispatch update for fdroid repo
|
||||||
uses: peter-evans/repository-dispatch@v3
|
uses: peter-evans/repository-dispatch@v3
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.PAT }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
repository: zaneschepke/fdroid
|
repository: wgtunnel/fdroid
|
||||||
event-type: fdroid-update
|
event-type: fdroid-update
|
||||||
|
|
||||||
publish-play:
|
publish-play:
|
||||||
if: ${{ inputs.track != 'none' && inputs.track != '' }}
|
if: ${{ inputs.track != 'none' }}
|
||||||
name: Publish to Google Play
|
name: Publish to Google Play
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
env:
|
env:
|
||||||
SIGNING_KEY_ALIAS: ${{ secrets.ANDROID_SIGNING_KEY_ALIAS }}
|
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
|
||||||
SIGNING_KEY_PASSWORD: ${{ secrets.ANDROID_SIGNING_KEY_PASSWORD }}
|
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
||||||
SIGNING_STORE_PASSWORD: ${{ secrets.ANDROID_SIGNING_STORE_PASSWORD }}
|
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
|
||||||
KEY_STORE_FILE: 'android_keystore.jks'
|
KEY_STORE_FILE: 'android_keystore.jks'
|
||||||
KEY_STORE_LOCATION: ${{ github.workspace }}/app/keystore/
|
KEY_STORE_LOCATION: ${{ github.workspace }}/app/keystore/
|
||||||
GH_USER: ${{ secrets.PAT_USERNAME }}
|
|
||||||
GH_TOKEN: ${{ secrets.PAT }}
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -262,7 +211,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fileName: ${{ env.KEY_STORE_FILE }}
|
fileName: ${{ env.KEY_STORE_FILE }}
|
||||||
fileDir: ${{ env.KEY_STORE_LOCATION }}
|
fileDir: ${{ env.KEY_STORE_LOCATION }}
|
||||||
encodedString: ${{ secrets.ANDROID_KEYSTORE }}
|
encodedString: ${{ secrets.KEYSTORE }}
|
||||||
|
|
||||||
# create keystore path for gradle to read
|
# create keystore path for gradle to read
|
||||||
- name: Create keystore path env var
|
- name: Create keystore path env var
|
||||||
@@ -282,4 +231,3 @@ jobs:
|
|||||||
|
|
||||||
- name: Distribute app to Prod track 🚀
|
- name: Distribute app to Prod track 🚀
|
||||||
run: (cd ${{ github.workspace }} && bundle install && bundle exec fastlane ${{ inputs.track }})
|
run: (cd ${{ github.workspace }} && bundle install && bundle exec fastlane ${{ inputs.track }})
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -70,5 +70,5 @@ lint/tmp/
|
|||||||
app/release/output.json
|
app/release/output.json
|
||||||
.idea/codeStyles/
|
.idea/codeStyles/
|
||||||
# where we keep our signing secrets locally
|
# where we keep our signing secrets locally
|
||||||
app/signing.properties
|
|
||||||
/.kotlin/
|
/.kotlin/
|
||||||
|
/app/keystore/
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
/build
|
/build
|
||||||
/release
|
/release
|
||||||
|
/src/main/assets/licenses.json
|
||||||
|
|||||||
+65
-85
@@ -6,35 +6,17 @@ plugins {
|
|||||||
alias(libs.plugins.ksp)
|
alias(libs.plugins.ksp)
|
||||||
alias(libs.plugins.compose.compiler)
|
alias(libs.plugins.compose.compiler)
|
||||||
alias(libs.plugins.grgit)
|
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 {
|
android {
|
||||||
namespace = Constants.APP_ID
|
namespace = Constants.APP_ID
|
||||||
compileSdk = Constants.TARGET_SDK
|
compileSdk = Constants.TARGET_SDK
|
||||||
|
|
||||||
androidResources { generateLocaleConfig = true }
|
androidResources { generateLocaleConfig = true }
|
||||||
|
|
||||||
// reproducibility
|
|
||||||
dependenciesInfo {
|
dependenciesInfo {
|
||||||
// Disables dependency metadata when building APKs.
|
|
||||||
includeInApk = false
|
includeInApk = false
|
||||||
// Disables dependency metadata when building Android App Bundles.
|
|
||||||
includeInBundle = false
|
includeInBundle = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,14 +24,12 @@ android {
|
|||||||
applicationId = Constants.APP_ID
|
applicationId = Constants.APP_ID
|
||||||
minSdk = Constants.MIN_SDK
|
minSdk = Constants.MIN_SDK
|
||||||
targetSdk = Constants.TARGET_SDK
|
targetSdk = Constants.TARGET_SDK
|
||||||
versionCode = Constants.VERSION_CODE + versionCodeIncrement
|
versionCode = computeVersionCode()
|
||||||
versionName = determineVersionName()
|
versionName = computeVersionName()
|
||||||
|
|
||||||
ksp { arg("room.schemaLocation", "$projectDir/schemas") }
|
ksp { arg("room.schemaLocation", "$projectDir/schemas") }
|
||||||
|
|
||||||
sourceSets {
|
sourceSets { getByName("debug").assets.srcDirs(files("$projectDir/schemas")) }
|
||||||
getByName("debug").assets.srcDirs(files("$projectDir/schemas")) // Room
|
|
||||||
}
|
|
||||||
|
|
||||||
buildConfigField(
|
buildConfigField(
|
||||||
"String[]",
|
"String[]",
|
||||||
@@ -63,15 +43,18 @@ android {
|
|||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
create(Constants.RELEASE) {
|
create(Constants.RELEASE) {
|
||||||
storeFile = getStoreFile()
|
storeFile = file(System.getenv("KEY_STORE_PATH") ?: "keystore/android_keystore.jks")
|
||||||
storePassword = getSigningProperty(Constants.STORE_PASS_VAR)
|
storePassword =
|
||||||
keyAlias = getSigningProperty(Constants.KEY_ALIAS_VAR)
|
LocalProperties.get("SIGNING_STORE_PASSWORD")
|
||||||
keyPassword = getSigningProperty(Constants.KEY_PASS_VAR)
|
?: 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 {
|
buildTypes {
|
||||||
// don't strip
|
|
||||||
packaging.jniLibs.keepDebugSymbols.addAll(
|
packaging.jniLibs.keepDebugSymbols.addAll(
|
||||||
listOf("libwg-go.so", "libwg-quick.so", "libwg.so")
|
listOf("libwg-go.so", "libwg-quick.so", "libwg.so")
|
||||||
)
|
)
|
||||||
@@ -87,6 +70,7 @@ android {
|
|||||||
signingConfig = signingConfigs.getByName(Constants.RELEASE)
|
signingConfig = signingConfigs.getByName(Constants.RELEASE)
|
||||||
resValue("string", "provider", "\"${Constants.APP_NAME}.provider\"")
|
resValue("string", "provider", "\"${Constants.APP_NAME}.provider\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
debug {
|
debug {
|
||||||
applicationIdSuffix = ".debug"
|
applicationIdSuffix = ".debug"
|
||||||
resValue("string", "app_name", "WG Tunnel - Debug")
|
resValue("string", "app_name", "WG Tunnel - Debug")
|
||||||
@@ -107,31 +91,28 @@ android {
|
|||||||
resValue("string", "app_name", "WG Tunnel - Nightly")
|
resValue("string", "app_name", "WG Tunnel - Nightly")
|
||||||
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.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 {
|
productFlavors {
|
||||||
create("fdroid") {
|
create("fdroid") {
|
||||||
dimension = Constants.TYPE
|
dimension = "type"
|
||||||
proguardFile("fdroid-rules.pro")
|
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 {
|
compileOptions {
|
||||||
|
isCoreLibraryDesugaringEnabled = true
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
isCoreLibraryDesugaringEnabled = true
|
|
||||||
}
|
}
|
||||||
kotlinOptions { jvmTarget = Constants.JVM_TARGET }
|
kotlinOptions { jvmTarget = Constants.JVM_TARGET }
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
@@ -139,6 +120,26 @@ android {
|
|||||||
buildConfig = true
|
buildConfig = true
|
||||||
}
|
}
|
||||||
packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" } }
|
packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" } }
|
||||||
|
|
||||||
|
licensee {
|
||||||
|
Constants.allowedLicenses.forEach { allow(it) }
|
||||||
|
allowUrl(Constants.XZING_LICENSE_URL)
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
dependencies {
|
||||||
@@ -147,8 +148,6 @@ dependencies {
|
|||||||
|
|
||||||
implementation(libs.androidx.core.ktx)
|
implementation(libs.androidx.core.ktx)
|
||||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||||
|
|
||||||
// helpers for implementing LifecycleOwner in a Service
|
|
||||||
implementation(libs.androidx.lifecycle.service)
|
implementation(libs.androidx.lifecycle.service)
|
||||||
implementation(libs.androidx.activity.compose)
|
implementation(libs.androidx.activity.compose)
|
||||||
implementation(platform(libs.androidx.compose.bom))
|
implementation(platform(libs.androidx.compose.bom))
|
||||||
@@ -160,7 +159,6 @@ dependencies {
|
|||||||
implementation(libs.material)
|
implementation(libs.material)
|
||||||
implementation(libs.androidx.storage)
|
implementation(libs.androidx.storage)
|
||||||
|
|
||||||
// test
|
|
||||||
testImplementation(libs.junit)
|
testImplementation(libs.junit)
|
||||||
testImplementation(libs.androidx.junit)
|
testImplementation(libs.androidx.junit)
|
||||||
androidTestImplementation(libs.androidx.junit)
|
androidTestImplementation(libs.androidx.junit)
|
||||||
@@ -171,83 +169,65 @@ dependencies {
|
|||||||
debugImplementation(libs.androidx.compose.ui.tooling)
|
debugImplementation(libs.androidx.compose.ui.tooling)
|
||||||
debugImplementation(libs.androidx.compose.manifest)
|
debugImplementation(libs.androidx.compose.manifest)
|
||||||
|
|
||||||
// tunnel
|
|
||||||
implementation(libs.tunnel)
|
implementation(libs.tunnel)
|
||||||
implementation(libs.amneziawg.android)
|
implementation(libs.amneziawg.android)
|
||||||
coreLibraryDesugaring(libs.desugar.jdk.libs)
|
coreLibraryDesugaring(libs.desugar.jdk.libs)
|
||||||
|
|
||||||
// logging
|
|
||||||
implementation(libs.timber)
|
implementation(libs.timber)
|
||||||
|
|
||||||
// compose navigation
|
|
||||||
implementation(libs.androidx.navigation.compose)
|
implementation(libs.androidx.navigation.compose)
|
||||||
implementation(libs.androidx.hilt.navigation.compose)
|
implementation(libs.androidx.hilt.navigation.compose)
|
||||||
|
|
||||||
// hilt
|
|
||||||
implementation(libs.hilt.android)
|
implementation(libs.hilt.android)
|
||||||
ksp(libs.hilt.android.compiler)
|
ksp(libs.hilt.android.compiler)
|
||||||
ksp(libs.androidx.hilt.compiler)
|
ksp(libs.androidx.hilt.compiler)
|
||||||
|
|
||||||
// accompanist
|
|
||||||
implementation(libs.accompanist.permissions)
|
implementation(libs.accompanist.permissions)
|
||||||
implementation(libs.accompanist.drawablepainter)
|
implementation(libs.accompanist.drawablepainter)
|
||||||
|
|
||||||
// storage
|
|
||||||
implementation(libs.androidx.room.runtime)
|
implementation(libs.androidx.room.runtime)
|
||||||
ksp(libs.androidx.room.compiler)
|
ksp(libs.androidx.room.compiler)
|
||||||
implementation(libs.androidx.room.ktx)
|
implementation(libs.androidx.room.ktx)
|
||||||
implementation(libs.androidx.datastore.preferences)
|
implementation(libs.androidx.datastore.preferences)
|
||||||
|
|
||||||
// lifecycle
|
|
||||||
implementation(libs.lifecycle.runtime.compose)
|
implementation(libs.lifecycle.runtime.compose)
|
||||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||||
implementation(libs.androidx.lifecycle.process)
|
implementation(libs.androidx.lifecycle.process)
|
||||||
|
|
||||||
// serialization
|
|
||||||
implementation(libs.kotlinx.serialization.json)
|
implementation(libs.kotlinx.serialization.json)
|
||||||
|
|
||||||
// ui
|
|
||||||
implementation(libs.zxing.android.embedded)
|
implementation(libs.zxing.android.embedded)
|
||||||
|
|
||||||
implementation(libs.material.icons.extended)
|
implementation(libs.material.icons.extended)
|
||||||
|
|
||||||
// bio
|
|
||||||
implementation(libs.androidx.biometric.ktx)
|
implementation(libs.androidx.biometric.ktx)
|
||||||
implementation(libs.pin.lock.compose)
|
implementation(libs.pin.lock.compose)
|
||||||
|
|
||||||
// shortcuts
|
|
||||||
implementation(libs.androidx.core)
|
implementation(libs.androidx.core)
|
||||||
|
|
||||||
// splash
|
|
||||||
implementation(libs.androidx.core.splashscreen)
|
implementation(libs.androidx.core.splashscreen)
|
||||||
|
|
||||||
// worker
|
|
||||||
implementation(libs.androidx.work.runtime)
|
implementation(libs.androidx.work.runtime)
|
||||||
implementation(libs.androidx.hilt.work)
|
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 {
|
tasks.register<Copy>("copyLicenseeJsonToAssets") {
|
||||||
return with(getBuildTaskName().lowercase()) {
|
dependsOn("licensee")
|
||||||
when {
|
val outputAssets = layout.projectDirectory.dir("src/main/assets")
|
||||||
contains(Constants.NIGHTLY) || contains(Constants.PRERELEASE) ->
|
from(layout.buildDirectory.file("reports/licensee/androidFdroidRelease/artifacts.json")) {
|
||||||
Constants.VERSION_NAME + "-${grgitService.service.get().grgit.head().abbreviatedId}"
|
rename("artifacts.json", "licenses.json")
|
||||||
else -> Constants.VERSION_NAME
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
into(outputAssets)
|
||||||
}
|
}
|
||||||
|
|
||||||
val incrementVersionCode by
|
tasks.named("preBuild") { dependsOn("copyLicenseeJsonToAssets") }
|
||||||
tasks.registering {
|
|
||||||
doLast {
|
|
||||||
val versionFile = file("$rootDir/versionCode.txt")
|
|
||||||
if (versionFile.exists()) {
|
|
||||||
versionFile.writeText(versionCodeIncrement.toString())
|
|
||||||
println("Incremented versionCode to $versionCodeIncrement")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.whenTaskAdded {
|
|
||||||
if (name.startsWith("assemble") && !name.lowercase().contains("debug")) {
|
|
||||||
dependsOn(incrementVersionCode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
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" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
|
|
||||||
<!--foreground service exempt android 14-->
|
<!--foreground service exempt android 14-->
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||||
<!--start service on boot permission-->
|
<!--start service on boot permission-->
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
<!--android tv support-->
|
|
||||||
|
|
||||||
<permission
|
<permission
|
||||||
android:name="${applicationId}.permission.CONTROL_TUNNELS"
|
android:name="${applicationId}.permission.CONTROL_TUNNELS"
|
||||||
@@ -63,10 +62,13 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.App.Start"
|
android:theme="@style/Theme.App.Start"
|
||||||
tools:targetApi="tiramisu">
|
tools:targetApi="tiramisu">
|
||||||
|
<activity
|
||||||
|
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
||||||
|
android:screenOrientation="portrait"
|
||||||
|
tools:replace="screenOrientation" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:banner="@mipmap/ic_banner"
|
|
||||||
android:windowSoftInputMode="adjustNothing"
|
android:windowSoftInputMode="adjustNothing"
|
||||||
android:theme="@style/Theme.WireguardAutoTunnel"
|
android:theme="@style/Theme.WireguardAutoTunnel"
|
||||||
android:configChanges="orientation|screenSize|keyboardHidden"
|
android:configChanges="orientation|screenSize|keyboardHidden"
|
||||||
@@ -80,10 +82,6 @@
|
|||||||
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
|
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
|
||||||
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
|
||||||
android:screenOrientation="portrait"
|
|
||||||
tools:replace="screenOrientation" />
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".core.shortcut.ShortcutsActivity"
|
android:name=".core.shortcut.ShortcutsActivity"
|
||||||
@@ -168,14 +166,11 @@
|
|||||||
<receiver
|
<receiver
|
||||||
android:name=".core.broadcast.RestartReceiver"
|
android:name=".core.broadcast.RestartReceiver"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false"
|
android:exported="false">
|
||||||
android:directBootAware="true">
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||||
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
|
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
|
||||||
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
|
|
||||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import android.annotation.SuppressLint
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
@@ -22,33 +21,14 @@ import androidx.compose.animation.slideInVertically
|
|||||||
import androidx.compose.animation.slideOutVertically
|
import androidx.compose.animation.slideOutVertically
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.gestures.detectTapGestures
|
import androidx.compose.foundation.gestures.detectTapGestures
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.layout.consumeWindowInsets
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.runtime.*
|
||||||
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.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.net.toUri
|
||||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
@@ -58,22 +38,21 @@ import androidx.navigation.compose.rememberNavController
|
|||||||
import androidx.navigation.toRoute
|
import androidx.navigation.toRoute
|
||||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.VpnDeniedDialog
|
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.VpnDeniedDialog
|
||||||
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.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.AutoTunnelScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.advanced.AutoTunnelAdvancedScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.advanced.AutoTunnelAdvancedScreen
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.LocationDisclosureScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.autotunnel.TunnelAutoTunnelScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.autotunnel.TunnelAutoTunnelScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.ConfigScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.ConfigScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.scanner.ScannerScreen
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel.SplitTunnelScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel.SplitTunnelScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.TunnelOptionsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.TunnelOptionsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.pin.PinLockScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.pin.PinLockScreen
|
||||||
@@ -82,12 +61,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.AppearanceScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.display.DisplayScreen
|
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.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.killswitch.KillSwitchScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.logs.LogsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.logs.LogsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.SupportScreen
|
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.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.AppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
@@ -125,8 +104,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
|
val isTv = isRunningOnTv()
|
||||||
val appUiState by viewModel.uiState.collectAsStateWithLifecycle()
|
val appUiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||||
val appViewState by viewModel.appViewState.collectAsStateWithLifecycle()
|
val appViewState by viewModel.appViewState.collectAsStateWithLifecycle()
|
||||||
|
val tunnelError by viewModel.tunnelManager.errorEvents.collectAsStateWithLifecycle(null)
|
||||||
|
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
val backStackEntry by navController.currentBackStackEntryAsState()
|
val backStackEntry by navController.currentBackStackEntryAsState()
|
||||||
@@ -136,6 +117,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
backStackEntry,
|
backStackEntry,
|
||||||
viewModel,
|
viewModel,
|
||||||
appUiState,
|
appUiState,
|
||||||
|
appViewState,
|
||||||
)
|
)
|
||||||
val snackbar = remember { SnackbarHostState() }
|
val snackbar = remember { SnackbarHostState() }
|
||||||
var showVpnPermissionDialog by remember { mutableStateOf(false) }
|
var showVpnPermissionDialog by remember { mutableStateOf(false) }
|
||||||
@@ -150,6 +132,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
vpnPermissionDenied = true
|
vpnPermissionDenied = true
|
||||||
} else {
|
} else {
|
||||||
vpnPermissionDenied = false
|
vpnPermissionDenied = false
|
||||||
|
showVpnPermissionDialog = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -167,6 +150,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
viewModel.handleEvent(AppEvent.SetBatteryOptimizeDisableShown)
|
viewModel.handleEvent(AppEvent.SetBatteryOptimizeDisableShown)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(tunnelError) {
|
||||||
|
if (tunnelError == null) return@LaunchedEffect
|
||||||
|
val message = tunnelError!!.second.toStringRes()
|
||||||
|
val context = this@MainActivity
|
||||||
|
snackbar.showSnackbar(
|
||||||
|
context.getString(R.string.tunnel_error_template, context.getString(message))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
with(appViewState) {
|
with(appViewState) {
|
||||||
LaunchedEffect(isConfigChanged) {
|
LaunchedEffect(isConfigChanged) {
|
||||||
if (isConfigChanged) {
|
if (isConfigChanged) {
|
||||||
@@ -182,21 +174,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
viewModel.handleEvent(AppEvent.MessageShown)
|
viewModel.handleEvent(AppEvent.MessageShown)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LaunchedEffect(appUiState.activeTunnels) {
|
|
||||||
appUiState.activeTunnels.mapNotNull { (tunnelConf, tunnelState) ->
|
|
||||||
(tunnelState.status as? TunnelStatus.Error)?.let { error ->
|
|
||||||
val message = error.error.toStringRes()
|
|
||||||
val context = this@MainActivity
|
|
||||||
snackbar.showSnackbar(
|
|
||||||
context.getString(
|
|
||||||
R.string.tunnel_error_template,
|
|
||||||
context.getString(message),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
viewModel.handleEvent(AppEvent.ClearTunnelError(tunnelConf))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LaunchedEffect(popBackStack) {
|
LaunchedEffect(popBackStack) {
|
||||||
if (popBackStack) {
|
if (popBackStack) {
|
||||||
navController.popBackStack()
|
navController.popBackStack()
|
||||||
@@ -218,153 +195,127 @@ class MainActivity : AppCompatActivity() {
|
|||||||
batteryActivity.launch(
|
batteryActivity.launch(
|
||||||
Intent().apply {
|
Intent().apply {
|
||||||
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
||||||
data = Uri.parse("package:${this@MainActivity.packageName}")
|
data = "package:${this@MainActivity.packageName}".toUri()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompositionLocalProvider(LocalNavController provides navController) {
|
CompositionLocalProvider(LocalIsAndroidTV provides isTv) {
|
||||||
WireguardAutoTunnelTheme(theme = appUiState.appState.theme) {
|
CompositionLocalProvider(LocalNavController provides navController) {
|
||||||
VpnDeniedDialog(
|
WireguardAutoTunnelTheme(theme = appUiState.appState.theme) {
|
||||||
showVpnPermissionDialog,
|
VpnDeniedDialog(
|
||||||
onDismiss = { showVpnPermissionDialog = false },
|
showVpnPermissionDialog,
|
||||||
)
|
onDismiss = {
|
||||||
|
showVpnPermissionDialog = false
|
||||||
|
vpnPermissionDenied = false
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.pointerInput(Unit) {
|
Modifier.pointerInput(Unit) {
|
||||||
detectTapGestures {
|
detectTapGestures {
|
||||||
viewModel.handleEvent(AppEvent.SetSelectedTunnel(null))
|
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
snackbarHost = {
|
||||||
|
SnackbarHost(snackbar) { snackbarData: SnackbarData ->
|
||||||
|
CustomSnackBar(
|
||||||
|
snackbarData.visuals.message,
|
||||||
|
isRtl = false,
|
||||||
|
containerColor =
|
||||||
|
MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
snackbarHost = {
|
topBar = { DynamicTopAppBar(navBarState) },
|
||||||
SnackbarHost(snackbar) { snackbarData: SnackbarData ->
|
bottomBar = {
|
||||||
CustomSnackBar(
|
AnimatedVisibility(
|
||||||
snackbarData.visuals.message,
|
visible = navBarState.showBottom,
|
||||||
isRtl = false,
|
enter = slideInVertically(initialOffsetY = { it }),
|
||||||
containerColor =
|
exit = slideOutVertically(targetOffsetY = { it }),
|
||||||
MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp),
|
) {
|
||||||
)
|
BottomNavbar(appUiState = appUiState)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
topBar = { DynamicTopAppBar(navBarState) },
|
) { padding ->
|
||||||
bottomBar = {
|
Box(
|
||||||
AnimatedVisibility(
|
modifier =
|
||||||
visible = navBarState.showBottom,
|
Modifier.fillMaxSize()
|
||||||
enter = slideInVertically(initialOffsetY = { it }),
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
exit = slideOutVertically(targetOffsetY = { it }),
|
.padding(padding)
|
||||||
|
.consumeWindowInsets(padding)
|
||||||
|
.imePadding()
|
||||||
) {
|
) {
|
||||||
CustomBottomNavbar(
|
NavHost(
|
||||||
listOf(
|
navController,
|
||||||
BottomNavItem(
|
startDestination =
|
||||||
name = stringResource(R.string.tunnels),
|
(if (appUiState.appState.isPinLockEnabled) Route.Lock
|
||||||
route = Route.Main,
|
else Route.Main),
|
||||||
icon = Icons.Rounded.Home,
|
) {
|
||||||
onClick = { navController.goFromRoot(Route.Main) },
|
composable<Route.Main> {
|
||||||
),
|
MainScreen(appUiState, appViewState, viewModel)
|
||||||
BottomNavItem(
|
}
|
||||||
name = stringResource(R.string.auto_tunnel),
|
composable<Route.Settings> {
|
||||||
route = Route.AutoTunnel,
|
SettingsScreen(appUiState, viewModel)
|
||||||
icon = Icons.Rounded.Bolt,
|
}
|
||||||
onClick = {
|
composable<Route.SettingsAdvanced> {
|
||||||
val route =
|
SettingsAdvancedScreen(appUiState, viewModel)
|
||||||
if (
|
}
|
||||||
appUiState.appState
|
composable<Route.LocationDisclosure> {
|
||||||
.isLocationDisclosureShown
|
LocationDisclosureScreen(appUiState, viewModel)
|
||||||
)
|
}
|
||||||
Route.AutoTunnel
|
composable<Route.AutoTunnel> {
|
||||||
else Route.LocationDisclosure
|
AutoTunnelScreen(appUiState, viewModel)
|
||||||
navController.goFromRoot(route)
|
}
|
||||||
},
|
composable<Route.Appearance> { AppearanceScreen() }
|
||||||
active = appUiState.isAutoTunnelActive,
|
composable<Route.Language> {
|
||||||
),
|
LanguageScreen(appUiState, viewModel)
|
||||||
BottomNavItem(
|
}
|
||||||
name = stringResource(R.string.settings),
|
composable<Route.Display> {
|
||||||
route = Route.Settings,
|
DisplayScreen(appUiState, viewModel)
|
||||||
icon = Icons.Rounded.Settings,
|
}
|
||||||
onClick = { navController.goFromRoot(Route.Settings) },
|
composable<Route.Support> {
|
||||||
),
|
SupportScreen(appViewModel = viewModel)
|
||||||
BottomNavItem(
|
}
|
||||||
name = stringResource(R.string.support),
|
composable<Route.License> { LicenseScreen() }
|
||||||
route = Route.Support,
|
composable<Route.AutoTunnelAdvanced> {
|
||||||
icon = Icons.Rounded.QuestionMark,
|
AutoTunnelAdvancedScreen(appUiState, viewModel)
|
||||||
onClick = { navController.goFromRoot(Route.Support) },
|
}
|
||||||
),
|
composable<Route.Logs> { LogsScreen(appViewState, viewModel) }
|
||||||
),
|
composable<Route.Config> { backStack ->
|
||||||
navBarState = navBarState,
|
val args = backStack.toRoute<Route.Config>()
|
||||||
)
|
val config =
|
||||||
}
|
appUiState.tunnels.firstOrNull { it.id == args.id }
|
||||||
},
|
ConfigScreen(config, viewModel)
|
||||||
) { padding ->
|
}
|
||||||
Box(
|
composable<Route.TunnelOptions> { backStack ->
|
||||||
modifier =
|
val args = backStack.toRoute<Route.TunnelOptions>()
|
||||||
Modifier.fillMaxSize()
|
appUiState.tunnels
|
||||||
.background(MaterialTheme.colorScheme.surface)
|
.firstOrNull { it.id == args.id }
|
||||||
.padding(padding)
|
?.let { config ->
|
||||||
.consumeWindowInsets(padding)
|
TunnelOptionsScreen(config, viewModel, appViewState)
|
||||||
.imePadding()
|
}
|
||||||
) {
|
}
|
||||||
NavHost(
|
composable<Route.Lock> { PinLockScreen(viewModel) }
|
||||||
navController,
|
composable<Route.KillSwitch> {
|
||||||
startDestination =
|
KillSwitchScreen(appUiState, viewModel)
|
||||||
(if (appUiState.appState.isPinLockEnabled) Route.Lock
|
}
|
||||||
else Route.Main),
|
composable<Route.SplitTunnel> { SplitTunnelScreen(viewModel) }
|
||||||
) {
|
composable<Route.TunnelAutoTunnel> { backStack ->
|
||||||
composable<Route.Main> {
|
val args = backStack.toRoute<Route.TunnelOptions>()
|
||||||
MainScreen(appUiState, appViewState, viewModel)
|
appUiState.tunnels
|
||||||
}
|
.firstOrNull { it.id == args.id }
|
||||||
composable<Route.Settings> {
|
?.let {
|
||||||
SettingsScreen(appUiState, appViewState, viewModel)
|
TunnelAutoTunnelScreen(
|
||||||
}
|
it,
|
||||||
composable<Route.SettingsAdvanced> {
|
appUiState.appSettings,
|
||||||
SettingsAdvancedScreen(appUiState, viewModel)
|
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,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -3,6 +3,7 @@ package com.zaneschepke.wireguardautotunnel.core.broadcast
|
|||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import com.zaneschepke.logcatter.LogReader
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
@@ -25,6 +26,8 @@ class RestartReceiver : BroadcastReceiver() {
|
|||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
@Inject lateinit var tunnelManager: TunnelManager
|
||||||
|
|
||||||
|
@Inject lateinit var logReader: LogReader
|
||||||
|
|
||||||
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
@@ -34,7 +37,9 @@ class RestartReceiver : BroadcastReceiver() {
|
|||||||
applicationScope.launch(ioDispatcher) {
|
applicationScope.launch(ioDispatcher) {
|
||||||
val settings = appDataRepository.settings.get()
|
val settings = appDataRepository.settings.get()
|
||||||
if (settings.isRestoreOnBootEnabled) {
|
if (settings.isRestoreOnBootEnabled) {
|
||||||
if (settings.isAutoTunnelEnabled && !serviceManager.autoTunnelActive.value) {
|
if (
|
||||||
|
settings.isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null
|
||||||
|
) {
|
||||||
Timber.d("Starting auto-tunnel on boot/update")
|
Timber.d("Starting auto-tunnel on boot/update")
|
||||||
serviceManager.startAutoTunnel()
|
serviceManager.startAutoTunnel()
|
||||||
} else {
|
} else {
|
||||||
@@ -44,6 +49,7 @@ class RestartReceiver : BroadcastReceiver() {
|
|||||||
} else {
|
} else {
|
||||||
Timber.d("Restore on boot disabled, skipping")
|
Timber.d("Restore on boot disabled, skipping")
|
||||||
}
|
}
|
||||||
|
if (intent.action == Intent.ACTION_MY_PACKAGE_REPLACED) logReader.deleteAndClearLogs()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+71
-55
@@ -1,10 +1,11 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.service
|
package com.zaneschepke.wireguardautotunnel.core.service
|
||||||
|
|
||||||
import android.app.Service
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.ServiceConnection
|
||||||
import android.net.VpnService
|
import android.net.VpnService
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import android.os.IBinder
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.AutoTunnelService
|
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.AutoTunnelService
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
@@ -13,7 +14,6 @@ import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
|||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestAutoTunnelTileServiceUpdate
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestAutoTunnelTileServiceUpdate
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestTunnelTileServiceStateUpdate
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestTunnelTileServiceStateUpdate
|
||||||
import jakarta.inject.Inject
|
import jakarta.inject.Inject
|
||||||
import kotlinx.coroutines.CompletableDeferred
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
@@ -37,23 +37,37 @@ constructor(
|
|||||||
|
|
||||||
private val autoTunnelMutex = Mutex()
|
private val autoTunnelMutex = Mutex()
|
||||||
|
|
||||||
private val _autoTunnelActive = MutableStateFlow(false)
|
private val _tunnelService = MutableStateFlow<TunnelForegroundService?>(null)
|
||||||
val autoTunnelActive = _autoTunnelActive.asStateFlow()
|
private val _autoTunnelService = MutableStateFlow<AutoTunnelService?>(null)
|
||||||
|
val autoTunnelService = _autoTunnelService.asStateFlow()
|
||||||
|
|
||||||
var autoTunnelService = CompletableDeferred<AutoTunnelService>()
|
private val tunnelServiceConnection =
|
||||||
var backgroundService = CompletableDeferred<TunnelForegroundService>()
|
object : ServiceConnection {
|
||||||
|
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
||||||
private fun <T : Service> startService(cls: Class<T>, background: Boolean) {
|
val binder = service as? TunnelForegroundService.LocalBinder
|
||||||
runCatching {
|
_tunnelService.value = binder?.service
|
||||||
val intent = Intent(context, cls)
|
Timber.d("TunnelForegroundService connected")
|
||||||
if (background) {
|
|
||||||
context.startForegroundService(intent)
|
|
||||||
} else {
|
|
||||||
context.startService(intent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.onFailure { Timber.e(it) }
|
|
||||||
}
|
override fun onServiceDisconnected(name: ComponentName) {
|
||||||
|
_tunnelService.value = null
|
||||||
|
Timber.d("TunnelForegroundService disconnected")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val autoTunnelServiceConnection =
|
||||||
|
object : ServiceConnection {
|
||||||
|
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
||||||
|
val binder = service as? AutoTunnelService.LocalBinder
|
||||||
|
_autoTunnelService.value = binder?.service
|
||||||
|
Timber.d("AutoTunnelService connected")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onServiceDisconnected(name: ComponentName) {
|
||||||
|
_autoTunnelService.value = null
|
||||||
|
Timber.d("AutoTunnelService disconnected")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun hasVpnPermission(): Boolean {
|
fun hasVpnPermission(): Boolean {
|
||||||
return VpnService.prepare(context) == null
|
return VpnService.prepare(context) == null
|
||||||
@@ -63,20 +77,13 @@ constructor(
|
|||||||
autoTunnelMutex.withLock {
|
autoTunnelMutex.withLock {
|
||||||
val settings = appDataRepository.settings.get()
|
val settings = appDataRepository.settings.get()
|
||||||
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = true))
|
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = true))
|
||||||
if (autoTunnelService.isCompleted) {
|
if (_autoTunnelService.value != null) return
|
||||||
_autoTunnelActive.update { true }
|
withContext(ioDispatcher) {
|
||||||
return
|
val intent = Intent(context, AutoTunnelService::class.java)
|
||||||
|
context.startForegroundService(intent)
|
||||||
|
context.bindService(intent, autoTunnelServiceConnection, Context.BIND_AUTO_CREATE)
|
||||||
|
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
||||||
}
|
}
|
||||||
runCatching {
|
|
||||||
autoTunnelService = CompletableDeferred()
|
|
||||||
startService(AutoTunnelService::class.java, !WireGuardAutoTunnel.isForeground())
|
|
||||||
_autoTunnelActive.update { true }
|
|
||||||
}
|
|
||||||
.onFailure {
|
|
||||||
Timber.e(it)
|
|
||||||
_autoTunnelActive.update { false }
|
|
||||||
}
|
|
||||||
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,43 +91,44 @@ constructor(
|
|||||||
autoTunnelMutex.withLock {
|
autoTunnelMutex.withLock {
|
||||||
val settings = appDataRepository.settings.get()
|
val settings = appDataRepository.settings.get()
|
||||||
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = false))
|
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = false))
|
||||||
if (!autoTunnelService.isCompleted) return
|
if (_autoTunnelService.value == null) return
|
||||||
runCatching {
|
_autoTunnelService.value?.let { service ->
|
||||||
val service = autoTunnelService.await()
|
service.stop()
|
||||||
service.stop()
|
try {
|
||||||
_autoTunnelActive.update { false }
|
context.unbindService(autoTunnelServiceConnection)
|
||||||
autoTunnelService = CompletableDeferred()
|
} finally {
|
||||||
|
_tunnelService.value = null
|
||||||
}
|
}
|
||||||
.onFailure { Timber.e(it) }
|
}
|
||||||
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startTunnelForegroundService() {
|
suspend fun startTunnelForegroundService() {
|
||||||
if (backgroundService.isCompleted) return
|
if (_tunnelService.value != null) return
|
||||||
runCatching {
|
withContext(ioDispatcher) {
|
||||||
backgroundService = CompletableDeferred()
|
applicationScope.launch(ioDispatcher) {
|
||||||
startService(
|
val intent = Intent(context, TunnelForegroundService::class.java)
|
||||||
TunnelForegroundService::class.java,
|
context.startForegroundService(intent)
|
||||||
!WireGuardAutoTunnel.isForeground(),
|
context.bindService(intent, tunnelServiceConnection, Context.BIND_AUTO_CREATE)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
.onFailure { Timber.e(it) }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun stopTunnelForegroundService() {
|
fun stopTunnelForegroundService() {
|
||||||
if (!backgroundService.isCompleted) return
|
_tunnelService.value?.let { service ->
|
||||||
runCatching {
|
service.stop()
|
||||||
val service = backgroundService.await()
|
try {
|
||||||
service.stop()
|
context.unbindService(tunnelServiceConnection)
|
||||||
backgroundService = CompletableDeferred()
|
} finally {
|
||||||
|
_tunnelService.value = null
|
||||||
}
|
}
|
||||||
.onFailure { Timber.e(it) }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleAutoTunnel() {
|
fun toggleAutoTunnel() {
|
||||||
applicationScope.launch(ioDispatcher) {
|
applicationScope.launch(ioDispatcher) {
|
||||||
if (_autoTunnelActive.value) stopAutoTunnel() else startAutoTunnel()
|
if (_autoTunnelService.value != null) stopAutoTunnel() else startAutoTunnel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,4 +139,12 @@ constructor(
|
|||||||
fun updateTunnelTile() {
|
fun updateTunnelTile() {
|
||||||
context.requestTunnelTileServiceStateUpdate()
|
context.requestTunnelTileServiceStateUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun handleTunnelServiceDestroy() {
|
||||||
|
_tunnelService.update { null }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun handleAutoTunnelServiceDestroy() {
|
||||||
|
_autoTunnelService.update { null }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-8
@@ -2,6 +2,7 @@ package com.zaneschepke.wireguardautotunnel.core.service
|
|||||||
|
|
||||||
import android.app.Notification
|
import android.app.Notification
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Binder
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import androidx.core.app.ServiceCompat
|
import androidx.core.app.ServiceCompat
|
||||||
import androidx.lifecycle.LifecycleService
|
import androidx.lifecycle.LifecycleService
|
||||||
@@ -23,7 +24,6 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.distinctByKeys
|
|||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CompletableDeferred
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.NonCancellable
|
import kotlinx.coroutines.NonCancellable
|
||||||
@@ -64,9 +64,12 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
|
|
||||||
private val jobsMutex = Mutex()
|
private val jobsMutex = Mutex()
|
||||||
|
|
||||||
|
class LocalBinder(val service: TunnelForegroundService) : Binder()
|
||||||
|
|
||||||
|
private val binder = LocalBinder(this)
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
serviceManager.backgroundService.complete(this)
|
|
||||||
ServiceCompat.startForeground(
|
ServiceCompat.startForeground(
|
||||||
this@TunnelForegroundService,
|
this@TunnelForegroundService,
|
||||||
NotificationManager.VPN_NOTIFICATION_ID,
|
NotificationManager.VPN_NOTIFICATION_ID,
|
||||||
@@ -75,14 +78,13 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBind(intent: Intent): IBinder? {
|
override fun onBind(intent: Intent): IBinder {
|
||||||
super.onBind(intent)
|
super.onBind(intent)
|
||||||
return null
|
return binder
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
super.onStartCommand(intent, flags, startId)
|
super.onStartCommand(intent, flags, startId)
|
||||||
serviceManager.backgroundService.complete(this)
|
|
||||||
ServiceCompat.startForeground(
|
ServiceCompat.startForeground(
|
||||||
this@TunnelForegroundService,
|
this@TunnelForegroundService,
|
||||||
NotificationManager.VPN_NOTIFICATION_ID,
|
NotificationManager.VPN_NOTIFICATION_ID,
|
||||||
@@ -163,8 +165,12 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
} else {
|
} else {
|
||||||
pingJobs[tun]?.cancel() // Cancel any stale job
|
pingJobs[tun]?.cancel() // Cancel any stale job
|
||||||
if (tun.isPingEnabled) {
|
if (tun.isPingEnabled) {
|
||||||
pingJobs[tun] = startPingJob(tun)
|
if (tun.isStaticallyConfigured()) {
|
||||||
Timber.d("Started ping job for ${tun.tunName}")
|
Timber.d("Skipping ping for statically configured tunnel")
|
||||||
|
} else {
|
||||||
|
pingJobs[tun] = startPingJob(tun)
|
||||||
|
Timber.d("Started ping job for ${tun.tunName}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,7 +279,7 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
serviceManager.backgroundService = CompletableDeferred()
|
serviceManager.handleTunnelServiceDestroy()
|
||||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-6
@@ -1,6 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.service.autotunnel
|
package com.zaneschepke.wireguardautotunnel.core.service.autotunnel
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Binder
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import androidx.core.app.ServiceCompat
|
import androidx.core.app.ServiceCompat
|
||||||
@@ -28,7 +29,6 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
|||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Provider
|
import javax.inject.Provider
|
||||||
import kotlinx.coroutines.CompletableDeferred
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.FlowPreview
|
import kotlinx.coroutines.FlowPreview
|
||||||
@@ -68,21 +68,23 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
|
|
||||||
private var killSwitchJob: Job? = null
|
private var killSwitchJob: Job? = null
|
||||||
|
|
||||||
|
class LocalBinder(val service: AutoTunnelService) : Binder()
|
||||||
|
|
||||||
|
private val binder = LocalBinder(this)
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
serviceManager.autoTunnelService.complete(this)
|
|
||||||
launchWatcherNotification()
|
launchWatcherNotification()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBind(intent: Intent): IBinder? {
|
override fun onBind(intent: Intent): IBinder {
|
||||||
super.onBind(intent)
|
super.onBind(intent)
|
||||||
return null
|
return binder
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
super.onStartCommand(intent, flags, startId)
|
super.onStartCommand(intent, flags, startId)
|
||||||
Timber.d("onStartCommand executed with startId: $startId")
|
Timber.d("onStartCommand executed with startId: $startId")
|
||||||
serviceManager.autoTunnelService.complete(this)
|
|
||||||
start()
|
start()
|
||||||
return START_STICKY
|
return START_STICKY
|
||||||
}
|
}
|
||||||
@@ -105,7 +107,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
serviceManager.autoTunnelService = CompletableDeferred()
|
serviceManager.handleAutoTunnelServiceDestroy()
|
||||||
restoreVpnKillSwitch()
|
restoreVpnKillSwitch()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -38,8 +38,8 @@ class AutoTunnelControlTile : TileService(), LifecycleOwner {
|
|||||||
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
Timber.d("Start listening called for auto tunnel tile")
|
Timber.d("Start listening called for auto tunnel tile")
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
serviceManager.autoTunnelActive.collect {
|
serviceManager.autoTunnelService.collect {
|
||||||
if (it) return@collect setActive()
|
if (it != null) return@collect setActive()
|
||||||
setInactive()
|
setInactive()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ class AutoTunnelControlTile : TileService(), LifecycleOwner {
|
|||||||
super.onClick()
|
super.onClick()
|
||||||
unlockAndRun {
|
unlockAndRun {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
if (serviceManager.autoTunnelActive.value) {
|
if (serviceManager.autoTunnelService.value != null) {
|
||||||
serviceManager.stopAutoTunnel()
|
serviceManager.stopAutoTunnel()
|
||||||
setInactive()
|
setInactive()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+4
-3
@@ -148,11 +148,12 @@ class TunnelControlTile : TileService(), LifecycleOwner {
|
|||||||
|
|
||||||
private fun setTileDescription(description: String) {
|
private fun setTileDescription(description: String) {
|
||||||
runCatching {
|
runCatching {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (qsTile == null) return@runCatching
|
||||||
qsTile.subtitle = description
|
|
||||||
}
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
qsTile.subtitle = description
|
||||||
qsTile.stateDescription = description
|
qsTile.stateDescription = description
|
||||||
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
qsTile.subtitle = description
|
||||||
}
|
}
|
||||||
qsTile.updateTile()
|
qsTile.updateTile()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
import com.wireguard.android.backend.BackendException
|
|
||||||
import com.wireguard.android.backend.Tunnel
|
import com.wireguard.android.backend.Tunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
@@ -11,14 +10,11 @@ import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
|||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendError
|
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
|
||||||
import kotlinx.coroutines.flow.update
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
@@ -31,6 +27,10 @@ abstract class BaseTunnel(
|
|||||||
private val serviceManager: ServiceManager,
|
private val serviceManager: ServiceManager,
|
||||||
) : TunnelProvider {
|
) : TunnelProvider {
|
||||||
|
|
||||||
|
private val _errorEvents =
|
||||||
|
MutableSharedFlow<Pair<TunnelConf, BackendError>>(replay = 0, extraBufferCapacity = 1)
|
||||||
|
override val errorEvents = _errorEvents.asSharedFlow()
|
||||||
|
|
||||||
private val activeTuns = MutableStateFlow<Map<TunnelConf, TunnelState>>(emptyMap())
|
private val activeTuns = MutableStateFlow<Map<TunnelConf, TunnelState>>(emptyMap())
|
||||||
private val tunThreads = ConcurrentHashMap<Int, Thread>()
|
private val tunThreads = ConcurrentHashMap<Int, Thread>()
|
||||||
override val activeTunnels = activeTuns.asStateFlow()
|
override val activeTunnels = activeTuns.asStateFlow()
|
||||||
@@ -45,37 +45,34 @@ abstract class BaseTunnel(
|
|||||||
|
|
||||||
abstract fun stopBackend(tunnel: TunnelConf)
|
abstract fun stopBackend(tunnel: TunnelConf)
|
||||||
|
|
||||||
override suspend fun clearError(tunnelConf: TunnelConf) =
|
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
|
||||||
|
|
||||||
override fun hasVpnPermission(): Boolean {
|
override fun hasVpnPermission(): Boolean {
|
||||||
return serviceManager.hasVpnPermission()
|
return serviceManager.hasVpnPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected suspend fun updateTunnelStatus(
|
protected suspend fun updateTunnelStatus(
|
||||||
tunnelConf: TunnelConf,
|
tunnelConf: TunnelConf,
|
||||||
state: TunnelStatus? = null,
|
status: TunnelStatus? = null,
|
||||||
stats: TunnelStatistics? = null,
|
stats: TunnelStatistics? = null,
|
||||||
) {
|
) {
|
||||||
tunStatusMutex.withLock {
|
tunStatusMutex.withLock {
|
||||||
activeTuns.update { current ->
|
activeTuns.update { currentTuns ->
|
||||||
val originalConf = current.getKeyById(tunnelConf.id) ?: tunnelConf
|
val originalConf = currentTuns.getKeyById(tunnelConf.id) ?: tunnelConf
|
||||||
val existingState = current.getValueById(tunnelConf.id) ?: TunnelState()
|
val existingState = currentTuns.getValueById(tunnelConf.id) ?: TunnelState()
|
||||||
val newState = state ?: existingState.status
|
val newState = status ?: existingState.status
|
||||||
if (newState == TunnelStatus.Down) {
|
if (newState == TunnelStatus.Down) {
|
||||||
Timber.d("Removing tunnel ${tunnelConf.id} from activeTunnels as state is DOWN")
|
Timber.d("Removing tunnel ${tunnelConf.id} from activeTunnels as state is DOWN")
|
||||||
cleanUpTunThread(tunnelConf)
|
cleanUpTunThread(tunnelConf)
|
||||||
current - originalConf
|
currentTuns - originalConf
|
||||||
} else if (existingState.status == newState && stats == null) {
|
} else if (existingState.status == newState && stats == null) {
|
||||||
Timber.d("Skipping redundant state update for ${tunnelConf.id}: $newState")
|
Timber.d("Skipping redundant state update for ${tunnelConf.id}: $newState")
|
||||||
current
|
currentTuns
|
||||||
} else {
|
} else {
|
||||||
val updated =
|
val updated =
|
||||||
existingState.copy(
|
existingState.copy(
|
||||||
status = newState,
|
status = newState,
|
||||||
statistics = stats ?: existingState.statistics,
|
statistics = stats ?: existingState.statistics,
|
||||||
)
|
)
|
||||||
current + (originalConf to updated)
|
currentTuns + (originalConf to updated)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,23 +114,17 @@ abstract class BaseTunnel(
|
|||||||
if (this@BaseTunnel is UserspaceTunnel) stopActiveTunnels()
|
if (this@BaseTunnel is UserspaceTunnel) stopActiveTunnels()
|
||||||
tunMutex.withLock {
|
tunMutex.withLock {
|
||||||
tunThreads[tunnelConf.id] = thread {
|
tunThreads[tunnelConf.id] = thread {
|
||||||
runCatching {
|
runBlocking {
|
||||||
runBlocking {
|
try {
|
||||||
try {
|
Timber.d("Starting tunnel ${tunnelConf.id}...")
|
||||||
Timber.d("Starting tunnel ${tunnelConf.id}...")
|
startTunnelInner(tunnelConf)
|
||||||
startTunnelInner(tunnelConf)
|
Timber.d("Started complete for tunnel ${tunnelConf.name}...")
|
||||||
Timber.d("Started complete for tunnel ${tunnelConf.name}...")
|
} catch (e: InterruptedException) {
|
||||||
} catch (e: BackendError) {
|
Timber.w(
|
||||||
Timber.e(e, "Failed to start tunnel ${tunnelConf.name} userspace")
|
"Tunnel start has been interrupted as ${tunnelConf.name} failed to start"
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Error(e))
|
)
|
||||||
} catch (e: InterruptedException) {
|
|
||||||
Timber.w(
|
|
||||||
"Tunnel start has been interrupted as ${tunnelConf.name} failed to start"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.onFailure { Timber.w("Tunnel start has been interrupted") }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,11 +138,10 @@ abstract class BaseTunnel(
|
|||||||
Timber.d("Started for tun ${tunnelConf.id}...")
|
Timber.d("Started for tun ${tunnelConf.id}...")
|
||||||
saveTunnelActiveState(tunnelConf, true)
|
saveTunnelActiveState(tunnelConf, true)
|
||||||
serviceManager.startTunnelForegroundService()
|
serviceManager.startTunnelForegroundService()
|
||||||
} catch (e: BackendException) {
|
} catch (e: BackendError) {
|
||||||
Timber.e(e, "Failed to start backend for ${tunnelConf.name}")
|
Timber.e(e, "Failed to start backend for ${tunnelConf.name}")
|
||||||
val backendError = e.toBackendError()
|
_errorEvents.emit(tunnelConf to e)
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Error(backendError))
|
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
||||||
throw backendError
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,26 +153,27 @@ abstract class BaseTunnel(
|
|||||||
override suspend fun stopTunnel(tunnelConf: TunnelConf?, reason: TunnelStatus.StopReason) {
|
override suspend fun stopTunnel(tunnelConf: TunnelConf?, reason: TunnelStatus.StopReason) {
|
||||||
if (tunnelConf == null) return stopActiveTunnels()
|
if (tunnelConf == null) return stopActiveTunnels()
|
||||||
tunMutex.withLock {
|
tunMutex.withLock {
|
||||||
try {
|
if (activeTuns.isStarting(tunnelConf.id))
|
||||||
if (activeTuns.isStarting(tunnelConf.id))
|
return handleStuckStartingTunnelShutdown(tunnelConf)
|
||||||
return handleStuckStartingTunnelShutdown(tunnelConf)
|
updateTunnelStatus(tunnelConf, TunnelStatus.Stopping(reason))
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Stopping(reason))
|
stopTunnelInner(tunnelConf)
|
||||||
stopTunnelInner(tunnelConf)
|
|
||||||
} catch (e: BackendError) {
|
|
||||||
Timber.e(e, "Failed to stop tunnel ${tunnelConf.id}")
|
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Error(e))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun stopTunnelInner(tunnelConf: TunnelConf) {
|
private suspend fun stopTunnelInner(tunnelConf: TunnelConf) {
|
||||||
val tunnel = activeTuns.findTunnel(tunnelConf.id) ?: return
|
try {
|
||||||
stopBackend(tunnel)
|
val tunnel = activeTuns.findTunnel(tunnelConf.id) ?: return
|
||||||
saveTunnelActiveState(tunnelConf, false)
|
stopBackend(tunnel)
|
||||||
removeActiveTunnel(tunnel)
|
saveTunnelActiveState(tunnelConf, false)
|
||||||
|
removeActiveTunnel(tunnel)
|
||||||
|
} catch (e: BackendError) {
|
||||||
|
Timber.e(e, "Failed to stop tunnel ${tunnelConf.id}")
|
||||||
|
_errorEvents.emit(tunnelConf to e)
|
||||||
|
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun handleServiceStateOnChange() {
|
private fun handleServiceStateOnChange() {
|
||||||
if (activeTuns.value.isEmpty() && bouncingTunnelIds.isEmpty())
|
if (activeTuns.value.isEmpty() && bouncingTunnelIds.isEmpty())
|
||||||
serviceManager.stopTunnelForegroundService()
|
serviceManager.stopTunnelForegroundService()
|
||||||
}
|
}
|
||||||
@@ -193,15 +184,15 @@ abstract class BaseTunnel(
|
|||||||
tunThreads[tunnel.id]?.let {
|
tunThreads[tunnel.id]?.let {
|
||||||
if (it.state != Thread.State.TERMINATED) {
|
if (it.state != Thread.State.TERMINATED) {
|
||||||
it.interrupt()
|
it.interrupt()
|
||||||
updateTunnelStatus(tunnel, TunnelStatus.Down)
|
|
||||||
} else {
|
} else {
|
||||||
Timber.d("Thread already terminated")
|
Timber.d("Thread already terminated")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "Failed to stop tunnel thread for ${tunnel.name}")
|
Timber.e(e, "Failed to stop tunnel thread for ${tunnel.name}")
|
||||||
|
} finally {
|
||||||
|
updateTunnelStatus(tunnel, TunnelStatus.Down)
|
||||||
}
|
}
|
||||||
cleanUpTunThread(tunnel)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cleanUpTunThread(tunnel: TunnelConf) {
|
private fun cleanUpTunThread(tunnel: TunnelConf) {
|
||||||
@@ -221,7 +212,7 @@ abstract class BaseTunnel(
|
|||||||
bouncingTunnelIds[tunnelConf.id] = reason
|
bouncingTunnelIds[tunnelConf.id] = reason
|
||||||
try {
|
try {
|
||||||
stopTunnel(tunnelConf, reason)
|
stopTunnel(tunnelConf, reason)
|
||||||
delay(300L)
|
delay(BOUNCE_DELAY)
|
||||||
startTunnel(tunnelConf)
|
startTunnel(tunnelConf)
|
||||||
} finally {
|
} finally {
|
||||||
bouncingTunnelIds.remove(tunnelConf.id)
|
bouncingTunnelIds.remove(tunnelConf.id)
|
||||||
@@ -235,4 +226,8 @@ abstract class BaseTunnel(
|
|||||||
|
|
||||||
override suspend fun runningTunnelNames(): Set<String> =
|
override suspend fun runningTunnelNames(): Set<String> =
|
||||||
activeTuns.value.keys.map { it.tunName }.toSet()
|
activeTuns.value.keys.map { it.tunName }.toSet()
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val BOUNCE_DELAY = 300L
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|||||||
import com.zaneschepke.wireguardautotunnel.di.Kernel
|
import com.zaneschepke.wireguardautotunnel.di.Kernel
|
||||||
import com.zaneschepke.wireguardautotunnel.di.Userspace
|
import com.zaneschepke.wireguardautotunnel.di.Userspace
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendError
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
@@ -15,6 +16,7 @@ import kotlinx.coroutines.CoroutineDispatcher
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.filterNotNull
|
import kotlinx.coroutines.flow.filterNotNull
|
||||||
import kotlinx.coroutines.flow.flatMapLatest
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
@@ -62,6 +64,9 @@ constructor(
|
|||||||
initialValue = emptyMap(),
|
initialValue = emptyMap(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
override val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
||||||
|
get() = tunnelProviderFlow.value.errorEvents
|
||||||
|
|
||||||
override val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason> =
|
override val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason> =
|
||||||
tunnelProviderFlow.value.bouncingTunnelIds
|
tunnelProviderFlow.value.bouncingTunnelIds
|
||||||
|
|
||||||
@@ -69,10 +74,6 @@ constructor(
|
|||||||
return userspaceTunnel.hasVpnPermission()
|
return userspaceTunnel.hasVpnPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun clearError(tunnelConf: TunnelConf) {
|
|
||||||
tunnelProviderFlow.value.clearError(tunnelConf)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun updateTunnelStatistics(tunnel: TunnelConf) {
|
override suspend fun updateTunnelStatistics(tunnel: TunnelConf) {
|
||||||
tunnelProviderFlow.value.updateTunnelStatistics(tunnel)
|
tunnelProviderFlow.value.updateTunnelStatistics(tunnel)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendError
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
|
||||||
interface TunnelProvider {
|
interface TunnelProvider {
|
||||||
@@ -46,11 +48,11 @@ interface TunnelProvider {
|
|||||||
|
|
||||||
val activeTunnels: StateFlow<Map<TunnelConf, TunnelState>>
|
val activeTunnels: StateFlow<Map<TunnelConf, TunnelState>>
|
||||||
|
|
||||||
|
val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
||||||
|
|
||||||
val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason>
|
val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason>
|
||||||
|
|
||||||
fun hasVpnPermission(): Boolean
|
fun hasVpnPermission(): Boolean
|
||||||
|
|
||||||
suspend fun clearError(tunnelConf: TunnelConf)
|
|
||||||
|
|
||||||
suspend fun updateTunnelStatistics(tunnel: TunnelConf)
|
suspend fun updateTunnelStatistics(tunnel: TunnelConf)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -50,8 +50,9 @@ constructor(
|
|||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
Timber.e(e, "Failed to stop tunnel ${tunnel.id}")
|
Timber.e(e, "Failed to stop tunnel ${tunnel.id}")
|
||||||
throw e.toBackendError()
|
throw e.toBackendError()
|
||||||
|
} finally {
|
||||||
|
handlePreviouslyEnabledVpnKillSwitch()
|
||||||
}
|
}
|
||||||
handlePreviouslyEnabledVpnKillSwitch()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop vpn kill switch if we need to resolve DNS for peer endpoints
|
// stop vpn kill switch if we need to resolve DNS for peer endpoints
|
||||||
@@ -69,7 +70,7 @@ constructor(
|
|||||||
// restore vpn kill switch if needed
|
// restore vpn kill switch if needed
|
||||||
private fun handlePreviouslyEnabledVpnKillSwitch() {
|
private fun handlePreviouslyEnabledVpnKillSwitch() {
|
||||||
// let auto tunnel handle this if it is active
|
// let auto tunnel handle this if it is active
|
||||||
if (!serviceManager.autoTunnelActive.value) {
|
if (serviceManager.autoTunnelService.value == null) {
|
||||||
previousBackendState?.let { (state, lanEnabled) ->
|
previousBackendState?.let { (state, lanEnabled) ->
|
||||||
Timber.d("Restoring kill switch configuration")
|
Timber.d("Restoring kill switch configuration")
|
||||||
val lan = if (lanEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS else emptyList()
|
val lan = if (lanEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS else emptyList()
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ constructor(
|
|||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
Timber.i("Service worker started")
|
Timber.i("Service worker started")
|
||||||
with(appDataRepository.settings.get()) {
|
with(appDataRepository.settings.get()) {
|
||||||
if (isAutoTunnelEnabled && !serviceManager.autoTunnelActive.value)
|
if (isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null)
|
||||||
return@with serviceManager.startAutoTunnel()
|
return@with serviceManager.startAutoTunnel()
|
||||||
if (tunnelManager.activeTunnels.value.isEmpty())
|
if (tunnelManager.activeTunnels.value.isEmpty())
|
||||||
tunnelManager.restorePreviousState()
|
tunnelManager.restorePreviousState()
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class DataStoreManager(
|
|||||||
val locationDisclosureShown = booleanPreferencesKey("LOCATION_DISCLOSURE_SHOWN")
|
val locationDisclosureShown = booleanPreferencesKey("LOCATION_DISCLOSURE_SHOWN")
|
||||||
val batteryDisableShown = booleanPreferencesKey("BATTERY_OPTIMIZE_DISABLE_SHOWN")
|
val batteryDisableShown = booleanPreferencesKey("BATTERY_OPTIMIZE_DISABLE_SHOWN")
|
||||||
val pinLockEnabled = booleanPreferencesKey("PIN_LOCK_ENABLED")
|
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 isLocalLogsEnabled = booleanPreferencesKey("LOCAL_LOGS_ENABLED")
|
||||||
val locale = stringPreferencesKey("LOCALE")
|
val locale = stringPreferencesKey("LOCALE")
|
||||||
val theme = stringPreferencesKey("THEME")
|
val theme = stringPreferencesKey("THEME")
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import timber.log.Timber
|
|||||||
class DatabaseCallback : RoomDatabase.Callback() {
|
class DatabaseCallback : RoomDatabase.Callback() {
|
||||||
override fun onCreate(db: SupportSQLiteDatabase) =
|
override fun onCreate(db: SupportSQLiteDatabase) =
|
||||||
db.run {
|
db.run {
|
||||||
// Notice non-ui thread is here
|
|
||||||
beginTransaction()
|
beginTransaction()
|
||||||
try {
|
try {
|
||||||
execSQL(Queries.createDefaultSettings())
|
execSQL(Queries.createDefaultSettings())
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data.model
|
||||||
|
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class Asset(
|
||||||
|
val name: String,
|
||||||
|
@SerialName("browser_download_url") val browserDownloadUrl: String,
|
||||||
|
)
|
||||||
@@ -7,7 +7,7 @@ data class GeneralState(
|
|||||||
val isLocationDisclosureShown: Boolean = LOCATION_DISCLOSURE_SHOWN_DEFAULT,
|
val isLocationDisclosureShown: Boolean = LOCATION_DISCLOSURE_SHOWN_DEFAULT,
|
||||||
val isBatteryOptimizationDisableShown: Boolean = BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT,
|
val isBatteryOptimizationDisableShown: Boolean = BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT,
|
||||||
val isPinLockEnabled: Boolean = PIN_LOCK_ENABLED_DEFAULT,
|
val isPinLockEnabled: Boolean = PIN_LOCK_ENABLED_DEFAULT,
|
||||||
val isTunnelStatsExpanded: Boolean = IS_TUNNEL_STATS_EXPANDED,
|
val expandedTunnelIds: List<Int> = emptyList(),
|
||||||
val isLocalLogsEnabled: Boolean = IS_LOGS_ENABLED_DEFAULT,
|
val isLocalLogsEnabled: Boolean = IS_LOGS_ENABLED_DEFAULT,
|
||||||
val isRemoteControlEnabled: Boolean = IS_REMOTE_CONTROL_ENABLED,
|
val isRemoteControlEnabled: Boolean = IS_REMOTE_CONTROL_ENABLED,
|
||||||
val remoteKey: String? = null,
|
val remoteKey: String? = null,
|
||||||
@@ -20,7 +20,7 @@ data class GeneralState(
|
|||||||
isLocationDisclosureShown,
|
isLocationDisclosureShown,
|
||||||
isBatteryOptimizationDisableShown,
|
isBatteryOptimizationDisableShown,
|
||||||
isPinLockEnabled,
|
isPinLockEnabled,
|
||||||
isTunnelStatsExpanded,
|
expandedTunnelIds,
|
||||||
isLocalLogsEnabled,
|
isLocalLogsEnabled,
|
||||||
isRemoteControlEnabled,
|
isRemoteControlEnabled,
|
||||||
remoteKey,
|
remoteKey,
|
||||||
@@ -35,7 +35,7 @@ data class GeneralState(
|
|||||||
isLocationDisclosureShown,
|
isLocationDisclosureShown,
|
||||||
isBatteryOptimizationDisableShown,
|
isBatteryOptimizationDisableShown,
|
||||||
isPinLockEnabled,
|
isPinLockEnabled,
|
||||||
isTunnelStatsExpanded,
|
expandedTunnelIds,
|
||||||
isLocalLogsEnabled,
|
isLocalLogsEnabled,
|
||||||
isRemoteControlEnabled,
|
isRemoteControlEnabled,
|
||||||
remoteKey,
|
remoteKey,
|
||||||
@@ -48,7 +48,6 @@ data class GeneralState(
|
|||||||
const val LOCATION_DISCLOSURE_SHOWN_DEFAULT = false
|
const val LOCATION_DISCLOSURE_SHOWN_DEFAULT = false
|
||||||
const val BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT = false
|
const val BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT = false
|
||||||
const val PIN_LOCK_ENABLED_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_LOGS_ENABLED_DEFAULT = false
|
||||||
const val IS_REMOTE_CONTROL_ENABLED = false
|
const val IS_REMOTE_CONTROL_ENABLED = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data.model
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.entity.AppUpdate
|
||||||
|
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>,
|
||||||
|
) {
|
||||||
|
fun toAppUpdate(): AppUpdate {
|
||||||
|
val apkAsset = assets.firstOrNull { it.name.endsWith(".apk") }
|
||||||
|
return AppUpdate(
|
||||||
|
version = tagName.removePrefix("v"),
|
||||||
|
title = name ?: "Update $tagName",
|
||||||
|
releaseNotes = body ?: "No release notes provided",
|
||||||
|
apkUrl = apkAsset?.browserDownloadUrl,
|
||||||
|
apkFileName = apkAsset?.name,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data.network
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.model.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.model.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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+32
-8
@@ -38,13 +38,36 @@ class DataStoreAppStateRepository(private val dataStoreManager: DataStoreManager
|
|||||||
dataStoreManager.saveToDataStore(DataStoreManager.batteryDisableShown, shown)
|
dataStoreManager.saveToDataStore(DataStoreManager.batteryDisableShown, shown)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun isTunnelStatsExpanded(): Boolean {
|
override suspend fun setTunnelExpanded(id: Int) {
|
||||||
return dataStoreManager.getFromStore(DataStoreManager.tunnelStatsExpanded)
|
val ids =
|
||||||
?: GeneralState.IS_TUNNEL_STATS_EXPANDED
|
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) {
|
override suspend fun removeTunnelExpanded(id: Int) {
|
||||||
dataStoreManager.saveToDataStore(DataStoreManager.tunnelStatsExpanded, expanded)
|
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) {
|
override suspend fun setTheme(theme: Theme) {
|
||||||
@@ -110,9 +133,10 @@ class DataStoreAppStateRepository(private val dataStoreManager: DataStoreManager
|
|||||||
isPinLockEnabled =
|
isPinLockEnabled =
|
||||||
pref[DataStoreManager.pinLockEnabled]
|
pref[DataStoreManager.pinLockEnabled]
|
||||||
?: GeneralState.PIN_LOCK_ENABLED_DEFAULT,
|
?: GeneralState.PIN_LOCK_ENABLED_DEFAULT,
|
||||||
isTunnelStatsExpanded =
|
expandedTunnelIds =
|
||||||
pref[DataStoreManager.tunnelStatsExpanded]
|
pref[DataStoreManager.expandedTunnelIds]?.split(",")?.mapNotNull {
|
||||||
?: GeneralState.IS_TUNNEL_STATS_EXPANDED,
|
it.toIntOrNull()
|
||||||
|
} ?: emptyList(),
|
||||||
isLocalLogsEnabled =
|
isLocalLogsEnabled =
|
||||||
pref[DataStoreManager.isLocalLogsEnabled]
|
pref[DataStoreManager.isLocalLogsEnabled]
|
||||||
?: GeneralState.IS_LOGS_ENABLED_DEFAULT,
|
?: GeneralState.IS_LOGS_ENABLED_DEFAULT,
|
||||||
|
|||||||
+98
@@ -0,0 +1,98 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
||||||
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.entity.AppUpdate
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.UpdateRepository
|
||||||
|
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 release =
|
||||||
|
if (BuildConfig.VERSION_NAME.contains("nightly")) {
|
||||||
|
gitHubApi.getNightlyRelease(githubOwner, githubRepo)
|
||||||
|
} else {
|
||||||
|
gitHubApi.getLatestRelease(githubOwner, githubRepo)
|
||||||
|
}
|
||||||
|
release.map { release ->
|
||||||
|
val apkAsset =
|
||||||
|
release.assets.find { asset ->
|
||||||
|
asset.name.startsWith("wgtunnel-full-v") && asset.name.endsWith(".apk")
|
||||||
|
}
|
||||||
|
val newVersion =
|
||||||
|
apkAsset?.name?.removePrefix("wgtunnel-full-v")?.removeSuffix(".apk")
|
||||||
|
?: return@map null
|
||||||
|
|
||||||
|
Timber.i("Latest version: $newVersion, current version: $currentVersion")
|
||||||
|
if (NumberUtils.compareVersions(newVersion, currentVersion) > 0) {
|
||||||
|
release.toAppUpdate()
|
||||||
|
} 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,19 +8,25 @@ import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
|||||||
import com.zaneschepke.wireguardautotunnel.data.DatabaseCallback
|
import com.zaneschepke.wireguardautotunnel.data.DatabaseCallback
|
||||||
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
||||||
import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
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.AppDataRoomRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.DataStoreAppStateRepository
|
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.RoomSettingsRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.RoomTunnelRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.RoomTunnelRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.UpdateRepository
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import io.ktor.client.HttpClient
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
|
||||||
@@ -35,7 +41,7 @@ class RepositoryModule {
|
|||||||
AppDatabase::class.java,
|
AppDatabase::class.java,
|
||||||
context.getString(R.string.db_name),
|
context.getString(R.string.db_name),
|
||||||
)
|
)
|
||||||
.fallbackToDestructiveMigration()
|
.fallbackToDestructiveMigration(true)
|
||||||
.addCallback(DatabaseCallback())
|
.addCallback(DatabaseCallback())
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
@@ -94,4 +100,34 @@ class RepositoryModule {
|
|||||||
): AppDataRepository {
|
): AppDataRepository {
|
||||||
return AppDataRoomRepository(settingsRepository, tunnelRepository, appStateRepository)
|
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,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ data class AppState(
|
|||||||
val isLocationDisclosureShown: Boolean,
|
val isLocationDisclosureShown: Boolean,
|
||||||
val isBatteryOptimizationDisableShown: Boolean,
|
val isBatteryOptimizationDisableShown: Boolean,
|
||||||
val isPinLockEnabled: Boolean,
|
val isPinLockEnabled: Boolean,
|
||||||
val isTunnelStatsExpanded: Boolean,
|
val expandedTunnelIds: List<Int>,
|
||||||
val isLocalLogsEnabled: Boolean,
|
val isLocalLogsEnabled: Boolean,
|
||||||
val isRemoteControlEnabled: Boolean,
|
val isRemoteControlEnabled: Boolean,
|
||||||
val remoteKey: String?,
|
val remoteKey: String?,
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.domain.entity
|
||||||
|
|
||||||
|
data class AppUpdate(
|
||||||
|
val version: String,
|
||||||
|
val title: String,
|
||||||
|
val releaseNotes: String,
|
||||||
|
val apkUrl: String?,
|
||||||
|
val apkFileName: String?,
|
||||||
|
)
|
||||||
@@ -4,12 +4,12 @@ import com.wireguard.android.backend.Tunnel
|
|||||||
import com.wireguard.config.Config
|
import com.wireguard.config.Config
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.*
|
import com.zaneschepke.wireguardautotunnel.util.extensions.*
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import timber.log.Timber
|
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
data class TunnelConf(
|
data class TunnelConf(
|
||||||
val id: Int = 0,
|
val id: Int = 0,
|
||||||
@@ -26,7 +26,6 @@ data class TunnelConf(
|
|||||||
val pingIp: String? = null,
|
val pingIp: String? = null,
|
||||||
val isEthernetTunnel: Boolean = false,
|
val isEthernetTunnel: Boolean = false,
|
||||||
val isIpv4Preferred: Boolean = true,
|
val isIpv4Preferred: Boolean = true,
|
||||||
val useCache: Boolean = false,
|
|
||||||
@Transient private var stateChangeCallback: ((Any) -> Unit)? = null,
|
@Transient private var stateChangeCallback: ((Any) -> Unit)? = null,
|
||||||
) : Tunnel, org.amnezia.awg.backend.Tunnel {
|
) : Tunnel, org.amnezia.awg.backend.Tunnel {
|
||||||
|
|
||||||
@@ -60,6 +59,10 @@ data class TunnelConf(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isStaticallyConfigured(): Boolean {
|
||||||
|
return toAmConfig().peers.all { it.endpoint.get().host.isValidIpv4orIpv6Address() }
|
||||||
|
}
|
||||||
|
|
||||||
fun copyWithCallback(
|
fun copyWithCallback(
|
||||||
id: Int = this.id,
|
id: Int = this.id,
|
||||||
tunName: String = this.tunName,
|
tunName: String = this.tunName,
|
||||||
@@ -92,9 +95,7 @@ data class TunnelConf(
|
|||||||
isEthernetTunnel,
|
isEthernetTunnel,
|
||||||
isIpv4Preferred,
|
isIpv4Preferred,
|
||||||
)
|
)
|
||||||
.apply {
|
.apply { stateChangeCallback = this@TunnelConf.stateChangeCallback }
|
||||||
stateChangeCallback = this@TunnelConf.stateChangeCallback
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toAmConfig(): org.amnezia.awg.config.Config {
|
fun toAmConfig(): org.amnezia.awg.config.Config {
|
||||||
@@ -109,8 +110,6 @@ data class TunnelConf(
|
|||||||
|
|
||||||
override fun isIpv4ResolutionPreferred(): Boolean = isIpv4Preferred
|
override fun isIpv4ResolutionPreferred(): Boolean = isIpv4Preferred
|
||||||
|
|
||||||
override fun useCache(): Boolean = useCache
|
|
||||||
|
|
||||||
override fun onStateChange(newState: org.amnezia.awg.backend.Tunnel.State) {
|
override fun onStateChange(newState: org.amnezia.awg.backend.Tunnel.State) {
|
||||||
stateChangeCallback?.invoke(newState)
|
stateChangeCallback?.invoke(newState)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.enums
|
package com.zaneschepke.wireguardautotunnel.domain.enums
|
||||||
|
|
||||||
enum class ConfigType {
|
enum class ConfigType {
|
||||||
AMNEZIA,
|
AM,
|
||||||
WG,
|
WG,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.enums
|
package com.zaneschepke.wireguardautotunnel.domain.enums
|
||||||
|
|
||||||
sealed class TunnelStatus {
|
sealed class TunnelStatus {
|
||||||
data class Error(val error: BackendError) : TunnelStatus()
|
|
||||||
|
|
||||||
data object Up : TunnelStatus()
|
data object Up : TunnelStatus()
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -17,9 +17,9 @@ interface AppStateRepository {
|
|||||||
|
|
||||||
suspend fun setBatteryOptimizationDisableShown(shown: Boolean)
|
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)
|
suspend fun setTheme(theme: Theme)
|
||||||
|
|
||||||
|
|||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.entity.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,
|
rxBytes = stats.rxBytes,
|
||||||
txBytes = stats.txBytes,
|
txBytes = stats.txBytes,
|
||||||
latestHandshakeEpochMillis = stats.latestHandshakeEpochMillis,
|
latestHandshakeEpochMillis = stats.latestHandshakeEpochMillis,
|
||||||
|
resolvedEndpoint = stats.resolvedEndpoint,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ abstract class TunnelStatistics {
|
|||||||
val rxBytes: Long,
|
val rxBytes: Long,
|
||||||
val txBytes: Long,
|
val txBytes: Long,
|
||||||
val latestHandshakeEpochMillis: Long,
|
val latestHandshakeEpochMillis: Long,
|
||||||
|
val resolvedEndpoint: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
abstract fun peerStats(peer: Key): PeerStats?
|
abstract fun peerStats(peer: Key): PeerStats?
|
||||||
|
|||||||
+1
@@ -12,6 +12,7 @@ class WireGuardStatistics(private val statistics: Statistics) : TunnelStatistics
|
|||||||
txBytes = peerStats.txBytes,
|
txBytes = peerStats.txBytes,
|
||||||
rxBytes = peerStats.rxBytes,
|
rxBytes = peerStats.rxBytes,
|
||||||
latestHandshakeEpochMillis = peerStats.latestHandshakeEpochMillis,
|
latestHandshakeEpochMillis = peerStats.latestHandshakeEpochMillis,
|
||||||
|
resolvedEndpoint = peerStats.resolvedEndpoint,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ sealed class Route {
|
|||||||
|
|
||||||
@Serializable data object Lock : Route()
|
@Serializable data object Lock : Route()
|
||||||
|
|
||||||
@Serializable data object Scanner : Route()
|
@Serializable data object License : Route()
|
||||||
|
|
||||||
@Serializable data class Config(val id: Int) : 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.animation.animateContentSize
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.combinedClickable
|
import androidx.compose.foundation.combinedClickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.indication
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.ripple
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.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.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ExpandingRowListItem(
|
fun ExpandingRowListItem(
|
||||||
leading: @Composable () -> Unit,
|
leading: @Composable () -> Unit,
|
||||||
text: String,
|
text: String,
|
||||||
onHold: () -> Unit = {},
|
onHold: () -> Unit,
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
|
onDoubleClick: () -> Unit,
|
||||||
trailing: @Composable () -> Unit,
|
trailing: @Composable () -> Unit,
|
||||||
isExpanded: Boolean,
|
isSelected: Boolean,
|
||||||
expanded: @Composable () -> Unit = {},
|
expanded: (@Composable () -> Unit)?,
|
||||||
) {
|
) {
|
||||||
|
val isTv = LocalIsAndroidTV.current
|
||||||
|
val haptic = LocalHapticFeedback.current
|
||||||
|
val interactionSource = remember { MutableInteractionSource() }
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.animateContentSize()
|
Modifier.animateContentSize()
|
||||||
.clip(RoundedCornerShape(8.dp))
|
.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 {
|
Column {
|
||||||
Row(
|
Row(
|
||||||
@@ -58,7 +84,7 @@ fun ExpandingRowListItem(
|
|||||||
}
|
}
|
||||||
trailing()
|
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),
|
||||||
|
)
|
||||||
|
}
|
||||||
+19
-15
@@ -3,21 +3,25 @@ package com.zaneschepke.wireguardautotunnel.ui.common.button.surface
|
|||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.Modifier
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SelectionItemLabel(
|
fun SelectionItemLabel(text: String, labelType: SelectionLabelType, modifier: Modifier = Modifier) {
|
||||||
textResId: Int,
|
|
||||||
style: androidx.compose.ui.text.TextStyle = MaterialTheme.typography.bodyMedium,
|
val style =
|
||||||
isDescription: Boolean = false,
|
when (labelType) {
|
||||||
) {
|
SelectionLabelType.DESCRIPTION ->
|
||||||
Text(
|
MaterialTheme.typography.bodySmall.copy(color = MaterialTheme.colorScheme.outline)
|
||||||
text = stringResource(textResId),
|
SelectionLabelType.TITLE ->
|
||||||
style =
|
MaterialTheme.typography.bodyMedium.copy(
|
||||||
style.copy(
|
color = MaterialTheme.colorScheme.onSurface
|
||||||
color =
|
)
|
||||||
if (isDescription) MaterialTheme.colorScheme.outline
|
}
|
||||||
else 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.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
import timber.log.Timber
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun rememberFileImportLauncherForResult(
|
fun rememberFileImportLauncherForResult(
|
||||||
onNoFileExplorer: () -> Unit,
|
onNoFileExplorer: () -> Unit,
|
||||||
onData: (data: Uri) -> Unit,
|
onData: (data: Uri) -> Unit,
|
||||||
): ManagedActivityResultLauncher<String, Uri?> {
|
): ManagedActivityResultLauncher<String, Uri?> {
|
||||||
|
val isTv = LocalIsAndroidTV.current
|
||||||
return rememberLauncherForActivityResult(
|
return rememberLauncherForActivityResult(
|
||||||
object : ActivityResultContracts.GetContent() {
|
object : ActivityResultContracts.GetContent() {
|
||||||
override fun createIntent(context: Context, input: String): Intent {
|
override fun createIntent(context: Context, input: String): Intent {
|
||||||
val intent =
|
val intent =
|
||||||
super.createIntent(context, input).apply {
|
super.createIntent(context, input).apply {
|
||||||
type =
|
type =
|
||||||
if (context.isRunningOnTv()) {
|
if (isTv) {
|
||||||
Constants.ALLOWED_TV_FILE_TYPES
|
Constants.ALLOWED_TV_FILE_TYPES
|
||||||
} else {
|
} else {
|
||||||
Constants.ALL_FILE_TYPES
|
Constants.ALL_FILE_TYPES
|
||||||
@@ -63,3 +65,43 @@ fun rememberFileImportLauncherForResult(
|
|||||||
onData(data)
|
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.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||||
import androidx.compose.ui.unit.LayoutDirection
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CustomSnackBar(
|
fun CustomSnackBar(
|
||||||
@@ -31,12 +30,10 @@ fun CustomSnackBar(
|
|||||||
isRtl: Boolean = true,
|
isRtl: Boolean = true,
|
||||||
containerColor: Color = MaterialTheme.colorScheme.surface,
|
containerColor: Color = MaterialTheme.colorScheme.surface,
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val isTv = LocalIsAndroidTV.current
|
||||||
Snackbar(
|
Snackbar(
|
||||||
containerColor = containerColor,
|
containerColor = containerColor,
|
||||||
modifier =
|
modifier = Modifier.fillMaxWidth(if (isTv) 1 / 3f else 2 / 3f).padding(bottom = 100.dp),
|
||||||
Modifier.fillMaxWidth(if (context.isRunningOnTv()) 1 / 3f else 2 / 3f)
|
|
||||||
.padding(bottom = 100.dp),
|
|
||||||
shape = RoundedCornerShape(16.dp),
|
shape = RoundedCornerShape(16.dp),
|
||||||
) {
|
) {
|
||||||
CompositionLocalProvider(
|
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 androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
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 android.annotation.SuppressLint
|
||||||
|
import androidx.compose.runtime.compositionLocalOf
|
||||||
|
import androidx.compose.runtime.staticCompositionLocalOf
|
||||||
import androidx.navigation.NavBackStackEntry
|
import androidx.navigation.NavBackStackEntry
|
||||||
import androidx.navigation.NavDestination.Companion.hasRoute
|
import androidx.navigation.NavDestination.Companion.hasRoute
|
||||||
import androidx.navigation.NavDestination.Companion.hierarchy
|
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||||
|
import androidx.navigation.NavHostController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
@@ -11,3 +14,7 @@ import kotlin.reflect.KClass
|
|||||||
fun <T : Route> NavBackStackEntry?.isCurrentRoute(cls: KClass<T>): Boolean {
|
fun <T : Route> NavBackStackEntry?.isCurrentRoute(cls: KClass<T>): Boolean {
|
||||||
return this?.destination?.hierarchy?.any { it.hasRoute(route = cls) } == true
|
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.*
|
||||||
import androidx.compose.animation.fadeIn
|
|
||||||
import androidx.compose.animation.fadeOut
|
|
||||||
import androidx.compose.animation.slideInVertically
|
|
||||||
import androidx.compose.animation.slideOutVertically
|
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
@@ -14,6 +10,7 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.state.NavBarState
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
+189
-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.foundation.layout.size
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.rounded.Add
|
import androidx.compose.material.icons.rounded.*
|
||||||
import androidx.compose.material.icons.rounded.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.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@@ -15,80 +12,126 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.State
|
import androidx.compose.runtime.State
|
||||||
import androidx.compose.runtime.produceState
|
import androidx.compose.runtime.produceState
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.navigation.NavBackStackEntry
|
import androidx.navigation.NavBackStackEntry
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.toRoute
|
import androidx.navigation.toRoute
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.isCurrentRoute
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
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.Brick
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.SilverTree
|
import com.zaneschepke.wireguardautotunnel.ui.theme.SilverTree
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
|
|
||||||
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
|
@Composable
|
||||||
fun currentNavBackStackEntryAsNavBarState(
|
fun currentNavBackStackEntryAsNavBarState(
|
||||||
navController: NavController,
|
navController: NavController,
|
||||||
backStackEntry: NavBackStackEntry?,
|
backStackEntry: NavBackStackEntry?,
|
||||||
viewModel: AppViewModel,
|
viewModel: AppViewModel,
|
||||||
uiState: AppUiState,
|
uiState: AppUiState,
|
||||||
|
appViewState: AppViewState,
|
||||||
): State<NavBarState> {
|
): 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 =
|
value =
|
||||||
when {
|
when {
|
||||||
backStackEntry.isCurrentRoute(Route.Main::class) -> {
|
backStackEntry.isCurrentRoute(Route.Main::class) -> {
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
showTop = true,
|
||||||
showBottom = true,
|
showBottom = true,
|
||||||
{ Text(stringResource(R.string.tunnels)) },
|
topTitle = { Text(stringResource(R.string.tunnels)) },
|
||||||
{
|
topTrailing = { TunnelActionBar() },
|
||||||
IconButton(
|
|
||||||
onClick = { viewModel.handleEvent(AppEvent.ToggleBottomSheet) }
|
|
||||||
) {
|
|
||||||
val icon = Icons.Rounded.Add
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
stringResource(R.string.add_tunnel),
|
|
||||||
modifier = Modifier.size(iconSize),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
route = Route.Main,
|
route = Route.Main,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
backStackEntry.isCurrentRoute(Route.AutoTunnel::class) -> {
|
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(
|
NavBarState(
|
||||||
showTop = true,
|
showTop = true,
|
||||||
showBottom = true,
|
showBottom = true,
|
||||||
{ Text(stringResource(R.string.auto_tunnel)) },
|
topTitle = { Text(stringResource(R.string.auto_tunnel)) },
|
||||||
{
|
topTrailing = {
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnel) }
|
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(
|
||||||
icon,
|
icon,
|
||||||
stringResource(description),
|
stringResource(label),
|
||||||
tint = color,
|
tint = tint,
|
||||||
modifier = Modifier.size(iconSize),
|
modifier = Modifier.size(iconSize),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -96,175 +139,161 @@ fun currentNavBackStackEntryAsNavBarState(
|
|||||||
route = Route.AutoTunnel,
|
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) -> {
|
backStackEntry.isCurrentRoute(Route.Logs::class) -> {
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
showTop = true,
|
||||||
showBottom = false,
|
showBottom = false,
|
||||||
{ Text(stringResource(R.string.logs)) },
|
topTitle = { Text(stringResource(R.string.logs)) },
|
||||||
{
|
topTrailing = {
|
||||||
IconButton(
|
ActionIconButton(Icons.Rounded.Menu, R.string.quick_actions) {
|
||||||
onClick = { viewModel.handleEvent(AppEvent.ToggleBottomSheet) }
|
viewModel.handleEvent(
|
||||||
) {
|
AppEvent.SetBottomSheet(AppViewState.BottomSheet.LOGS)
|
||||||
val icon = Icons.Rounded.Menu
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
stringResource(R.string.quick_actions),
|
|
||||||
modifier = Modifier.size(iconSize),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
route = Route.Logs,
|
route = Route.Logs,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
backStackEntry.isCurrentRoute(Route.TunnelOptions::class) -> {
|
|
||||||
val args = backStackEntry?.toRoute<Route.TunnelOptions>()
|
backStackEntry.isCurrentRoute(Route.Settings::class) ->
|
||||||
val tunnel = uiState.tunnels.find { it.id == args?.id }
|
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
showTop = true,
|
||||||
showBottom = true,
|
showBottom = true,
|
||||||
{ tunnel?.name?.let { Text(it) } },
|
topTitle = { Text(stringResource(R.string.settings)) },
|
||||||
{
|
route = Route.Settings,
|
||||||
IconButton(
|
)
|
||||||
onClick = {
|
|
||||||
|
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.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 {
|
tunnel?.id?.let {
|
||||||
navController.navigate(Route.Config(id = it))
|
viewModel.handleEvent(
|
||||||
|
AppEvent.SetShowModal(AppViewState.ModalType.QR)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) {
|
ActionIconButton(Icons.Rounded.Edit, R.string.edit_tunnel) {
|
||||||
val icon = Icons.Rounded.Edit
|
tunnel?.id?.let { navController.navigate(Route.Config(it)) }
|
||||||
Icon(
|
}
|
||||||
icon,
|
|
||||||
stringResource(R.string.edit_tunnel),
|
|
||||||
modifier = Modifier.size(iconSize),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
route = args?.let { Route.TunnelOptions(it.id) },
|
route = args?.let { Route.TunnelOptions(it.id) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
backStackEntry.isCurrentRoute(Route.SplitTunnel::class) -> {
|
backStackEntry.isCurrentRoute(Route.SplitTunnel::class) -> {
|
||||||
val args = backStackEntry?.toRoute<Route.SplitTunnel>()
|
val args = backStackEntry?.toRoute<Route.SplitTunnel>()
|
||||||
val name = uiState.tunnels.find { it.id == args?.id }?.name
|
val name = uiState.tunnels.find { it.id == args?.id }?.name
|
||||||
|
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
showTop = true,
|
||||||
showBottom = true,
|
showBottom = true,
|
||||||
{ name?.let { Text(it) } },
|
topTitle = { name?.let { Text(it) } },
|
||||||
{
|
topTrailing = {
|
||||||
IconButton(
|
ActionIconButton(Icons.Rounded.Save, R.string.save) {
|
||||||
onClick = { viewModel.handleEvent(AppEvent.InvokeScreenAction) }
|
viewModel.handleEvent(AppEvent.InvokeScreenAction)
|
||||||
) {
|
|
||||||
val icon = Icons.Rounded.Save
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
stringResource(R.string.save),
|
|
||||||
modifier = Modifier.size(iconSize),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
route = args?.let { Route.SplitTunnel(it.id) },
|
route = args?.let { Route.SplitTunnel(it.id) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
backStackEntry.isCurrentRoute(Route.Config::class) -> {
|
backStackEntry.isCurrentRoute(Route.Config::class) -> {
|
||||||
val args = backStackEntry?.toRoute<Route.Config>()
|
val args = backStackEntry?.toRoute<Route.Config>()
|
||||||
val name = uiState.tunnels.find { it.id == args?.id }?.name
|
val name = uiState.tunnels.find { it.id == args?.id }?.name
|
||||||
|
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
showTop = true,
|
||||||
showBottom = true,
|
showBottom = true,
|
||||||
{ name?.let { Text(it) } },
|
topTitle = { name?.let { Text(it) } },
|
||||||
{
|
topTrailing = {
|
||||||
IconButton(
|
ActionIconButton(Icons.Rounded.Save, R.string.save) {
|
||||||
onClick = { viewModel.handleEvent(AppEvent.InvokeScreenAction) }
|
viewModel.handleEvent(AppEvent.InvokeScreenAction)
|
||||||
) {
|
|
||||||
val icon = Icons.Rounded.Save
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
stringResource(R.string.save),
|
|
||||||
modifier = Modifier.size(iconSize),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
route = args?.let { Route.Config(it.id) },
|
route = args?.let { Route.Config(it.id) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
backStackEntry.isCurrentRoute(Route.TunnelAutoTunnel::class) -> {
|
backStackEntry.isCurrentRoute(Route.TunnelAutoTunnel::class) -> {
|
||||||
val args = backStackEntry?.toRoute<Route.TunnelAutoTunnel>()
|
val args = backStackEntry?.toRoute<Route.TunnelAutoTunnel>()
|
||||||
val name = uiState.tunnels.find { it.id == args?.id }?.name
|
val name = uiState.tunnels.find { it.id == args?.id }?.name
|
||||||
|
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
showTop = true,
|
||||||
showBottom = true,
|
showBottom = true,
|
||||||
{ name?.let { Text(it) } },
|
topTitle = { name?.let { Text(it) } },
|
||||||
route = args?.let { Route.TunnelAutoTunnel(it.id) },
|
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)
|
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.layout.padding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material3.HorizontalDivider
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
@@ -24,8 +22,10 @@ import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
|||||||
import com.google.accompanist.permissions.isGranted
|
import com.google.accompanist.permissions.isGranted
|
||||||
import com.google.accompanist.permissions.rememberPermissionState
|
import com.google.accompanist.permissions.rememberPermissionState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
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.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.AdvancedSettingsItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.NetworkTunnelingItems
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.NetworkTunnelingItems
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.WifiTunnelingItems
|
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.screens.settings.components.LocationServicesDialog
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isLocationServicesEnabled
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isLocationServicesEnabled
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
|
|
||||||
@OptIn(ExperimentalPermissionsApi::class)
|
@OptIn(ExperimentalPermissionsApi::class)
|
||||||
@@ -41,6 +40,7 @@ import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
|||||||
fun AutoTunnelScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
fun AutoTunnelScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
|
val isTv = LocalIsAndroidTV.current
|
||||||
val fineLocationState = rememberPermissionState(Manifest.permission.ACCESS_FINE_LOCATION)
|
val fineLocationState = rememberPermissionState(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||||
var currentText by remember { mutableStateOf("") }
|
var currentText by remember { mutableStateOf("") }
|
||||||
var isBackgroundLocationGranted by remember { mutableStateOf(true) }
|
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.P) checkFineLocationGranted()
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
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()
|
checkFineLocationGranted()
|
||||||
} else {
|
} else {
|
||||||
val backgroundLocationState =
|
val backgroundLocationState =
|
||||||
rememberPermissionState(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
rememberPermissionState(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
||||||
isBackgroundLocationGranted = backgroundLocationState.status.isGranted
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,9 +108,9 @@ fun AutoTunnelScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
|||||||
{ isWifiNameReadable() },
|
{ isWifiNameReadable() },
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
SectionDivider()
|
||||||
SurfaceSelectionGroupButton(items = NetworkTunnelingItems(uiState, viewModel))
|
SurfaceSelectionGroupButton(items = NetworkTunnelingItems(uiState, viewModel))
|
||||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
SectionDivider()
|
||||||
SurfaceSelectionGroupButton(
|
SurfaceSelectionGroupButton(
|
||||||
items =
|
items =
|
||||||
listOf(
|
listOf(
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components
|
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components
|
||||||
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.AirplanemodeActive
|
import androidx.compose.material.icons.outlined.PublicOff
|
||||||
import androidx.compose.material.icons.outlined.SettingsEthernet
|
import androidx.compose.material.icons.outlined.SettingsEthernet
|
||||||
import androidx.compose.material.icons.outlined.SignalCellular4Bar
|
import androidx.compose.material.icons.outlined.SignalCellular4Bar
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@@ -95,7 +95,7 @@ fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<Se
|
|||||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnEthernet) },
|
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnEthernet) },
|
||||||
),
|
),
|
||||||
SelectionItem(
|
SelectionItem(
|
||||||
leadingIcon = Icons.Outlined.AirplanemodeActive,
|
leadingIcon = Icons.Outlined.PublicOff,
|
||||||
title = {
|
title = {
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.stop_on_no_internet),
|
stringResource(R.string.stop_on_no_internet),
|
||||||
|
|||||||
+3
-4
@@ -20,7 +20,6 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.input.KeyboardCapitalization
|
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.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ClickableIconButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ClickableIconButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.textbox.CustomTextField
|
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)
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -40,7 +39,7 @@ fun TrustedNetworkTextBox(
|
|||||||
onValueChange: (network: String) -> Unit,
|
onValueChange: (network: String) -> Unit,
|
||||||
supporting: @Composable () -> Unit,
|
supporting: @Composable () -> Unit,
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val isTv = LocalIsAndroidTV.current
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
FlowRow(
|
FlowRow(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
@@ -49,7 +48,7 @@ fun TrustedNetworkTextBox(
|
|||||||
trustedNetworks.forEach { ssid ->
|
trustedNetworks.forEach { ssid ->
|
||||||
ClickableIconButton(
|
ClickableIconButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
if (context.isRunningOnTv()) {
|
if (isTv) {
|
||||||
onDelete(ssid)
|
onDelete(ssid)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+31
-20
@@ -22,16 +22,15 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.networkmonitor.NetworkStatus
|
import com.zaneschepke.networkmonitor.NetworkStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.LearnMoreLinkLabel
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.LearnMoreLinkLabel
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||||
@@ -48,7 +47,7 @@ fun WifiTunnelingItems(
|
|||||||
isWifiNameReadable: () -> Boolean,
|
isWifiNameReadable: () -> Boolean,
|
||||||
): List<SelectionItem> {
|
): List<SelectionItem> {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val clipboard = LocalClipboardManager.current
|
val clipboardHelper = rememberClipboardHelper()
|
||||||
|
|
||||||
val baseItems =
|
val baseItems =
|
||||||
listOf(
|
listOf(
|
||||||
@@ -71,29 +70,41 @@ fun WifiTunnelingItems(
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
description = {
|
description = {
|
||||||
val wifiName by
|
val wifiInfo by
|
||||||
remember(uiState.networkStatus) {
|
remember(uiState.networkStatus) {
|
||||||
derivedStateOf {
|
derivedStateOf {
|
||||||
(uiState.networkStatus as? NetworkStatus.Connected)
|
(uiState.networkStatus as? NetworkStatus.Connected)
|
||||||
?.takeIf { it.wifiConnected }
|
?.takeIf { it.wifiConnected }
|
||||||
?.wifiSsid
|
.let { Pair(it?.wifiSsid, it?.securityType) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Text(
|
val (wifiName, securityType) = wifiInfo
|
||||||
text =
|
Column {
|
||||||
wifiName?.let { stringResource(R.string.wifi_name_template, it) }
|
Text(
|
||||||
?: stringResource(R.string.inactive),
|
text =
|
||||||
style =
|
wifiName?.let { stringResource(R.string.wifi_name_template, it) }
|
||||||
MaterialTheme.typography.bodySmall.copy(
|
?: stringResource(R.string.inactive),
|
||||||
color = MaterialTheme.colorScheme.outline
|
style =
|
||||||
),
|
MaterialTheme.typography.bodySmall.copy(
|
||||||
maxLines = 1,
|
color = MaterialTheme.colorScheme.outline
|
||||||
overflow = TextOverflow.Ellipsis,
|
),
|
||||||
modifier =
|
maxLines = 1,
|
||||||
Modifier.clickable {
|
overflow = TextOverflow.Ellipsis,
|
||||||
wifiName?.let { clipboard.setText(AnnotatedString(it)) }
|
modifier =
|
||||||
},
|
Modifier.clickable { wifiName?.let { clipboardHelper.copy(it) } },
|
||||||
)
|
)
|
||||||
|
securityType?.let {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.security_template, it.name),
|
||||||
|
style =
|
||||||
|
MaterialTheme.typography.bodySmall.copy(
|
||||||
|
color = MaterialTheme.colorScheme.outline
|
||||||
|
),
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnWifi) },
|
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnWifi) },
|
||||||
),
|
),
|
||||||
|
|||||||
+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.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@@ -11,10 +11,10 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.components.AppSettingsItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components.AppSettingsItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.components.LocationDisclosureHeader
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components.LocationDisclosureHeader
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.components.SkipItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components.SkipItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.goFromRoot
|
import com.zaneschepke.wireguardautotunnel.util.extensions.goFromRoot
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
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.Icons
|
||||||
import androidx.compose.material.icons.outlined.LocationOn
|
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.padding
|
||||||
import androidx.compose.foundation.layout.size
|
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.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
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.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.journeyapps.barcodescanner.ScanContract
|
||||||
|
import com.journeyapps.barcodescanner.ScanOptions
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileImportLauncherForResult
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileImportLauncherForResult
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.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.TunnelImportSheet
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.TunnelList
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.TunnelList
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.UrlImportDialog
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.UrlImportDialog
|
||||||
@@ -32,9 +31,8 @@ import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
|||||||
@Composable
|
@Composable
|
||||||
fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: AppViewModel) {
|
fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: AppViewModel) {
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val clipboard = LocalClipboardManager.current
|
val clipboard = rememberClipboardHelper()
|
||||||
|
|
||||||
var showDeleteTunnelAlertDialog by remember { mutableStateOf(false) }
|
|
||||||
var showUrlImportDialog by remember { mutableStateOf(false) }
|
var showUrlImportDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
val tunnelFileImportResultLauncher =
|
val tunnelFileImportResultLauncher =
|
||||||
@@ -49,6 +47,17 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
|||||||
onData = { data -> viewModel.handleEvent(AppEvent.ImportTunnelFromFile(data)) },
|
onData = { data -> viewModel.handleEvent(AppEvent.ImportTunnelFromFile(data)) },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val scanLauncher =
|
||||||
|
rememberLauncherForActivityResult(
|
||||||
|
contract = ScanContract(),
|
||||||
|
onResult = { result ->
|
||||||
|
{
|
||||||
|
if (result != null && result.contents.isNotEmpty())
|
||||||
|
viewModel.handleEvent(AppEvent.ImportTunnelFromQrCode(result.contents))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
val requestPermissionLauncher =
|
val requestPermissionLauncher =
|
||||||
rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted
|
rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted
|
||||||
->
|
->
|
||||||
@@ -60,16 +69,17 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
|||||||
)
|
)
|
||||||
return@rememberLauncherForActivityResult
|
return@rememberLauncherForActivityResult
|
||||||
}
|
}
|
||||||
navController.navigate(Route.Scanner)
|
scanLauncher.launch(ScanOptions().setDesiredBarcodeFormats(ScanOptions.QR_CODE))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showDeleteTunnelAlertDialog && appViewState.selectedTunnel != null) {
|
if (appViewState.showModal == AppViewState.ModalType.DELETE) {
|
||||||
InfoDialog(
|
InfoDialog(
|
||||||
onDismiss = { showDeleteTunnelAlertDialog = false },
|
onDismiss = {
|
||||||
|
viewModel.handleEvent(AppEvent.SetShowModal(AppViewState.ModalType.NONE))
|
||||||
|
},
|
||||||
onAttest = {
|
onAttest = {
|
||||||
appViewState.selectedTunnel.let { viewModel.handleEvent(AppEvent.DeleteTunnel(it)) }
|
viewModel.handleEvent(AppEvent.DeleteSelectedTunnels)
|
||||||
showDeleteTunnelAlertDialog = false
|
viewModel.handleEvent(AppEvent.SetShowModal(AppViewState.ModalType.NONE))
|
||||||
viewModel.handleEvent(AppEvent.SetSelectedTunnel(null))
|
|
||||||
},
|
},
|
||||||
title = { Text(text = stringResource(R.string.delete_tunnel)) },
|
title = { Text(text = stringResource(R.string.delete_tunnel)) },
|
||||||
body = { Text(text = stringResource(R.string.delete_tunnel_message)) },
|
body = { Text(text = stringResource(R.string.delete_tunnel_message)) },
|
||||||
@@ -77,21 +87,35 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
TunnelImportSheet(
|
when (appViewState.bottomSheet) {
|
||||||
appViewState.showBottomSheet,
|
AppViewState.BottomSheet.EXPORT_TUNNELS -> {
|
||||||
onDismiss = { viewModel.handleEvent(AppEvent.ToggleBottomSheet) },
|
ExportTunnelsBottomSheet(viewModel)
|
||||||
onFileClick = { tunnelFileImportResultLauncher.launch(Constants.ALLOWED_TV_FILE_TYPES) },
|
}
|
||||||
onQrClick = { requestPermissionLauncher.launch(android.Manifest.permission.CAMERA) },
|
AppViewState.BottomSheet.IMPORT_TUNNELS -> {
|
||||||
onClipboardClick = {
|
TunnelImportSheet(
|
||||||
clipboard.getText()?.text?.let {
|
onDismiss = {
|
||||||
viewModel.handleEvent(AppEvent.ImportTunnelFromClipboard(it))
|
viewModel.handleEvent(AppEvent.SetBottomSheet(AppViewState.BottomSheet.NONE))
|
||||||
}
|
},
|
||||||
},
|
onFileClick = {
|
||||||
onManualImportClick = {
|
tunnelFileImportResultLauncher.launch(Constants.ALLOWED_TV_FILE_TYPES)
|
||||||
navController.navigate(Route.Config(Constants.MANUAL_TUNNEL_CONFIG_ID))
|
},
|
||||||
},
|
onQrClick = {
|
||||||
onUrlClick = { showUrlImportDialog = true },
|
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) {
|
if (showUrlImportDialog) {
|
||||||
UrlImportDialog(
|
UrlImportDialog(
|
||||||
@@ -105,22 +129,11 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
|||||||
|
|
||||||
TunnelList(
|
TunnelList(
|
||||||
appUiState = appUiState,
|
appUiState = appUiState,
|
||||||
activeTunnels = appUiState.activeTunnels,
|
selectedTunnels = appViewState.selectedTunnels,
|
||||||
selectedTunnel = appViewState.selectedTunnel,
|
|
||||||
onSetSelectedTunnel = { viewModel.handleEvent(AppEvent.SetSelectedTunnel(it)) },
|
|
||||||
onDeleteTunnel = {
|
|
||||||
viewModel.handleEvent(AppEvent.SetSelectedTunnel(it))
|
|
||||||
showDeleteTunnelAlertDialog = true
|
|
||||||
},
|
|
||||||
onToggleTunnel = { tunnel, checked ->
|
onToggleTunnel = { tunnel, checked ->
|
||||||
if (checked) viewModel.handleEvent(AppEvent.StartTunnel(tunnel))
|
if (checked) viewModel.handleEvent(AppEvent.StartTunnel(tunnel))
|
||||||
else viewModel.handleEvent(AppEvent.StopTunnel(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),
|
modifier = Modifier.fillMaxSize().padding(vertical = 24.dp).padding(horizontal = 12.dp),
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
)
|
)
|
||||||
|
|||||||
+130
@@ -0,0 +1,130 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.FolderZip
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.HorizontalDivider
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.ModalBottomSheet
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
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.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.ConfigType
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileExportLauncherForResult
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.AuthorizationPromptWrapper
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppViewState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.hasSAFSupport
|
||||||
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun ExportTunnelsBottomSheet(viewModel: AppViewModel) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val isTv = LocalIsAndroidTV.current
|
||||||
|
|
||||||
|
var exportConfigType by remember { mutableStateOf(ConfigType.WG) }
|
||||||
|
var showAuthPrompt by remember { mutableStateOf(false) }
|
||||||
|
var isAuthorized by remember { mutableStateOf(false) }
|
||||||
|
var shouldExport by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
val selectedTunnelsExportLauncher =
|
||||||
|
rememberFileExportLauncherForResult(
|
||||||
|
mimeType = Constants.ZIP_FILE_MIME_TYPE,
|
||||||
|
onResult = { file ->
|
||||||
|
if (file != null) {
|
||||||
|
viewModel.handleEvent(AppEvent.ExportSelectedTunnels(exportConfigType, file))
|
||||||
|
} else {
|
||||||
|
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
||||||
|
viewModel.handleEvent(AppEvent.SetBottomSheet(AppViewState.BottomSheet.NONE))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
fun handleFileExport() {
|
||||||
|
if (context.hasSAFSupport(Constants.ZIP_FILE_MIME_TYPE)) {
|
||||||
|
selectedTunnelsExportLauncher.launch(Constants.DEFAULT_EXPORT_FILE_NAME)
|
||||||
|
} else {
|
||||||
|
viewModel.handleEvent(AppEvent.ExportSelectedTunnels(exportConfigType, null))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(shouldExport) {
|
||||||
|
if (shouldExport) {
|
||||||
|
handleFileExport()
|
||||||
|
shouldExport = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showAuthPrompt) {
|
||||||
|
AuthorizationPromptWrapper(
|
||||||
|
onDismiss = { showAuthPrompt = false },
|
||||||
|
onSuccess = {
|
||||||
|
showAuthPrompt = false
|
||||||
|
isAuthorized = true
|
||||||
|
shouldExport = true
|
||||||
|
},
|
||||||
|
viewModel = viewModel,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
ModalBottomSheet(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surface,
|
||||||
|
onDismissRequest = {
|
||||||
|
viewModel.handleEvent(AppEvent.SetBottomSheet(AppViewState.BottomSheet.NONE))
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
ExportOptionRow(
|
||||||
|
label = stringResource(R.string.export_tunnels_amnezia),
|
||||||
|
onClick = {
|
||||||
|
exportConfigType = ConfigType.AM
|
||||||
|
if (!isAuthorized && !isTv) {
|
||||||
|
showAuthPrompt = true
|
||||||
|
} else {
|
||||||
|
shouldExport = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
HorizontalDivider()
|
||||||
|
|
||||||
|
ExportOptionRow(
|
||||||
|
label = stringResource(R.string.export_tunnels_wireguard),
|
||||||
|
onClick = {
|
||||||
|
exportConfigType = ConfigType.WG
|
||||||
|
if (!isAuthorized && !isTv) {
|
||||||
|
showAuthPrompt = true
|
||||||
|
} else {
|
||||||
|
shouldExport = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ExportOptionRow(label: String, onClick: () -> Unit) {
|
||||||
|
Row(modifier = Modifier.fillMaxWidth().clickable(onClick = onClick).padding(10.dp)) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Filled.FolderZip,
|
||||||
|
contentDescription = label,
|
||||||
|
modifier = Modifier.padding(10.dp),
|
||||||
|
)
|
||||||
|
Text(text = label, modifier = Modifier.padding(10.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
+67
-77
@@ -23,13 +23,12 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||||
|
|
||||||
// TODO refactor this component
|
// TODO refactor this component
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun TunnelImportSheet(
|
fun TunnelImportSheet(
|
||||||
show: Boolean,
|
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
onFileClick: () -> Unit,
|
onFileClick: () -> Unit,
|
||||||
onQrClick: () -> Unit,
|
onQrClick: () -> Unit,
|
||||||
@@ -37,72 +36,49 @@ fun TunnelImportSheet(
|
|||||||
onClipboardClick: () -> Unit,
|
onClipboardClick: () -> Unit,
|
||||||
onUrlClick: () -> Unit,
|
onUrlClick: () -> Unit,
|
||||||
) {
|
) {
|
||||||
|
val isTv = LocalIsAndroidTV.current
|
||||||
|
|
||||||
val sheetState = rememberModalBottomSheetState()
|
val sheetState = rememberModalBottomSheetState()
|
||||||
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
if (show) {
|
ModalBottomSheet(
|
||||||
ModalBottomSheet(
|
containerColor = MaterialTheme.colorScheme.surface,
|
||||||
containerColor = MaterialTheme.colorScheme.surface,
|
onDismissRequest = { onDismiss() },
|
||||||
onDismissRequest = { onDismiss() },
|
sheetState = sheetState,
|
||||||
sheetState = sheetState,
|
) {
|
||||||
|
Row(
|
||||||
|
modifier =
|
||||||
|
Modifier.fillMaxWidth()
|
||||||
|
.clickable {
|
||||||
|
onDismiss()
|
||||||
|
onFileClick()
|
||||||
|
}
|
||||||
|
.padding(10.dp)
|
||||||
) {
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.FileOpen,
|
||||||
|
contentDescription = stringResource(id = R.string.open_file),
|
||||||
|
modifier = Modifier.padding(10.dp),
|
||||||
|
)
|
||||||
|
Text(stringResource(id = R.string.add_tunnels_text), modifier = Modifier.padding(10.dp))
|
||||||
|
}
|
||||||
|
if (!isTv) {
|
||||||
|
HorizontalDivider()
|
||||||
Row(
|
Row(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.fillMaxWidth()
|
Modifier.fillMaxWidth()
|
||||||
.clickable {
|
.clickable {
|
||||||
onDismiss()
|
onDismiss()
|
||||||
onFileClick()
|
onQrClick()
|
||||||
}
|
}
|
||||||
.padding(10.dp)
|
.padding(10.dp)
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Filled.FileOpen,
|
Icons.Filled.QrCode,
|
||||||
contentDescription = stringResource(id = R.string.open_file),
|
contentDescription = stringResource(id = R.string.qr_scan),
|
||||||
modifier = Modifier.padding(10.dp),
|
modifier = Modifier.padding(10.dp),
|
||||||
)
|
)
|
||||||
Text(
|
Text(stringResource(id = R.string.add_from_qr), modifier = Modifier.padding(10.dp))
|
||||||
stringResource(id = R.string.add_tunnels_text),
|
|
||||||
modifier = Modifier.padding(10.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (!context.isRunningOnTv()) {
|
|
||||||
HorizontalDivider()
|
|
||||||
Row(
|
|
||||||
modifier =
|
|
||||||
Modifier.fillMaxWidth()
|
|
||||||
.clickable {
|
|
||||||
onDismiss()
|
|
||||||
onQrClick()
|
|
||||||
}
|
|
||||||
.padding(10.dp)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Filled.QrCode,
|
|
||||||
contentDescription = stringResource(id = R.string.qr_scan),
|
|
||||||
modifier = Modifier.padding(10.dp),
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
stringResource(id = R.string.add_from_qr),
|
|
||||||
modifier = Modifier.padding(10.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
HorizontalDivider()
|
|
||||||
Row(
|
|
||||||
modifier =
|
|
||||||
Modifier.fillMaxWidth()
|
|
||||||
.clickable {
|
|
||||||
onDismiss()
|
|
||||||
onClipboardClick()
|
|
||||||
}
|
|
||||||
.padding(10.dp)
|
|
||||||
) {
|
|
||||||
val icon = Icons.Filled.ContentPasteGo
|
|
||||||
Icon(icon, contentDescription = icon.name, modifier = Modifier.padding(10.dp))
|
|
||||||
Text(
|
|
||||||
stringResource(id = R.string.add_from_clipboard),
|
|
||||||
modifier = Modifier.padding(10.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
HorizontalDivider()
|
HorizontalDivider()
|
||||||
Row(
|
Row(
|
||||||
@@ -110,37 +86,51 @@ fun TunnelImportSheet(
|
|||||||
Modifier.fillMaxWidth()
|
Modifier.fillMaxWidth()
|
||||||
.clickable {
|
.clickable {
|
||||||
onDismiss()
|
onDismiss()
|
||||||
onUrlClick()
|
onClipboardClick()
|
||||||
}
|
}
|
||||||
.padding(10.dp)
|
.padding(10.dp)
|
||||||
) {
|
) {
|
||||||
Icon(
|
val icon = Icons.Filled.ContentPasteGo
|
||||||
Icons.Filled.Link,
|
Icon(icon, contentDescription = icon.name, modifier = Modifier.padding(10.dp))
|
||||||
contentDescription = stringResource(id = R.string.add_from_url),
|
|
||||||
modifier = Modifier.padding(10.dp),
|
|
||||||
)
|
|
||||||
Text(stringResource(id = R.string.add_from_url), modifier = Modifier.padding(10.dp))
|
|
||||||
}
|
|
||||||
HorizontalDivider()
|
|
||||||
Row(
|
|
||||||
modifier =
|
|
||||||
Modifier.fillMaxWidth()
|
|
||||||
.clickable {
|
|
||||||
onDismiss()
|
|
||||||
onManualImportClick()
|
|
||||||
}
|
|
||||||
.padding(10.dp)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Filled.Create,
|
|
||||||
contentDescription = stringResource(id = R.string.create_import),
|
|
||||||
modifier = Modifier.padding(10.dp),
|
|
||||||
)
|
|
||||||
Text(
|
Text(
|
||||||
stringResource(id = R.string.create_import),
|
stringResource(id = R.string.add_from_clipboard),
|
||||||
modifier = Modifier.padding(10.dp),
|
modifier = Modifier.padding(10.dp),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
HorizontalDivider()
|
||||||
|
Row(
|
||||||
|
modifier =
|
||||||
|
Modifier.fillMaxWidth()
|
||||||
|
.clickable {
|
||||||
|
onDismiss()
|
||||||
|
onUrlClick()
|
||||||
|
}
|
||||||
|
.padding(10.dp)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Link,
|
||||||
|
contentDescription = stringResource(id = R.string.add_from_url),
|
||||||
|
modifier = Modifier.padding(10.dp),
|
||||||
|
)
|
||||||
|
Text(stringResource(id = R.string.add_from_url), modifier = Modifier.padding(10.dp))
|
||||||
|
}
|
||||||
|
HorizontalDivider()
|
||||||
|
Row(
|
||||||
|
modifier =
|
||||||
|
Modifier.fillMaxWidth()
|
||||||
|
.clickable {
|
||||||
|
onDismiss()
|
||||||
|
onManualImportClick()
|
||||||
|
}
|
||||||
|
.padding(10.dp)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Create,
|
||||||
|
contentDescription = stringResource(id = R.string.create_import),
|
||||||
|
modifier = Modifier.padding(10.dp),
|
||||||
|
)
|
||||||
|
Text(stringResource(id = R.string.create_import), modifier = Modifier.padding(10.dp))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+40
-18
@@ -7,6 +7,7 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.overscroll
|
import androidx.compose.foundation.overscroll
|
||||||
|
import androidx.compose.foundation.rememberOverscrollEffect
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@@ -17,9 +18,13 @@ import androidx.compose.ui.unit.dp
|
|||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.getValueById
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.getValueById
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
import java.text.Collator
|
import java.text.Collator
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -27,21 +32,24 @@ import java.util.*
|
|||||||
@Composable
|
@Composable
|
||||||
fun TunnelList(
|
fun TunnelList(
|
||||||
appUiState: AppUiState,
|
appUiState: AppUiState,
|
||||||
activeTunnels: Map<TunnelConf, TunnelState>,
|
selectedTunnels: List<TunnelConf>,
|
||||||
selectedTunnel: TunnelConf?,
|
|
||||||
onSetSelectedTunnel: (TunnelConf?) -> Unit,
|
|
||||||
onDeleteTunnel: (TunnelConf) -> Unit,
|
|
||||||
onToggleTunnel: (TunnelConf, Boolean) -> Unit,
|
|
||||||
onExpandStats: () -> Unit,
|
|
||||||
onCopyTunnel: (TunnelConf) -> Unit,
|
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
onToggleTunnel: (TunnelConf, Boolean) -> Unit,
|
||||||
viewModel: AppViewModel,
|
viewModel: AppViewModel,
|
||||||
) {
|
) {
|
||||||
|
val isTv = LocalIsAndroidTV.current
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
val navController = LocalNavController.current
|
||||||
val collator = Collator.getInstance(Locale.getDefault())
|
val collator = Collator.getInstance(Locale.getDefault())
|
||||||
val sortedTunnels =
|
val sortedTunnels =
|
||||||
remember(appUiState.tunnels) {
|
remember(appUiState.tunnels) {
|
||||||
appUiState.tunnels.sortedWith(compareBy(collator) { it.tunName })
|
appUiState.tunnels.sortedWith(
|
||||||
|
compareBy(
|
||||||
|
// primary tunnel first
|
||||||
|
{ !it.isPrimaryTunnel },
|
||||||
|
{ collator.compare(it.tunName, "") },
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
@@ -50,7 +58,7 @@ fun TunnelList(
|
|||||||
modifier =
|
modifier =
|
||||||
modifier
|
modifier
|
||||||
.pointerInput(Unit) { if (appUiState.tunnels.isEmpty()) return@pointerInput }
|
.pointerInput(Unit) { if (appUiState.tunnels.isEmpty()) return@pointerInput }
|
||||||
.overscroll(ScrollableDefaults.overscrollEffect()),
|
.overscroll(rememberOverscrollEffect()),
|
||||||
state = rememberLazyListState(0, appUiState.tunnels.count()),
|
state = rememberLazyListState(0, appUiState.tunnels.count()),
|
||||||
userScrollEnabled = true,
|
userScrollEnabled = true,
|
||||||
reverseLayout = false,
|
reverseLayout = false,
|
||||||
@@ -60,19 +68,33 @@ fun TunnelList(
|
|||||||
item { GettingStartedLabel(onClick = { context.openWebUrl(it) }) }
|
item { GettingStartedLabel(onClick = { context.openWebUrl(it) }) }
|
||||||
}
|
}
|
||||||
items(sortedTunnels, key = { it.id }) { tunnel ->
|
items(sortedTunnels, key = { it.id }) { tunnel ->
|
||||||
val tunnelState = activeTunnels.getValueById(tunnel.id) ?: TunnelState()
|
val tunnelState =
|
||||||
|
remember(appUiState.activeTunnels) {
|
||||||
|
appUiState.activeTunnels.getValueById(tunnel.id) ?: TunnelState()
|
||||||
|
}
|
||||||
|
val selected = remember(selectedTunnels) { selectedTunnels.any { it.id == tunnel.id } }
|
||||||
TunnelRowItem(
|
TunnelRowItem(
|
||||||
isActive = tunnelState.status.isUpOrStarting(),
|
state = tunnelState,
|
||||||
expanded = appUiState.appState.isTunnelStatsExpanded,
|
expanded = appUiState.appState.expandedTunnelIds.contains(tunnel.id),
|
||||||
isSelected = selectedTunnel?.id == tunnel.id,
|
isSelected = selected,
|
||||||
tunnel = tunnel,
|
tunnel = tunnel,
|
||||||
tunnelState = tunnelState,
|
tunnelState = tunnelState,
|
||||||
onSetSelectedTunnel = { onSetSelectedTunnel(it) },
|
onClick = {
|
||||||
onClick = onExpandStats,
|
if (selectedTunnels.isNotEmpty() && !isTv) {
|
||||||
onCopy = { onCopyTunnel(tunnel) },
|
viewModel.handleEvent(AppEvent.ToggleSelectedTunnel(tunnel))
|
||||||
onDelete = { onDeleteTunnel(tunnel) },
|
} else {
|
||||||
|
navController.navigate(Route.TunnelOptions(tunnel.id))
|
||||||
|
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onDoubleClick = {
|
||||||
|
viewModel.handleEvent(AppEvent.ToggleTunnelStatsExpanded(tunnel.id))
|
||||||
|
},
|
||||||
|
onToggleSelectedTunnel = {
|
||||||
|
viewModel.handleEvent(AppEvent.ToggleSelectedTunnel(it))
|
||||||
|
},
|
||||||
onSwitchClick = { checked -> onToggleTunnel(tunnel, checked) },
|
onSwitchClick = { checked -> onToggleTunnel(tunnel, checked) },
|
||||||
viewModel = viewModel,
|
isTv = isTv,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+66
-175
@@ -2,221 +2,112 @@ package com.zaneschepke.wireguardautotunnel.ui.screens.main.components
|
|||||||
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.rounded.Circle
|
import androidx.compose.material.icons.rounded.Circle
|
||||||
import androidx.compose.material.icons.rounded.CopyAll
|
import androidx.compose.material.icons.rounded.KeyboardArrowDown
|
||||||
import androidx.compose.material.icons.rounded.Delete
|
|
||||||
import androidx.compose.material.icons.rounded.Info
|
|
||||||
import androidx.compose.material.icons.rounded.Settings
|
import androidx.compose.material.icons.rounded.Settings
|
||||||
import androidx.compose.material.icons.rounded.SettingsEthernet
|
import androidx.compose.material.icons.rounded.SettingsEthernet
|
||||||
import androidx.compose.material.icons.rounded.Smartphone
|
import androidx.compose.material.icons.rounded.Smartphone
|
||||||
import androidx.compose.material.icons.rounded.Star
|
import androidx.compose.material.icons.rounded.Star
|
||||||
|
import androidx.compose.material3.Checkbox
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.minimumInteractiveComponentSize
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
|
||||||
import androidx.compose.ui.focus.focusRequester
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.ExpandingRowListItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.ExpandingRowListItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asColor
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asColor
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TunnelRowItem(
|
fun TunnelRowItem(
|
||||||
isActive: Boolean,
|
state: TunnelState,
|
||||||
expanded: Boolean,
|
|
||||||
isSelected: Boolean,
|
isSelected: Boolean,
|
||||||
|
expanded: Boolean,
|
||||||
tunnel: TunnelConf,
|
tunnel: TunnelConf,
|
||||||
tunnelState: TunnelState,
|
tunnelState: TunnelState,
|
||||||
onSetSelectedTunnel: (TunnelConf?) -> Unit,
|
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
onCopy: () -> Unit,
|
onDoubleClick: () -> Unit,
|
||||||
onDelete: () -> Unit,
|
onToggleSelectedTunnel: (TunnelConf) -> Unit,
|
||||||
onSwitchClick: (Boolean) -> Unit,
|
onSwitchClick: (Boolean) -> Unit,
|
||||||
viewModel: AppViewModel,
|
isTv: Boolean,
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val leadingIconColor =
|
||||||
val navController = LocalNavController.current
|
remember(state) {
|
||||||
val haptic = LocalHapticFeedback.current
|
if (state.status.isUp()) tunnelState.statistics.asColor() else Color.Gray
|
||||||
val itemFocusRequester = remember { FocusRequester() }
|
}
|
||||||
val isTv = context.isRunningOnTv()
|
|
||||||
|
|
||||||
val leadingIconColor = if (!isActive) Color.Gray else tunnelState.statistics.asColor()
|
|
||||||
|
|
||||||
val (leadingIcon, size) =
|
val (leadingIcon, size) =
|
||||||
when {
|
remember(tunnel) {
|
||||||
tunnel.isPrimaryTunnel -> Pair(Icons.Rounded.Star, 16.dp)
|
when {
|
||||||
tunnel.isMobileDataTunnel -> Pair(Icons.Rounded.Smartphone, 16.dp)
|
tunnel.isPrimaryTunnel -> Pair(Icons.Rounded.Star, 16.dp)
|
||||||
tunnel.isEthernetTunnel -> Pair(Icons.Rounded.SettingsEthernet, 16.dp)
|
tunnel.isMobileDataTunnel -> Pair(Icons.Rounded.Smartphone, 16.dp)
|
||||||
else -> Pair(Icons.Rounded.Circle, 14.dp)
|
tunnel.isEthernetTunnel -> Pair(Icons.Rounded.SettingsEthernet, 16.dp)
|
||||||
|
else -> Pair(Icons.Rounded.Circle, 14.dp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpandingRowListItem(
|
ExpandingRowListItem(
|
||||||
leading = {
|
leading = {
|
||||||
Icon(
|
Row(
|
||||||
leadingIcon,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
stringResource(R.string.status),
|
horizontalArrangement = Arrangement.spacedBy(4.dp, Alignment.Start),
|
||||||
tint = leadingIconColor,
|
) {
|
||||||
modifier = Modifier.size(size),
|
if (isTv) {
|
||||||
)
|
Checkbox(
|
||||||
},
|
isSelected,
|
||||||
text = tunnel.tunName,
|
onCheckedChange = { onToggleSelectedTunnel(tunnel) },
|
||||||
onHold = {
|
modifier = Modifier.minimumInteractiveComponentSize().size(12.dp),
|
||||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
|
||||||
onSetSelectedTunnel(tunnel)
|
|
||||||
},
|
|
||||||
onClick = {
|
|
||||||
if (!isTv) {
|
|
||||||
if (isActive) onClick()
|
|
||||||
} else {
|
|
||||||
onSetSelectedTunnel(tunnel)
|
|
||||||
itemFocusRequester.requestFocus()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
isExpanded = expanded && isActive,
|
|
||||||
expanded = {
|
|
||||||
if (isActive && expanded) TunnelStatisticsRow(tunnelState.statistics, tunnel)
|
|
||||||
},
|
|
||||||
trailing = {
|
|
||||||
if (isSelected && !isTv) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly,
|
|
||||||
) {
|
|
||||||
IconButton(
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
onClick = {
|
|
||||||
onSetSelectedTunnel(null)
|
|
||||||
navController.navigate(Route.TunnelOptions(tunnel.id))
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Rounded.Settings,
|
|
||||||
stringResource(id = R.string.settings),
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
IconButton(
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
onClick = {
|
|
||||||
onCopy()
|
|
||||||
onSetSelectedTunnel(null)
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Rounded.CopyAll,
|
|
||||||
stringResource(R.string.copy),
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
IconButton(
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
enabled = !isActive,
|
|
||||||
onClick = { onDelete() },
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Rounded.Delete,
|
|
||||||
stringResource(R.string.delete_tunnel),
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (isTv) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly,
|
|
||||||
) {
|
|
||||||
IconButton(
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
onClick = {
|
|
||||||
navController.navigate(Route.TunnelOptions(tunnel.id))
|
|
||||||
onSetSelectedTunnel(null)
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Rounded.Settings,
|
|
||||||
stringResource(id = R.string.settings),
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
IconButton(
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
onClick = {
|
|
||||||
if (isActive) {
|
|
||||||
onClick()
|
|
||||||
} else {
|
|
||||||
viewModel.handleEvent(
|
|
||||||
AppEvent.ShowMessage(
|
|
||||||
StringValue.StringResource(R.string.turn_on_tunnel)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Rounded.Info,
|
|
||||||
stringResource(R.string.info),
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
IconButton(modifier = Modifier.weight(1f), onClick = onCopy) {
|
|
||||||
Icon(
|
|
||||||
Icons.Rounded.CopyAll,
|
|
||||||
stringResource(R.string.copy),
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
IconButton(
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
onClick = {
|
|
||||||
if (isActive) {
|
|
||||||
viewModel.handleEvent(
|
|
||||||
AppEvent.ShowMessage(
|
|
||||||
StringValue.StringResource(R.string.turn_off_tunnel)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
onDelete()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Rounded.Delete,
|
|
||||||
stringResource(R.string.delete_tunnel),
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
ScaledSwitch(
|
|
||||||
modifier = Modifier.focusRequester(itemFocusRequester).weight(1f),
|
|
||||||
checked = isActive,
|
|
||||||
onClick = onSwitchClick,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
Icon(
|
||||||
ScaledSwitch(
|
leadingIcon,
|
||||||
modifier = Modifier.focusRequester(itemFocusRequester),
|
stringResource(R.string.status),
|
||||||
checked = isActive,
|
tint = leadingIconColor,
|
||||||
onClick = onSwitchClick,
|
modifier = Modifier.size(size),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
text = tunnel.tunName,
|
||||||
|
onHold = { if (!isTv) onToggleSelectedTunnel(tunnel) },
|
||||||
|
onClick = { if (!isTv) onClick() },
|
||||||
|
onDoubleClick = { if (!isTv) onDoubleClick() },
|
||||||
|
expanded = {
|
||||||
|
if (expanded) {
|
||||||
|
TunnelStatisticsRow(tunnelState.statistics, tunnel)
|
||||||
|
} else null
|
||||||
|
},
|
||||||
|
trailing = {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End),
|
||||||
|
) {
|
||||||
|
if (isTv) {
|
||||||
|
IconButton(onClick = onDoubleClick) {
|
||||||
|
Icon(
|
||||||
|
Icons.Rounded.KeyboardArrowDown,
|
||||||
|
contentDescription = stringResource(R.string.info),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
IconButton(onClick = onClick) {
|
||||||
|
Icon(
|
||||||
|
Icons.Rounded.Settings,
|
||||||
|
contentDescription = stringResource(R.string.settings),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ScaledSwitch(checked = state.status.isUpOrStarting(), onClick = onSwitchClick)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isSelected = isSelected,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+67
-23
@@ -8,6 +8,9 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.derivedStateOf
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
@@ -21,49 +24,90 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.toThreeDecimalPlaceSt
|
|||||||
@Composable
|
@Composable
|
||||||
fun TunnelStatisticsRow(statistics: TunnelStatistics?, tunnelConf: TunnelConf) {
|
fun TunnelStatisticsRow(statistics: TunnelStatistics?, tunnelConf: TunnelConf) {
|
||||||
val config = TunnelConf.configFromAmQuick(tunnelConf.wgQuick)
|
val config = TunnelConf.configFromAmQuick(tunnelConf.wgQuick)
|
||||||
config.peers.forEach { peer ->
|
Column(
|
||||||
Row(
|
modifier = Modifier.fillMaxWidth().padding(start = 45.dp, bottom = 10.dp, end = 10.dp),
|
||||||
modifier = Modifier.fillMaxWidth().padding(end = 10.dp, bottom = 10.dp, start = 45.dp),
|
verticalArrangement = Arrangement.spacedBy(10.dp, Alignment.CenterVertically),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
horizontalAlignment = Alignment.Start,
|
||||||
horizontalArrangement = Arrangement.spacedBy(5.dp, Alignment.Start),
|
) {
|
||||||
) {
|
config.peers.forEach { peer ->
|
||||||
val peerId = peer.publicKey.toBase64().subSequence(0, 3).toString() + "***"
|
val peerId = remember { peer.publicKey.toBase64().subSequence(0, 3).toString() + "***" }
|
||||||
val peerRx = statistics?.peerStats(peer.publicKey)?.rxBytes ?: 0
|
val endpoint =
|
||||||
val peerTx = statistics?.peerStats(peer.publicKey)?.txBytes ?: 0
|
remember(statistics) { statistics?.peerStats(peer.publicKey)?.resolvedEndpoint }
|
||||||
val peerTxMB = NumberUtils.bytesToMB(peerTx).toThreeDecimalPlaceString()
|
val peerRxMB by
|
||||||
val peerRxMB = NumberUtils.bytesToMB(peerRx).toThreeDecimalPlaceString()
|
remember(statistics) {
|
||||||
val handshake =
|
derivedStateOf {
|
||||||
statistics?.peerStats(peer.publicKey)?.latestHandshakeEpochMillis?.let {
|
statistics
|
||||||
if (it == 0L) {
|
?.peerStats(peer.publicKey)
|
||||||
stringResource(R.string.never)
|
?.rxBytes
|
||||||
} else {
|
?.let { NumberUtils.bytesToMB(it) }
|
||||||
"${NumberUtils.getSecondsBetweenTimestampAndNow(it)} ${stringResource(R.string.sec)}"
|
?.toThreeDecimalPlaceString()
|
||||||
}
|
}
|
||||||
} ?: stringResource(R.string.never)
|
}
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
val peerTxMB by
|
||||||
|
remember(statistics) {
|
||||||
|
derivedStateOf {
|
||||||
|
statistics
|
||||||
|
?.peerStats(peer.publicKey)
|
||||||
|
?.txBytes
|
||||||
|
?.let { NumberUtils.bytesToMB(it) }
|
||||||
|
?.toThreeDecimalPlaceString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val handshake by
|
||||||
|
remember(statistics) {
|
||||||
|
derivedStateOf {
|
||||||
|
statistics?.peerStats(peer.publicKey)?.latestHandshakeEpochMillis?.let {
|
||||||
|
if (it == 0L) {
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
"${NumberUtils.getSecondsBetweenTimestampAndNow(it)}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start),
|
||||||
|
) {
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.peer).lowercase() + ": $peerId",
|
stringResource(R.string.peer).lowercase() + ": $peerId",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
"tx: $peerTxMB MB",
|
stringResource(R.string.handshake) +
|
||||||
|
": ${if(handshake == null) stringResource(R.string.never) else handshake + " " + stringResource(R.string.sec)}",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start),
|
||||||
|
) {
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.handshake) + ": $handshake",
|
"rx: ${peerRxMB ?: 0.00} MB",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
"rx: $peerRxMB MB",
|
"tx: ${peerTxMB ?: 0.00} MB",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if (endpoint != null) {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
"endpoint: $endpoint",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.outline,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-7
@@ -16,16 +16,15 @@ import androidx.compose.material3.OutlinedTextField
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
|
||||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||||
import androidx.compose.ui.text.input.VisualTransformation
|
import androidx.compose.ui.text.input.VisualTransformation
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationTextBox
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationTextBox
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.InterfaceProxy
|
import com.zaneschepke.wireguardautotunnel.ui.state.InterfaceProxy
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -38,7 +37,7 @@ fun InterfaceFields(
|
|||||||
onInterfaceChange: (InterfaceProxy) -> Unit,
|
onInterfaceChange: (InterfaceProxy) -> Unit,
|
||||||
) {
|
) {
|
||||||
val keyboardController = LocalSoftwareKeyboardController.current
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
val clipboardManager = LocalClipboardManager.current
|
val clipboardManager = rememberClipboardHelper()
|
||||||
val keyboardActions = KeyboardActions(onDone = { keyboardController?.hide() })
|
val keyboardActions = KeyboardActions(onDone = { keyboardController?.hide() })
|
||||||
val keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done)
|
val keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done)
|
||||||
|
|
||||||
@@ -53,8 +52,9 @@ fun InterfaceFields(
|
|||||||
if (isAuthenticated) VisualTransformation.None else PasswordVisualTransformation(),
|
if (isAuthenticated) VisualTransformation.None else PasswordVisualTransformation(),
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
IconButton(
|
IconButton(
|
||||||
enabled = isAuthenticated,
|
enabled = true,
|
||||||
onClick = {
|
onClick = {
|
||||||
|
if (!isAuthenticated) return@IconButton showAuthPrompt()
|
||||||
val keypair = com.wireguard.crypto.KeyPair()
|
val keypair = com.wireguard.crypto.KeyPair()
|
||||||
onInterfaceChange(
|
onInterfaceChange(
|
||||||
interfaceState.copy(
|
interfaceState.copy(
|
||||||
@@ -88,9 +88,7 @@ fun InterfaceFields(
|
|||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
IconButton(
|
IconButton(onClick = { clipboardManager.copy(interfaceState.publicKey) }) {
|
||||||
onClick = { clipboardManager.setText(AnnotatedString(interfaceState.publicKey)) }
|
|
||||||
) {
|
|
||||||
Icon(Icons.Rounded.ContentCopy, stringResource(R.string.copy_public_key))
|
Icon(Icons.Rounded.ContentCopy, stringResource(R.string.copy_public_key))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+5
-2
@@ -27,6 +27,10 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.state.ConfigUi
|
|||||||
@Composable
|
@Composable
|
||||||
fun InterfaceSection(uiState: ConfigUiState, viewModel: ConfigViewModel) {
|
fun InterfaceSection(uiState: ConfigUiState, viewModel: ConfigViewModel) {
|
||||||
var isDropDownExpanded by remember { mutableStateOf(false) }
|
var isDropDownExpanded by remember { mutableStateOf(false) }
|
||||||
|
val isAmneziaCompatibilitySet =
|
||||||
|
remember(uiState.configProxy.`interface`) {
|
||||||
|
uiState.configProxy.`interface`.isAmneziaCompatibilityModeSet()
|
||||||
|
}
|
||||||
|
|
||||||
Surface(shape = RoundedCornerShape(12.dp), color = MaterialTheme.colorScheme.surface) {
|
Surface(shape = RoundedCornerShape(12.dp), color = MaterialTheme.colorScheme.surface) {
|
||||||
Column(
|
Column(
|
||||||
@@ -44,8 +48,7 @@ fun InterfaceSection(uiState: ConfigUiState, viewModel: ConfigViewModel) {
|
|||||||
onExpandedChange = { isDropDownExpanded = it },
|
onExpandedChange = { isDropDownExpanded = it },
|
||||||
showScripts = uiState.showScripts,
|
showScripts = uiState.showScripts,
|
||||||
showAmneziaValues = uiState.showAmneziaValues,
|
showAmneziaValues = uiState.showAmneziaValues,
|
||||||
isAmneziaCompatibilitySet =
|
isAmneziaCompatibilitySet = isAmneziaCompatibilitySet,
|
||||||
uiState.configProxy.`interface`.isAmneziaCompatibilityModeSet(),
|
|
||||||
onToggleScripts = viewModel::toggleScripts,
|
onToggleScripts = viewModel::toggleScripts,
|
||||||
onToggleAmneziaValues = viewModel::toggleAmneziaValues,
|
onToggleAmneziaValues = viewModel::toggleAmneziaValues,
|
||||||
onToggleAmneziaCompatibility = viewModel::toggleAmneziaCompatibility,
|
onToggleAmneziaCompatibility = viewModel::toggleAmneziaCompatibility,
|
||||||
|
|||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main.scanner
|
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.DisposableEffect
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.viewinterop.AndroidView
|
|
||||||
import com.journeyapps.barcodescanner.CompoundBarcodeView
|
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun ScannerScreen(viewModel: AppViewModel) {
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
val barcodeView = remember {
|
|
||||||
CompoundBarcodeView(context).apply {
|
|
||||||
this.initializeFromIntent((context as Activity).intent)
|
|
||||||
this.setStatusText("")
|
|
||||||
this.decodeSingle { result ->
|
|
||||||
result.text?.let { barCodeOrQr ->
|
|
||||||
viewModel.handleEvent(AppEvent.ImportTunnelFromQrCode(barCodeOrQr))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AndroidView(factory = { barcodeView })
|
|
||||||
DisposableEffect(Unit) {
|
|
||||||
barcodeView.resume()
|
|
||||||
onDispose { barcodeView.pause() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+15
-17
@@ -1,12 +1,15 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel
|
||||||
|
|
||||||
import androidx.compose.animation.Crossfade
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.animation.core.tween
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
@@ -34,21 +37,16 @@ fun SplitTunnelScreen(
|
|||||||
appViewModel.handleEvent(AppEvent.PopBackStack(true))
|
appViewModel.handleEvent(AppEvent.PopBackStack(true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (uiState.loading) {
|
||||||
Crossfade(
|
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||||
targetState = uiState.loading,
|
CircularProgressIndicator(modifier = Modifier.size(30.dp), strokeWidth = 5.dp)
|
||||||
animationSpec = tween(200),
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
) { isLoading ->
|
|
||||||
if (isLoading) {
|
|
||||||
SplitTunnelSkeleton()
|
|
||||||
} else {
|
|
||||||
SplitTunnelContent(
|
|
||||||
uiState = uiState,
|
|
||||||
onSplitOptionChange = viewModel::updateSplitOption,
|
|
||||||
onAppSelectionToggle = viewModel::toggleAppSelection,
|
|
||||||
onQueryChange = viewModel::onSearchQuery,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
SplitTunnelContent(
|
||||||
|
uiState = uiState,
|
||||||
|
onSplitOptionChange = viewModel::updateSplitOption,
|
||||||
|
onAppSelectionToggle = viewModel::toggleAppSelection,
|
||||||
|
onQueryChange = viewModel::onSearchQuery,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-92
@@ -1,92 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel
|
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.layout.width
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.animation.ShimmerEffect
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun SplitTunnelSkeleton() {
|
|
||||||
val shimmerBrush = ShimmerEffect()
|
|
||||||
|
|
||||||
Column(
|
|
||||||
verticalArrangement = Arrangement.spacedBy(24.dp, Alignment.CenterVertically),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(top = 24.dp),
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp).height(45.dp),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
|
||||||
) {
|
|
||||||
repeat(3) {
|
|
||||||
Box(
|
|
||||||
modifier =
|
|
||||||
Modifier.weight(1f)
|
|
||||||
.height(45.dp)
|
|
||||||
.clip(RoundedCornerShape(8.dp))
|
|
||||||
.background(shimmerBrush)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp).height(45.dp),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier =
|
|
||||||
Modifier.height(45.dp)
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clip(RoundedCornerShape(8.dp))
|
|
||||||
.background(shimmerBrush)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
LazyColumn(
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.Top,
|
|
||||||
contentPadding = PaddingValues(top = 10.dp),
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
) {
|
|
||||||
items(20) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp, vertical = 8.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier =
|
|
||||||
Modifier.size(iconSize).clip(CircleShape).background(shimmerBrush)
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(16.dp))
|
|
||||||
Box(
|
|
||||||
modifier =
|
|
||||||
Modifier.height(20.dp)
|
|
||||||
.weight(1f)
|
|
||||||
.clip(RoundedCornerShape(4.dp))
|
|
||||||
.background(shimmerBrush)
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(16.dp))
|
|
||||||
Box(modifier = Modifier.size(24.dp).clip(CircleShape).background(shimmerBrush))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+15
-9
@@ -18,7 +18,6 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
|||||||
import java.text.Collator
|
import java.text.Collator
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
@@ -65,7 +64,7 @@ constructor(
|
|||||||
|
|
||||||
val installedPackages = packages.map { it.packageName }.toSet()
|
val installedPackages = packages.map { it.packageName }.toSet()
|
||||||
|
|
||||||
// remove uninstalled apps
|
// Remove uninstalled apps
|
||||||
proxyInterface.includedApplications.retainAll { it in installedPackages }
|
proxyInterface.includedApplications.retainAll { it in installedPackages }
|
||||||
proxyInterface.excludedApplications.retainAll { it in installedPackages }
|
proxyInterface.excludedApplications.retainAll { it in installedPackages }
|
||||||
|
|
||||||
@@ -97,17 +96,19 @@ constructor(
|
|||||||
selected,
|
selected,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.sortedWith(compareBy(collator) { it.first.name })
|
.sortedWith(
|
||||||
|
compareByDescending<Pair<TunnelApp, Boolean>> { it.second }
|
||||||
|
.thenBy(collator) { it.first.name }
|
||||||
|
)
|
||||||
|
|
||||||
allTunneledApps = tunneledApps
|
allTunneledApps = tunneledApps
|
||||||
|
|
||||||
delay(500)
|
|
||||||
|
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
SplitTunnelUiState(
|
SplitTunnelUiState(
|
||||||
loading = false,
|
loading = false,
|
||||||
tunnelConf = tunnel,
|
tunnelConf = tunnel,
|
||||||
tunneledApps = tunneledApps,
|
tunneledApps = tunneledApps,
|
||||||
|
queriedApps = tunneledApps,
|
||||||
splitOption = splitOption,
|
splitOption = splitOption,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -116,14 +117,14 @@ constructor(
|
|||||||
fun onSearchQuery(query: String) {
|
fun onSearchQuery(query: String) {
|
||||||
val filteredApps =
|
val filteredApps =
|
||||||
if (query.isBlank()) {
|
if (query.isBlank()) {
|
||||||
allTunneledApps
|
_uiState.value.tunneledApps
|
||||||
} else {
|
} else {
|
||||||
allTunneledApps.filter {
|
_uiState.value.tunneledApps.filter {
|
||||||
it.first.name.contains(query, ignoreCase = true) ||
|
it.first.name.contains(query, ignoreCase = true) ||
|
||||||
it.first.`package`.contains(query, ignoreCase = true)
|
it.first.`package`.contains(query, ignoreCase = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_uiState.update { it.copy(searchQuery = query, tunneledApps = filteredApps) }
|
_uiState.update { it.copy(searchQuery = query, queriedApps = filteredApps) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateSplitOption(newOption: SplitOption) {
|
fun updateSplitOption(newOption: SplitOption) {
|
||||||
@@ -136,7 +137,12 @@ constructor(
|
|||||||
currentState.tunneledApps.map { (app, selected) ->
|
currentState.tunneledApps.map { (app, selected) ->
|
||||||
if (app.`package` == packageName) Pair(app, !selected) else Pair(app, selected)
|
if (app.`package` == packageName) Pair(app, !selected) else Pair(app, selected)
|
||||||
}
|
}
|
||||||
_uiState.value = currentState.copy(tunneledApps = updatedApps)
|
val updatedQueryApps =
|
||||||
|
currentState.queriedApps.map { (app, selected) ->
|
||||||
|
if (app.`package` == packageName) Pair(app, !selected) else Pair(app, selected)
|
||||||
|
}
|
||||||
|
_uiState.value =
|
||||||
|
currentState.copy(tunneledApps = updatedApps, queriedApps = updatedQueryApps)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveChanges() =
|
fun saveChanges() =
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ fun SplitTunnelContent(
|
|||||||
)
|
)
|
||||||
if (uiState.splitOption != SplitOption.ALL) {
|
if (uiState.splitOption != SplitOption.ALL) {
|
||||||
AppListSection(
|
AppListSection(
|
||||||
apps = uiState.tunneledApps,
|
apps = uiState.queriedApps,
|
||||||
onAppSelectionToggle = onAppSelectionToggle,
|
onAppSelectionToggle = onAppSelectionToggle,
|
||||||
onQueryChange = onQueryChange,
|
onQueryChange = onQueryChange,
|
||||||
uiState.searchQuery,
|
uiState.searchQuery,
|
||||||
|
|||||||
+1
@@ -6,6 +6,7 @@ data class SplitTunnelUiState(
|
|||||||
val loading: Boolean = true,
|
val loading: Boolean = true,
|
||||||
val tunnelConf: TunnelConf? = null,
|
val tunnelConf: TunnelConf? = null,
|
||||||
val tunneledApps: SplitTunnelApps = emptyList(),
|
val tunneledApps: SplitTunnelApps = emptyList(),
|
||||||
|
val queriedApps: SplitTunnelApps = emptyList(),
|
||||||
val splitOption: SplitOption = SplitOption.ALL,
|
val splitOption: SplitOption = SplitOption.ALL,
|
||||||
val searchQuery: String = "",
|
val searchQuery: String = "",
|
||||||
val success: Boolean? = null,
|
val success: Boolean? = null,
|
||||||
|
|||||||
+39
-19
@@ -6,33 +6,53 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
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.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.AutoTunnelingItem
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.PingConfigItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.*
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.PingRestartItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.AuthorizationPromptWrapper
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.PrimaryTunnelItem
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppViewState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.ServerIpv4Item
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.SplitTunnelingItem
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TunnelOptionsScreen(tunnelConf: TunnelConf, appUiState: AppUiState, viewModel: AppViewModel) {
|
fun TunnelOptionsScreen(
|
||||||
var currentText by remember { mutableStateOf("") }
|
tunnelConf: TunnelConf,
|
||||||
|
viewModel: AppViewModel,
|
||||||
|
appViewState: AppViewState,
|
||||||
|
) {
|
||||||
|
val isTv = LocalIsAndroidTV.current
|
||||||
|
|
||||||
LaunchedEffect(tunnelConf.tunnelNetworks) { currentText = "" }
|
var showAuthPrompt by remember { mutableStateOf(!isTv) }
|
||||||
|
var isAuthorized by remember { mutableStateOf(isTv) }
|
||||||
|
|
||||||
|
if (appViewState.showModal == AppViewState.ModalType.QR) {
|
||||||
|
|
||||||
|
// Show authorization prompt if needed
|
||||||
|
if (showAuthPrompt) {
|
||||||
|
AuthorizationPromptWrapper(
|
||||||
|
onDismiss = { showAuthPrompt = false },
|
||||||
|
onSuccess = {
|
||||||
|
showAuthPrompt = false
|
||||||
|
isAuthorized = true
|
||||||
|
},
|
||||||
|
viewModel = viewModel,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (isAuthorized) {
|
||||||
|
QrCodeDialog(
|
||||||
|
tunnelConf = tunnelConf,
|
||||||
|
onDismiss = {
|
||||||
|
viewModel.handleEvent(AppEvent.SetShowModal(AppViewState.ModalType.NONE))
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.Start,
|
horizontalAlignment = Alignment.Start,
|
||||||
@@ -52,7 +72,7 @@ fun TunnelOptionsScreen(tunnelConf: TunnelConf, appUiState: AppUiState, viewMode
|
|||||||
SplitTunnelingItem(tunnelConf),
|
SplitTunnelingItem(tunnelConf),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
SectionDivider()
|
||||||
SurfaceSelectionGroupButton(
|
SurfaceSelectionGroupButton(
|
||||||
items =
|
items =
|
||||||
buildList {
|
buildList {
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AutoTunnelingItem(tunnelConf: TunnelConf): SelectionItem {
|
fun AutoTunnelingItem(tunnelConf: TunnelConf): SelectionItem {
|
||||||
|
|||||||
+190
@@ -0,0 +1,190 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.Image
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.outlined.Check
|
||||||
|
import androidx.compose.material.icons.outlined.VpnKey
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.MultiChoiceSegmentedButtonRow
|
||||||
|
import androidx.compose.material3.SegmentedButton
|
||||||
|
import androidx.compose.material3.SegmentedButtonDefaults
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.window.DialogProperties
|
||||||
|
import com.zaneschepke.wireguardautotunnel.MainActivity
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.ConfigType
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.setScreenBrightness
|
||||||
|
import io.github.alexzhirkevich.qrose.options.QrBallShape
|
||||||
|
import io.github.alexzhirkevich.qrose.options.QrBrush
|
||||||
|
import io.github.alexzhirkevich.qrose.options.QrErrorCorrectionLevel
|
||||||
|
import io.github.alexzhirkevich.qrose.options.QrFrameShape
|
||||||
|
import io.github.alexzhirkevich.qrose.options.QrOptions
|
||||||
|
import io.github.alexzhirkevich.qrose.options.QrPixelShape
|
||||||
|
import io.github.alexzhirkevich.qrose.options.circle
|
||||||
|
import io.github.alexzhirkevich.qrose.options.roundCorners
|
||||||
|
import io.github.alexzhirkevich.qrose.options.solid
|
||||||
|
import io.github.alexzhirkevich.qrose.rememberQrCodePainter
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun QrCodeDialog(tunnelConf: TunnelConf, onDismiss: () -> Unit) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val activity = context as? MainActivity
|
||||||
|
|
||||||
|
// Handle screen brightness
|
||||||
|
DisposableEffect(Unit) {
|
||||||
|
activity?.setScreenBrightness(1.0f)
|
||||||
|
onDispose { activity?.setScreenBrightness(-1f) }
|
||||||
|
}
|
||||||
|
|
||||||
|
QrCodeAlertDialog(tunnelConf = tunnelConf, onDismiss = onDismiss)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun QrCodeAlertDialog(tunnelConf: TunnelConf, onDismiss: () -> Unit) {
|
||||||
|
Surface(color = Color.White, tonalElevation = 0.dp) {
|
||||||
|
AlertDialog(
|
||||||
|
containerColor = Color.White,
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text(stringResource(R.string.done), color = MaterialTheme.colorScheme.surface)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
text = tunnelConf.name,
|
||||||
|
color = Color.Black,
|
||||||
|
style = MaterialTheme.typography.titleLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
text = { QrCodeContent(tunnelConf = tunnelConf) },
|
||||||
|
properties = DialogProperties(usePlatformDefaultWidth = true),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun QrCodeContent(tunnelConf: TunnelConf) {
|
||||||
|
var selectedOption by remember { mutableStateOf(ConfigType.WG) }
|
||||||
|
val qrCodeText =
|
||||||
|
when (selectedOption) {
|
||||||
|
ConfigType.AM -> tunnelConf.toAmConfig().toAwgQuickString(true)
|
||||||
|
ConfigType.WG -> tunnelConf.toWgConfig().toWgQuickString(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp, Alignment.Top),
|
||||||
|
) {
|
||||||
|
val qrCodePainter = rememberQrCodePainter(data = qrCodeText, options = createQrOptions())
|
||||||
|
Image(
|
||||||
|
painter = qrCodePainter,
|
||||||
|
contentDescription = stringResource(R.string.show_qr),
|
||||||
|
modifier =
|
||||||
|
Modifier.size(300.dp)
|
||||||
|
.align(Alignment.CenterHorizontally)
|
||||||
|
.padding(16.dp)
|
||||||
|
.background(Color.White),
|
||||||
|
)
|
||||||
|
ConfigTypeSelector(
|
||||||
|
selectedOption = selectedOption,
|
||||||
|
onOptionSelected = { selectedOption = it },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ConfigTypeSelector(selectedOption: ConfigType, onOptionSelected: (ConfigType) -> Unit) {
|
||||||
|
MultiChoiceSegmentedButtonRow(modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp)) {
|
||||||
|
ConfigType.entries.sortedDescending().forEachIndexed { index, entry ->
|
||||||
|
val isActive = selectedOption == entry
|
||||||
|
val typeName =
|
||||||
|
stringResource(
|
||||||
|
when (entry) {
|
||||||
|
ConfigType.AM -> R.string.amnezia
|
||||||
|
ConfigType.WG -> R.string.wireguard
|
||||||
|
}
|
||||||
|
)
|
||||||
|
SegmentedButton(
|
||||||
|
shape =
|
||||||
|
SegmentedButtonDefaults.itemShape(
|
||||||
|
index = index,
|
||||||
|
count = ConfigType.entries.size,
|
||||||
|
baseShape = RoundedCornerShape(8.dp),
|
||||||
|
),
|
||||||
|
icon = {
|
||||||
|
SegmentedButtonDefaults.Icon(
|
||||||
|
active = isActive,
|
||||||
|
activeContent = {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.Check,
|
||||||
|
contentDescription = stringResource(R.string.select),
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.size(SegmentedButtonDefaults.IconSize),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.VpnKey,
|
||||||
|
contentDescription = typeName,
|
||||||
|
tint = Color.Black,
|
||||||
|
modifier = Modifier.size(SegmentedButtonDefaults.IconSize),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
colors =
|
||||||
|
SegmentedButtonDefaults.colors()
|
||||||
|
.copy(
|
||||||
|
activeContainerColor = Color.White,
|
||||||
|
inactiveContainerColor = Color.White,
|
||||||
|
),
|
||||||
|
onCheckedChange = { onOptionSelected(entry) },
|
||||||
|
checked = isActive,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = typeName,
|
||||||
|
color = Color.Black,
|
||||||
|
style = MaterialTheme.typography.labelMedium,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createQrOptions(): QrOptions = QrOptions {
|
||||||
|
shapes {
|
||||||
|
darkPixel = QrPixelShape.circle()
|
||||||
|
ball = QrBallShape.circle()
|
||||||
|
frame = QrFrameShape.roundCorners(0.2f)
|
||||||
|
}
|
||||||
|
colors {
|
||||||
|
dark = QrBrush.solid(Color.Black)
|
||||||
|
frame = QrBrush.solid(Color.Black)
|
||||||
|
ball = QrBrush.solid(Color.Black)
|
||||||
|
}
|
||||||
|
errorCorrectionLevel = QrErrorCorrectionLevel.Medium
|
||||||
|
}
|
||||||
+1
-1
@@ -11,7 +11,7 @@ import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SplitTunnelingItem(tunnelConf: TunnelConf): SelectionItem {
|
fun SplitTunnelingItem(tunnelConf: TunnelConf): SelectionItem {
|
||||||
|
|||||||
+4
-5
@@ -3,21 +3,20 @@ package com.zaneschepke.wireguardautotunnel.ui.screens.pin
|
|||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
import xyz.teamgravity.pin_lock_compose.PinLock
|
import xyz.teamgravity.pin_lock_compose.PinLock
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PinLockScreen(viewModel: AppViewModel) {
|
fun PinLockScreen(viewModel: AppViewModel) {
|
||||||
val context = LocalContext.current
|
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
|
val isTv = LocalIsAndroidTV.current
|
||||||
PinLock(
|
PinLock(
|
||||||
title = { pinExists ->
|
title = { pinExists ->
|
||||||
Text(
|
Text(
|
||||||
@@ -34,7 +33,7 @@ fun PinLockScreen(viewModel: AppViewModel) {
|
|||||||
textColor = MaterialTheme.colorScheme.onSurface,
|
textColor = MaterialTheme.colorScheme.onSurface,
|
||||||
onPinCorrect = {
|
onPinCorrect = {
|
||||||
// pin is correct, navigate or hide pin lock
|
// pin is correct, navigate or hide pin lock
|
||||||
if (context.isRunningOnTv()) {
|
if (isTv) {
|
||||||
navController.navigate(Route.Main)
|
navController.navigate(Route.Main)
|
||||||
} else {
|
} else {
|
||||||
val isPopped = navController.popBackStack()
|
val isPopped = navController.popBackStack()
|
||||||
|
|||||||
+12
-20
@@ -8,23 +8,21 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material3.HorizontalDivider
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.platform.LocalFocusManager
|
import androidx.compose.ui.platform.LocalFocusManager
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
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.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.AdvancedSettingsItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.AlwaysOnVpnItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.AlwaysOnVpnItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.AppShortcutsItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.AppShortcutsItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.AppearanceItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.AppearanceItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.ExportTunnelsBottomSheet
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.KernelModeItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.KernelModeItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.KillSwitchItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.KillSwitchItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.LocalLoggingItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.LocalLoggingItem
|
||||||
@@ -32,21 +30,15 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.PinLoc
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.ReadLogsItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.ReadLogsItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.RestartAtBootItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.RestartAtBootItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppViewState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SettingsScreen(uiState: AppUiState, appViewState: AppViewState, viewModel: AppViewModel) {
|
fun SettingsScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||||
val context = LocalContext.current
|
val isTv = LocalIsAndroidTV.current
|
||||||
val focusManager = LocalFocusManager.current
|
val focusManager = LocalFocusManager.current
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val isRunningOnTv = remember { context.isRunningOnTv() }
|
|
||||||
val interactionSource = remember { MutableInteractionSource() }
|
|
||||||
|
|
||||||
if (appViewState.showBottomSheet) {
|
val interactionSource = remember { MutableInteractionSource() }
|
||||||
ExportTunnelsBottomSheet(viewModel, isRunningOnTv)
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.Start,
|
horizontalAlignment = Alignment.Start,
|
||||||
@@ -57,7 +49,7 @@ fun SettingsScreen(uiState: AppUiState, appViewState: AppViewState, viewModel: A
|
|||||||
.padding(vertical = 24.dp)
|
.padding(vertical = 24.dp)
|
||||||
.padding(horizontal = 12.dp)
|
.padding(horizontal = 12.dp)
|
||||||
.then(
|
.then(
|
||||||
if (!isRunningOnTv) {
|
if (!isTv) {
|
||||||
Modifier.clickable(
|
Modifier.clickable(
|
||||||
indication = null,
|
indication = null,
|
||||||
interactionSource = interactionSource,
|
interactionSource = interactionSource,
|
||||||
@@ -72,12 +64,12 @@ fun SettingsScreen(uiState: AppUiState, appViewState: AppViewState, viewModel: A
|
|||||||
items =
|
items =
|
||||||
buildList {
|
buildList {
|
||||||
add(AppShortcutsItem(uiState, viewModel))
|
add(AppShortcutsItem(uiState, viewModel))
|
||||||
if (!isRunningOnTv) add(AlwaysOnVpnItem(uiState, viewModel))
|
if (!isTv) add(AlwaysOnVpnItem(uiState, viewModel))
|
||||||
add(KillSwitchItem())
|
add(KillSwitchItem())
|
||||||
add(RestartAtBootItem(uiState, viewModel))
|
add(RestartAtBootItem(uiState, viewModel))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
SectionDivider()
|
||||||
SurfaceSelectionGroupButton(
|
SurfaceSelectionGroupButton(
|
||||||
items =
|
items =
|
||||||
buildList {
|
buildList {
|
||||||
@@ -87,10 +79,10 @@ fun SettingsScreen(uiState: AppUiState, appViewState: AppViewState, viewModel: A
|
|||||||
add(PinLockItem(uiState, viewModel))
|
add(PinLockItem(uiState, viewModel))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
SectionDivider()
|
||||||
if (!isRunningOnTv) {
|
if (!isTv) {
|
||||||
SurfaceSelectionGroupButton(items = listOf(KernelModeItem(uiState, viewModel)))
|
SurfaceSelectionGroupButton(items = listOf(KernelModeItem(uiState, viewModel)))
|
||||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
SectionDivider()
|
||||||
}
|
}
|
||||||
SurfaceSelectionGroupButton(
|
SurfaceSelectionGroupButton(
|
||||||
items =
|
items =
|
||||||
|
|||||||
+3
-5
@@ -8,20 +8,19 @@ import androidx.compose.material3.MaterialTheme
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun RemoteControlItem(uiState: AppUiState, viewModel: AppViewModel): SelectionItem {
|
fun RemoteControlItem(uiState: AppUiState, viewModel: AppViewModel): SelectionItem {
|
||||||
val clipboardManager = LocalClipboardManager.current
|
val clipboardManager = rememberClipboardHelper()
|
||||||
|
|
||||||
return SelectionItem(
|
return SelectionItem(
|
||||||
leadingIcon = Icons.Filled.SmartToy,
|
leadingIcon = Icons.Filled.SmartToy,
|
||||||
@@ -42,8 +41,7 @@ fun RemoteControlItem(uiState: AppUiState, viewModel: AppViewModel): SelectionIt
|
|||||||
),
|
),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
modifier =
|
modifier = Modifier.clickable { clipboardManager.copy(key) },
|
||||||
Modifier.clickable { clipboardManager.setText(AnnotatedString(key)) },
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -4,12 +4,11 @@ import androidx.compose.foundation.layout.Arrangement
|
|||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.HorizontalDivider
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.components.DisplayThemeItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.components.DisplayThemeItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.components.LanguageItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.components.LanguageItem
|
||||||
@@ -23,9 +22,9 @@ fun AppearanceScreen() {
|
|||||||
modifier = Modifier.fillMaxSize().padding(vertical = 24.dp).padding(horizontal = 12.dp),
|
modifier = Modifier.fillMaxSize().padding(vertical = 24.dp).padding(horizontal = 12.dp),
|
||||||
) {
|
) {
|
||||||
SurfaceSelectionGroupButton(items = listOf(LanguageItem()))
|
SurfaceSelectionGroupButton(items = listOf(LanguageItem()))
|
||||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
SectionDivider()
|
||||||
SurfaceSelectionGroupButton(items = listOf(NotificationsItem()))
|
SurfaceSelectionGroupButton(items = listOf(NotificationsItem()))
|
||||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
SectionDivider()
|
||||||
SurfaceSelectionGroupButton(items = listOf(DisplayThemeItem()))
|
SurfaceSelectionGroupButton(items = listOf(DisplayThemeItem()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ import com.zaneschepke.wireguardautotunnel.R
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DisplayThemeItem(): SelectionItem {
|
fun DisplayThemeItem(): SelectionItem {
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ import com.zaneschepke.wireguardautotunnel.R
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LanguageItem(): SelectionItem {
|
fun LanguageItem(): SelectionItem {
|
||||||
|
|||||||
+16
-20
@@ -23,25 +23,21 @@ fun DisplayScreen(appUiState: AppUiState, viewModel: AppViewModel) {
|
|||||||
verticalArrangement = Arrangement.spacedBy(24.dp, Alignment.Top),
|
verticalArrangement = Arrangement.spacedBy(24.dp, Alignment.Top),
|
||||||
modifier = Modifier.fillMaxSize().padding(top = 24.dp).padding(horizontal = 24.dp),
|
modifier = Modifier.fillMaxSize().padding(top = 24.dp).padding(horizontal = 24.dp),
|
||||||
) {
|
) {
|
||||||
IconSurfaceButton(
|
enumValues<Theme>().forEach {
|
||||||
title = stringResource(R.string.automatic),
|
val title =
|
||||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.AUTOMATIC)) },
|
when (it) {
|
||||||
selected = appUiState.appState.theme == Theme.AUTOMATIC,
|
Theme.DARK -> stringResource(R.string.dark)
|
||||||
)
|
Theme.LIGHT -> stringResource(R.string.light)
|
||||||
IconSurfaceButton(
|
Theme.AUTOMATIC -> stringResource(R.string.automatic)
|
||||||
title = stringResource(R.string.light),
|
Theme.DYNAMIC -> stringResource(R.string.dynamic)
|
||||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.LIGHT)) },
|
Theme.DARKER -> stringResource(R.string.darker)
|
||||||
selected = appUiState.appState.theme == Theme.LIGHT,
|
Theme.AMOLED -> stringResource(R.string.amoled)
|
||||||
)
|
}
|
||||||
IconSurfaceButton(
|
IconSurfaceButton(
|
||||||
title = stringResource(R.string.dark),
|
title = title,
|
||||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.DARK)) },
|
onClick = { viewModel.handleEvent(AppEvent.SetTheme(it)) },
|
||||||
selected = appUiState.appState.theme == Theme.DARK,
|
selected = appUiState.appState.theme == it,
|
||||||
)
|
)
|
||||||
IconSurfaceButton(
|
}
|
||||||
title = stringResource(R.string.dynamic),
|
|
||||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.DYNAMIC)) },
|
|
||||||
selected = appUiState.appState.theme == Theme.DYNAMIC,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-7
@@ -8,13 +8,12 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.language.components.AutomaticLanguageItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.language.components.AutomaticLanguageItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.language.components.LanguageItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.language.components.LanguageItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.LocaleUtil
|
import com.zaneschepke.wireguardautotunnel.util.LocaleUtil
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
import java.text.Collator
|
import java.text.Collator
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -22,9 +21,7 @@ import java.util.*
|
|||||||
@Composable
|
@Composable
|
||||||
fun LanguageScreen(appUiState: AppUiState, viewModel: AppViewModel) {
|
fun LanguageScreen(appUiState: AppUiState, viewModel: AppViewModel) {
|
||||||
val collator = Collator.getInstance(Locale.getDefault())
|
val collator = Collator.getInstance(Locale.getDefault())
|
||||||
|
val isTv = LocalIsAndroidTV.current
|
||||||
val context = LocalContext.current
|
|
||||||
val isAndroidTv = remember { context.isRunningOnTv() }
|
|
||||||
|
|
||||||
val locales =
|
val locales =
|
||||||
LocaleUtil.supportedLocales.map {
|
LocaleUtil.supportedLocales.map {
|
||||||
@@ -42,9 +39,9 @@ fun LanguageScreen(appUiState: AppUiState, viewModel: AppViewModel) {
|
|||||||
verticalArrangement = Arrangement.Top,
|
verticalArrangement = Arrangement.Top,
|
||||||
modifier = Modifier.padding(horizontal = 12.dp),
|
modifier = Modifier.padding(horizontal = 12.dp),
|
||||||
) {
|
) {
|
||||||
item { AutomaticLanguageItem(appUiState, viewModel, isAndroidTv) }
|
item { AutomaticLanguageItem(appUiState, viewModel, isTv) }
|
||||||
items(sortedLocales, key = { it }) { locale ->
|
items(sortedLocales, key = { it }) { locale ->
|
||||||
LanguageItem(locale, appUiState, viewModel, isAndroidTv)
|
LanguageItem(locale, appUiState, viewModel, isTv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ import com.zaneschepke.wireguardautotunnel.R
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AppearanceItem(): SelectionItem {
|
fun AppearanceItem(): SelectionItem {
|
||||||
|
|||||||
-104
@@ -1,104 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.settings.components
|
|
||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.FolderZip
|
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
||||||
import androidx.compose.material3.HorizontalDivider
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.ModalBottomSheet
|
|
||||||
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.ui.Modifier
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.ConfigType
|
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
|
||||||
fun ExportTunnelsBottomSheet(viewModel: AppViewModel, isRunningOnTv: Boolean) {
|
|
||||||
var showAuthPrompt by remember { mutableStateOf(false) }
|
|
||||||
var isAuthorized by remember { mutableStateOf(false) }
|
|
||||||
var exportType by remember { mutableStateOf(ConfigType.WG) }
|
|
||||||
|
|
||||||
fun handleExport() {
|
|
||||||
viewModel.handleEvent(AppEvent.ToggleBottomSheet)
|
|
||||||
viewModel.handleEvent(AppEvent.ExportTunnels(exportType))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (showAuthPrompt) {
|
|
||||||
AuthorizationPromptWrapper(
|
|
||||||
onDismiss = { showAuthPrompt = false },
|
|
||||||
onSuccess = {
|
|
||||||
showAuthPrompt = false
|
|
||||||
isAuthorized = true
|
|
||||||
handleExport()
|
|
||||||
},
|
|
||||||
viewModel = viewModel,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
ModalBottomSheet(
|
|
||||||
containerColor = MaterialTheme.colorScheme.surface,
|
|
||||||
onDismissRequest = { viewModel.handleEvent(AppEvent.ToggleBottomSheet) },
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier =
|
|
||||||
Modifier.fillMaxWidth()
|
|
||||||
.clickable {
|
|
||||||
exportType = ConfigType.AMNEZIA
|
|
||||||
if (!isAuthorized && !isRunningOnTv) {
|
|
||||||
showAuthPrompt = true
|
|
||||||
return@clickable
|
|
||||||
}
|
|
||||||
handleExport()
|
|
||||||
}
|
|
||||||
.padding(10.dp)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Filled.FolderZip,
|
|
||||||
contentDescription = stringResource(R.string.export_tunnels_amnezia),
|
|
||||||
modifier = Modifier.padding(10.dp),
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
stringResource(R.string.export_tunnels_amnezia),
|
|
||||||
modifier = Modifier.padding(10.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
HorizontalDivider()
|
|
||||||
Row(
|
|
||||||
modifier =
|
|
||||||
Modifier.fillMaxWidth()
|
|
||||||
.clickable {
|
|
||||||
exportType = ConfigType.WG
|
|
||||||
if (!isAuthorized && !isRunningOnTv) {
|
|
||||||
showAuthPrompt = true
|
|
||||||
return@clickable
|
|
||||||
}
|
|
||||||
handleExport()
|
|
||||||
}
|
|
||||||
.padding(10.dp)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Filled.FolderZip,
|
|
||||||
contentDescription = stringResource(R.string.export_tunnels_wireguard),
|
|
||||||
modifier = Modifier.padding(10.dp),
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
stringResource(R.string.export_tunnels_wireguard),
|
|
||||||
modifier = Modifier.padding(10.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -10,7 +10,7 @@ import com.zaneschepke.wireguardautotunnel.R
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun KillSwitchItem(): SelectionItem {
|
fun KillSwitchItem(): SelectionItem {
|
||||||
|
|||||||
+11
-2
@@ -3,10 +3,12 @@ package com.zaneschepke.wireguardautotunnel.ui.screens.settings.components
|
|||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.ViewHeadline
|
import androidx.compose.material.icons.outlined.ViewHeadline
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItemLabel
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItemLabel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionLabelType
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
@@ -15,8 +17,15 @@ import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
|||||||
fun LocalLoggingItem(uiState: AppUiState, viewModel: AppViewModel): SelectionItem {
|
fun LocalLoggingItem(uiState: AppUiState, viewModel: AppViewModel): SelectionItem {
|
||||||
return SelectionItem(
|
return SelectionItem(
|
||||||
leadingIcon = Icons.Outlined.ViewHeadline,
|
leadingIcon = Icons.Outlined.ViewHeadline,
|
||||||
title = { SelectionItemLabel(R.string.local_logging) },
|
title = {
|
||||||
description = { SelectionItemLabel(R.string.enable_local_logging, isDescription = true) },
|
SelectionItemLabel(stringResource(R.string.local_logging), SelectionLabelType.TITLE)
|
||||||
|
},
|
||||||
|
description = {
|
||||||
|
SelectionItemLabel(
|
||||||
|
stringResource(R.string.enable_local_logging),
|
||||||
|
SelectionLabelType.DESCRIPTION,
|
||||||
|
)
|
||||||
|
},
|
||||||
trailing = {
|
trailing = {
|
||||||
ScaledSwitch(
|
ScaledSwitch(
|
||||||
checked = uiState.appState.isLocalLogsEnabled,
|
checked = uiState.appState.isLocalLogsEnabled,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user