Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e4fcdc634 | |||
| 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 |
@@ -1,4 +1,5 @@
|
|||||||
name: build
|
name: Build
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
@@ -12,6 +13,14 @@ on:
|
|||||||
- prerelease
|
- prerelease
|
||||||
- nightly
|
- nightly
|
||||||
- release
|
- release
|
||||||
|
flavor:
|
||||||
|
type: choice
|
||||||
|
description: "Product flavor"
|
||||||
|
required: true
|
||||||
|
default: fdroid
|
||||||
|
options:
|
||||||
|
- fdroid
|
||||||
|
- full
|
||||||
secrets:
|
secrets:
|
||||||
SIGNING_KEY_ALIAS:
|
SIGNING_KEY_ALIAS:
|
||||||
required: false
|
required: false
|
||||||
@@ -30,6 +39,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 +55,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 +63,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 +82,47 @@ 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: Create service_account.json
|
||||||
if: ${{ inputs.build_type != 'debug' }}
|
if: ${{ inputs.build_type != 'debug' }}
|
||||||
id: createServiceAccount
|
id: createServiceAccount
|
||||||
run: echo '${{ secrets.ANDROID_SERVICE_ACCOUNT_JSON }}' > service_account.json
|
run: echo '${{ secrets.SERVICE_ACCOUNT_JSON }}' > service_account.json
|
||||||
|
- name: Build APK
|
||||||
- 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 }}/release/wgtunnel-${{ inputs.flavor }}-release-*.apk
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
if-no-files-found: warn
|
||||||
@@ -7,7 +7,7 @@ on:
|
|||||||
inputs:
|
inputs:
|
||||||
track:
|
track:
|
||||||
type: choice
|
type: choice
|
||||||
description: "Google play release track"
|
description: "Google Play release track"
|
||||||
options:
|
options:
|
||||||
- none
|
- none
|
||||||
- internal
|
- internal
|
||||||
@@ -30,12 +30,28 @@ on:
|
|||||||
description: "Tag name for release"
|
description: "Tag name for release"
|
||||||
required: false
|
required: false
|
||||||
default: nightly
|
default: nightly
|
||||||
|
flavor:
|
||||||
|
type: choice
|
||||||
|
description: "Product flavor"
|
||||||
|
required: true
|
||||||
|
default: full
|
||||||
|
options:
|
||||||
|
- fdroid
|
||||||
|
- full
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
flavor:
|
||||||
|
type: string
|
||||||
|
description: "Product flavor"
|
||||||
|
required: false
|
||||||
|
default: full
|
||||||
|
|
||||||
env:
|
env:
|
||||||
UPLOAD_DIR_ANDROID: android_artifacts
|
UPLOAD_DIR_ANDROID: android_artifacts
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
|
packages: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check_commits:
|
check_commits:
|
||||||
@@ -43,66 +59,73 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
has_new_commits: ${{ steps.check.outputs.new_commits }}
|
has_new_commits: ${{ steps.check.outputs.new_commits }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # This fetches all history so we can check commits
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Check for new commits
|
- name: Check for new commits
|
||||||
id: check
|
id: check
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
GITHUB_TOKEN: ${{ secrets.PAT }}
|
||||||
run: |
|
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 }})
|
NEW_COMMITS=$(git rev-list --count --after="$(date -Iseconds -d '23 hours ago')" ${{ github.sha }})
|
||||||
echo "new_commits=$NEW_COMMITS" >> $GITHUB_OUTPUT
|
echo "new_commits=$NEW_COMMITS" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
build:
|
build-fdroid:
|
||||||
if: ${{ inputs.release_type != 'none' }}
|
if: ${{ inputs.release_type == 'release' || inputs.flavor == 'fdroid' }}
|
||||||
uses: ./.github/workflows/build.yml
|
uses: ./.github/workflows/build.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
with:
|
with:
|
||||||
build_type: ${{ inputs.release_type == '' && 'nightly' || inputs.release_type }}
|
build_type: ${{ inputs.release_type == '' && 'nightly' || inputs.release_type }}
|
||||||
|
flavor: fdroid
|
||||||
|
|
||||||
|
build-full:
|
||||||
|
if: ${{ inputs.release_type == 'release' || inputs.release_type == 'nightly' || inputs.release_type == 'prerelease' || inputs.flavor == 'full' }}
|
||||||
|
uses: ./.github/workflows/build.yml
|
||||||
|
secrets: inherit
|
||||||
|
with:
|
||||||
|
build_type: ${{ inputs.release_type == '' && 'nightly' || inputs.release_type }}
|
||||||
|
flavor: full
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
needs:
|
needs:
|
||||||
- check_commits
|
- check_commits
|
||||||
- build
|
- build-full
|
||||||
if: ${{ needs.check_commits.outputs.has_new_commits > 0 && inputs.release_type != 'none' }}
|
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:
|
||||||
|
fetch-depth: 0
|
||||||
|
ref: main
|
||||||
- name: Install system dependencies
|
- name: Install system dependencies
|
||||||
run: |
|
run: |
|
||||||
sudo apt update && sudo apt install -y gh apksigner
|
sudo apt update && sudo apt install -y gh apksigner
|
||||||
|
- name: Set TAG_NAME
|
||||||
# update latest tag
|
run: |
|
||||||
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||||
|
echo "TAG_NAME=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV
|
||||||
|
elif [ "${{ github.event_name }}" = "schedule" ]; then
|
||||||
|
echo "TAG_NAME=nightly" >> $GITHUB_ENV
|
||||||
|
echo "RELEASE_TYPE=nightly" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
- name: Set latest tag
|
- name: Set latest tag
|
||||||
uses: rickstaa/action-create-tag@v1
|
uses: rickstaa/action-create-tag@v1
|
||||||
id: tag_creation
|
id: tag_creation
|
||||||
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: 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
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
latest: true
|
latest: true
|
||||||
|
|
||||||
- name: Generate Changelog
|
- name: Generate Changelog
|
||||||
id: changelog
|
id: changelog
|
||||||
uses: requarks/changelog-action@v1
|
uses: requarks/changelog-action@v1
|
||||||
@@ -110,40 +133,20 @@ jobs:
|
|||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
toTag: ${{ github.event_name == 'schedule' && 'nightly' || steps.latest_release.outputs.tag_name }}
|
toTag: ${{ github.event_name == 'schedule' && 'nightly' || 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
|
||||||
|
|
||||||
- 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
|
||||||
@@ -152,32 +155,40 @@ jobs:
|
|||||||
if: ${{ contains(env.TAG_NAME, 'nightly') }}
|
if: ${{ contains(env.TAG_NAME, 'nightly') }}
|
||||||
run: |
|
run: |
|
||||||
echo "RELEASE_NOTES=Nightly build for the latest development version of the app." >> $GITHUB_ENV
|
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: Delete previous release
|
||||||
id: checksum
|
if: ${{ contains(env.TAG_NAME, 'nightly') || inputs.release_type == 'prerelease' }}
|
||||||
run: |
|
uses: ClementTsang/delete-tag-and-release@v0.4.0
|
||||||
file_path=$(find ${{ github.workspace }}/temp -type f -iname "*.apk" | tail -n1)
|
with:
|
||||||
echo "checksum=$(apksigner verify -print-certs $file_path | grep -Po "(?<=SHA-256 digest:) .*" | tr -d "[:blank:]")" >> $GITHUB_OUTPUT
|
tag_name: ${{ env.TAG_NAME }}
|
||||||
|
delete_release: true
|
||||||
|
|
||||||
- name: Create Release with Fastlane changelog notes
|
|
||||||
id: create_release
|
|
||||||
uses: softprops/action-gh-release@v2
|
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Get checksums
|
||||||
|
id: checksum
|
||||||
|
run: |
|
||||||
|
checksums=""
|
||||||
|
for file_path in $(find ${{ github.workspace }}/temp -type f -iname "*.apk"); do
|
||||||
|
checksum=$(apksigner verify -print-certs $file_path | grep -Po "(?<=SHA-256 digest:) .*" | tr -d "[:blank:]")
|
||||||
|
checksums="$checksums\n$file_path: $checksum"
|
||||||
|
done
|
||||||
|
echo "checksum<<EOF" >> $GITHUB_OUTPUT
|
||||||
|
echo -e "$checksums" >> $GITHUB_OUTPUT
|
||||||
|
echo "EOF" >> $GITHUB_OUTPUT
|
||||||
|
- name: Create Release
|
||||||
|
id: create_release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
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 }}
|
||||||
```
|
```
|
||||||
@@ -196,18 +207,20 @@ jobs:
|
|||||||
make_latest: ${{ inputs.release_type == 'release' }}
|
make_latest: ${{ inputs.release_type == 'release' }}
|
||||||
files: |
|
files: |
|
||||||
${{ github.workspace }}/temp/*
|
${{ github.workspace }}/temp/*
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
publish-fdroid:
|
publish-fdroid-public:
|
||||||
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:
|
||||||
@@ -216,13 +229,11 @@ jobs:
|
|||||||
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
|
||||||
@@ -244,7 +255,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
|
||||||
@@ -264,4 +275,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 }})
|
||||||
|
|
||||||
|
|||||||
@@ -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/
|
||||||
|
|||||||
@@ -9,33 +9,14 @@ plugins {
|
|||||||
alias(libs.plugins.licensee)
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,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[]",
|
||||||
@@ -64,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")
|
||||||
)
|
)
|
||||||
@@ -88,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")
|
||||||
@@ -108,27 +91,21 @@ 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 {
|
flavorDimensions.add("type")
|
||||||
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)
|
|
||||||
productFlavors {
|
productFlavors {
|
||||||
create("fdroid") {
|
create("fdroid") {
|
||||||
dimension = Constants.TYPE
|
dimension = "type"
|
||||||
proguardFile("fdroid-rules.pro")
|
buildConfigField("String", "FLAVOR", "\"fdroid\"")
|
||||||
}
|
}
|
||||||
create("general") { dimension = Constants.TYPE }
|
create("google") {
|
||||||
|
dimension = "type"
|
||||||
|
buildConfigField("String", "FLAVOR", "\"google\"")
|
||||||
}
|
}
|
||||||
|
create("full") { dimension = "type" }
|
||||||
|
}
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
@@ -144,10 +121,23 @@ android {
|
|||||||
licensee {
|
licensee {
|
||||||
Constants.allowedLicenses.forEach { allow(it) }
|
Constants.allowedLicenses.forEach { allow(it) }
|
||||||
allowUrl(Constants.XZING_LICENSE_URL)
|
allowUrl(Constants.XZING_LICENSE_URL)
|
||||||
|
|
||||||
// Fix for qrcode-kotlin (MIT, custom URL)
|
|
||||||
allowUrl("https://rafaellins.mit-license.org/2021/")
|
allowUrl("https://rafaellins.mit-license.org/2021/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
@@ -156,8 +146,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))
|
||||||
@@ -169,7 +157,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)
|
||||||
@@ -180,107 +167,63 @@ 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)
|
||||||
|
|
||||||
// util
|
|
||||||
implementation(libs.qrcode.kotlin)
|
implementation(libs.qrcode.kotlin)
|
||||||
implementation(libs.semver4j)
|
implementation(libs.semver4j)
|
||||||
|
|
||||||
// Ktor
|
|
||||||
implementation(libs.ktor.client.core)
|
implementation(libs.ktor.client.core)
|
||||||
implementation(libs.ktor.client.okhttp)
|
implementation(libs.ktor.client.okhttp)
|
||||||
implementation(libs.ktor.client.cio)
|
implementation(libs.ktor.client.cio)
|
||||||
implementation(libs.ktor.client.content.negotiation)
|
implementation(libs.ktor.client.content.negotiation)
|
||||||
implementation(libs.ktor.serialization.kotlinx.json)
|
implementation(libs.ktor.serialization.kotlinx.json)
|
||||||
}
|
implementation(libs.slf4j.android)
|
||||||
|
|
||||||
fun determineVersionName(): String {
|
|
||||||
return with(getBuildTaskName().lowercase()) {
|
|
||||||
when {
|
|
||||||
contains(Constants.NIGHTLY) || contains(Constants.PRERELEASE) ->
|
|
||||||
Constants.VERSION_NAME + "-${grgitService.service.get().grgit.head().abbreviatedId}"
|
|
||||||
else -> Constants.VERSION_NAME
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val incrementVersionCode by
|
|
||||||
tasks.registering {
|
|
||||||
doLast {
|
|
||||||
val versionFile = file("$rootDir/versionCode.txt")
|
|
||||||
if (versionFile.exists()) {
|
|
||||||
versionFile.writeText(versionCodeIncrement.toString())
|
|
||||||
println("Incremented versionCode to $versionCodeIncrement")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.whenTaskAdded {
|
|
||||||
if (name.startsWith("assemble") && !name.lowercase().contains("debug")) {
|
|
||||||
dependsOn(incrementVersionCode)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<Copy>("copyLicenseeJsonToAssets") {
|
tasks.register<Copy>("copyLicenseeJsonToAssets") {
|
||||||
dependsOn("licensee")
|
dependsOn("licensee")
|
||||||
|
|
||||||
val outputAssets = layout.projectDirectory.dir("src/main/assets")
|
val outputAssets = layout.projectDirectory.dir("src/main/assets")
|
||||||
|
|
||||||
from(layout.buildDirectory.file("reports/licensee/androidFdroidRelease/artifacts.json")) {
|
from(layout.buildDirectory.file("reports/licensee/androidFdroidRelease/artifacts.json")) {
|
||||||
rename("artifacts.json", "licenses.json")
|
rename("artifacts.json", "licenses.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
into(outputAssets)
|
into(outputAssets)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<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">
|
||||||
<!--updater-->
|
|
||||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
|
||||||
|
|
||||||
<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" />
|
||||||
@@ -54,7 +52,7 @@
|
|||||||
<application
|
<application
|
||||||
android:name=".WireGuardAutoTunnel"
|
android:name=".WireGuardAutoTunnel"
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
android:banner="@drawable/ic_banner"
|
android:banner="@mipmap/ic_banner"
|
||||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||||
android:enableOnBackInvokedCallback="true"
|
android:enableOnBackInvokedCallback="true"
|
||||||
android:fullBackupContent="@xml/backup_rules"
|
android:fullBackupContent="@xml/backup_rules"
|
||||||
@@ -67,7 +65,6 @@
|
|||||||
<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"
|
||||||
|
|||||||
@@ -39,7 +39,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 {
|
||||||
|
|||||||
@@ -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,22 +37,36 @@ 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) {
|
||||||
|
val binder = service as? TunnelForegroundService.LocalBinder
|
||||||
|
_tunnelService.value = binder?.service
|
||||||
|
Timber.d("TunnelForegroundService connected")
|
||||||
|
}
|
||||||
|
|
||||||
private fun <T : Service> startService(cls: Class<T>, background: Boolean) {
|
override fun onServiceDisconnected(name: ComponentName) {
|
||||||
runCatching {
|
_tunnelService.value = null
|
||||||
val intent = Intent(context, cls)
|
Timber.d("TunnelForegroundService disconnected")
|
||||||
if (background) {
|
|
||||||
context.startForegroundService(intent)
|
|
||||||
} else {
|
|
||||||
context.startService(intent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onFailure { Timber.e(it) }
|
|
||||||
|
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 {
|
||||||
@@ -63,64 +77,58 @@ 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)
|
||||||
runCatching {
|
context.bindService(intent, autoTunnelServiceConnection, Context.BIND_AUTO_CREATE)
|
||||||
autoTunnelService = CompletableDeferred()
|
|
||||||
startService(AutoTunnelService::class.java, !WireGuardAutoTunnel.isForeground())
|
|
||||||
_autoTunnelActive.update { true }
|
|
||||||
}
|
|
||||||
.onFailure {
|
|
||||||
Timber.e(it)
|
|
||||||
_autoTunnelActive.update { false }
|
|
||||||
}
|
|
||||||
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun stopAutoTunnel() {
|
suspend fun stopAutoTunnel() {
|
||||||
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()
|
||||||
_autoTunnelActive.update { false }
|
try {
|
||||||
autoTunnelService = CompletableDeferred()
|
context.unbindService(autoTunnelServiceConnection)
|
||||||
|
} 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 {
|
|
||||||
val service = backgroundService.await()
|
|
||||||
service.stop()
|
service.stop()
|
||||||
backgroundService = CompletableDeferred()
|
try {
|
||||||
|
context.unbindService(tunnelServiceConnection)
|
||||||
|
} 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 }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
@@ -273,7 +275,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()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -193,16 +193,17 @@ 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)
|
cleanUpTunThread(tunnel)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun cleanUpTunThread(tunnel: TunnelConf) {
|
private fun cleanUpTunThread(tunnel: TunnelConf) {
|
||||||
Timber.d("Removing thread for ${tunnel.name}")
|
Timber.d("Removing thread for ${tunnel.name}")
|
||||||
|
|||||||
@@ -69,7 +69,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()
|
||||||
|
|||||||
@@ -4,4 +4,6 @@ import com.zaneschepke.wireguardautotunnel.data.model.GitHubRelease
|
|||||||
|
|
||||||
interface GitHubApi {
|
interface GitHubApi {
|
||||||
suspend fun getLatestRelease(owner: String, repo: String): Result<GitHubRelease>
|
suspend fun getLatestRelease(owner: String, repo: String): Result<GitHubRelease>
|
||||||
|
|
||||||
|
suspend fun getNightlyRelease(owner: String, repo: String): Result<GitHubRelease>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,4 +24,33 @@ class KtorGitHubApi(private val client: HttpClient) : GitHubApi {
|
|||||||
Result.failure(e)
|
Result.failure(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun getNightlyRelease(owner: String, repo: String): Result<GitHubRelease> {
|
||||||
|
return try {
|
||||||
|
// Fetch all releases
|
||||||
|
val releases: List<GitHubRelease> =
|
||||||
|
client.get("https://api.github.com/repos/$owner/$repo/releases").body()
|
||||||
|
|
||||||
|
// Find the first release with "nightly" in the tag_name (case-insensitive)
|
||||||
|
val nightlyRelease =
|
||||||
|
releases.firstOrNull { release ->
|
||||||
|
release.tagName.contains("nightly", ignoreCase = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nightlyRelease != null) {
|
||||||
|
Result.success(nightlyRelease)
|
||||||
|
} else {
|
||||||
|
Result.failure(Exception("No release with 'nightly' tag found"))
|
||||||
|
}
|
||||||
|
} catch (e: ClientRequestException) {
|
||||||
|
when (e.response.status) {
|
||||||
|
HttpStatusCode.Forbidden -> Result.failure(Exception("Rate limit exceeded"))
|
||||||
|
HttpStatusCode.NotFound ->
|
||||||
|
Result.failure(Exception("Repository or release not found"))
|
||||||
|
else -> Result.failure(e)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Result.failure(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppUpdate
|
import com.zaneschepke.wireguardautotunnel.domain.entity.AppUpdate
|
||||||
@@ -16,6 +17,7 @@ import io.ktor.utils.io.readAvailable
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
class GitHubUpdateRepository(
|
class GitHubUpdateRepository(
|
||||||
private val gitHubApi: GitHubApi,
|
private val gitHubApi: GitHubApi,
|
||||||
@@ -27,11 +29,24 @@ class GitHubUpdateRepository(
|
|||||||
) : UpdateRepository {
|
) : UpdateRepository {
|
||||||
override suspend fun checkForUpdate(currentVersion: String): Result<AppUpdate?> =
|
override suspend fun checkForUpdate(currentVersion: String): Result<AppUpdate?> =
|
||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
gitHubApi.getLatestRelease(githubOwner, githubRepo).map { release ->
|
Timber.i("Checking for update")
|
||||||
if (
|
val release =
|
||||||
NumberUtils.compareVersions(release.tagName.removePrefix("v"), currentVersion) >
|
if (BuildConfig.VERSION_NAME.contains("nightly")) {
|
||||||
0
|
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()
|
release.toAppUpdate()
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
|
|||||||
@@ -2,22 +2,21 @@ package com.zaneschepke.wireguardautotunnel.ui.common
|
|||||||
|
|
||||||
import androidx.compose.animation.animateContentSize
|
import androidx.compose.animation.animateContentSize
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.combinedClickable
|
import androidx.compose.foundation.combinedClickable
|
||||||
import androidx.compose.foundation.indication
|
import androidx.compose.foundation.indication
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.interaction.PressInteraction
|
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.ripple
|
import androidx.compose.material3.ripple
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
@@ -44,9 +43,15 @@ fun ExpandingRowListItem(
|
|||||||
modifier =
|
modifier =
|
||||||
Modifier.animateContentSize()
|
Modifier.animateContentSize()
|
||||||
.clip(RoundedCornerShape(8.dp))
|
.clip(RoundedCornerShape(8.dp))
|
||||||
|
.background(
|
||||||
|
if (isSelected) MaterialTheme.colorScheme.primary.copy(alpha = 0.1f)
|
||||||
|
else Color.Transparent
|
||||||
|
)
|
||||||
.then(
|
.then(
|
||||||
if (!isTv) {
|
if (!isTv) {
|
||||||
Modifier.combinedClickable(
|
Modifier.combinedClickable(
|
||||||
|
interactionSource = interactionSource,
|
||||||
|
indication = ripple(),
|
||||||
onClick = onClick,
|
onClick = onClick,
|
||||||
onLongClick = {
|
onLongClick = {
|
||||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
@@ -54,22 +59,9 @@ fun ExpandingRowListItem(
|
|||||||
},
|
},
|
||||||
onDoubleClick = onDoubleClick,
|
onDoubleClick = onDoubleClick,
|
||||||
)
|
)
|
||||||
.indication(
|
|
||||||
interactionSource = interactionSource,
|
|
||||||
indication = ripple(),
|
|
||||||
)
|
|
||||||
} else Modifier
|
} else Modifier
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
LaunchedEffect(isSelected) {
|
|
||||||
if (isSelected) {
|
|
||||||
interactionSource.emit(PressInteraction.Press(Offset.Zero))
|
|
||||||
} else {
|
|
||||||
interactionSource.emit(
|
|
||||||
PressInteraction.Release(PressInteraction.Press(Offset.Zero))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Column {
|
Column {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),
|
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),
|
||||||
|
|||||||
@@ -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) }
|
||||||
|
}
|
||||||
@@ -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),
|
||||||
|
|||||||
@@ -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,14 +70,16 @@ 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) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val (wifiName, securityType) = wifiInfo
|
||||||
|
Column {
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
wifiName?.let { stringResource(R.string.wifi_name_template, it) }
|
wifiName?.let { stringResource(R.string.wifi_name_template, it) }
|
||||||
@@ -90,10 +91,20 @@ fun WifiTunnelingItems(
|
|||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.clickable {
|
Modifier.clickable { wifiName?.let { clipboardHelper.copy(it) } },
|
||||||
wifiName?.let { clipboard.setText(AnnotatedString(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) },
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileImportLauncherForResult
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileImportLauncherForResult
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ExportTunnelsBottomSheet
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ExportTunnelsBottomSheet
|
||||||
@@ -29,7 +29,7 @@ import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
|||||||
@Composable
|
@Composable
|
||||||
fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: AppViewModel) {
|
fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: AppViewModel) {
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val clipboard = LocalClipboardManager.current
|
val clipboard = rememberClipboardHelper()
|
||||||
|
|
||||||
var showUrlImportDialog by remember { mutableStateOf(false) }
|
var showUrlImportDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
@@ -90,8 +90,9 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
|||||||
requestPermissionLauncher.launch(android.Manifest.permission.CAMERA)
|
requestPermissionLauncher.launch(android.Manifest.permission.CAMERA)
|
||||||
},
|
},
|
||||||
onClipboardClick = {
|
onClipboardClick = {
|
||||||
clipboard.getText()?.text?.let {
|
clipboard.paste { result ->
|
||||||
viewModel.handleEvent(AppEvent.ImportTunnelFromClipboard(it))
|
if (result != null)
|
||||||
|
viewModel.handleEvent(AppEvent.ImportTunnelFromClipboard(result))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onManualImportClick = {
|
onManualImportClick = {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.overscroll
|
import androidx.compose.foundation.overscroll
|
||||||
|
import androidx.compose.foundation.rememberOverscrollEffect
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@@ -18,6 +19,7 @@ import com.zaneschepke.wireguardautotunnel.core.tunnel.getValueById
|
|||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||||
@@ -35,12 +37,19 @@ fun TunnelList(
|
|||||||
onToggleTunnel: (TunnelConf, Boolean) -> Unit,
|
onToggleTunnel: (TunnelConf, Boolean) -> Unit,
|
||||||
viewModel: AppViewModel,
|
viewModel: AppViewModel,
|
||||||
) {
|
) {
|
||||||
|
val isTv = LocalIsAndroidTV.current
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val collator = Collator.getInstance(Locale.getDefault())
|
val collator = Collator.getInstance(Locale.getDefault())
|
||||||
val sortedTunnels =
|
val sortedTunnels =
|
||||||
remember(appUiState.tunnels) {
|
remember(appUiState.tunnels) {
|
||||||
appUiState.tunnels.sortedWith(compareBy(collator) { it.tunName })
|
appUiState.tunnels.sortedWith(
|
||||||
|
compareBy(
|
||||||
|
// primary tunnel first
|
||||||
|
{ !it.isPrimaryTunnel },
|
||||||
|
{ collator.compare(it.tunName, "") },
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
@@ -49,7 +58,7 @@ fun TunnelList(
|
|||||||
modifier =
|
modifier =
|
||||||
modifier
|
modifier
|
||||||
.pointerInput(Unit) { if (appUiState.tunnels.isEmpty()) return@pointerInput }
|
.pointerInput(Unit) { if (appUiState.tunnels.isEmpty()) return@pointerInput }
|
||||||
.overscroll(ScrollableDefaults.overscrollEffect()),
|
.overscroll(rememberOverscrollEffect()),
|
||||||
state = rememberLazyListState(0, appUiState.tunnels.count()),
|
state = rememberLazyListState(0, appUiState.tunnels.count()),
|
||||||
userScrollEnabled = true,
|
userScrollEnabled = true,
|
||||||
reverseLayout = false,
|
reverseLayout = false,
|
||||||
@@ -71,8 +80,12 @@ fun TunnelList(
|
|||||||
tunnel = tunnel,
|
tunnel = tunnel,
|
||||||
tunnelState = tunnelState,
|
tunnelState = tunnelState,
|
||||||
onClick = {
|
onClick = {
|
||||||
|
if (selectedTunnels.isNotEmpty() && !isTv) {
|
||||||
|
viewModel.handleEvent(AppEvent.ToggleSelectedTunnel(tunnel))
|
||||||
|
} else {
|
||||||
navController.navigate(Route.TunnelOptions(tunnel.id))
|
navController.navigate(Route.TunnelOptions(tunnel.id))
|
||||||
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onDoubleClick = {
|
onDoubleClick = {
|
||||||
viewModel.handleEvent(AppEvent.ToggleTunnelStatsExpanded(tunnel.id))
|
viewModel.handleEvent(AppEvent.ToggleTunnelStatsExpanded(tunnel.id))
|
||||||
@@ -81,6 +94,7 @@ fun TunnelList(
|
|||||||
viewModel.handleEvent(AppEvent.ToggleSelectedTunnel(it))
|
viewModel.handleEvent(AppEvent.ToggleSelectedTunnel(it))
|
||||||
},
|
},
|
||||||
onSwitchClick = { checked -> onToggleTunnel(tunnel, checked) },
|
onSwitchClick = { checked -> onToggleTunnel(tunnel, checked) },
|
||||||
|
isTv = isTv,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
|||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.ExpandingRowListItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.ExpandingRowListItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asColor
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asColor
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -40,9 +39,8 @@ fun TunnelRowItem(
|
|||||||
onDoubleClick: () -> Unit,
|
onDoubleClick: () -> Unit,
|
||||||
onToggleSelectedTunnel: (TunnelConf) -> Unit,
|
onToggleSelectedTunnel: (TunnelConf) -> Unit,
|
||||||
onSwitchClick: (Boolean) -> Unit,
|
onSwitchClick: (Boolean) -> Unit,
|
||||||
|
isTv: Boolean,
|
||||||
) {
|
) {
|
||||||
val isTv = LocalIsAndroidTV.current
|
|
||||||
|
|
||||||
val leadingIconColor =
|
val leadingIconColor =
|
||||||
remember(state) {
|
remember(state) {
|
||||||
if (state.status.isUp()) tunnelState.statistics.asColor() else Color.Gray
|
if (state.status.isUp()) tunnelState.statistics.asColor() else Color.Gray
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
@@ -88,9 +87,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))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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,14 +37,10 @@ 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 {
|
} else {
|
||||||
SplitTunnelContent(
|
SplitTunnelContent(
|
||||||
uiState = uiState,
|
uiState = uiState,
|
||||||
@@ -51,4 +50,3 @@ fun SplitTunnelScreen(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,7 +18,6 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
|||||||
import java.text.Collator
|
import java.text.Collator
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
@@ -50,7 +49,6 @@ constructor(
|
|||||||
tunnelId?.let { loadInitialState(it) }
|
tunnelId?.let { loadInitialState(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO improve this loading experience
|
|
||||||
private fun loadInitialState(tunnelId: Int) =
|
private fun loadInitialState(tunnelId: Int) =
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val tunnel = tunnelRepository.getById(tunnelId) ?: return@launch
|
val tunnel = tunnelRepository.getById(tunnelId) ?: return@launch
|
||||||
@@ -66,7 +64,7 @@ constructor(
|
|||||||
|
|
||||||
val installedPackages = packages.map { it.packageName }.toSet()
|
val installedPackages = packages.map { it.packageName }.toSet()
|
||||||
|
|
||||||
// remove uninstalled apps
|
// Remove uninstalled apps
|
||||||
proxyInterface.includedApplications.retainAll { it in installedPackages }
|
proxyInterface.includedApplications.retainAll { it in installedPackages }
|
||||||
proxyInterface.excludedApplications.retainAll { it in installedPackages }
|
proxyInterface.excludedApplications.retainAll { it in installedPackages }
|
||||||
|
|
||||||
@@ -98,12 +96,13 @@ constructor(
|
|||||||
selected,
|
selected,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.sortedWith(compareBy(collator) { it.first.name })
|
.sortedWith(
|
||||||
|
compareByDescending<Pair<TunnelApp, Boolean>> { it.second }
|
||||||
|
.thenBy(collator) { it.first.name }
|
||||||
|
)
|
||||||
|
|
||||||
allTunneledApps = tunneledApps
|
allTunneledApps = tunneledApps
|
||||||
|
|
||||||
delay(500)
|
|
||||||
|
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
SplitTunnelUiState(
|
SplitTunnelUiState(
|
||||||
loading = false,
|
loading = false,
|
||||||
|
|||||||
@@ -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)) },
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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),
|
||||||
) {
|
) {
|
||||||
|
enumValues<Theme>().forEach {
|
||||||
|
val title =
|
||||||
|
when (it) {
|
||||||
|
Theme.DARK -> stringResource(R.string.dark)
|
||||||
|
Theme.LIGHT -> stringResource(R.string.light)
|
||||||
|
Theme.AUTOMATIC -> stringResource(R.string.automatic)
|
||||||
|
Theme.DYNAMIC -> stringResource(R.string.dynamic)
|
||||||
|
Theme.DARKER -> stringResource(R.string.darker)
|
||||||
|
Theme.AMOLED -> stringResource(R.string.amoled)
|
||||||
|
}
|
||||||
IconSurfaceButton(
|
IconSurfaceButton(
|
||||||
title = stringResource(R.string.automatic),
|
title = title,
|
||||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.AUTOMATIC)) },
|
onClick = { viewModel.handleEvent(AppEvent.SetTheme(it)) },
|
||||||
selected = appUiState.appState.theme == Theme.AUTOMATIC,
|
selected = appUiState.appState.theme == it,
|
||||||
)
|
|
||||||
IconSurfaceButton(
|
|
||||||
title = stringResource(R.string.light),
|
|
||||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.LIGHT)) },
|
|
||||||
selected = appUiState.appState.theme == Theme.LIGHT,
|
|
||||||
)
|
|
||||||
IconSurfaceButton(
|
|
||||||
title = stringResource(R.string.dark),
|
|
||||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.DARK)) },
|
|
||||||
selected = appUiState.appState.theme == Theme.DARK,
|
|
||||||
)
|
|
||||||
IconSurfaceButton(
|
|
||||||
title = stringResource(R.string.dynamic),
|
|
||||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.DYNAMIC)) },
|
|
||||||
selected = appUiState.appState.theme == Theme.DYNAMIC,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,17 +11,16 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.zaneschepke.logcatter.model.LogMessage
|
import com.zaneschepke.logcatter.model.LogMessage
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.text.LogTypeLabel
|
import com.zaneschepke.wireguardautotunnel.ui.common.text.LogTypeLabel
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LogItem(log: LogMessage) {
|
fun LogItem(log: LogMessage) {
|
||||||
val clipboardManager = LocalClipboardManager.current
|
val clipboardManager = rememberClipboardHelper()
|
||||||
val fontSize = 10.sp
|
val fontSize = 10.sp
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
@@ -32,7 +31,7 @@ fun LogItem(log: LogMessage) {
|
|||||||
.clickable(
|
.clickable(
|
||||||
interactionSource = remember { MutableInteractionSource() },
|
interactionSource = remember { MutableInteractionSource() },
|
||||||
indication = null,
|
indication = null,
|
||||||
onClick = { clipboardManager.setText(AnnotatedString(log.toString())) },
|
onClick = { clipboardManager.copy(log.toString()) },
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
Text(text = log.tag, modifier = Modifier.fillMaxSize(0.3f), fontSize = fontSize)
|
Text(text = log.tag, modifier = Modifier.fillMaxSize(0.3f), fontSize = fontSize)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import androidx.compose.ui.res.stringResource
|
|||||||
import androidx.compose.ui.unit.dp
|
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.google.zxing.client.android.BuildConfig
|
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
||||||
@@ -23,8 +23,8 @@ import com.zaneschepke.wireguardautotunnel.ui.common.label.GroupLabel
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.ContactSupportOptions
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.ContactSupportOptions
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.GeneralSupportOptions
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.GeneralSupportOptions
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.UpdateSection
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.UpdateSection
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.canInstallPackages
|
import com.zaneschepke.wireguardautotunnel.util.extensions.canInstallPackages
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestInstallPackagesPermission
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestInstallPackagesPermission
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.showToast
|
import com.zaneschepke.wireguardautotunnel.util.extensions.showToast
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
@@ -54,6 +54,10 @@ fun SupportScreen(viewModel: SupportViewModel = hiltViewModel(), appViewModel: A
|
|||||||
InfoDialog(
|
InfoDialog(
|
||||||
onDismiss = { viewModel.handleUpdateShown() },
|
onDismiss = { viewModel.handleUpdateShown() },
|
||||||
onAttest = {
|
onAttest = {
|
||||||
|
if (BuildConfig.FLAVOR != "full") {
|
||||||
|
uiState.appUpdate?.apkUrl?.let { context.openWebUrl(it) }
|
||||||
|
return@InfoDialog
|
||||||
|
}
|
||||||
if (context.canInstallPackages()) {
|
if (context.canInstallPackages()) {
|
||||||
viewModel.handleDownloadAndInstallApk()
|
viewModel.handleDownloadAndInstallApk()
|
||||||
} else {
|
} else {
|
||||||
@@ -80,7 +84,12 @@ fun SupportScreen(viewModel: SupportViewModel = hiltViewModel(), appViewModel: A
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
confirmText = { Text(stringResource(R.string.download_and_install)) },
|
confirmText = {
|
||||||
|
Text(
|
||||||
|
if (BuildConfig.FLAVOR != "full") stringResource(R.string.download)
|
||||||
|
else stringResource(R.string.download_and_install)
|
||||||
|
)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,17 +117,21 @@ fun SupportScreen(viewModel: SupportViewModel = hiltViewModel(), appViewModel: A
|
|||||||
) {
|
) {
|
||||||
GroupLabel(
|
GroupLabel(
|
||||||
stringResource(R.string.thank_you),
|
stringResource(R.string.thank_you),
|
||||||
modifier = Modifier.padding(horizontal = 12.dp),
|
modifier = Modifier.padding(horizontal = 12.dp).padding(bottom = 12.dp),
|
||||||
)
|
)
|
||||||
if (BuildConfig.BUILD_TYPE == Constants.RELEASE) {
|
|
||||||
UpdateSection(
|
UpdateSection(
|
||||||
onUpdateCheck = {
|
onUpdateCheck = {
|
||||||
|
if (
|
||||||
|
BuildConfig.DEBUG ||
|
||||||
|
BuildConfig.VERSION_NAME.contains("beta") ||
|
||||||
|
BuildConfig.FLAVOR == "google"
|
||||||
|
)
|
||||||
|
return@UpdateSection context.showToast(R.string.update_check_unsupported)
|
||||||
context.showToast(R.string.checking_for_update)
|
context.showToast(R.string.checking_for_update)
|
||||||
viewModel.handleUpdateCheck()
|
viewModel.handleUpdateCheck()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
SectionDivider()
|
SectionDivider()
|
||||||
}
|
|
||||||
GeneralSupportOptions(context)
|
GeneralSupportOptions(context)
|
||||||
SectionDivider()
|
SectionDivider()
|
||||||
ContactSupportOptions(context)
|
ContactSupportOptions(context)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.support.components
|
package com.zaneschepke.wireguardautotunnel.ui.screens.support.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.CloudDownload
|
import androidx.compose.material.icons.filled.CloudDownload
|
||||||
import androidx.compose.material.icons.rounded.CloudDownload
|
import androidx.compose.material.icons.rounded.CloudDownload
|
||||||
@@ -11,7 +12,6 @@ import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionIte
|
|||||||
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.common.button.surface.SelectionLabelType
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun UpdateSection(onUpdateCheck: () -> Unit = {}) {
|
fun UpdateSection(onUpdateCheck: () -> Unit = {}) {
|
||||||
@@ -26,16 +26,20 @@ fun UpdateSection(onUpdateCheck: () -> Unit = {}) {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
description = {
|
description = {
|
||||||
val versionName =
|
Column {
|
||||||
if (BuildConfig.BUILD_TYPE == Constants.RELEASE) {
|
|
||||||
"v${BuildConfig.VERSION_NAME}"
|
|
||||||
} else {
|
|
||||||
"v${BuildConfig.VERSION_NAME}-${BuildConfig.BUILD_TYPE}"
|
|
||||||
}
|
|
||||||
SelectionItemLabel(
|
SelectionItemLabel(
|
||||||
stringResource(R.string.version_template, versionName),
|
stringResource(
|
||||||
|
R.string.version_template,
|
||||||
|
"v${BuildConfig.VERSION_NAME +
|
||||||
|
if(BuildConfig.DEBUG) "-debug" else "" }",
|
||||||
|
),
|
||||||
SelectionLabelType.DESCRIPTION,
|
SelectionLabelType.DESCRIPTION,
|
||||||
)
|
)
|
||||||
|
SelectionItemLabel(
|
||||||
|
stringResource(R.string.flavor_template, BuildConfig.FLAVOR),
|
||||||
|
SelectionLabelType.DESCRIPTION,
|
||||||
|
)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onClick = onUpdateCheck,
|
onClick = onUpdateCheck,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ val Plantation = Color(0xFF264A49)
|
|||||||
val Shark = Color(0xFF21272A)
|
val Shark = Color(0xFF21272A)
|
||||||
val BalticSea = Color(0xFF1C1B1F)
|
val BalticSea = Color(0xFF1C1B1F)
|
||||||
|
|
||||||
|
// amoled
|
||||||
|
val ElectricTeal = Color(0xFF4DD0E1)
|
||||||
|
|
||||||
// Status colors
|
// Status colors
|
||||||
val SilverTree = Color(0xFF6DB58B)
|
val SilverTree = Color(0xFF6DB58B)
|
||||||
val Brick = Color(0xFFCE4257)
|
val Brick = Color(0xFFCE4257)
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ enum class Theme {
|
|||||||
AUTOMATIC,
|
AUTOMATIC,
|
||||||
LIGHT,
|
LIGHT,
|
||||||
DARK,
|
DARK,
|
||||||
|
DARKER,
|
||||||
|
AMOLED,
|
||||||
DYNAMIC,
|
DYNAMIC,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +61,18 @@ fun WireguardAutoTunnelTheme(theme: Theme = Theme.AUTOMATIC, content: @Composabl
|
|||||||
isDark = true
|
isDark = true
|
||||||
DarkColorScheme
|
DarkColorScheme
|
||||||
}
|
}
|
||||||
|
Theme.DARKER -> {
|
||||||
|
isDark = true
|
||||||
|
DarkColorScheme.copy(surface = BalticSea, background = BalticSea)
|
||||||
|
}
|
||||||
|
Theme.AMOLED -> {
|
||||||
|
isDark = true
|
||||||
|
DarkColorScheme.copy(
|
||||||
|
surface = Color.Black,
|
||||||
|
background = Color.Black,
|
||||||
|
primary = ElectricTeal,
|
||||||
|
)
|
||||||
|
}
|
||||||
Theme.LIGHT -> {
|
Theme.LIGHT -> {
|
||||||
isDark = false
|
isDark = false
|
||||||
LightColorScheme
|
LightColorScheme
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.math.BigDecimal
|
|||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
object NumberUtils {
|
object NumberUtils {
|
||||||
private const val BYTES_IN_KB = 1024.0
|
private const val BYTES_IN_KB = 1024.0
|
||||||
@@ -41,8 +42,13 @@ object NumberUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun compareVersions(newVersion: String, currentVersion: String): Int {
|
fun compareVersions(newVersion: String, currentVersion: String): Int {
|
||||||
|
try {
|
||||||
val newSemver = Semver(newVersion, Semver.SemverType.LOOSE)
|
val newSemver = Semver(newVersion, Semver.SemverType.LOOSE)
|
||||||
val currentSemver = Semver(currentVersion, Semver.SemverType.LOOSE)
|
val currentSemver = Semver(currentVersion, Semver.SemverType.LOOSE)
|
||||||
return newSemver.compareTo(currentSemver)
|
return newSemver.compareTo(currentSemver)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Timber.e(e, "Failed to compare versions $newVersion and $currentVersion")
|
||||||
|
return 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ constructor(
|
|||||||
appDataRepository.tunnels.flow,
|
appDataRepository.tunnels.flow,
|
||||||
appDataRepository.appState.flow,
|
appDataRepository.appState.flow,
|
||||||
tunnelManager.activeTunnels,
|
tunnelManager.activeTunnels,
|
||||||
serviceManager.autoTunnelActive,
|
serviceManager.autoTunnelService.map { it != null },
|
||||||
networkMonitor.networkStatusFlow,
|
networkMonitor.networkStatusFlow,
|
||||||
) { array ->
|
) { array ->
|
||||||
val settings = array[0] as AppSettings
|
val settings = array[0] as AppSettings
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 5.1 KiB |
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@color/ic_banner_background"/>
|
|
||||||
<foreground android:drawable="@mipmap/ic_banner_foreground"/>
|
|
||||||
</adaptive-icon>
|
|
||||||
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 115 KiB |
|
After Width: | Height: | Size: 166 KiB |
@@ -220,7 +220,9 @@
|
|||||||
<string name="tunnel_error_template">Tunnel failed with: %1$s</string>
|
<string name="tunnel_error_template">Tunnel failed with: %1$s</string>
|
||||||
<string name="wifi_name_template">Active: %1$s</string>
|
<string name="wifi_name_template">Active: %1$s</string>
|
||||||
<string name="remote_key_template">Key: %1$s</string>
|
<string name="remote_key_template">Key: %1$s</string>
|
||||||
<string name="version_template">Current version: %1$s</string>
|
<string name="version_template">Version: %1$s</string>
|
||||||
|
<string name="security_template">Security: %1$s</string>
|
||||||
|
<string name="flavor_template">Flavor: %1$s</string>
|
||||||
<string name="config_error">config error</string>
|
<string name="config_error">config error</string>
|
||||||
<string name="dns_resolve_error">dns resolution error</string>
|
<string name="dns_resolve_error">dns resolution error</string>
|
||||||
<string name="invalid_config_error">invalid_config_error</string>
|
<string name="invalid_config_error">invalid_config_error</string>
|
||||||
@@ -253,4 +255,7 @@
|
|||||||
<string name="install_updated_permission">This app needs permission to install updates.</string>
|
<string name="install_updated_permission">This app needs permission to install updates.</string>
|
||||||
<string name="allow">Allow</string>
|
<string name="allow">Allow</string>
|
||||||
<string name="licenses">Licenses</string>
|
<string name="licenses">Licenses</string>
|
||||||
|
<string name="update_check_unsupported">Update check not supported this build type.</string>
|
||||||
|
<string name="darker">Darker</string>
|
||||||
|
<string name="amoled">AMOLED</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -6,3 +6,8 @@ repositories {
|
|||||||
google()
|
google()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("org.semver4j:semver4j:5.6.0")
|
||||||
|
implementation("org.ajoberstar.grgit:grgit-core:5.3.0")
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,21 +1,16 @@
|
|||||||
object Constants {
|
object Constants {
|
||||||
const val VERSION_NAME = "3.8.3"
|
const val VERSION_NAME = "3.9.0"
|
||||||
const val JVM_TARGET = "17"
|
const val JVM_TARGET = "17"
|
||||||
const val VERSION_CODE = 38300
|
const val VERSION_CODE = 38900
|
||||||
const val TARGET_SDK = 35
|
const val TARGET_SDK = 35
|
||||||
const val MIN_SDK = 26
|
const val MIN_SDK = 26
|
||||||
const val APP_ID = "com.zaneschepke.wireguardautotunnel"
|
const val APP_ID = "com.zaneschepke.wireguardautotunnel"
|
||||||
const val APP_NAME = "wgtunnel"
|
const val APP_NAME = "wgtunnel"
|
||||||
|
|
||||||
const val STORE_PASS_VAR = "SIGNING_STORE_PASSWORD"
|
// build types
|
||||||
const val KEY_ALIAS_VAR = "SIGNING_KEY_ALIAS"
|
|
||||||
const val KEY_PASS_VAR = "SIGNING_KEY_PASSWORD"
|
|
||||||
const val KEY_STORE_PATH_VAR = "KEY_STORE_PATH"
|
|
||||||
|
|
||||||
const val RELEASE = "release"
|
const val RELEASE = "release"
|
||||||
const val NIGHTLY = "nightly"
|
const val NIGHTLY = "nightly"
|
||||||
const val PRERELEASE = "prerelease"
|
const val PRERELEASE = "prerelease"
|
||||||
const val TYPE = "type"
|
|
||||||
|
|
||||||
val allowedLicenses = listOf("MIT", "Apache-2.0", "BSD-3-Clause")
|
val allowedLicenses = listOf("MIT", "Apache-2.0", "BSD-3-Clause")
|
||||||
const val XZING_LICENSE_URL: String = "https://github.com/journeyapps/zxing-android-embedded/blob/master/COPYING"
|
const val XZING_LICENSE_URL: String = "https://github.com/journeyapps/zxing-android-embedded/blob/master/COPYING"
|
||||||
|
|||||||
@@ -1,76 +1,7 @@
|
|||||||
|
|
||||||
|
import org.ajoberstar.grgit.Grgit
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import java.io.File
|
import org.semver4j.Semver
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
fun Project.getCurrentFlavor(): String {
|
|
||||||
val taskRequestsStr = gradle.startParameter.taskRequests.toString()
|
|
||||||
val pattern: java.util.regex.Pattern =
|
|
||||||
if (taskRequestsStr.contains(":app:assemble")) {
|
|
||||||
java.util.regex.Pattern.compile(":app:assemble(\\w+)(Release|Debug)")
|
|
||||||
} else {
|
|
||||||
java.util.regex.Pattern.compile(":app:bundle(\\w+)(Release|Debug)")
|
|
||||||
}
|
|
||||||
|
|
||||||
val matcher = pattern.matcher(taskRequestsStr)
|
|
||||||
val flavor =
|
|
||||||
if (matcher.find()) {
|
|
||||||
matcher.group(1).lowercase()
|
|
||||||
} else {
|
|
||||||
print("NO FLAVOR FOUND")
|
|
||||||
""
|
|
||||||
}
|
|
||||||
return flavor
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Project.getBuildTaskName(): String {
|
|
||||||
val taskRequestsStr = gradle.startParameter.taskRequests[0].toString()
|
|
||||||
return taskRequestsStr.also {
|
|
||||||
project.logger.lifecycle("Build task: $it")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getLocalProperty(key: String, file: String = "local.properties"): String? {
|
|
||||||
val properties = Properties()
|
|
||||||
val localProperties = File(file)
|
|
||||||
if (localProperties.isFile) {
|
|
||||||
java.io.InputStreamReader(java.io.FileInputStream(localProperties), Charsets.UTF_8)
|
|
||||||
.use { reader ->
|
|
||||||
properties.load(reader)
|
|
||||||
}
|
|
||||||
} else return null
|
|
||||||
return properties.getProperty(key)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun Project.getSigningProperties(): Properties {
|
|
||||||
return Properties().apply {
|
|
||||||
// created local file for signing details
|
|
||||||
try {
|
|
||||||
load(file("signing.properties").reader())
|
|
||||||
} catch (_: Exception) {
|
|
||||||
load(file("signing_template.properties").reader())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Project.getStoreFile(): File {
|
|
||||||
return file(
|
|
||||||
System.getenv()
|
|
||||||
.getOrDefault(
|
|
||||||
Constants.KEY_STORE_PATH_VAR,
|
|
||||||
getSigningProperties().getProperty(Constants.KEY_STORE_PATH_VAR),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Project.getSigningProperty(property: String): String {
|
|
||||||
// try to get secrets from env first for pipeline build, then properties file for local
|
|
||||||
return System.getenv()
|
|
||||||
.getOrDefault(
|
|
||||||
property,
|
|
||||||
getSigningProperties().getProperty(property),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Project.languageList(): List<String> {
|
fun Project.languageList(): List<String> {
|
||||||
return fileTree("../app/src/main/res") { include("**/strings.xml") }
|
return fileTree("../app/src/main/res") { include("**/strings.xml") }
|
||||||
@@ -84,6 +15,100 @@ fun Project.languageList(): List<String> {
|
|||||||
.toList() + "en"
|
.toList() + "en"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the Git commit hash
|
||||||
|
fun Project.getGitCommitHash(): String {
|
||||||
|
var grgit: Grgit? = null
|
||||||
|
try {
|
||||||
|
grgit = Grgit.open(mapOf("currentDir" to projectDir))
|
||||||
|
return grgit.head().abbreviatedId
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logger.warn("Failed to get Git commit hash: ${e.message}. Using fallback.")
|
||||||
|
return "unknown"
|
||||||
|
} finally {
|
||||||
|
grgit?.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get commit count since last commit for versionCode increment
|
||||||
|
fun Project.getCommitCountSinceLastCommit(): Int {
|
||||||
|
var grgit: Grgit? = null
|
||||||
|
try {
|
||||||
|
grgit = Grgit.open(mapOf("currentDir" to projectDir))
|
||||||
|
val headCommit = grgit.head()
|
||||||
|
val log = grgit.log(mapOf(
|
||||||
|
"includes" to listOf(headCommit.id)
|
||||||
|
))
|
||||||
|
return log.size
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logger.warn("Failed to get commit count: ${e.message}. Using fallback.")
|
||||||
|
return 0
|
||||||
|
} finally {
|
||||||
|
grgit?.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get versionCode increment for nightly/pre-release
|
||||||
|
fun Project.getVersionCodeIncrement(): Int {
|
||||||
|
val isNightlyBuild = gradle.startParameter.taskNames.any { it.lowercase().contains("nightly") }
|
||||||
|
val isPreReleaseBuild = gradle.startParameter.taskNames.any { it.lowercase().contains("prerelease") }
|
||||||
|
if (!isNightlyBuild && !isPreReleaseBuild) return 0
|
||||||
|
|
||||||
|
return System.getenv("GITHUB_RUN_NUMBER")?.toIntOrNull()
|
||||||
|
?: System.getenv("CI_BUILD_NUMBER")?.toIntOrNull()
|
||||||
|
?: getCommitCountSinceLastCommit()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute versionName dynamic bumping for nightly/pre-release
|
||||||
|
fun Project.computeVersionName(): String {
|
||||||
|
val isNightlyBuild = isNightlyBuild()
|
||||||
|
val isPreReleaseBuild = isPrereleaseBuild()
|
||||||
|
|
||||||
|
// Static version from Constants.kt
|
||||||
|
val baseVersion = Semver.parse(Constants.VERSION_NAME) ?: Semver.of(0, 0, 0)
|
||||||
|
|
||||||
|
return when {
|
||||||
|
isNightlyBuild -> {
|
||||||
|
// Bump patch for nightly
|
||||||
|
val nightlyVersion = Semver.of(
|
||||||
|
baseVersion.major,
|
||||||
|
baseVersion.minor,
|
||||||
|
baseVersion.patch + 1
|
||||||
|
)
|
||||||
|
"${nightlyVersion}-nightly+git.${getGitCommitHash()}"
|
||||||
|
}
|
||||||
|
isPreReleaseBuild -> {
|
||||||
|
// Bump minor for pre-release
|
||||||
|
val preReleaseVersion = Semver.of(
|
||||||
|
baseVersion.major,
|
||||||
|
baseVersion.minor + 1,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
"${preReleaseVersion}-beta+git.${getGitCommitHash()}"
|
||||||
|
}
|
||||||
|
else -> Constants.VERSION_NAME
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Project.isNightlyBuild(): Boolean {
|
||||||
|
return gradle.startParameter.taskNames.any { it.lowercase().contains(Constants.NIGHTLY) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Project.isPrereleaseBuild(): Boolean {
|
||||||
|
return gradle.startParameter.taskNames.any { it.lowercase().contains(Constants.PRERELEASE) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute versionCode (static baseline, dynamic bumping for nightly/pre-release)
|
||||||
|
fun Project.computeVersionCode(): Int {
|
||||||
|
val isNightlyBuild = isNightlyBuild()
|
||||||
|
val isPreReleaseBuild = isPrereleaseBuild()
|
||||||
|
var versionCode = Constants.VERSION_CODE
|
||||||
|
|
||||||
|
if (isPreReleaseBuild) {
|
||||||
|
versionCode += 100 // Minor bump
|
||||||
|
}
|
||||||
|
if (isNightlyBuild) {
|
||||||
|
versionCode += 1 // Patch bump
|
||||||
|
}
|
||||||
|
|
||||||
|
return versionCode + getVersionCodeIncrement()
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.util.Properties
|
||||||
|
|
||||||
|
object LocalProperties {
|
||||||
|
|
||||||
|
private val properties by lazy {
|
||||||
|
val props = Properties()
|
||||||
|
val file = File("local.properties")
|
||||||
|
if (file.exists()) {
|
||||||
|
FileInputStream(file).use { props.load(it) }
|
||||||
|
}
|
||||||
|
props
|
||||||
|
}
|
||||||
|
|
||||||
|
fun get(key: String): String? = properties.getProperty(key)
|
||||||
|
|
||||||
|
fun getOrDefault(key: String, default: String): String = properties.getProperty(key, default)
|
||||||
|
}
|
||||||
@@ -4,25 +4,25 @@ platform :android do
|
|||||||
|
|
||||||
desc 'Deploy a new internal version to the Google Play Store'
|
desc 'Deploy a new internal version to the Google Play Store'
|
||||||
lane :internal do
|
lane :internal do
|
||||||
gradle(task: "clean bundleGeneralRelease")
|
gradle(task: "clean bundleGoogleRelease")
|
||||||
upload_to_play_store(track: 'internal', skip_upload_apk: true)
|
upload_to_play_store(track: 'internal', skip_upload_apk: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Deploy an alpha version to the Google Play"
|
desc "Deploy an alpha version to the Google Play"
|
||||||
lane :alpha do
|
lane :alpha do
|
||||||
gradle(task: "clean bundleGeneralRelease")
|
gradle(task: "clean bundleGoogleRelease")
|
||||||
upload_to_play_store(track: 'alpha', skip_upload_apk: true)
|
upload_to_play_store(track: 'alpha', skip_upload_apk: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Deploy a beta version to the Google Play"
|
desc "Deploy a beta version to the Google Play"
|
||||||
lane :beta do
|
lane :beta do
|
||||||
gradle(task: "clean bundleGeneralRelease")
|
gradle(task: "clean bundleGoogleRelease")
|
||||||
upload_to_play_store(track: 'beta', skip_upload_apk: true)
|
upload_to_play_store(track: 'beta', skip_upload_apk: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Deploy a new version to the Google Play"
|
desc "Deploy a new version to the Google Play"
|
||||||
lane :production do
|
lane :production do
|
||||||
gradle(task: "clean bundleGeneralRelease")
|
gradle(task: "clean bundleGoogleRelease")
|
||||||
upload_to_play_store(skip_upload_apk: true)
|
upload_to_play_store(skip_upload_apk: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
What's new:
|
||||||
|
- Fix Android TV Banners
|
||||||
|
- Add multi-select for tunnels
|
||||||
|
- Add in-app update checker
|
||||||
|
- Add license screen
|
||||||
|
- Various bug fixes
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||||
# Specifies the JVM arguments used for the daemon process.
|
# Specifies the JVM arguments used for the daemon process.
|
||||||
# The setting is particularly useful for tweaking memory settings.
|
# The setting is particularly useful for tweaking memory settings.
|
||||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8
|
||||||
# When configured, Gradle will run in incubating parallel mode.
|
# When configured, Gradle will run in incubating parallel mode.
|
||||||
# This option should only be used with decoupled projects. More details, visit
|
# This option should only be used with decoupled projects. More details, visit
|
||||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||||
|
|||||||
@@ -5,31 +5,31 @@ amneziawgAndroid = "1.3.8"
|
|||||||
androidx-junit = "1.2.1"
|
androidx-junit = "1.2.1"
|
||||||
appcompat = "1.7.0"
|
appcompat = "1.7.0"
|
||||||
biometricKtx = "1.2.0-alpha05"
|
biometricKtx = "1.2.0-alpha05"
|
||||||
markdownCompose = "0.5.7"
|
|
||||||
coreKtx = "1.16.0"
|
coreKtx = "1.16.0"
|
||||||
datastorePreferences = "1.1.4"
|
datastorePreferences = "1.1.4"
|
||||||
desugar_jdk_libs = "2.1.5"
|
desugar_jdk_libs = "2.1.5"
|
||||||
espressoCore = "3.6.1"
|
espressoCore = "3.6.1"
|
||||||
hiltAndroid = "2.56.1"
|
hiltAndroid = "2.56.2"
|
||||||
hiltCompiler = "1.2.0"
|
hiltCompiler = "1.2.0"
|
||||||
junit = "4.13.2"
|
junit = "4.13.2"
|
||||||
kotlinx-serialization-json = "1.8.1"
|
kotlinx-serialization-json = "1.8.1"
|
||||||
ktorClientCore = "3.1.1"
|
ktorClientCore = "3.1.2"
|
||||||
lifecycle-runtime-compose = "2.8.7"
|
lifecycle-runtime-compose = "2.8.7"
|
||||||
material3 = "1.3.2"
|
material3 = "1.3.2"
|
||||||
navigationCompose = "2.8.9"
|
navigationCompose = "2.8.9"
|
||||||
pinLockCompose = "1.0.4"
|
pinLockCompose = "1.0.4"
|
||||||
qrcodeKotlin = "4.4.1"
|
qrcodeKotlin = "4.4.1"
|
||||||
roomVersion = "2.7.0"
|
roomVersion = "2.7.1"
|
||||||
semver4j = "3.1.0"
|
semver4j = "3.1.0"
|
||||||
|
slf4jAndroid = "1.7.36"
|
||||||
timber = "5.0.1"
|
timber = "5.0.1"
|
||||||
tunnel = "1.2.14"
|
tunnel = "1.2.14"
|
||||||
androidGradlePlugin = "8.9.2"
|
androidGradlePlugin = "8.9.2"
|
||||||
kotlin = "2.1.20"
|
kotlin = "2.1.20"
|
||||||
ksp = "2.1.20-2.0.0"
|
ksp = "2.1.20-2.0.0"
|
||||||
composeBom = "2025.04.00"
|
composeBom = "2025.04.01"
|
||||||
compose = "1.7.8"
|
compose = "1.7.8"
|
||||||
workRuntimeKtxVersion = "2.10.0"
|
workRuntimeKtxVersion = "2.10.1"
|
||||||
zxingAndroidEmbedded = "4.3.0"
|
zxingAndroidEmbedded = "4.3.0"
|
||||||
coreSplashscreen = "1.0.1"
|
coreSplashscreen = "1.0.1"
|
||||||
gradlePlugins-grgit = "5.3.0"
|
gradlePlugins-grgit = "5.3.0"
|
||||||
@@ -38,7 +38,7 @@ gradlePlugins-grgit = "5.3.0"
|
|||||||
material = "1.12.0"
|
material = "1.12.0"
|
||||||
storage = "1.5.0"
|
storage = "1.5.0"
|
||||||
ktfmt = "0.22.0"
|
ktfmt = "0.22.0"
|
||||||
licensee = "1.12.0"
|
licensee = "1.13.0"
|
||||||
|
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
@@ -95,12 +95,12 @@ ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktorCli
|
|||||||
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktorClientCore" }
|
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktorClientCore" }
|
||||||
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktorClientCore" }
|
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktorClientCore" }
|
||||||
lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle-runtime-compose" }
|
lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle-runtime-compose" }
|
||||||
markdown-compose = { module = "com.github.jeziellago:compose-markdown", version.ref = "markdownCompose" }
|
|
||||||
material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "compose" }
|
material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "compose" }
|
||||||
|
|
||||||
pin-lock-compose = { module = "com.zaneschepke:pin_lock_compose", version.ref = "pinLockCompose" }
|
pin-lock-compose = { module = "com.zaneschepke:pin_lock_compose", version.ref = "pinLockCompose" }
|
||||||
qrcode-kotlin = { module = "io.github.g0dkar:qrcode-kotlin", version.ref = "qrcodeKotlin" }
|
qrcode-kotlin = { module = "io.github.g0dkar:qrcode-kotlin", version.ref = "qrcodeKotlin" }
|
||||||
semver4j = { module = "com.vdurmont:semver4j", version.ref = "semver4j" }
|
semver4j = { module = "com.vdurmont:semver4j", version.ref = "semver4j" }
|
||||||
|
slf4j-android = { module = "org.slf4j:slf4j-android", version.ref = "slf4jAndroid" }
|
||||||
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
|
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
|
||||||
tunnel = { module = "com.zaneschepke:wireguard-android", version.ref = "tunnel" }
|
tunnel = { module = "com.zaneschepke:wireguard-android", version.ref = "tunnel" }
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ plugins {
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "com.zaneschepke.networkmonitor"
|
namespace = "com.zaneschepke.networkmonitor"
|
||||||
compileSdk = 34
|
compileSdk = Constants.TARGET_SDK
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdk = 26
|
minSdk = Constants.MIN_SDK
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
consumerProguardFiles("consumer-rules.pro")
|
consumerProguardFiles("consumer-rules.pro")
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import android.net.NetworkRequest
|
|||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import com.wireguard.android.util.RootShell
|
import com.wireguard.android.util.RootShell
|
||||||
|
import java.util.Collections
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.channels.awaitClose
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
@@ -45,10 +46,18 @@ class AndroidNetworkMonitor(
|
|||||||
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||||
|
|
||||||
@get:Synchronized @set:Synchronized var currentSsid: String? = null
|
@get:Synchronized @set:Synchronized var currentSsid: String? = null
|
||||||
|
@get:Synchronized @set:Synchronized var securityType: WifiSecurityType? = null
|
||||||
|
|
||||||
@get:Synchronized @set:Synchronized var wifiConnected = false
|
@get:Synchronized @set:Synchronized var wifiConnected = false
|
||||||
|
|
||||||
data class WifiState(val connected: Boolean = false, val ssid: String? = null)
|
// Track active Wi-Fi networks and last active network ID
|
||||||
|
private val activeNetworks = Collections.synchronizedSet(mutableSetOf<Network>())
|
||||||
|
|
||||||
|
data class WifiState(
|
||||||
|
val connected: Boolean = false,
|
||||||
|
val ssid: String? = null,
|
||||||
|
val securityType: WifiSecurityType? = null,
|
||||||
|
)
|
||||||
|
|
||||||
data class TransportState(val connected: Boolean = false)
|
data class TransportState(val connected: Boolean = false)
|
||||||
|
|
||||||
@@ -72,15 +81,15 @@ class AndroidNetworkMonitor(
|
|||||||
|
|
||||||
suspend fun handleUnknownWifi() {
|
suspend fun handleUnknownWifi() {
|
||||||
val newSsid = getWifiSsid()
|
val newSsid = getWifiSsid()
|
||||||
|
val securityType = wifiManager?.getCurrentSecurityType()
|
||||||
// Only update if new SSID is valid; preserve existing valid SSID otherwise
|
// Only update if new SSID is valid; preserve existing valid SSID otherwise
|
||||||
if (newSsid != null && newSsid != WifiManager.UNKNOWN_SSID) {
|
if (newSsid != null && newSsid != WifiManager.UNKNOWN_SSID) {
|
||||||
currentSsid = newSsid
|
currentSsid = newSsid
|
||||||
trySend(WifiState(connected = wifiConnected, ssid = currentSsid))
|
trySend(WifiState(wifiConnected, currentSsid, securityType))
|
||||||
} else if (currentSsid == null || currentSsid == WifiManager.UNKNOWN_SSID) {
|
} else if (currentSsid == null || currentSsid == WifiManager.UNKNOWN_SSID) {
|
||||||
currentSsid = newSsid
|
currentSsid = newSsid
|
||||||
trySend(WifiState(connected = wifiConnected, ssid = currentSsid))
|
trySend(WifiState(wifiConnected, currentSsid, securityType))
|
||||||
}
|
}
|
||||||
Timber.d("handleUnknownWifi: currentSsid=$currentSsid")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val locationPermissionReceiver =
|
val locationPermissionReceiver =
|
||||||
@@ -139,18 +148,34 @@ class AndroidNetworkMonitor(
|
|||||||
object : ConnectivityManager.NetworkCallback() {
|
object : ConnectivityManager.NetworkCallback() {
|
||||||
override fun onAvailable(network: Network) {
|
override fun onAvailable(network: Network) {
|
||||||
Timber.d("Wi-Fi onAvailable: network=$network")
|
Timber.d("Wi-Fi onAvailable: network=$network")
|
||||||
|
activeNetworks.add(network)
|
||||||
launch {
|
launch {
|
||||||
currentSsid = getWifiSsid()
|
currentSsid = getWifiSsid()
|
||||||
|
securityType = wifiManager?.getCurrentSecurityType()
|
||||||
wifiConnected = true
|
wifiConnected = true
|
||||||
trySend(WifiState(connected = true, ssid = currentSsid))
|
trySend(
|
||||||
|
WifiState(
|
||||||
|
connected = true,
|
||||||
|
ssid = currentSsid,
|
||||||
|
securityType = securityType,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLost(network: Network) {
|
override fun onLost(network: Network) {
|
||||||
Timber.d("Wi-Fi onLost: network=$network")
|
Timber.d("Wi-Fi onLost: network=$network")
|
||||||
|
activeNetworks.remove(network)
|
||||||
|
if (activeNetworks.isEmpty()) {
|
||||||
|
Timber.d(
|
||||||
|
"All Wi-Fi networks disconnected, clearing currentSsid and wifiConnected"
|
||||||
|
)
|
||||||
currentSsid = null
|
currentSsid = null
|
||||||
wifiConnected = false
|
wifiConnected = false
|
||||||
trySend(WifiState(connected = false, ssid = null))
|
trySend(WifiState(connected = false, ssid = null, securityType = null))
|
||||||
|
} else {
|
||||||
|
Timber.d("Wi-Fi onLost, but still connected to other networks, ignoring")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,6 +253,7 @@ class AndroidNetworkMonitor(
|
|||||||
if (hasAnyConnection) {
|
if (hasAnyConnection) {
|
||||||
NetworkStatus.Connected(
|
NetworkStatus.Connected(
|
||||||
wifiSsid = wifi.ssid,
|
wifiSsid = wifi.ssid,
|
||||||
|
securityType = wifi.securityType,
|
||||||
wifiConnected = wifi.connected,
|
wifiConnected = wifi.connected,
|
||||||
cellularConnected = cellular.connected,
|
cellularConnected = cellular.connected,
|
||||||
ethernetConnected = ethernet.connected,
|
ethernetConnected = ethernet.connected,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.zaneschepke.networkmonitor
|
package com.zaneschepke.networkmonitor
|
||||||
|
|
||||||
|
import android.net.wifi.WifiManager
|
||||||
|
import android.os.Build
|
||||||
import com.wireguard.android.util.RootShell
|
import com.wireguard.android.util.RootShell
|
||||||
|
|
||||||
fun RootShell.getCurrentWifiName(): String? {
|
fun RootShell.getCurrentWifiName(): String? {
|
||||||
@@ -10,3 +12,12 @@ fun RootShell.getCurrentWifiName(): String? {
|
|||||||
)
|
)
|
||||||
return response.firstOrNull()
|
return response.firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
fun WifiManager.getCurrentSecurityType(): WifiSecurityType? {
|
||||||
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
WifiSecurityType.from(connectionInfo.currentSecurityType)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ sealed class NetworkStatus {
|
|||||||
|
|
||||||
data class Connected(
|
data class Connected(
|
||||||
val wifiSsid: String? = null,
|
val wifiSsid: String? = null,
|
||||||
|
val securityType: WifiSecurityType? = null,
|
||||||
override val wifiConnected: Boolean = false,
|
override val wifiConnected: Boolean = false,
|
||||||
override val ethernetConnected: Boolean = false,
|
override val ethernetConnected: Boolean = false,
|
||||||
override val cellularConnected: Boolean = false,
|
override val cellularConnected: Boolean = false,
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.zaneschepke.networkmonitor
|
||||||
|
|
||||||
|
import android.net.wifi.WifiInfo
|
||||||
|
|
||||||
|
enum class WifiSecurityType {
|
||||||
|
UNKNOWN,
|
||||||
|
OPEN,
|
||||||
|
WEP,
|
||||||
|
WPA2, // WPA and WPA2
|
||||||
|
WPA3, // WPA3-Personal (SAE)
|
||||||
|
OWE,
|
||||||
|
WAPI, // All WAPI_PSK and WAPI_CERT
|
||||||
|
EAP, // All EAP (covers both WPA3 and others)
|
||||||
|
PASSPOINT, // All Passpoint versions
|
||||||
|
DPP;
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun from(securityType: Int): WifiSecurityType {
|
||||||
|
return when (securityType) {
|
||||||
|
WifiInfo.SECURITY_TYPE_OPEN -> OPEN
|
||||||
|
WifiInfo.SECURITY_TYPE_WEP -> WEP
|
||||||
|
WifiInfo.SECURITY_TYPE_PSK -> WPA2
|
||||||
|
WifiInfo.SECURITY_TYPE_EAP -> EAP
|
||||||
|
WifiInfo.SECURITY_TYPE_SAE -> WPA3
|
||||||
|
WifiInfo.SECURITY_TYPE_OWE -> OWE
|
||||||
|
WifiInfo.SECURITY_TYPE_WAPI_PSK,
|
||||||
|
WifiInfo.SECURITY_TYPE_WAPI_CERT -> WAPI
|
||||||
|
WifiInfo.SECURITY_TYPE_EAP_WPA3_ENTERPRISE -> EAP
|
||||||
|
WifiInfo.SECURITY_TYPE_EAP_WPA3_ENTERPRISE_192_BIT -> EAP
|
||||||
|
WifiInfo.SECURITY_TYPE_PASSPOINT_R1_R2,
|
||||||
|
WifiInfo.SECURITY_TYPE_PASSPOINT_R3 -> PASSPOINT
|
||||||
|
WifiInfo.SECURITY_TYPE_DPP -> DPP
|
||||||
|
WifiInfo.SECURITY_TYPE_UNKNOWN -> UNKNOWN
|
||||||
|
else -> UNKNOWN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
0
|
|
||||||