mirror of
https://github.com/wgtunnel/android.git
synced 2026-06-02 08:33:40 +02:00
Compare commits
30 Commits
weblate-changes
...
3.9.0
| Author | SHA1 | Date | |
|---|---|---|---|
| af759a3909 | |||
| b467d66554 | |||
| c833e15c8f | |||
| eec1bbd2f6 | |||
| 969e9dfe03 | |||
| aeb590db8c | |||
| 312062aa36 | |||
| 287732dfb8 | |||
| dca72a70e8 | |||
| 1c6543554f | |||
| 8c01f5bea4 | |||
| dd9f329721 | |||
| f30c48a90a | |||
| 4707d3eb95 | |||
| cedc2db326 | |||
| 256e3f7951 | |||
| 9e797b24d6 | |||
| f2b9eb526e | |||
| abb29607d3 | |||
| f6d7cbc032 | |||
| 9304d79775 | |||
| 4d18decbf7 | |||
| 76186c092f | |||
| c90a7bbaf5 | |||
| d3d70ab2e7 | |||
| 9b2d4a3fb5 | |||
| d7741c37c5 | |||
| 6046e4131f | |||
| 4b2d2d20db | |||
| a09501aaf5 |
+43
-41
@@ -1,4 +1,5 @@
|
||||
name: build
|
||||
name: Build
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
@@ -12,6 +13,14 @@ on:
|
||||
- prerelease
|
||||
- nightly
|
||||
- release
|
||||
flavor:
|
||||
type: choice
|
||||
description: "Product flavor"
|
||||
required: true
|
||||
default: fdroid
|
||||
options:
|
||||
- fdroid
|
||||
- full
|
||||
secrets:
|
||||
SIGNING_KEY_ALIAS:
|
||||
required: false
|
||||
@@ -30,6 +39,11 @@ on:
|
||||
description: "Build type"
|
||||
required: true
|
||||
default: debug
|
||||
flavor:
|
||||
type: string
|
||||
description: "Product flavor"
|
||||
required: false
|
||||
default: fdroid
|
||||
secrets:
|
||||
SIGNING_KEY_ALIAS:
|
||||
required: false
|
||||
@@ -41,6 +55,7 @@ on:
|
||||
required: false
|
||||
KEYSTORE:
|
||||
required: false
|
||||
|
||||
env:
|
||||
UPLOAD_DIR_ANDROID: android_artifacts
|
||||
|
||||
@@ -48,15 +63,17 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
SIGNING_KEY_ALIAS: ${{ secrets.ANDROID_SIGNING_KEY_ALIAS }}
|
||||
SIGNING_KEY_PASSWORD: ${{ secrets.ANDROID_SIGNING_KEY_PASSWORD }}
|
||||
SIGNING_STORE_PASSWORD: ${{ secrets.ANDROID_SIGNING_STORE_PASSWORD }}
|
||||
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
|
||||
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
||||
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
|
||||
KEY_STORE_FILE: 'android_keystore.jks'
|
||||
KEY_STORE_LOCATION: ${{ github.workspace }}/app/keystore/
|
||||
outputs:
|
||||
UPLOAD_DIR_ANDROID: ${{ env.UPLOAD_DIR_ANDROID }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
@@ -65,61 +82,46 @@ jobs:
|
||||
cache: gradle
|
||||
- name: Grant execute permission for gradlew
|
||||
run: chmod +x gradlew
|
||||
|
||||
# Here we need to decode keystore.jks from base64 string and place it
|
||||
# in the folder specified in the release signing configuration
|
||||
- name: Decode Keystore
|
||||
id: decode_keystore
|
||||
uses: timheuer/base64-to-file@v1.2
|
||||
with:
|
||||
fileName: ${{ env.KEY_STORE_FILE }}
|
||||
fileDir: ${{ env.KEY_STORE_LOCATION }}
|
||||
encodedString: ${{ secrets.ANDROID_KEYSTORE }}
|
||||
|
||||
# create keystore path for gradle to read
|
||||
encodedString: ${{ secrets.KEYSTORE }}
|
||||
- name: Create keystore path env var
|
||||
if: ${{ inputs.build_type != 'debug' }}
|
||||
run: |
|
||||
store_path=${{ env.KEY_STORE_LOCATION }}${{ env.KEY_STORE_FILE }}
|
||||
echo "KEY_STORE_PATH=$store_path" >> $GITHUB_ENV
|
||||
|
||||
- name: Create service_account.json
|
||||
if: ${{ inputs.build_type != 'debug' }}
|
||||
id: createServiceAccount
|
||||
run: echo '${{ secrets.ANDROID_SERVICE_ACCOUNT_JSON }}' > service_account.json
|
||||
|
||||
- name: Build Fdroid Release APK
|
||||
if: ${{ inputs.build_type == 'release' }}
|
||||
run: ./gradlew :app:assembleFdroidRelease --info
|
||||
|
||||
- name: Build Fdroid Prerelease APK
|
||||
if: ${{ inputs.build_type == 'prerelease' }}
|
||||
run: ./gradlew :app:assembleFdroidPrerelease --info
|
||||
|
||||
- name: Build Fdroid Nightly APK
|
||||
if: ${{ inputs.build_type == 'nightly' }}
|
||||
run: ./gradlew :app:assembleFdroidNightly --info
|
||||
|
||||
- name: Build Debug APK
|
||||
if: ${{ inputs.build_type == 'debug' }}
|
||||
run: ./gradlew :app:assembleFdroidDebug --stacktrace
|
||||
|
||||
# bump versionCode for nightly and prerelease builds
|
||||
- name: Commit and push versionCode changes
|
||||
if: ${{ inputs.build_type == 'nightly' || inputs.build_type == 'prerelease' }}
|
||||
run: echo '${{ secrets.SERVICE_ACCOUNT_JSON }}' > service_account.json
|
||||
- name: Build APK
|
||||
run: |
|
||||
git config --global user.name 'GitHub Actions'
|
||||
git config --global user.email 'actions@github.com'
|
||||
git add versionCode.txt
|
||||
git commit -m "Automated build update"
|
||||
|
||||
flavor=${{ inputs.flavor }}
|
||||
build_type=${{ inputs.build_type }}
|
||||
case $build_type in
|
||||
"release")
|
||||
./gradlew :app:assemble${flavor^}Release --info
|
||||
;;
|
||||
"prerelease")
|
||||
./gradlew :app:assemble${flavor^}Prerelease --info
|
||||
;;
|
||||
"nightly")
|
||||
./gradlew :app:assemble${flavor^}Nightly --info
|
||||
;;
|
||||
"debug")
|
||||
./gradlew :app:assemble${flavor^}Debug --stacktrace
|
||||
;;
|
||||
esac
|
||||
- name: Get release apk path
|
||||
id: apk-path
|
||||
run: echo "path=$(find . -regex '^.*/build/outputs/apk/fdroid/${{ inputs.build_type }}/.*\.apk$' -type f | head -1 | tail -c+2)" >> $GITHUB_OUTPUT
|
||||
|
||||
run: echo "path=$(find . -regex '^.*/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/.*\.apk$' -type f | head -1 | tail -c+2)" >> $GITHUB_OUTPUT
|
||||
- name: Upload release apk
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ env.UPLOAD_DIR_ANDROID }}
|
||||
path: ${{github.workspace}}/${{ steps.apk-path.outputs.path }}
|
||||
retention-days: 1
|
||||
path: ${{ github.workspace }}/${{ steps.apk-path.outputs.path }}
|
||||
retention-days: 1
|
||||
@@ -2,12 +2,12 @@ name: publish
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "4 3 * * *"
|
||||
- cron: "4 3 * * *"
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
track:
|
||||
type: choice
|
||||
description: "Google play release track"
|
||||
description: "Google Play release track"
|
||||
options:
|
||||
- none
|
||||
- internal
|
||||
@@ -30,12 +30,28 @@ on:
|
||||
description: "Tag name for release"
|
||||
required: false
|
||||
default: nightly
|
||||
flavor:
|
||||
type: choice
|
||||
description: "Product flavor"
|
||||
required: true
|
||||
default: full
|
||||
options:
|
||||
- fdroid
|
||||
- full
|
||||
workflow_call:
|
||||
inputs:
|
||||
flavor:
|
||||
type: string
|
||||
description: "Product flavor"
|
||||
required: false
|
||||
default: full
|
||||
|
||||
env:
|
||||
UPLOAD_DIR_ANDROID: android_artifacts
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
jobs:
|
||||
check_commits:
|
||||
@@ -43,66 +59,73 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
has_new_commits: ${{ steps.check.outputs.new_commits }}
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # This fetches all history so we can check commits
|
||||
|
||||
fetch-depth: 0
|
||||
- name: Check for new commits
|
||||
id: check
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
||||
run: |
|
||||
# This script checks for commits newer than 23 hours ago
|
||||
NEW_COMMITS=$(git rev-list --count --after="$(date -Iseconds -d '23 hours ago')" ${{ github.sha }})
|
||||
echo "new_commits=$NEW_COMMITS" >> $GITHUB_OUTPUT
|
||||
|
||||
build:
|
||||
if: ${{ inputs.release_type != 'none' }}
|
||||
build-fdroid:
|
||||
if: ${{ inputs.release_type == 'release' || inputs.flavor == 'fdroid' }}
|
||||
uses: ./.github/workflows/build.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
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:
|
||||
needs:
|
||||
- check_commits
|
||||
- build
|
||||
- build-full
|
||||
if: ${{ needs.check_commits.outputs.has_new_commits > 0 && inputs.release_type != 'none' }}
|
||||
name: publish-github
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
GH_USER: ${{ secrets.PAT_USERNAME }}
|
||||
# GH needed for gh cli
|
||||
GH_TOKEN: ${{ secrets.PAT }}
|
||||
GH_REPO: ${{ github.repository }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
ref: main
|
||||
- name: Install system dependencies
|
||||
run: |
|
||||
sudo apt update && sudo apt install -y gh apksigner
|
||||
|
||||
# update latest tag
|
||||
- name: Set TAG_NAME
|
||||
run: |
|
||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||
echo "TAG_NAME=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV
|
||||
elif [ "${{ github.event_name }}" = "schedule" ]; then
|
||||
echo "TAG_NAME=nightly" >> $GITHUB_ENV
|
||||
echo "RELEASE_TYPE=nightly" >> $GITHUB_ENV
|
||||
fi
|
||||
- name: Set latest tag
|
||||
uses: rickstaa/action-create-tag@v1
|
||||
id: tag_creation
|
||||
with:
|
||||
tag: "latest" # or any tag name you wish to use
|
||||
tag: "latest"
|
||||
message: "Automated tag for HEAD commit"
|
||||
force_push_tag: true
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
tag_exists_error: false
|
||||
|
||||
- name: Get latest release
|
||||
id: latest_release
|
||||
uses: kaliber5/action-get-release@v1
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
latest: true
|
||||
|
||||
- name: Generate Changelog
|
||||
id: changelog
|
||||
uses: requarks/changelog-action@v1
|
||||
@@ -110,40 +133,19 @@ jobs:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
toTag: ${{ github.event_name == 'schedule' && 'nightly' || steps.latest_release.outputs.tag_name }}
|
||||
fromTag: "latest"
|
||||
writeToFile: false # we won't write to file, just output
|
||||
|
||||
- name: Get version code
|
||||
if: ${{ inputs.release_type == 'release' }}
|
||||
run: |
|
||||
version_code=$(grep "VERSION_CODE" buildSrc/src/main/kotlin/Constants.kt | awk '{print $5}' | tr -d '\n')
|
||||
echo "VERSION_CODE=$version_code" >> $GITHUB_ENV
|
||||
|
||||
- name: Push changes
|
||||
if: ${{ inputs.release_type == '' || inputs.release_type == 'nightly' || inputs.release_type == 'prerelease' }}
|
||||
uses: ad-m/github-push-action@master
|
||||
with:
|
||||
github_token: ${{ secrets.PAT }}
|
||||
branch: ${{ github.ref }}
|
||||
|
||||
writeToFile: false
|
||||
- name: Make download dir
|
||||
run: mkdir ${{ github.workspace }}/temp
|
||||
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: ${{ env.UPLOAD_DIR_ANDROID }}
|
||||
path: ${{ github.workspace }}/temp
|
||||
|
||||
# Setup TAG_NAME, which is used as a general "name"
|
||||
- if: github.event_name == 'workflow_dispatch'
|
||||
run: echo "TAG_NAME=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV
|
||||
- if: github.event_name == 'schedule'
|
||||
run: echo "TAG_NAME=nightly" >> $GITHUB_ENV
|
||||
|
||||
- name: Set version release notes
|
||||
if: ${{ inputs.release_type == 'release' }}
|
||||
run: |
|
||||
RELEASE_NOTES="$(cat ${{ github.workspace }}/fastlane/metadata/android/en-US/changelogs/${{ env.VERSION_CODE }}.txt)"
|
||||
VERSION_NAME=$(grep "const val VERSION_NAME" buildSrc/src/main/kotlin/Constants.kt | awk -F'"' '{print $2}')
|
||||
RELEASE_NOTES="$(cat ${{ github.workspace }}/fastlane/metadata/android/en-US/changelogs/${VERSION_NAME}.txt || echo "No changelog found for ${VERSION_NAME}")"
|
||||
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
|
||||
echo "$RELEASE_NOTES" >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
@@ -152,32 +154,40 @@ jobs:
|
||||
if: ${{ contains(env.TAG_NAME, 'nightly') }}
|
||||
run: |
|
||||
echo "RELEASE_NOTES=Nightly build for the latest development version of the app." >> $GITHUB_ENV
|
||||
gh release delete nightly --yes || true
|
||||
git push origin :nightly || true
|
||||
|
||||
- name: On prerelease release notes
|
||||
if: ${{ inputs.release_type == 'prerelease' }}
|
||||
run: |
|
||||
echo "RELEASE_NOTES=Testing version of app for specific feature." >> $GITHUB_ENV
|
||||
gh release delete ${{ github.event.inputs.tag_name }} --yes || true
|
||||
|
||||
- name: Get checksum
|
||||
id: checksum
|
||||
run: |
|
||||
file_path=$(find ${{ github.workspace }}/temp -type f -iname "*.apk" | tail -n1)
|
||||
echo "checksum=$(apksigner verify -print-certs $file_path | grep -Po "(?<=SHA-256 digest:) .*" | tr -d "[:blank:]")" >> $GITHUB_OUTPUT
|
||||
|
||||
|
||||
- name: Create Release with Fastlane changelog notes
|
||||
id: create_release
|
||||
uses: softprops/action-gh-release@v2
|
||||
- name: Delete previous release
|
||||
if: ${{ contains(env.TAG_NAME, 'nightly') || inputs.release_type == 'prerelease' }}
|
||||
uses: ClementTsang/delete-tag-and-release@v0.3.1
|
||||
with:
|
||||
tag_name: ${{ env.TAG_NAME }}
|
||||
delete_release: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Get checksums
|
||||
id: checksum
|
||||
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:
|
||||
body: |
|
||||
${{ env.RELEASE_NOTES }}
|
||||
|
||||
SHA-256 fingerprint for the 4096-bit signing certificate:
|
||||
SHA-256 fingerprints for the 4096-bit signing certificate:
|
||||
```sh
|
||||
${{ steps.checksum.outputs.checksum }}
|
||||
```
|
||||
@@ -196,18 +206,20 @@ jobs:
|
||||
make_latest: ${{ inputs.release_type == 'release' }}
|
||||
files: |
|
||||
${{ github.workspace }}/temp/*
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
publish-fdroid:
|
||||
publish-fdroid-public:
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- build
|
||||
- build-fdroid
|
||||
if: inputs.release_type == 'release'
|
||||
steps:
|
||||
- name: Dispatch update for fdroid repo
|
||||
uses: peter-evans/repository-dispatch@v3
|
||||
with:
|
||||
token: ${{ secrets.PAT }}
|
||||
repository: zaneschepke/fdroid
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
repository: wgtunnel/fdroid
|
||||
event-type: fdroid-update
|
||||
|
||||
publish-play:
|
||||
@@ -216,13 +228,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
env:
|
||||
SIGNING_KEY_ALIAS: ${{ secrets.ANDROID_SIGNING_KEY_ALIAS }}
|
||||
SIGNING_KEY_PASSWORD: ${{ secrets.ANDROID_SIGNING_KEY_PASSWORD }}
|
||||
SIGNING_STORE_PASSWORD: ${{ secrets.ANDROID_SIGNING_STORE_PASSWORD }}
|
||||
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
|
||||
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
||||
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
|
||||
KEY_STORE_FILE: 'android_keystore.jks'
|
||||
KEY_STORE_LOCATION: ${{ github.workspace }}/app/keystore/
|
||||
GH_USER: ${{ secrets.PAT_USERNAME }}
|
||||
GH_TOKEN: ${{ secrets.PAT }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -244,7 +254,7 @@ jobs:
|
||||
with:
|
||||
fileName: ${{ env.KEY_STORE_FILE }}
|
||||
fileDir: ${{ env.KEY_STORE_LOCATION }}
|
||||
encodedString: ${{ secrets.ANDROID_KEYSTORE }}
|
||||
encodedString: ${{ secrets.KEYSTORE }}
|
||||
|
||||
# create keystore path for gradle to read
|
||||
- name: Create keystore path env var
|
||||
@@ -263,5 +273,4 @@ jobs:
|
||||
bundler-cache: true
|
||||
|
||||
- name: Distribute app to Prod track 🚀
|
||||
run: (cd ${{ github.workspace }} && bundle install && bundle exec fastlane ${{ inputs.track }})
|
||||
|
||||
run: (cd ${{ github.workspace }} && bundle install && bundle exec fastlane ${{ inputs.track }})
|
||||
+1
-1
@@ -70,5 +70,5 @@ lint/tmp/
|
||||
app/release/output.json
|
||||
.idea/codeStyles/
|
||||
# where we keep our signing secrets locally
|
||||
app/signing.properties
|
||||
/.kotlin/
|
||||
/app/keystore/
|
||||
|
||||
+2
-1
@@ -1,2 +1,3 @@
|
||||
/build
|
||||
/release
|
||||
/release
|
||||
/src/main/assets/licenses.json
|
||||
|
||||
+61
-84
@@ -6,35 +6,17 @@ plugins {
|
||||
alias(libs.plugins.ksp)
|
||||
alias(libs.plugins.compose.compiler)
|
||||
alias(libs.plugins.grgit)
|
||||
alias(libs.plugins.licensee)
|
||||
}
|
||||
|
||||
val versionFile = file("$rootDir/versionCode.txt")
|
||||
|
||||
val versionCodeIncrement =
|
||||
with(getBuildTaskName().lowercase()) {
|
||||
when {
|
||||
this.contains(Constants.NIGHTLY) || this.contains(Constants.PRERELEASE) -> {
|
||||
if (versionFile.exists()) {
|
||||
versionFile.readText().trim().toInt() + 1
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = Constants.APP_ID
|
||||
compileSdk = Constants.TARGET_SDK
|
||||
|
||||
androidResources { generateLocaleConfig = true }
|
||||
|
||||
// reproducibility
|
||||
dependenciesInfo {
|
||||
// Disables dependency metadata when building APKs.
|
||||
includeInApk = false
|
||||
// Disables dependency metadata when building Android App Bundles.
|
||||
includeInBundle = false
|
||||
}
|
||||
|
||||
@@ -42,14 +24,12 @@ android {
|
||||
applicationId = Constants.APP_ID
|
||||
minSdk = Constants.MIN_SDK
|
||||
targetSdk = Constants.TARGET_SDK
|
||||
versionCode = Constants.VERSION_CODE + versionCodeIncrement
|
||||
versionName = determineVersionName()
|
||||
versionCode = computeVersionCode()
|
||||
versionName = computeVersionName()
|
||||
|
||||
ksp { arg("room.schemaLocation", "$projectDir/schemas") }
|
||||
|
||||
sourceSets {
|
||||
getByName("debug").assets.srcDirs(files("$projectDir/schemas")) // Room
|
||||
}
|
||||
sourceSets { getByName("debug").assets.srcDirs(files("$projectDir/schemas")) }
|
||||
|
||||
buildConfigField(
|
||||
"String[]",
|
||||
@@ -63,15 +43,18 @@ android {
|
||||
|
||||
signingConfigs {
|
||||
create(Constants.RELEASE) {
|
||||
storeFile = getStoreFile()
|
||||
storePassword = getSigningProperty(Constants.STORE_PASS_VAR)
|
||||
keyAlias = getSigningProperty(Constants.KEY_ALIAS_VAR)
|
||||
keyPassword = getSigningProperty(Constants.KEY_PASS_VAR)
|
||||
storeFile = file(System.getenv("KEY_STORE_PATH") ?: "keystore/android_keystore.jks")
|
||||
storePassword =
|
||||
LocalProperties.get("SIGNING_STORE_PASSWORD")
|
||||
?: System.getenv("SIGNING_STORE_PASSWORD")
|
||||
keyAlias =
|
||||
LocalProperties.get("SIGNING_KEY_ALIAS") ?: System.getenv("SIGNING_KEY_ALIAS")
|
||||
keyPassword =
|
||||
LocalProperties.get("SIGNING_KEY_PASSWORD") ?: System.getenv("SIGNING_KEY_PASSWORD")
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
// don't strip
|
||||
packaging.jniLibs.keepDebugSymbols.addAll(
|
||||
listOf("libwg-go.so", "libwg-quick.so", "libwg.so")
|
||||
)
|
||||
@@ -87,6 +70,7 @@ android {
|
||||
signingConfig = signingConfigs.getByName(Constants.RELEASE)
|
||||
resValue("string", "provider", "\"${Constants.APP_NAME}.provider\"")
|
||||
}
|
||||
|
||||
debug {
|
||||
applicationIdSuffix = ".debug"
|
||||
resValue("string", "app_name", "WG Tunnel - Debug")
|
||||
@@ -107,27 +91,21 @@ android {
|
||||
resValue("string", "app_name", "WG Tunnel - Nightly")
|
||||
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.nightly\"")
|
||||
}
|
||||
|
||||
applicationVariants.all {
|
||||
val variant = this
|
||||
variant.outputs
|
||||
.map { it as com.android.build.gradle.internal.api.BaseVariantOutputImpl }
|
||||
.forEach { output ->
|
||||
val outputFileName =
|
||||
"${Constants.APP_NAME}-${variant.flavorName}-" +
|
||||
"${variant.buildType.name}-${variant.versionName}.apk"
|
||||
output.outputFileName = outputFileName
|
||||
}
|
||||
}
|
||||
}
|
||||
flavorDimensions.add(Constants.TYPE)
|
||||
|
||||
flavorDimensions.add("type")
|
||||
productFlavors {
|
||||
create("fdroid") {
|
||||
dimension = Constants.TYPE
|
||||
proguardFile("fdroid-rules.pro")
|
||||
dimension = "type"
|
||||
buildConfigField("String", "FLAVOR", "\"fdroid\"")
|
||||
}
|
||||
create("general") { dimension = Constants.TYPE }
|
||||
create("google") {
|
||||
dimension = "type"
|
||||
buildConfigField("String", "FLAVOR", "\"google\"")
|
||||
}
|
||||
create("full") { dimension = "type" }
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
@@ -139,6 +117,27 @@ android {
|
||||
buildConfig = true
|
||||
}
|
||||
packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" } }
|
||||
|
||||
licensee {
|
||||
Constants.allowedLicenses.forEach { allow(it) }
|
||||
allowUrl(Constants.XZING_LICENSE_URL)
|
||||
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 {
|
||||
@@ -147,8 +146,6 @@ dependencies {
|
||||
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||
|
||||
// helpers for implementing LifecycleOwner in a Service
|
||||
implementation(libs.androidx.lifecycle.service)
|
||||
implementation(libs.androidx.activity.compose)
|
||||
implementation(platform(libs.androidx.compose.bom))
|
||||
@@ -160,7 +157,6 @@ dependencies {
|
||||
implementation(libs.material)
|
||||
implementation(libs.androidx.storage)
|
||||
|
||||
// test
|
||||
testImplementation(libs.junit)
|
||||
testImplementation(libs.androidx.junit)
|
||||
androidTestImplementation(libs.androidx.junit)
|
||||
@@ -171,83 +167,64 @@ dependencies {
|
||||
debugImplementation(libs.androidx.compose.ui.tooling)
|
||||
debugImplementation(libs.androidx.compose.manifest)
|
||||
|
||||
// tunnel
|
||||
implementation(libs.tunnel)
|
||||
implementation(libs.amneziawg.android)
|
||||
coreLibraryDesugaring(libs.desugar.jdk.libs)
|
||||
|
||||
// logging
|
||||
implementation(libs.timber)
|
||||
|
||||
// compose navigation
|
||||
implementation(libs.androidx.navigation.compose)
|
||||
implementation(libs.androidx.hilt.navigation.compose)
|
||||
|
||||
// hilt
|
||||
implementation(libs.hilt.android)
|
||||
ksp(libs.hilt.android.compiler)
|
||||
ksp(libs.androidx.hilt.compiler)
|
||||
|
||||
// accompanist
|
||||
implementation(libs.accompanist.permissions)
|
||||
implementation(libs.accompanist.drawablepainter)
|
||||
|
||||
// storage
|
||||
implementation(libs.androidx.room.runtime)
|
||||
ksp(libs.androidx.room.compiler)
|
||||
implementation(libs.androidx.room.ktx)
|
||||
implementation(libs.androidx.datastore.preferences)
|
||||
|
||||
// lifecycle
|
||||
implementation(libs.lifecycle.runtime.compose)
|
||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||
implementation(libs.androidx.lifecycle.process)
|
||||
|
||||
// serialization
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
|
||||
// ui
|
||||
implementation(libs.zxing.android.embedded)
|
||||
implementation(libs.material.icons.extended)
|
||||
|
||||
// bio
|
||||
implementation(libs.androidx.biometric.ktx)
|
||||
implementation(libs.pin.lock.compose)
|
||||
|
||||
// shortcuts
|
||||
implementation(libs.androidx.core)
|
||||
|
||||
// splash
|
||||
implementation(libs.androidx.core.splashscreen)
|
||||
|
||||
// worker
|
||||
implementation(libs.androidx.work.runtime)
|
||||
implementation(libs.androidx.hilt.work)
|
||||
|
||||
implementation(libs.qrcode.kotlin)
|
||||
implementation(libs.semver4j)
|
||||
|
||||
implementation(libs.ktor.client.core)
|
||||
implementation(libs.ktor.client.okhttp)
|
||||
implementation(libs.ktor.client.cio)
|
||||
implementation(libs.ktor.client.content.negotiation)
|
||||
implementation(libs.ktor.serialization.kotlinx.json)
|
||||
implementation(libs.slf4j.android)
|
||||
}
|
||||
|
||||
fun determineVersionName(): String {
|
||||
return with(getBuildTaskName().lowercase()) {
|
||||
when {
|
||||
contains(Constants.NIGHTLY) || contains(Constants.PRERELEASE) ->
|
||||
Constants.VERSION_NAME + "-${grgitService.service.get().grgit.head().abbreviatedId}"
|
||||
else -> Constants.VERSION_NAME
|
||||
}
|
||||
tasks.register<Copy>("copyLicenseeJsonToAssets") {
|
||||
dependsOn("licensee")
|
||||
val outputAssets = layout.projectDirectory.dir("src/main/assets")
|
||||
from(layout.buildDirectory.file("reports/licensee/androidFdroidRelease/artifacts.json")) {
|
||||
rename("artifacts.json", "licenses.json")
|
||||
}
|
||||
into(outputAssets)
|
||||
}
|
||||
|
||||
val incrementVersionCode by
|
||||
tasks.registering {
|
||||
doLast {
|
||||
val versionFile = file("$rootDir/versionCode.txt")
|
||||
if (versionFile.exists()) {
|
||||
versionFile.writeText(versionCodeIncrement.toString())
|
||||
println("Incremented versionCode to $versionCodeIncrement")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.whenTaskAdded {
|
||||
if (name.startsWith("assemble") && !name.lowercase().contains("debug")) {
|
||||
dependsOn(incrementVersionCode)
|
||||
}
|
||||
}
|
||||
tasks.named("preBuild") { dependsOn("copyLicenseeJsonToAssets") }
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- Permissions specific to full -->
|
||||
<!--updater-->
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
</manifest>
|
||||
@@ -2,7 +2,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
|
||||
<!--foreground service exempt android 14-->
|
||||
@@ -16,7 +16,6 @@
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
<!--start service on boot permission-->
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<!--android tv support-->
|
||||
|
||||
<permission
|
||||
android:name="${applicationId}.permission.CONTROL_TUNNELS"
|
||||
@@ -53,7 +52,7 @@
|
||||
<application
|
||||
android:name=".WireGuardAutoTunnel"
|
||||
android:allowBackup="false"
|
||||
android:banner="@drawable/ic_banner"
|
||||
android:banner="@mipmap/ic_banner"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
@@ -66,7 +65,6 @@
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:banner="@mipmap/ic_banner"
|
||||
android:windowSoftInputMode="adjustNothing"
|
||||
android:theme="@style/Theme.WireguardAutoTunnel"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden"
|
||||
@@ -171,7 +169,8 @@
|
||||
android:exported="false"
|
||||
android:directBootAware="true">
|
||||
<intent-filter>
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<action android:name="android.intent.action.SCREEN_ON" />
|
||||
<action android:name="android.intent.action.USER_PRESENT" />
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
@@ -22,33 +21,15 @@ import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.consumeWindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.imePadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Bolt
|
||||
import androidx.compose.material.icons.rounded.Home
|
||||
import androidx.compose.material.icons.rounded.QuestionMark
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.icons.rounded.Settings
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SnackbarData
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.navigation.compose.NavHost
|
||||
@@ -62,14 +43,15 @@ import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.VpnDeniedDialog
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.CustomBottomNavbar
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.DynamicTopAppBar
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.currentNavBackStackEntryAsNavBarState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.CustomSnackBar
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.BottomNavbar
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.DynamicTopAppBar
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.currentNavBackStackEntryAsNavBarState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.AutoTunnelScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.advanced.AutoTunnelAdvancedScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.LocationDisclosureScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.autotunnel.TunnelAutoTunnelScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.ConfigScreen
|
||||
@@ -82,12 +64,12 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.settings.advanced.Settings
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.AppearanceScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.display.DisplayScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.language.LanguageScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.LocationDisclosureScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.killswitch.KillSwitchScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.logs.LogsScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.SupportScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.license.LicenseScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.WireguardAutoTunnelTheme
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.goFromRoot
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
@@ -125,6 +107,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
setContent {
|
||||
val isTv = isRunningOnTv()
|
||||
val appUiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||
val appViewState by viewModel.appViewState.collectAsStateWithLifecycle()
|
||||
|
||||
@@ -136,6 +119,7 @@ class MainActivity : AppCompatActivity() {
|
||||
backStackEntry,
|
||||
viewModel,
|
||||
appUiState,
|
||||
appViewState,
|
||||
)
|
||||
val snackbar = remember { SnackbarHostState() }
|
||||
var showVpnPermissionDialog by remember { mutableStateOf(false) }
|
||||
@@ -218,153 +202,125 @@ class MainActivity : AppCompatActivity() {
|
||||
batteryActivity.launch(
|
||||
Intent().apply {
|
||||
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
||||
data = Uri.parse("package:${this@MainActivity.packageName}")
|
||||
data = "package:${this@MainActivity.packageName}".toUri()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CompositionLocalProvider(LocalNavController provides navController) {
|
||||
WireguardAutoTunnelTheme(theme = appUiState.appState.theme) {
|
||||
VpnDeniedDialog(
|
||||
showVpnPermissionDialog,
|
||||
onDismiss = { showVpnPermissionDialog = false },
|
||||
)
|
||||
CompositionLocalProvider(LocalIsAndroidTV provides isTv) {
|
||||
CompositionLocalProvider(LocalNavController provides navController) {
|
||||
WireguardAutoTunnelTheme(theme = appUiState.appState.theme) {
|
||||
VpnDeniedDialog(
|
||||
showVpnPermissionDialog,
|
||||
onDismiss = { showVpnPermissionDialog = false },
|
||||
)
|
||||
|
||||
Scaffold(
|
||||
modifier =
|
||||
Modifier.pointerInput(Unit) {
|
||||
detectTapGestures {
|
||||
viewModel.handleEvent(AppEvent.SetSelectedTunnel(null))
|
||||
Scaffold(
|
||||
modifier =
|
||||
Modifier.pointerInput(Unit) {
|
||||
detectTapGestures {
|
||||
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
||||
}
|
||||
},
|
||||
snackbarHost = {
|
||||
SnackbarHost(snackbar) { snackbarData: SnackbarData ->
|
||||
CustomSnackBar(
|
||||
snackbarData.visuals.message,
|
||||
isRtl = false,
|
||||
containerColor =
|
||||
MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp),
|
||||
)
|
||||
}
|
||||
},
|
||||
snackbarHost = {
|
||||
SnackbarHost(snackbar) { snackbarData: SnackbarData ->
|
||||
CustomSnackBar(
|
||||
snackbarData.visuals.message,
|
||||
isRtl = false,
|
||||
containerColor =
|
||||
MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp),
|
||||
)
|
||||
}
|
||||
},
|
||||
topBar = { DynamicTopAppBar(navBarState) },
|
||||
bottomBar = {
|
||||
AnimatedVisibility(
|
||||
visible = navBarState.showBottom,
|
||||
enter = slideInVertically(initialOffsetY = { it }),
|
||||
exit = slideOutVertically(targetOffsetY = { it }),
|
||||
topBar = { DynamicTopAppBar(navBarState) },
|
||||
bottomBar = {
|
||||
AnimatedVisibility(
|
||||
visible = navBarState.showBottom,
|
||||
enter = slideInVertically(initialOffsetY = { it }),
|
||||
exit = slideOutVertically(targetOffsetY = { it }),
|
||||
) {
|
||||
BottomNavbar(appUiState = appUiState)
|
||||
}
|
||||
},
|
||||
) { padding ->
|
||||
Box(
|
||||
modifier =
|
||||
Modifier.fillMaxSize()
|
||||
.background(MaterialTheme.colorScheme.surface)
|
||||
.padding(padding)
|
||||
.consumeWindowInsets(padding)
|
||||
.imePadding()
|
||||
) {
|
||||
CustomBottomNavbar(
|
||||
listOf(
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.tunnels),
|
||||
route = Route.Main,
|
||||
icon = Icons.Rounded.Home,
|
||||
onClick = { navController.goFromRoot(Route.Main) },
|
||||
),
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.auto_tunnel),
|
||||
route = Route.AutoTunnel,
|
||||
icon = Icons.Rounded.Bolt,
|
||||
onClick = {
|
||||
val route =
|
||||
if (
|
||||
appUiState.appState
|
||||
.isLocationDisclosureShown
|
||||
)
|
||||
Route.AutoTunnel
|
||||
else Route.LocationDisclosure
|
||||
navController.goFromRoot(route)
|
||||
},
|
||||
active = appUiState.isAutoTunnelActive,
|
||||
),
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.settings),
|
||||
route = Route.Settings,
|
||||
icon = Icons.Rounded.Settings,
|
||||
onClick = { navController.goFromRoot(Route.Settings) },
|
||||
),
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.support),
|
||||
route = Route.Support,
|
||||
icon = Icons.Rounded.QuestionMark,
|
||||
onClick = { navController.goFromRoot(Route.Support) },
|
||||
),
|
||||
),
|
||||
navBarState = navBarState,
|
||||
)
|
||||
}
|
||||
},
|
||||
) { padding ->
|
||||
Box(
|
||||
modifier =
|
||||
Modifier.fillMaxSize()
|
||||
.background(MaterialTheme.colorScheme.surface)
|
||||
.padding(padding)
|
||||
.consumeWindowInsets(padding)
|
||||
.imePadding()
|
||||
) {
|
||||
NavHost(
|
||||
navController,
|
||||
startDestination =
|
||||
(if (appUiState.appState.isPinLockEnabled) Route.Lock
|
||||
else Route.Main),
|
||||
) {
|
||||
composable<Route.Main> {
|
||||
MainScreen(appUiState, appViewState, viewModel)
|
||||
}
|
||||
composable<Route.Settings> {
|
||||
SettingsScreen(appUiState, appViewState, viewModel)
|
||||
}
|
||||
composable<Route.SettingsAdvanced> {
|
||||
SettingsAdvancedScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.LocationDisclosure> {
|
||||
LocationDisclosureScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.AutoTunnel> {
|
||||
AutoTunnelScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Appearance> { AppearanceScreen() }
|
||||
composable<Route.Language> { LanguageScreen(appUiState, viewModel) }
|
||||
composable<Route.Display> { DisplayScreen(appUiState, viewModel) }
|
||||
composable<Route.Support> { SupportScreen() }
|
||||
composable<Route.AutoTunnelAdvanced> {
|
||||
AutoTunnelAdvancedScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Logs> { LogsScreen(appViewState, viewModel) }
|
||||
composable<Route.Config> { backStack ->
|
||||
val args = backStack.toRoute<Route.Config>()
|
||||
val config = appUiState.tunnels.firstOrNull { it.id == args.id }
|
||||
ConfigScreen(config, viewModel)
|
||||
}
|
||||
composable<Route.TunnelOptions> { backStack ->
|
||||
val args = backStack.toRoute<Route.TunnelOptions>()
|
||||
appUiState.tunnels
|
||||
.firstOrNull { it.id == args.id }
|
||||
?.let { config ->
|
||||
TunnelOptionsScreen(config, appUiState, viewModel)
|
||||
}
|
||||
}
|
||||
composable<Route.Lock> { PinLockScreen(viewModel) }
|
||||
composable<Route.Scanner> { ScannerScreen(viewModel) }
|
||||
composable<Route.KillSwitch> {
|
||||
KillSwitchScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.SplitTunnel> { SplitTunnelScreen(viewModel) }
|
||||
composable<Route.TunnelAutoTunnel> { backStack ->
|
||||
val args = backStack.toRoute<Route.TunnelOptions>()
|
||||
appUiState.tunnels
|
||||
.firstOrNull { it.id == args.id }
|
||||
?.let {
|
||||
TunnelAutoTunnelScreen(
|
||||
it,
|
||||
appUiState.appSettings,
|
||||
viewModel,
|
||||
)
|
||||
}
|
||||
NavHost(
|
||||
navController,
|
||||
startDestination =
|
||||
(if (appUiState.appState.isPinLockEnabled) Route.Lock
|
||||
else Route.Main),
|
||||
) {
|
||||
composable<Route.Main> {
|
||||
MainScreen(appUiState, appViewState, viewModel)
|
||||
}
|
||||
composable<Route.Settings> {
|
||||
SettingsScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.SettingsAdvanced> {
|
||||
SettingsAdvancedScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.LocationDisclosure> {
|
||||
LocationDisclosureScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.AutoTunnel> {
|
||||
AutoTunnelScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Appearance> { AppearanceScreen() }
|
||||
composable<Route.Language> {
|
||||
LanguageScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Display> {
|
||||
DisplayScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Support> {
|
||||
SupportScreen(appViewModel = viewModel)
|
||||
}
|
||||
composable<Route.License> { LicenseScreen() }
|
||||
composable<Route.AutoTunnelAdvanced> {
|
||||
AutoTunnelAdvancedScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Logs> { LogsScreen(appViewState, viewModel) }
|
||||
composable<Route.Config> { backStack ->
|
||||
val args = backStack.toRoute<Route.Config>()
|
||||
val config =
|
||||
appUiState.tunnels.firstOrNull { it.id == args.id }
|
||||
ConfigScreen(config, viewModel)
|
||||
}
|
||||
composable<Route.TunnelOptions> { backStack ->
|
||||
val args = backStack.toRoute<Route.TunnelOptions>()
|
||||
appUiState.tunnels
|
||||
.firstOrNull { it.id == args.id }
|
||||
?.let { config ->
|
||||
TunnelOptionsScreen(config, viewModel)
|
||||
}
|
||||
}
|
||||
composable<Route.Lock> { PinLockScreen(viewModel) }
|
||||
composable<Route.Scanner> { ScannerScreen(viewModel) }
|
||||
composable<Route.KillSwitch> {
|
||||
KillSwitchScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.SplitTunnel> { SplitTunnelScreen(viewModel) }
|
||||
composable<Route.TunnelAutoTunnel> { backStack ->
|
||||
val args = backStack.toRoute<Route.TunnelOptions>()
|
||||
appUiState.tunnels
|
||||
.firstOrNull { it.id == args.id }
|
||||
?.let {
|
||||
TunnelAutoTunnelScreen(
|
||||
it,
|
||||
appUiState.appSettings,
|
||||
viewModel,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -8,6 +8,7 @@ import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
@@ -29,6 +30,10 @@ class RestartReceiver : BroadcastReceiver() {
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
Timber.d("RestartReceiver triggered with action: ${intent.action}")
|
||||
// screen on for Android TV only to help with sleep shutdowns
|
||||
val isTv = context.isRunningOnTv()
|
||||
if (intent.action == Intent.ACTION_SCREEN_ON && !isTv) return
|
||||
if (intent.action == Intent.ACTION_USER_PRESENT && !isTv) return
|
||||
serviceManager.updateTunnelTile()
|
||||
serviceManager.updateAutoTunnelTile()
|
||||
applicationScope.launch(ioDispatcher) {
|
||||
|
||||
@@ -25,7 +25,7 @@ class DataStoreManager(
|
||||
val locationDisclosureShown = booleanPreferencesKey("LOCATION_DISCLOSURE_SHOWN")
|
||||
val batteryDisableShown = booleanPreferencesKey("BATTERY_OPTIMIZE_DISABLE_SHOWN")
|
||||
val pinLockEnabled = booleanPreferencesKey("PIN_LOCK_ENABLED")
|
||||
val tunnelStatsExpanded = booleanPreferencesKey("TUNNEL_STATS_EXPANDED")
|
||||
val expandedTunnelIds = stringPreferencesKey("EXPANDED_TUNNEL_IDS")
|
||||
val isLocalLogsEnabled = booleanPreferencesKey("LOCAL_LOGS_ENABLED")
|
||||
val locale = stringPreferencesKey("LOCALE")
|
||||
val theme = stringPreferencesKey("THEME")
|
||||
|
||||
@@ -7,7 +7,6 @@ import timber.log.Timber
|
||||
class DatabaseCallback : RoomDatabase.Callback() {
|
||||
override fun onCreate(db: SupportSQLiteDatabase) =
|
||||
db.run {
|
||||
// Notice non-ui thread is here
|
||||
beginTransaction()
|
||||
try {
|
||||
execSQL(Queries.createDefaultSettings())
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.model
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Asset(
|
||||
val name: String,
|
||||
@SerialName("browser_download_url") val browserDownloadUrl: String,
|
||||
)
|
||||
@@ -7,7 +7,7 @@ data class GeneralState(
|
||||
val isLocationDisclosureShown: Boolean = LOCATION_DISCLOSURE_SHOWN_DEFAULT,
|
||||
val isBatteryOptimizationDisableShown: Boolean = BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT,
|
||||
val isPinLockEnabled: Boolean = PIN_LOCK_ENABLED_DEFAULT,
|
||||
val isTunnelStatsExpanded: Boolean = IS_TUNNEL_STATS_EXPANDED,
|
||||
val expandedTunnelIds: List<Int> = emptyList(),
|
||||
val isLocalLogsEnabled: Boolean = IS_LOGS_ENABLED_DEFAULT,
|
||||
val isRemoteControlEnabled: Boolean = IS_REMOTE_CONTROL_ENABLED,
|
||||
val remoteKey: String? = null,
|
||||
@@ -20,7 +20,7 @@ data class GeneralState(
|
||||
isLocationDisclosureShown,
|
||||
isBatteryOptimizationDisableShown,
|
||||
isPinLockEnabled,
|
||||
isTunnelStatsExpanded,
|
||||
expandedTunnelIds,
|
||||
isLocalLogsEnabled,
|
||||
isRemoteControlEnabled,
|
||||
remoteKey,
|
||||
@@ -35,7 +35,7 @@ data class GeneralState(
|
||||
isLocationDisclosureShown,
|
||||
isBatteryOptimizationDisableShown,
|
||||
isPinLockEnabled,
|
||||
isTunnelStatsExpanded,
|
||||
expandedTunnelIds,
|
||||
isLocalLogsEnabled,
|
||||
isRemoteControlEnabled,
|
||||
remoteKey,
|
||||
@@ -48,7 +48,6 @@ data class GeneralState(
|
||||
const val LOCATION_DISCLOSURE_SHOWN_DEFAULT = false
|
||||
const val BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT = false
|
||||
const val PIN_LOCK_ENABLED_DEFAULT = false
|
||||
const val IS_TUNNEL_STATS_EXPANDED = false
|
||||
const val IS_LOGS_ENABLED_DEFAULT = false
|
||||
const val IS_REMOTE_CONTROL_ENABLED = false
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.model
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppUpdate
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class GitHubRelease(
|
||||
@SerialName("tag_name") val tagName: String,
|
||||
val name: String?,
|
||||
val body: String?,
|
||||
val assets: List<Asset>,
|
||||
) {
|
||||
fun toAppUpdate(): AppUpdate {
|
||||
val apkAsset = assets.firstOrNull { it.name.endsWith(".apk") }
|
||||
return AppUpdate(
|
||||
version = tagName.removePrefix("v"),
|
||||
title = name ?: "Update $tagName",
|
||||
releaseNotes = body ?: "No release notes provided",
|
||||
apkUrl = apkAsset?.browserDownloadUrl,
|
||||
apkFileName = apkAsset?.name,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.network
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.GitHubRelease
|
||||
|
||||
interface GitHubApi {
|
||||
suspend fun getLatestRelease(owner: String, repo: String): Result<GitHubRelease>
|
||||
|
||||
suspend fun getNightlyRelease(owner: String, repo: String): Result<GitHubRelease>
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.network
|
||||
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.okhttp.OkHttp
|
||||
import io.ktor.client.plugins.HttpTimeout
|
||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
object KtorClient {
|
||||
fun create(): HttpClient {
|
||||
return HttpClient(OkHttp) {
|
||||
install(ContentNegotiation) {
|
||||
json(
|
||||
Json {
|
||||
ignoreUnknownKeys = true
|
||||
isLenient = true
|
||||
}
|
||||
)
|
||||
}
|
||||
install(HttpTimeout) {
|
||||
requestTimeoutMillis = 15000
|
||||
connectTimeoutMillis = 15000
|
||||
socketTimeoutMillis = 15000
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.network
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.GitHubRelease
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.body
|
||||
import io.ktor.client.plugins.ClientRequestException
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.http.HttpStatusCode
|
||||
|
||||
class KtorGitHubApi(private val client: HttpClient) : GitHubApi {
|
||||
override suspend fun getLatestRelease(owner: String, repo: String): Result<GitHubRelease> {
|
||||
return try {
|
||||
val response: GitHubRelease =
|
||||
client.get("https://api.github.com/repos/$owner/$repo/releases/latest").body()
|
||||
Result.success(response)
|
||||
} catch (e: ClientRequestException) {
|
||||
when (e.response.status) {
|
||||
HttpStatusCode.Forbidden -> Result.failure(Exception("Rate limit exceeded"))
|
||||
HttpStatusCode.NotFound ->
|
||||
Result.failure(Exception("Repository or release not found"))
|
||||
else -> Result.failure(e)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getNightlyRelease(owner: String, repo: String): Result<GitHubRelease> {
|
||||
return try {
|
||||
// Fetch all releases
|
||||
val releases: List<GitHubRelease> =
|
||||
client.get("https://api.github.com/repos/$owner/$repo/releases").body()
|
||||
|
||||
// Find the first release with "nightly" in the tag_name (case-insensitive)
|
||||
val nightlyRelease =
|
||||
releases.firstOrNull { release ->
|
||||
release.tagName.contains("nightly", ignoreCase = true)
|
||||
}
|
||||
|
||||
if (nightlyRelease != null) {
|
||||
Result.success(nightlyRelease)
|
||||
} else {
|
||||
Result.failure(Exception("No release with 'nightly' tag found"))
|
||||
}
|
||||
} catch (e: ClientRequestException) {
|
||||
when (e.response.status) {
|
||||
HttpStatusCode.Forbidden -> Result.failure(Exception("Rate limit exceeded"))
|
||||
HttpStatusCode.NotFound ->
|
||||
Result.failure(Exception("Repository or release not found"))
|
||||
else -> Result.failure(e)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
-8
@@ -38,13 +38,36 @@ class DataStoreAppStateRepository(private val dataStoreManager: DataStoreManager
|
||||
dataStoreManager.saveToDataStore(DataStoreManager.batteryDisableShown, shown)
|
||||
}
|
||||
|
||||
override suspend fun isTunnelStatsExpanded(): Boolean {
|
||||
return dataStoreManager.getFromStore(DataStoreManager.tunnelStatsExpanded)
|
||||
?: GeneralState.IS_TUNNEL_STATS_EXPANDED
|
||||
override suspend fun setTunnelExpanded(id: Int) {
|
||||
val ids =
|
||||
dataStoreManager
|
||||
.getFromStore(DataStoreManager.expandedTunnelIds)
|
||||
?.split(",")
|
||||
?.mapNotNull { it.toIntOrNull() } ?: emptyList()
|
||||
|
||||
if (ids.contains(id)) return
|
||||
|
||||
val updatedList = ids.toMutableList().apply { add(id) }
|
||||
dataStoreManager.saveToDataStore(
|
||||
DataStoreManager.expandedTunnelIds,
|
||||
updatedList.joinToString(","),
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun setTunnelStatsExpanded(expanded: Boolean) {
|
||||
dataStoreManager.saveToDataStore(DataStoreManager.tunnelStatsExpanded, expanded)
|
||||
override suspend fun removeTunnelExpanded(id: Int) {
|
||||
val ids =
|
||||
dataStoreManager
|
||||
.getFromStore(DataStoreManager.expandedTunnelIds)
|
||||
?.split(",")
|
||||
?.mapNotNull { it.toIntOrNull() } ?: emptyList()
|
||||
|
||||
if (ids.isEmpty() || !ids.contains(id)) return
|
||||
|
||||
val updatedList = ids.toMutableList().apply { remove(id) }
|
||||
dataStoreManager.saveToDataStore(
|
||||
DataStoreManager.expandedTunnelIds,
|
||||
updatedList.joinToString(","),
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun setTheme(theme: Theme) {
|
||||
@@ -110,9 +133,10 @@ class DataStoreAppStateRepository(private val dataStoreManager: DataStoreManager
|
||||
isPinLockEnabled =
|
||||
pref[DataStoreManager.pinLockEnabled]
|
||||
?: GeneralState.PIN_LOCK_ENABLED_DEFAULT,
|
||||
isTunnelStatsExpanded =
|
||||
pref[DataStoreManager.tunnelStatsExpanded]
|
||||
?: GeneralState.IS_TUNNEL_STATS_EXPANDED,
|
||||
expandedTunnelIds =
|
||||
pref[DataStoreManager.expandedTunnelIds]?.split(",")?.mapNotNull {
|
||||
it.toIntOrNull()
|
||||
} ?: emptyList(),
|
||||
isLocalLogsEnabled =
|
||||
pref[DataStoreManager.isLocalLogsEnabled]
|
||||
?: GeneralState.IS_LOGS_ENABLED_DEFAULT,
|
||||
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||
|
||||
import android.content.Context
|
||||
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
||||
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppUpdate
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.UpdateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.client.statement.bodyAsChannel
|
||||
import io.ktor.http.contentLength
|
||||
import io.ktor.utils.io.ByteReadChannel
|
||||
import io.ktor.utils.io.readAvailable
|
||||
import java.io.File
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
|
||||
class GitHubUpdateRepository(
|
||||
private val gitHubApi: GitHubApi,
|
||||
private val httpClient: HttpClient,
|
||||
private val githubOwner: String,
|
||||
private val githubRepo: String,
|
||||
private val context: Context,
|
||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||
) : UpdateRepository {
|
||||
override suspend fun checkForUpdate(currentVersion: String): Result<AppUpdate?> =
|
||||
withContext(ioDispatcher) {
|
||||
Timber.i("Checking for update")
|
||||
val release =
|
||||
if (BuildConfig.VERSION_NAME.contains("nightly")) {
|
||||
gitHubApi.getNightlyRelease(githubOwner, githubRepo)
|
||||
} else {
|
||||
gitHubApi.getLatestRelease(githubOwner, githubRepo)
|
||||
}
|
||||
release.map { release ->
|
||||
val apkAsset =
|
||||
release.assets.find { asset ->
|
||||
asset.name.startsWith("wgtunnel-full-v") && asset.name.endsWith(".apk")
|
||||
}
|
||||
val newVersion =
|
||||
apkAsset?.name?.removePrefix("wgtunnel-full-v")?.removeSuffix(".apk")
|
||||
?: return@map null
|
||||
|
||||
Timber.i("Latest version: $newVersion, current version: $currentVersion")
|
||||
if (NumberUtils.compareVersions(newVersion, currentVersion) > 0) {
|
||||
release.toAppUpdate()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun downloadApk(
|
||||
apkUrl: String,
|
||||
fileName: String,
|
||||
onProgress: (Float) -> Unit,
|
||||
): Result<File> =
|
||||
withContext(ioDispatcher) {
|
||||
try {
|
||||
// clean up old files
|
||||
context.getExternalFilesDir(null)?.listFiles()?.forEach { file ->
|
||||
if (file.extension == "apk") file.delete()
|
||||
}
|
||||
|
||||
val response: HttpResponse = httpClient.get(apkUrl)
|
||||
|
||||
val apkFile = File(context.getExternalFilesDir(null), fileName)
|
||||
|
||||
val channel: ByteReadChannel = response.bodyAsChannel()
|
||||
val totalBytes: Long = response.contentLength() ?: -1L
|
||||
var bytesCopied = 0L
|
||||
|
||||
apkFile.outputStream().use { output ->
|
||||
val buffer = ByteArray(8 * 1024)
|
||||
|
||||
while (!channel.isClosedForRead) {
|
||||
val bytesRead = channel.readAvailable(buffer)
|
||||
if (bytesRead <= 0) break
|
||||
output.write(buffer, 0, bytesRead)
|
||||
bytesCopied += bytesRead
|
||||
|
||||
if (totalBytes > 0) {
|
||||
val progress = bytesCopied.toFloat() / totalBytes
|
||||
onProgress(progress.coerceIn(0f, 1f))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Result.success(apkFile)
|
||||
} catch (e: Exception) {
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,19 +8,25 @@ import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
||||
import com.zaneschepke.wireguardautotunnel.data.DatabaseCallback
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
||||
import com.zaneschepke.wireguardautotunnel.data.network.KtorClient
|
||||
import com.zaneschepke.wireguardautotunnel.data.network.KtorGitHubApi
|
||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRoomRepository
|
||||
import com.zaneschepke.wireguardautotunnel.data.repository.DataStoreAppStateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.data.repository.GitHubUpdateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.data.repository.RoomSettingsRepository
|
||||
import com.zaneschepke.wireguardautotunnel.data.repository.RoomTunnelRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.UpdateRepository
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import io.ktor.client.HttpClient
|
||||
import javax.inject.Singleton
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
|
||||
@@ -35,7 +41,7 @@ class RepositoryModule {
|
||||
AppDatabase::class.java,
|
||||
context.getString(R.string.db_name),
|
||||
)
|
||||
.fallbackToDestructiveMigration()
|
||||
.fallbackToDestructiveMigration(true)
|
||||
.addCallback(DatabaseCallback())
|
||||
.build()
|
||||
}
|
||||
@@ -94,4 +100,34 @@ class RepositoryModule {
|
||||
): AppDataRepository {
|
||||
return AppDataRoomRepository(settingsRepository, tunnelRepository, appStateRepository)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideHttpClient(): HttpClient {
|
||||
return KtorClient.create()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideGitHubApi(client: HttpClient): GitHubApi {
|
||||
return KtorGitHubApi(client)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideUpdateRepository(
|
||||
gitHubApi: GitHubApi,
|
||||
client: HttpClient,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
@ApplicationContext context: Context,
|
||||
): UpdateRepository {
|
||||
return GitHubUpdateRepository(
|
||||
gitHubApi,
|
||||
client,
|
||||
"wgtunnel",
|
||||
"wgtunnel",
|
||||
context,
|
||||
ioDispatcher,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ data class AppState(
|
||||
val isLocationDisclosureShown: Boolean,
|
||||
val isBatteryOptimizationDisableShown: Boolean,
|
||||
val isPinLockEnabled: Boolean,
|
||||
val isTunnelStatsExpanded: Boolean,
|
||||
val expandedTunnelIds: List<Int>,
|
||||
val isLocalLogsEnabled: Boolean,
|
||||
val isRemoteControlEnabled: Boolean,
|
||||
val remoteKey: String?,
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.entity
|
||||
|
||||
data class AppUpdate(
|
||||
val version: String,
|
||||
val title: String,
|
||||
val releaseNotes: String,
|
||||
val apkUrl: String?,
|
||||
val apkFileName: String?,
|
||||
)
|
||||
@@ -4,12 +4,12 @@ import com.wireguard.android.backend.Tunnel
|
||||
import com.wireguard.config.Config
|
||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.*
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
import java.io.InputStream
|
||||
import java.net.InetAddress
|
||||
import java.nio.charset.StandardCharsets
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
|
||||
data class TunnelConf(
|
||||
val id: Int = 0,
|
||||
@@ -92,9 +92,7 @@ data class TunnelConf(
|
||||
isEthernetTunnel,
|
||||
isIpv4Preferred,
|
||||
)
|
||||
.apply {
|
||||
stateChangeCallback = this@TunnelConf.stateChangeCallback
|
||||
}
|
||||
.apply { stateChangeCallback = this@TunnelConf.stateChangeCallback }
|
||||
}
|
||||
|
||||
fun toAmConfig(): org.amnezia.awg.config.Config {
|
||||
|
||||
+2
-2
@@ -17,9 +17,9 @@ interface AppStateRepository {
|
||||
|
||||
suspend fun setBatteryOptimizationDisableShown(shown: Boolean)
|
||||
|
||||
suspend fun isTunnelStatsExpanded(): Boolean
|
||||
suspend fun setTunnelExpanded(id: Int)
|
||||
|
||||
suspend fun setTunnelStatsExpanded(expanded: Boolean)
|
||||
suspend fun removeTunnelExpanded(id: Int)
|
||||
|
||||
suspend fun setTheme(theme: Theme)
|
||||
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppUpdate
|
||||
import java.io.File
|
||||
|
||||
interface UpdateRepository {
|
||||
suspend fun checkForUpdate(currentVersion: String): Result<AppUpdate?>
|
||||
|
||||
suspend fun downloadApk(
|
||||
apkUrl: String,
|
||||
fileName: String,
|
||||
onProgress: (Float) -> Unit,
|
||||
): Result<File>
|
||||
}
|
||||
@@ -31,6 +31,8 @@ sealed class Route {
|
||||
|
||||
@Serializable data object Scanner : Route()
|
||||
|
||||
@Serializable data object License : Route()
|
||||
|
||||
@Serializable data class Config(val id: Int) : Route()
|
||||
|
||||
@Serializable
|
||||
|
||||
+45
-11
@@ -3,39 +3,73 @@ package com.zaneschepke.wireguardautotunnel.ui.common
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.indication
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.PressInteraction
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.ripple
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun ExpandingRowListItem(
|
||||
leading: @Composable () -> Unit,
|
||||
text: String,
|
||||
onHold: () -> Unit = {},
|
||||
onHold: () -> Unit,
|
||||
onClick: () -> Unit,
|
||||
onDoubleClick: () -> Unit,
|
||||
trailing: @Composable () -> Unit,
|
||||
isExpanded: Boolean,
|
||||
expanded: @Composable () -> Unit = {},
|
||||
isSelected: Boolean,
|
||||
expanded: (@Composable () -> Unit)?,
|
||||
) {
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
val haptic = LocalHapticFeedback.current
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
|
||||
Box(
|
||||
modifier =
|
||||
Modifier.animateContentSize()
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.combinedClickable(onClick = { onClick() }, onLongClick = { onHold() })
|
||||
.then(
|
||||
if (!isTv) {
|
||||
Modifier.combinedClickable(
|
||||
onClick = onClick,
|
||||
onLongClick = {
|
||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onHold()
|
||||
},
|
||||
onDoubleClick = onDoubleClick,
|
||||
)
|
||||
.indication(
|
||||
interactionSource = interactionSource,
|
||||
indication = ripple(),
|
||||
)
|
||||
} else Modifier
|
||||
)
|
||||
) {
|
||||
LaunchedEffect(isSelected) {
|
||||
if (isSelected) {
|
||||
interactionSource.emit(PressInteraction.Press(Offset.Zero))
|
||||
} else {
|
||||
interactionSource.emit(
|
||||
PressInteraction.Release(PressInteraction.Press(Offset.Zero))
|
||||
)
|
||||
}
|
||||
}
|
||||
Column {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),
|
||||
@@ -58,7 +92,7 @@ fun ExpandingRowListItem(
|
||||
}
|
||||
trailing()
|
||||
}
|
||||
if (isExpanded) expanded()
|
||||
expanded?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun SectionDivider() {
|
||||
HorizontalDivider(
|
||||
color = MaterialTheme.colorScheme.outline.copy(0.30f),
|
||||
modifier = Modifier.padding(horizontal = 12.dp),
|
||||
)
|
||||
}
|
||||
+19
-15
@@ -3,21 +3,25 @@ package com.zaneschepke.wireguardautotunnel.ui.common.button.surface
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.Modifier
|
||||
|
||||
@Composable
|
||||
fun SelectionItemLabel(
|
||||
textResId: Int,
|
||||
style: androidx.compose.ui.text.TextStyle = MaterialTheme.typography.bodyMedium,
|
||||
isDescription: Boolean = false,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(textResId),
|
||||
style =
|
||||
style.copy(
|
||||
color =
|
||||
if (isDescription) MaterialTheme.colorScheme.outline
|
||||
else MaterialTheme.colorScheme.onSurface
|
||||
),
|
||||
)
|
||||
fun SelectionItemLabel(text: String, labelType: SelectionLabelType, modifier: Modifier = Modifier) {
|
||||
|
||||
val style =
|
||||
when (labelType) {
|
||||
SelectionLabelType.DESCRIPTION ->
|
||||
MaterialTheme.typography.bodySmall.copy(color = MaterialTheme.colorScheme.outline)
|
||||
SelectionLabelType.TITLE ->
|
||||
MaterialTheme.typography.bodyMedium.copy(
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
}
|
||||
|
||||
Text(text = text, style = style, modifier = modifier)
|
||||
}
|
||||
|
||||
enum class SelectionLabelType {
|
||||
DESCRIPTION,
|
||||
TITLE,
|
||||
}
|
||||
|
||||
+44
-2
@@ -9,21 +9,23 @@ import androidx.activity.compose.ManagedActivityResultLauncher
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.runtime.Composable
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import timber.log.Timber
|
||||
|
||||
@Composable
|
||||
fun rememberFileImportLauncherForResult(
|
||||
onNoFileExplorer: () -> Unit,
|
||||
onData: (data: Uri) -> Unit,
|
||||
): ManagedActivityResultLauncher<String, Uri?> {
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
return rememberLauncherForActivityResult(
|
||||
object : ActivityResultContracts.GetContent() {
|
||||
override fun createIntent(context: Context, input: String): Intent {
|
||||
val intent =
|
||||
super.createIntent(context, input).apply {
|
||||
type =
|
||||
if (context.isRunningOnTv()) {
|
||||
if (isTv) {
|
||||
Constants.ALLOWED_TV_FILE_TYPES
|
||||
} else {
|
||||
Constants.ALL_FILE_TYPES
|
||||
@@ -63,3 +65,43 @@ fun rememberFileImportLauncherForResult(
|
||||
onData(data)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun rememberFileExportLauncherForResult(
|
||||
mimeType: String = Constants.ZIP_FILE_MIME_TYPE,
|
||||
onResult: (Uri?) -> Unit,
|
||||
): ManagedActivityResultLauncher<String, Uri?> {
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
return rememberLauncherForActivityResult(
|
||||
contract =
|
||||
object : ActivityResultContracts.CreateDocument(mimeType) {
|
||||
override fun createIntent(context: Context, input: String): Intent {
|
||||
super.createIntent(context, input)
|
||||
val intent =
|
||||
Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type =
|
||||
if (isTv) {
|
||||
Constants.ALLOWED_TV_FILE_TYPES
|
||||
} else {
|
||||
mimeType
|
||||
}
|
||||
putExtra(Intent.EXTRA_TITLE, input)
|
||||
}
|
||||
|
||||
Timber.d("Returning SAF intent for launch")
|
||||
return intent
|
||||
}
|
||||
}
|
||||
) { uri ->
|
||||
Timber.d("SAF onResult called with Uri: $uri")
|
||||
if (uri != null) {
|
||||
Timber.d(
|
||||
"Uri details: scheme=${uri.scheme}, authority=${uri.authority}, path=${uri.path}"
|
||||
)
|
||||
} else {
|
||||
Timber.d("SAF picker canceled or failed to return a Uri")
|
||||
}
|
||||
onResult(uri)
|
||||
}
|
||||
}
|
||||
|
||||
-115
@@ -1,115 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.Badge
|
||||
import androidx.compose.material3.BadgedBox
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.SilverTree
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
|
||||
@Composable
|
||||
fun BottomBarTabs(
|
||||
tabs: List<BottomNavItem>,
|
||||
selectedTabIndex: Int,
|
||||
isChildRoute: Boolean,
|
||||
onTabSelected: (BottomNavItem) -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val isRunningOnTv = remember { context.isRunningOnTv() }
|
||||
|
||||
Row(
|
||||
modifier =
|
||||
Modifier.fillMaxWidth().height(64.dp).padding(horizontal = 8.dp).padding(top = 12.dp),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
tabs.forEachIndexed { index, tab ->
|
||||
Column(
|
||||
modifier =
|
||||
Modifier.weight(1f)
|
||||
.fillMaxHeight()
|
||||
.background(Color.Transparent)
|
||||
.then(
|
||||
if (isRunningOnTv) {
|
||||
Modifier.clickable {
|
||||
if (index == selectedTabIndex && !isChildRoute) return@clickable
|
||||
tab.onClick.invoke()
|
||||
onTabSelected(tab)
|
||||
}
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
)
|
||||
.pointerInput(Unit) {
|
||||
detectTapGestures {
|
||||
if (index == selectedTabIndex && !isChildRoute)
|
||||
return@detectTapGestures
|
||||
tab.onClick.invoke()
|
||||
onTabSelected(tab)
|
||||
}
|
||||
},
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
) {
|
||||
val animatedColor by
|
||||
animateColorAsState(
|
||||
targetValue = MaterialTheme.colorScheme.primary,
|
||||
animationSpec = spring(stiffness = Spring.StiffnessLow),
|
||||
label = "animatedColor",
|
||||
)
|
||||
val color =
|
||||
if (selectedTabIndex == index) animatedColor
|
||||
else MaterialTheme.colorScheme.onSurface
|
||||
|
||||
if (tab.active) {
|
||||
BadgedBox(
|
||||
badge = {
|
||||
Badge(
|
||||
modifier = Modifier.offset(x = 8.dp, y = ((-8).dp)).size(6.dp),
|
||||
containerColor = SilverTree,
|
||||
)
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
imageVector = tab.icon,
|
||||
contentDescription = tab.name,
|
||||
tint = color,
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Icon(
|
||||
imageVector = tab.icon,
|
||||
contentDescription = tab.name,
|
||||
tint = color,
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-121
@@ -1,121 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.systemBars
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.geometry.CornerRadius
|
||||
import androidx.compose.ui.geometry.RoundRect
|
||||
import androidx.compose.ui.geometry.toRect
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Path
|
||||
import androidx.compose.ui.graphics.PathEffect
|
||||
import androidx.compose.ui.graphics.PathMeasure
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
|
||||
@Composable
|
||||
fun CustomBottomNavbar(tabs: List<BottomNavItem>, navBarState: NavBarState) {
|
||||
var selectedTabIndex by remember { mutableIntStateOf(0) }
|
||||
var isChildRoute by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(tabs) {}
|
||||
when (navBarState.route) {
|
||||
Route.Main -> {
|
||||
selectedTabIndex = 0
|
||||
isChildRoute = false
|
||||
}
|
||||
Route.AutoTunnel -> {
|
||||
selectedTabIndex = 1
|
||||
isChildRoute = false
|
||||
}
|
||||
Route.Settings -> {
|
||||
selectedTabIndex = 2
|
||||
isChildRoute = false
|
||||
}
|
||||
Route.Support -> {
|
||||
selectedTabIndex = 3
|
||||
isChildRoute = false
|
||||
}
|
||||
else -> isChildRoute = true
|
||||
}
|
||||
|
||||
val systemBars = WindowInsets.systemBars
|
||||
val bottomPadding = with(LocalDensity.current) { systemBars.getBottom(this).toDp() }
|
||||
val navHeight = 64.dp + bottomPadding
|
||||
|
||||
Box(modifier = Modifier.fillMaxWidth().height(navHeight).background(Color.Transparent)) {
|
||||
BottomBarTabs(
|
||||
tabs = tabs,
|
||||
selectedTabIndex = selectedTabIndex,
|
||||
isChildRoute = isChildRoute,
|
||||
onTabSelected = { selectedTabIndex = tabs.indexOf(it) },
|
||||
)
|
||||
|
||||
val animatedSelectedTabIndex by
|
||||
animateFloatAsState(
|
||||
targetValue = selectedTabIndex.toFloat(),
|
||||
label = "animatedSelectedTabIndex",
|
||||
animationSpec =
|
||||
spring(
|
||||
stiffness = Spring.StiffnessLow,
|
||||
dampingRatio = Spring.DampingRatioLowBouncy,
|
||||
),
|
||||
)
|
||||
|
||||
val animatedColor by
|
||||
animateColorAsState(
|
||||
targetValue = MaterialTheme.colorScheme.primary,
|
||||
label = "animatedColor",
|
||||
animationSpec = spring(stiffness = Spring.StiffnessLow),
|
||||
)
|
||||
|
||||
Canvas(modifier = Modifier.fillMaxWidth().height(navHeight)) {
|
||||
val path =
|
||||
Path().apply { addRoundRect(RoundRect(size.toRect(), CornerRadius(size.height))) }
|
||||
val length = PathMeasure().apply { setPath(path, false) }.length
|
||||
|
||||
val tabWidth = size.width / tabs.size
|
||||
drawPath(
|
||||
path,
|
||||
brush =
|
||||
Brush.horizontalGradient(
|
||||
colors =
|
||||
listOf(
|
||||
animatedColor.copy(alpha = 0f),
|
||||
animatedColor.copy(alpha = 1f),
|
||||
animatedColor.copy(alpha = 1f),
|
||||
animatedColor.copy(alpha = 0f),
|
||||
),
|
||||
startX = tabWidth * animatedSelectedTabIndex,
|
||||
endX = tabWidth * (animatedSelectedTabIndex + 1),
|
||||
),
|
||||
style =
|
||||
Stroke(
|
||||
width = 4f,
|
||||
pathEffect =
|
||||
PathEffect.dashPathEffect(intervals = floatArrayOf(length / 2, length)),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.navigation.NavHostController
|
||||
|
||||
val LocalNavController =
|
||||
compositionLocalOf<NavHostController> { error("NavController was not provided") }
|
||||
+3
-6
@@ -19,11 +19,10 @@ import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||
import androidx.compose.ui.unit.LayoutDirection
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
|
||||
@Composable
|
||||
fun CustomSnackBar(
|
||||
@@ -31,12 +30,10 @@ fun CustomSnackBar(
|
||||
isRtl: Boolean = true,
|
||||
containerColor: Color = MaterialTheme.colorScheme.surface,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
Snackbar(
|
||||
containerColor = containerColor,
|
||||
modifier =
|
||||
Modifier.fillMaxWidth(if (context.isRunningOnTv()) 1 / 3f else 2 / 3f)
|
||||
.padding(bottom = 100.dp),
|
||||
modifier = Modifier.fillMaxWidth(if (isTv) 1 / 3f else 2 / 3f).padding(bottom = 100.dp),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
) {
|
||||
CompositionLocalProvider(
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.enums
|
||||
|
||||
enum class InterfaceActions {
|
||||
TOGGLE_AMNEZIA_VALUES,
|
||||
SET_AMNEZIA_COMPATIBILITY,
|
||||
TOGGLE_SHOW_SCRIPTS,
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.enums
|
||||
|
||||
enum class PeerActions {
|
||||
EXCLUDE_LAN
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation
|
||||
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
+8
-1
@@ -1,9 +1,12 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.navigation.NavBackStackEntry
|
||||
import androidx.navigation.NavDestination.Companion.hasRoute
|
||||
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||
import androidx.navigation.NavHostController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@@ -11,3 +14,7 @@ import kotlin.reflect.KClass
|
||||
fun <T : Route> NavBackStackEntry?.isCurrentRoute(cls: KClass<T>): Boolean {
|
||||
return this?.destination?.hierarchy?.any { it.hasRoute(route = cls) } == true
|
||||
}
|
||||
|
||||
val LocalNavController =
|
||||
compositionLocalOf<NavHostController> { error("NavController was not provided") }
|
||||
val LocalIsAndroidTV = staticCompositionLocalOf { false }
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation.components
|
||||
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Bolt
|
||||
import androidx.compose.material.icons.rounded.Home
|
||||
import androidx.compose.material.icons.rounded.QuestionMark
|
||||
import androidx.compose.material.icons.rounded.Settings
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.BottomNavItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.isCurrentRoute
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.SilverTree
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.goFromRoot
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun BottomNavbar(appUiState: AppUiState) {
|
||||
val navController = LocalNavController.current
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
|
||||
val items =
|
||||
listOf(
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.tunnels),
|
||||
route = Route.Main,
|
||||
icon = Icons.Rounded.Home,
|
||||
onClick = { navController.goFromRoot(Route.Main) },
|
||||
),
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.auto_tunnel),
|
||||
route = Route.AutoTunnel,
|
||||
icon = Icons.Rounded.Bolt,
|
||||
onClick = {
|
||||
val route =
|
||||
if (appUiState.appState.isLocationDisclosureShown) Route.AutoTunnel
|
||||
else Route.LocationDisclosure
|
||||
navController.goFromRoot(route)
|
||||
},
|
||||
active = appUiState.isAutoTunnelActive,
|
||||
),
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.settings),
|
||||
route = Route.Settings,
|
||||
icon = Icons.Rounded.Settings,
|
||||
onClick = { navController.goFromRoot(Route.Settings) },
|
||||
),
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.support),
|
||||
route = Route.Support,
|
||||
icon = Icons.Rounded.QuestionMark,
|
||||
onClick = { navController.goFromRoot(Route.Support) },
|
||||
),
|
||||
)
|
||||
// Define ripple configuration based on platform
|
||||
val rippleConfiguration =
|
||||
if (isTv) {
|
||||
RippleConfiguration()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
// Apply ripple configuration only if needed
|
||||
CompositionLocalProvider(LocalRippleConfiguration provides rippleConfiguration) {
|
||||
NavigationBar(containerColor = MaterialTheme.colorScheme.surface) {
|
||||
items.forEach { item ->
|
||||
val isSelected = navBackStackEntry.isCurrentRoute(item.route::class)
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
|
||||
NavigationBarItem(
|
||||
icon = {
|
||||
if (item.active) {
|
||||
BadgedBox(
|
||||
badge = {
|
||||
Badge(
|
||||
modifier =
|
||||
Modifier.offset(x = 8.dp, y = (-8).dp).size(6.dp),
|
||||
containerColor = SilverTree,
|
||||
)
|
||||
}
|
||||
) {
|
||||
Icon(imageVector = item.icon, contentDescription = item.name)
|
||||
}
|
||||
} else {
|
||||
Icon(imageVector = item.icon, contentDescription = item.name)
|
||||
}
|
||||
},
|
||||
onClick = { navController.goFromRoot(item.route) },
|
||||
selected = isSelected,
|
||||
enabled = true,
|
||||
label = null,
|
||||
alwaysShowLabel = false,
|
||||
colors =
|
||||
NavigationBarItemDefaults.colors(
|
||||
selectedIconColor = MaterialTheme.colorScheme.primary,
|
||||
unselectedIconColor = MaterialTheme.colorScheme.onBackground,
|
||||
indicatorColor = Color.Transparent,
|
||||
),
|
||||
interactionSource = interactionSource,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-6
@@ -1,10 +1,6 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation.components
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.animation.*
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
@@ -14,6 +10,7 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.NavBarState
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
+186
-157
@@ -1,12 +1,18 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation.components
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Add
|
||||
import androidx.compose.material.icons.rounded.CopyAll
|
||||
import androidx.compose.material.icons.rounded.Delete
|
||||
import androidx.compose.material.icons.rounded.Download
|
||||
import androidx.compose.material.icons.rounded.Edit
|
||||
import androidx.compose.material.icons.rounded.Menu
|
||||
import androidx.compose.material.icons.rounded.PlayArrow
|
||||
import androidx.compose.material.icons.rounded.Save
|
||||
import androidx.compose.material.icons.rounded.SelectAll
|
||||
import androidx.compose.material.icons.rounded.Stop
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
@@ -15,80 +21,126 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.navigation.NavBackStackEntry
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.toRoute
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.isCurrentRoute
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppViewState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.NavBarState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Brick
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.SilverTree
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
|
||||
data class NavBarState(
|
||||
val showTop: Boolean = true,
|
||||
val showBottom: Boolean = true,
|
||||
val topTitle: @Composable (() -> Unit)? = null,
|
||||
val topTrailing: @Composable (() -> Unit)? = null,
|
||||
val route: Route? = null,
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun currentNavBackStackEntryAsNavBarState(
|
||||
navController: NavController,
|
||||
backStackEntry: NavBackStackEntry?,
|
||||
viewModel: AppViewModel,
|
||||
uiState: AppUiState,
|
||||
appViewState: AppViewState,
|
||||
): State<NavBarState> {
|
||||
return produceState(initialValue = NavBarState(), key1 = backStackEntry, key2 = uiState) {
|
||||
fun isActiveSelected() =
|
||||
uiState.activeTunnels.any { active ->
|
||||
appViewState.selectedTunnels.any { it.id == active.key.id }
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ActionIconButton(icon: ImageVector, labelRes: Int, onClick: () -> Unit) {
|
||||
IconButton(onClick = onClick) {
|
||||
Icon(
|
||||
icon,
|
||||
contentDescription = stringResource(labelRes),
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun TunnelActionBar() {
|
||||
val selectedCount = appViewState.selectedTunnels.size
|
||||
val showDelete = !isActiveSelected()
|
||||
|
||||
Row {
|
||||
if (selectedCount == 0) {
|
||||
ActionIconButton(Icons.Rounded.Add, R.string.add_tunnel) {
|
||||
viewModel.handleEvent(
|
||||
AppEvent.SetBottomSheet(AppViewState.BottomSheet.IMPORT_TUNNELS)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
ActionIconButton(Icons.Rounded.SelectAll, R.string.select_all) {
|
||||
viewModel.handleEvent(AppEvent.ToggleSelectAllTunnels)
|
||||
}
|
||||
// due to permissions, and SAF issues on TV, not support less than Android 10 on
|
||||
// Android TV for file exports
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
ActionIconButton(Icons.Rounded.Download, R.string.download) {
|
||||
viewModel.handleEvent(
|
||||
AppEvent.SetBottomSheet(AppViewState.BottomSheet.EXPORT_TUNNELS)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedCount == 1) {
|
||||
ActionIconButton(Icons.Rounded.CopyAll, R.string.copy) {
|
||||
viewModel.handleEvent(AppEvent.CopySelectedTunnel)
|
||||
}
|
||||
}
|
||||
|
||||
if (showDelete) {
|
||||
ActionIconButton(Icons.Rounded.Delete, R.string.delete_tunnel) {
|
||||
viewModel.handleEvent(AppEvent.SetShowModal(AppViewState.ModalType.DELETE))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return produceState(
|
||||
initialValue = NavBarState(),
|
||||
key1 = backStackEntry,
|
||||
key2 = uiState,
|
||||
key3 = appViewState,
|
||||
) {
|
||||
value =
|
||||
when {
|
||||
backStackEntry.isCurrentRoute(Route.Main::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.tunnels)) },
|
||||
{
|
||||
IconButton(
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleBottomSheet) }
|
||||
) {
|
||||
val icon = Icons.Rounded.Add
|
||||
Icon(
|
||||
icon,
|
||||
stringResource(R.string.add_tunnel),
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
}
|
||||
},
|
||||
topTitle = { Text(stringResource(R.string.tunnels)) },
|
||||
topTrailing = { TunnelActionBar() },
|
||||
route = Route.Main,
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.AutoTunnel::class) -> {
|
||||
val (icon, label, tint) =
|
||||
if (uiState.appSettings.isAutoTunnelEnabled) {
|
||||
Triple(Icons.Rounded.Stop, R.string.stop_auto, Brick)
|
||||
} else {
|
||||
Triple(Icons.Rounded.PlayArrow, R.string.start_auto, SilverTree)
|
||||
}
|
||||
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.auto_tunnel)) },
|
||||
{
|
||||
topTitle = { Text(stringResource(R.string.auto_tunnel)) },
|
||||
topTrailing = {
|
||||
IconButton(
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnel) }
|
||||
) {
|
||||
val (icon, description, color) =
|
||||
if (uiState.appSettings.isAutoTunnelEnabled) {
|
||||
Triple(Icons.Rounded.Stop, R.string.stop_auto, Brick)
|
||||
} else {
|
||||
Triple(
|
||||
Icons.Rounded.PlayArrow,
|
||||
R.string.start_auto,
|
||||
SilverTree,
|
||||
)
|
||||
}
|
||||
Icon(
|
||||
icon,
|
||||
stringResource(description),
|
||||
tint = color,
|
||||
stringResource(label),
|
||||
tint = tint,
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
}
|
||||
@@ -96,175 +148,152 @@ fun currentNavBackStackEntryAsNavBarState(
|
||||
route = Route.AutoTunnel,
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.AutoTunnelAdvanced::class) ||
|
||||
backStackEntry.isCurrentRoute(Route.SettingsAdvanced::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.advanced_settings)) },
|
||||
route = Route.AutoTunnelAdvanced,
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.Settings::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.settings)) },
|
||||
{
|
||||
IconButton(
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleBottomSheet) }
|
||||
) {
|
||||
val icon = Icons.Rounded.Menu
|
||||
Icon(
|
||||
icon,
|
||||
stringResource(R.string.quick_actions),
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
}
|
||||
},
|
||||
route = Route.Settings,
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.KillSwitch::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.kill_switch)) },
|
||||
route = Route.KillSwitch,
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.Appearance::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.appearance)) },
|
||||
route = Route.Appearance,
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.Language::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.language)) },
|
||||
route = Route.Language,
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.Display::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.display_theme)) },
|
||||
route = Route.Display,
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Logs::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = false,
|
||||
{ Text(stringResource(R.string.logs)) },
|
||||
{
|
||||
IconButton(
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleBottomSheet) }
|
||||
) {
|
||||
val icon = Icons.Rounded.Menu
|
||||
Icon(
|
||||
icon,
|
||||
stringResource(R.string.quick_actions),
|
||||
modifier = Modifier.size(iconSize),
|
||||
topTitle = { Text(stringResource(R.string.logs)) },
|
||||
topTrailing = {
|
||||
ActionIconButton(Icons.Rounded.Menu, R.string.quick_actions) {
|
||||
viewModel.handleEvent(
|
||||
AppEvent.SetBottomSheet(AppViewState.BottomSheet.LOGS)
|
||||
)
|
||||
}
|
||||
},
|
||||
route = Route.Logs,
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.TunnelOptions::class) -> {
|
||||
val args = backStackEntry?.toRoute<Route.TunnelOptions>()
|
||||
val tunnel = uiState.tunnels.find { it.id == args?.id }
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Settings::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ tunnel?.name?.let { Text(it) } },
|
||||
{
|
||||
IconButton(
|
||||
onClick = {
|
||||
tunnel?.id?.let {
|
||||
navController.navigate(Route.Config(id = it))
|
||||
}
|
||||
}
|
||||
) {
|
||||
val icon = Icons.Rounded.Edit
|
||||
Icon(
|
||||
icon,
|
||||
stringResource(R.string.edit_tunnel),
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
topTitle = { Text(stringResource(R.string.settings)) },
|
||||
route = Route.Settings,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Appearance::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.appearance)) },
|
||||
route = Route.Appearance,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Language::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.language)) },
|
||||
route = Route.Language,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Display::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.display_theme)) },
|
||||
route = Route.Display,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.KillSwitch::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.kill_switch)) },
|
||||
route = Route.KillSwitch,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Support::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.support)) },
|
||||
route = Route.Support,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.License::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.licenses)) },
|
||||
route = Route.License,
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.AutoTunnelAdvanced::class) ||
|
||||
backStackEntry.isCurrentRoute(Route.SettingsAdvanced::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.advanced_settings)) },
|
||||
route = Route.AutoTunnelAdvanced,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.TunnelOptions::class) -> {
|
||||
val args = backStackEntry?.toRoute<Route.TunnelOptions>()
|
||||
val tunnel = uiState.tunnels.find { it.id == args?.id }
|
||||
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { tunnel?.name?.let { Text(it) } },
|
||||
topTrailing = {
|
||||
ActionIconButton(Icons.Rounded.Edit, R.string.edit_tunnel) {
|
||||
tunnel?.id?.let { navController.navigate(Route.Config(it)) }
|
||||
}
|
||||
},
|
||||
route = args?.let { Route.TunnelOptions(it.id) },
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.SplitTunnel::class) -> {
|
||||
val args = backStackEntry?.toRoute<Route.SplitTunnel>()
|
||||
val name = uiState.tunnels.find { it.id == args?.id }?.name
|
||||
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ name?.let { Text(it) } },
|
||||
{
|
||||
IconButton(
|
||||
onClick = { viewModel.handleEvent(AppEvent.InvokeScreenAction) }
|
||||
) {
|
||||
val icon = Icons.Rounded.Save
|
||||
Icon(
|
||||
icon,
|
||||
stringResource(R.string.save),
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
topTitle = { name?.let { Text(it) } },
|
||||
topTrailing = {
|
||||
ActionIconButton(Icons.Rounded.Save, R.string.save) {
|
||||
viewModel.handleEvent(AppEvent.InvokeScreenAction)
|
||||
}
|
||||
},
|
||||
route = args?.let { Route.SplitTunnel(it.id) },
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Config::class) -> {
|
||||
val args = backStackEntry?.toRoute<Route.Config>()
|
||||
val name = uiState.tunnels.find { it.id == args?.id }?.name
|
||||
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ name?.let { Text(it) } },
|
||||
{
|
||||
IconButton(
|
||||
onClick = { viewModel.handleEvent(AppEvent.InvokeScreenAction) }
|
||||
) {
|
||||
val icon = Icons.Rounded.Save
|
||||
Icon(
|
||||
icon,
|
||||
stringResource(R.string.save),
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
topTitle = { name?.let { Text(it) } },
|
||||
topTrailing = {
|
||||
ActionIconButton(Icons.Rounded.Save, R.string.save) {
|
||||
viewModel.handleEvent(AppEvent.InvokeScreenAction)
|
||||
}
|
||||
},
|
||||
route = args?.let { Route.Config(it.id) },
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.TunnelAutoTunnel::class) -> {
|
||||
val args = backStackEntry?.toRoute<Route.TunnelAutoTunnel>()
|
||||
val name = uiState.tunnels.find { it.id == args?.id }?.name
|
||||
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ name?.let { Text(it) } },
|
||||
topTitle = { name?.let { Text(it) } },
|
||||
route = args?.let { Route.TunnelAutoTunnel(it.id) },
|
||||
)
|
||||
}
|
||||
backStackEntry.isCurrentRoute(Route.Support::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
{ Text(stringResource(R.string.support)) },
|
||||
route = Route.Support,
|
||||
)
|
||||
}
|
||||
|
||||
else -> NavBarState(showTop = false, showBottom = false)
|
||||
}
|
||||
}
|
||||
+7
-8
@@ -8,8 +8,6 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -24,8 +22,10 @@ import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||
import com.google.accompanist.permissions.isGranted
|
||||
import com.google.accompanist.permissions.rememberPermissionState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.AdvancedSettingsItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.NetworkTunnelingItems
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.WifiTunnelingItems
|
||||
@@ -33,7 +33,6 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.Backgr
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.LocationServicesDialog
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isLocationServicesEnabled
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
|
||||
@OptIn(ExperimentalPermissionsApi::class)
|
||||
@@ -41,6 +40,7 @@ import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
fun AutoTunnelScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||
val context = LocalContext.current
|
||||
val navController = LocalNavController.current
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
val fineLocationState = rememberPermissionState(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
var currentText by remember { mutableStateOf("") }
|
||||
var isBackgroundLocationGranted by remember { mutableStateOf(true) }
|
||||
@@ -67,12 +67,11 @@ fun AutoTunnelScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) checkFineLocationGranted()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
if (context.isRunningOnTv() && Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
|
||||
if (isTv && Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
|
||||
checkFineLocationGranted()
|
||||
} else {
|
||||
val backgroundLocationState =
|
||||
rememberPermissionState(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
||||
isBackgroundLocationGranted = backgroundLocationState.status.isGranted
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,9 +108,9 @@ fun AutoTunnelScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||
{ isWifiNameReadable() },
|
||||
)
|
||||
)
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
||||
SectionDivider()
|
||||
SurfaceSelectionGroupButton(items = NetworkTunnelingItems(uiState, viewModel))
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
||||
SectionDivider()
|
||||
SurfaceSelectionGroupButton(
|
||||
items =
|
||||
listOf(
|
||||
|
||||
+3
-4
@@ -20,7 +20,6 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardCapitalization
|
||||
@@ -28,7 +27,7 @@ import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ClickableIconButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.textbox.CustomTextField
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
@@ -40,7 +39,7 @@ fun TrustedNetworkTextBox(
|
||||
onValueChange: (network: String) -> Unit,
|
||||
supporting: @Composable () -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
FlowRow(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
@@ -49,7 +48,7 @@ fun TrustedNetworkTextBox(
|
||||
trustedNetworks.forEach { ssid ->
|
||||
ClickableIconButton(
|
||||
onClick = {
|
||||
if (context.isRunningOnTv()) {
|
||||
if (isTv) {
|
||||
onDelete(ssid)
|
||||
}
|
||||
},
|
||||
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -11,10 +11,10 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.components.AppSettingsItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.components.LocationDisclosureHeader
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.components.SkipItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components.AppSettingsItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components.LocationDisclosureHeader
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components.SkipItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.goFromRoot
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.components
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.LocationOn
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.components
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.settings.disclosure.components
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components
|
||||
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
+38
-39
@@ -5,11 +5,7 @@ import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -18,7 +14,8 @@ import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileImportLauncherForResult
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ExportTunnelsBottomSheet
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.TunnelImportSheet
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.TunnelList
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.UrlImportDialog
|
||||
@@ -34,7 +31,6 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
||||
val navController = LocalNavController.current
|
||||
val clipboard = LocalClipboardManager.current
|
||||
|
||||
var showDeleteTunnelAlertDialog by remember { mutableStateOf(false) }
|
||||
var showUrlImportDialog by remember { mutableStateOf(false) }
|
||||
|
||||
val tunnelFileImportResultLauncher =
|
||||
@@ -63,13 +59,14 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
||||
navController.navigate(Route.Scanner)
|
||||
}
|
||||
|
||||
if (showDeleteTunnelAlertDialog && appViewState.selectedTunnel != null) {
|
||||
if (appViewState.showModal == AppViewState.ModalType.DELETE) {
|
||||
InfoDialog(
|
||||
onDismiss = { showDeleteTunnelAlertDialog = false },
|
||||
onDismiss = {
|
||||
viewModel.handleEvent(AppEvent.SetShowModal(AppViewState.ModalType.NONE))
|
||||
},
|
||||
onAttest = {
|
||||
appViewState.selectedTunnel.let { viewModel.handleEvent(AppEvent.DeleteTunnel(it)) }
|
||||
showDeleteTunnelAlertDialog = false
|
||||
viewModel.handleEvent(AppEvent.SetSelectedTunnel(null))
|
||||
viewModel.handleEvent(AppEvent.DeleteSelectedTunnels)
|
||||
viewModel.handleEvent(AppEvent.SetShowModal(AppViewState.ModalType.NONE))
|
||||
},
|
||||
title = { Text(text = stringResource(R.string.delete_tunnel)) },
|
||||
body = { Text(text = stringResource(R.string.delete_tunnel_message)) },
|
||||
@@ -77,21 +74,34 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
||||
)
|
||||
}
|
||||
|
||||
TunnelImportSheet(
|
||||
appViewState.showBottomSheet,
|
||||
onDismiss = { viewModel.handleEvent(AppEvent.ToggleBottomSheet) },
|
||||
onFileClick = { tunnelFileImportResultLauncher.launch(Constants.ALLOWED_TV_FILE_TYPES) },
|
||||
onQrClick = { requestPermissionLauncher.launch(android.Manifest.permission.CAMERA) },
|
||||
onClipboardClick = {
|
||||
clipboard.getText()?.text?.let {
|
||||
viewModel.handleEvent(AppEvent.ImportTunnelFromClipboard(it))
|
||||
}
|
||||
},
|
||||
onManualImportClick = {
|
||||
navController.navigate(Route.Config(Constants.MANUAL_TUNNEL_CONFIG_ID))
|
||||
},
|
||||
onUrlClick = { showUrlImportDialog = true },
|
||||
)
|
||||
when (appViewState.bottomSheet) {
|
||||
AppViewState.BottomSheet.EXPORT_TUNNELS -> {
|
||||
ExportTunnelsBottomSheet(viewModel)
|
||||
}
|
||||
AppViewState.BottomSheet.IMPORT_TUNNELS -> {
|
||||
TunnelImportSheet(
|
||||
onDismiss = {
|
||||
viewModel.handleEvent(AppEvent.SetBottomSheet(AppViewState.BottomSheet.NONE))
|
||||
},
|
||||
onFileClick = {
|
||||
tunnelFileImportResultLauncher.launch(Constants.ALLOWED_TV_FILE_TYPES)
|
||||
},
|
||||
onQrClick = {
|
||||
requestPermissionLauncher.launch(android.Manifest.permission.CAMERA)
|
||||
},
|
||||
onClipboardClick = {
|
||||
clipboard.getText()?.text?.let {
|
||||
viewModel.handleEvent(AppEvent.ImportTunnelFromClipboard(it))
|
||||
}
|
||||
},
|
||||
onManualImportClick = {
|
||||
navController.navigate(Route.Config(Constants.MANUAL_TUNNEL_CONFIG_ID))
|
||||
},
|
||||
onUrlClick = { showUrlImportDialog = true },
|
||||
)
|
||||
}
|
||||
else -> Unit
|
||||
}
|
||||
|
||||
if (showUrlImportDialog) {
|
||||
UrlImportDialog(
|
||||
@@ -105,22 +115,11 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
||||
|
||||
TunnelList(
|
||||
appUiState = appUiState,
|
||||
activeTunnels = appUiState.activeTunnels,
|
||||
selectedTunnel = appViewState.selectedTunnel,
|
||||
onSetSelectedTunnel = { viewModel.handleEvent(AppEvent.SetSelectedTunnel(it)) },
|
||||
onDeleteTunnel = {
|
||||
viewModel.handleEvent(AppEvent.SetSelectedTunnel(it))
|
||||
showDeleteTunnelAlertDialog = true
|
||||
},
|
||||
selectedTunnels = appViewState.selectedTunnels,
|
||||
onToggleTunnel = { tunnel, checked ->
|
||||
if (checked) viewModel.handleEvent(AppEvent.StartTunnel(tunnel))
|
||||
else viewModel.handleEvent(AppEvent.StopTunnel(tunnel))
|
||||
},
|
||||
onExpandStats = { viewModel.handleEvent(AppEvent.ToggleTunnelStatsExpanded) },
|
||||
onCopyTunnel = {
|
||||
viewModel.handleEvent(AppEvent.CopyTunnel(it))
|
||||
viewModel.handleEvent(AppEvent.SetSelectedTunnel(null))
|
||||
},
|
||||
modifier = Modifier.fillMaxSize().padding(vertical = 24.dp).padding(horizontal = 12.dp),
|
||||
viewModel = viewModel,
|
||||
)
|
||||
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.FolderZip
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.ModalBottomSheet
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.ConfigType
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileExportLauncherForResult
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.AuthorizationPromptWrapper
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppViewState
|
||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.hasSAFSupport
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ExportTunnelsBottomSheet(viewModel: AppViewModel) {
|
||||
val context = LocalContext.current
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
|
||||
var exportConfigType by remember { mutableStateOf(ConfigType.WG) }
|
||||
var showAuthPrompt by remember { mutableStateOf(false) }
|
||||
var isAuthorized by remember { mutableStateOf(false) }
|
||||
var shouldExport by remember { mutableStateOf(false) }
|
||||
|
||||
val selectedTunnelsExportLauncher =
|
||||
rememberFileExportLauncherForResult(
|
||||
mimeType = Constants.ZIP_FILE_MIME_TYPE,
|
||||
onResult = { file ->
|
||||
if (file != null) {
|
||||
viewModel.handleEvent(AppEvent.ExportSelectedTunnels(exportConfigType, file))
|
||||
} else {
|
||||
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
||||
viewModel.handleEvent(AppEvent.SetBottomSheet(AppViewState.BottomSheet.NONE))
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
fun handleFileExport() {
|
||||
if (context.hasSAFSupport(Constants.ZIP_FILE_MIME_TYPE)) {
|
||||
selectedTunnelsExportLauncher.launch(Constants.DEFAULT_EXPORT_FILE_NAME)
|
||||
} else {
|
||||
viewModel.handleEvent(AppEvent.ExportSelectedTunnels(exportConfigType, null))
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(shouldExport) {
|
||||
if (shouldExport) {
|
||||
handleFileExport()
|
||||
shouldExport = false
|
||||
}
|
||||
}
|
||||
|
||||
if (showAuthPrompt) {
|
||||
AuthorizationPromptWrapper(
|
||||
onDismiss = { showAuthPrompt = false },
|
||||
onSuccess = {
|
||||
showAuthPrompt = false
|
||||
isAuthorized = true
|
||||
shouldExport = true
|
||||
},
|
||||
viewModel = viewModel,
|
||||
)
|
||||
}
|
||||
|
||||
ModalBottomSheet(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
onDismissRequest = {
|
||||
viewModel.handleEvent(AppEvent.SetBottomSheet(AppViewState.BottomSheet.NONE))
|
||||
},
|
||||
) {
|
||||
ExportOptionRow(
|
||||
label = stringResource(R.string.export_tunnels_amnezia),
|
||||
onClick = {
|
||||
exportConfigType = ConfigType.AMNEZIA
|
||||
if (!isAuthorized && !isTv) {
|
||||
showAuthPrompt = true
|
||||
} else {
|
||||
shouldExport = true
|
||||
}
|
||||
},
|
||||
)
|
||||
HorizontalDivider()
|
||||
|
||||
ExportOptionRow(
|
||||
label = stringResource(R.string.export_tunnels_wireguard),
|
||||
onClick = {
|
||||
exportConfigType = ConfigType.WG
|
||||
if (!isAuthorized && !isTv) {
|
||||
showAuthPrompt = true
|
||||
} else {
|
||||
shouldExport = true
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ExportOptionRow(label: String, onClick: () -> Unit) {
|
||||
Row(modifier = Modifier.fillMaxWidth().clickable(onClick = onClick).padding(10.dp)) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.FolderZip,
|
||||
contentDescription = label,
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
Text(text = label, modifier = Modifier.padding(10.dp))
|
||||
}
|
||||
}
|
||||
+67
-77
@@ -23,13 +23,12 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
|
||||
// TODO refactor this component
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun TunnelImportSheet(
|
||||
show: Boolean,
|
||||
onDismiss: () -> Unit,
|
||||
onFileClick: () -> Unit,
|
||||
onQrClick: () -> Unit,
|
||||
@@ -37,72 +36,49 @@ fun TunnelImportSheet(
|
||||
onClipboardClick: () -> Unit,
|
||||
onUrlClick: () -> Unit,
|
||||
) {
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
|
||||
val sheetState = rememberModalBottomSheetState()
|
||||
|
||||
val context = LocalContext.current
|
||||
if (show) {
|
||||
ModalBottomSheet(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
onDismissRequest = { onDismiss() },
|
||||
sheetState = sheetState,
|
||||
ModalBottomSheet(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
onDismissRequest = { onDismiss() },
|
||||
sheetState = sheetState,
|
||||
) {
|
||||
Row(
|
||||
modifier =
|
||||
Modifier.fillMaxWidth()
|
||||
.clickable {
|
||||
onDismiss()
|
||||
onFileClick()
|
||||
}
|
||||
.padding(10.dp)
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.FileOpen,
|
||||
contentDescription = stringResource(id = R.string.open_file),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
Text(stringResource(id = R.string.add_tunnels_text), modifier = Modifier.padding(10.dp))
|
||||
}
|
||||
if (!isTv) {
|
||||
HorizontalDivider()
|
||||
Row(
|
||||
modifier =
|
||||
Modifier.fillMaxWidth()
|
||||
.clickable {
|
||||
onDismiss()
|
||||
onFileClick()
|
||||
onQrClick()
|
||||
}
|
||||
.padding(10.dp)
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.FileOpen,
|
||||
contentDescription = stringResource(id = R.string.open_file),
|
||||
Icons.Filled.QrCode,
|
||||
contentDescription = stringResource(id = R.string.qr_scan),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
Text(
|
||||
stringResource(id = R.string.add_tunnels_text),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
}
|
||||
if (!context.isRunningOnTv()) {
|
||||
HorizontalDivider()
|
||||
Row(
|
||||
modifier =
|
||||
Modifier.fillMaxWidth()
|
||||
.clickable {
|
||||
onDismiss()
|
||||
onQrClick()
|
||||
}
|
||||
.padding(10.dp)
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.QrCode,
|
||||
contentDescription = stringResource(id = R.string.qr_scan),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
Text(
|
||||
stringResource(id = R.string.add_from_qr),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
}
|
||||
HorizontalDivider()
|
||||
Row(
|
||||
modifier =
|
||||
Modifier.fillMaxWidth()
|
||||
.clickable {
|
||||
onDismiss()
|
||||
onClipboardClick()
|
||||
}
|
||||
.padding(10.dp)
|
||||
) {
|
||||
val icon = Icons.Filled.ContentPasteGo
|
||||
Icon(icon, contentDescription = icon.name, modifier = Modifier.padding(10.dp))
|
||||
Text(
|
||||
stringResource(id = R.string.add_from_clipboard),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
}
|
||||
Text(stringResource(id = R.string.add_from_qr), modifier = Modifier.padding(10.dp))
|
||||
}
|
||||
HorizontalDivider()
|
||||
Row(
|
||||
@@ -110,37 +86,51 @@ fun TunnelImportSheet(
|
||||
Modifier.fillMaxWidth()
|
||||
.clickable {
|
||||
onDismiss()
|
||||
onUrlClick()
|
||||
onClipboardClick()
|
||||
}
|
||||
.padding(10.dp)
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.Link,
|
||||
contentDescription = stringResource(id = R.string.add_from_url),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
Text(stringResource(id = R.string.add_from_url), modifier = Modifier.padding(10.dp))
|
||||
}
|
||||
HorizontalDivider()
|
||||
Row(
|
||||
modifier =
|
||||
Modifier.fillMaxWidth()
|
||||
.clickable {
|
||||
onDismiss()
|
||||
onManualImportClick()
|
||||
}
|
||||
.padding(10.dp)
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.Create,
|
||||
contentDescription = stringResource(id = R.string.create_import),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
val icon = Icons.Filled.ContentPasteGo
|
||||
Icon(icon, contentDescription = icon.name, modifier = Modifier.padding(10.dp))
|
||||
Text(
|
||||
stringResource(id = R.string.create_import),
|
||||
stringResource(id = R.string.add_from_clipboard),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
HorizontalDivider()
|
||||
Row(
|
||||
modifier =
|
||||
Modifier.fillMaxWidth()
|
||||
.clickable {
|
||||
onDismiss()
|
||||
onUrlClick()
|
||||
}
|
||||
.padding(10.dp)
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.Link,
|
||||
contentDescription = stringResource(id = R.string.add_from_url),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
Text(stringResource(id = R.string.add_from_url), modifier = Modifier.padding(10.dp))
|
||||
}
|
||||
HorizontalDivider()
|
||||
Row(
|
||||
modifier =
|
||||
Modifier.fillMaxWidth()
|
||||
.clickable {
|
||||
onDismiss()
|
||||
onManualImportClick()
|
||||
}
|
||||
.padding(10.dp)
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.Create,
|
||||
contentDescription = stringResource(id = R.string.create_import),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
Text(stringResource(id = R.string.create_import), modifier = Modifier.padding(10.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+24
-16
@@ -17,9 +17,12 @@ import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.getValueById
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
import java.text.Collator
|
||||
import java.util.*
|
||||
|
||||
@@ -27,17 +30,13 @@ import java.util.*
|
||||
@Composable
|
||||
fun TunnelList(
|
||||
appUiState: AppUiState,
|
||||
activeTunnels: Map<TunnelConf, TunnelState>,
|
||||
selectedTunnel: TunnelConf?,
|
||||
onSetSelectedTunnel: (TunnelConf?) -> Unit,
|
||||
onDeleteTunnel: (TunnelConf) -> Unit,
|
||||
onToggleTunnel: (TunnelConf, Boolean) -> Unit,
|
||||
onExpandStats: () -> Unit,
|
||||
onCopyTunnel: (TunnelConf) -> Unit,
|
||||
selectedTunnels: List<TunnelConf>,
|
||||
modifier: Modifier = Modifier,
|
||||
onToggleTunnel: (TunnelConf, Boolean) -> Unit,
|
||||
viewModel: AppViewModel,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val navController = LocalNavController.current
|
||||
val collator = Collator.getInstance(Locale.getDefault())
|
||||
val sortedTunnels =
|
||||
remember(appUiState.tunnels) {
|
||||
@@ -60,19 +59,28 @@ fun TunnelList(
|
||||
item { GettingStartedLabel(onClick = { context.openWebUrl(it) }) }
|
||||
}
|
||||
items(sortedTunnels, key = { it.id }) { tunnel ->
|
||||
val tunnelState = activeTunnels.getValueById(tunnel.id) ?: TunnelState()
|
||||
val tunnelState =
|
||||
remember(appUiState.activeTunnels) {
|
||||
appUiState.activeTunnels.getValueById(tunnel.id) ?: TunnelState()
|
||||
}
|
||||
val selected = remember(selectedTunnels) { selectedTunnels.any { it.id == tunnel.id } }
|
||||
TunnelRowItem(
|
||||
isActive = tunnelState.status.isUpOrStarting(),
|
||||
expanded = appUiState.appState.isTunnelStatsExpanded,
|
||||
isSelected = selectedTunnel?.id == tunnel.id,
|
||||
state = tunnelState,
|
||||
expanded = appUiState.appState.expandedTunnelIds.contains(tunnel.id),
|
||||
isSelected = selected,
|
||||
tunnel = tunnel,
|
||||
tunnelState = tunnelState,
|
||||
onSetSelectedTunnel = { onSetSelectedTunnel(it) },
|
||||
onClick = onExpandStats,
|
||||
onCopy = { onCopyTunnel(tunnel) },
|
||||
onDelete = { onDeleteTunnel(tunnel) },
|
||||
onClick = {
|
||||
navController.navigate(Route.TunnelOptions(tunnel.id))
|
||||
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
||||
},
|
||||
onDoubleClick = {
|
||||
viewModel.handleEvent(AppEvent.ToggleTunnelStatsExpanded(tunnel.id))
|
||||
},
|
||||
onToggleSelectedTunnel = {
|
||||
viewModel.handleEvent(AppEvent.ToggleSelectedTunnel(it))
|
||||
},
|
||||
onSwitchClick = { checked -> onToggleTunnel(tunnel, checked) },
|
||||
viewModel = viewModel,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+67
-174
@@ -2,221 +2,114 @@ package com.zaneschepke.wireguardautotunnel.ui.screens.main.components
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Circle
|
||||
import androidx.compose.material.icons.rounded.CopyAll
|
||||
import androidx.compose.material.icons.rounded.Delete
|
||||
import androidx.compose.material.icons.rounded.Info
|
||||
import androidx.compose.material.icons.rounded.KeyboardArrowDown
|
||||
import androidx.compose.material.icons.rounded.Settings
|
||||
import androidx.compose.material.icons.rounded.SettingsEthernet
|
||||
import androidx.compose.material.icons.rounded.Smartphone
|
||||
import androidx.compose.material.icons.rounded.Star
|
||||
import androidx.compose.material3.Checkbox
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.minimumInteractiveComponentSize
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.ExpandingRowListItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asColor
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
|
||||
@Composable
|
||||
fun TunnelRowItem(
|
||||
isActive: Boolean,
|
||||
expanded: Boolean,
|
||||
state: TunnelState,
|
||||
isSelected: Boolean,
|
||||
expanded: Boolean,
|
||||
tunnel: TunnelConf,
|
||||
tunnelState: TunnelState,
|
||||
onSetSelectedTunnel: (TunnelConf?) -> Unit,
|
||||
onClick: () -> Unit,
|
||||
onCopy: () -> Unit,
|
||||
onDelete: () -> Unit,
|
||||
onDoubleClick: () -> Unit,
|
||||
onToggleSelectedTunnel: (TunnelConf) -> Unit,
|
||||
onSwitchClick: (Boolean) -> Unit,
|
||||
viewModel: AppViewModel,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val navController = LocalNavController.current
|
||||
val haptic = LocalHapticFeedback.current
|
||||
val itemFocusRequester = remember { FocusRequester() }
|
||||
val isTv = context.isRunningOnTv()
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
|
||||
val leadingIconColor = if (!isActive) Color.Gray else tunnelState.statistics.asColor()
|
||||
val leadingIconColor =
|
||||
remember(state) {
|
||||
if (state.status.isUp()) tunnelState.statistics.asColor() else Color.Gray
|
||||
}
|
||||
|
||||
val (leadingIcon, size) =
|
||||
when {
|
||||
tunnel.isPrimaryTunnel -> Pair(Icons.Rounded.Star, 16.dp)
|
||||
tunnel.isMobileDataTunnel -> Pair(Icons.Rounded.Smartphone, 16.dp)
|
||||
tunnel.isEthernetTunnel -> Pair(Icons.Rounded.SettingsEthernet, 16.dp)
|
||||
else -> Pair(Icons.Rounded.Circle, 14.dp)
|
||||
remember(tunnel) {
|
||||
when {
|
||||
tunnel.isPrimaryTunnel -> Pair(Icons.Rounded.Star, 16.dp)
|
||||
tunnel.isMobileDataTunnel -> Pair(Icons.Rounded.Smartphone, 16.dp)
|
||||
tunnel.isEthernetTunnel -> Pair(Icons.Rounded.SettingsEthernet, 16.dp)
|
||||
else -> Pair(Icons.Rounded.Circle, 14.dp)
|
||||
}
|
||||
}
|
||||
|
||||
ExpandingRowListItem(
|
||||
leading = {
|
||||
Icon(
|
||||
leadingIcon,
|
||||
stringResource(R.string.status),
|
||||
tint = leadingIconColor,
|
||||
modifier = Modifier.size(size),
|
||||
)
|
||||
},
|
||||
text = tunnel.tunName,
|
||||
onHold = {
|
||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onSetSelectedTunnel(tunnel)
|
||||
},
|
||||
onClick = {
|
||||
if (!isTv) {
|
||||
if (isActive) onClick()
|
||||
} else {
|
||||
onSetSelectedTunnel(tunnel)
|
||||
itemFocusRequester.requestFocus()
|
||||
}
|
||||
},
|
||||
isExpanded = expanded && isActive,
|
||||
expanded = {
|
||||
if (isActive && expanded) TunnelStatisticsRow(tunnelState.statistics, tunnel)
|
||||
},
|
||||
trailing = {
|
||||
if (isSelected && !isTv) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly,
|
||||
) {
|
||||
IconButton(
|
||||
modifier = Modifier.weight(1f),
|
||||
onClick = {
|
||||
onSetSelectedTunnel(null)
|
||||
navController.navigate(Route.TunnelOptions(tunnel.id))
|
||||
},
|
||||
) {
|
||||
Icon(
|
||||
Icons.Rounded.Settings,
|
||||
stringResource(id = R.string.settings),
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
}
|
||||
IconButton(
|
||||
modifier = Modifier.weight(1f),
|
||||
onClick = {
|
||||
onCopy()
|
||||
onSetSelectedTunnel(null)
|
||||
},
|
||||
) {
|
||||
Icon(
|
||||
Icons.Rounded.CopyAll,
|
||||
stringResource(R.string.copy),
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
}
|
||||
IconButton(
|
||||
modifier = Modifier.weight(1f),
|
||||
enabled = !isActive,
|
||||
onClick = { onDelete() },
|
||||
) {
|
||||
Icon(
|
||||
Icons.Rounded.Delete,
|
||||
stringResource(R.string.delete_tunnel),
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
} else if (isTv) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly,
|
||||
) {
|
||||
IconButton(
|
||||
modifier = Modifier.weight(1f),
|
||||
onClick = {
|
||||
navController.navigate(Route.TunnelOptions(tunnel.id))
|
||||
onSetSelectedTunnel(null)
|
||||
},
|
||||
) {
|
||||
Icon(
|
||||
Icons.Rounded.Settings,
|
||||
stringResource(id = R.string.settings),
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
}
|
||||
IconButton(
|
||||
modifier = Modifier.weight(1f),
|
||||
onClick = {
|
||||
if (isActive) {
|
||||
onClick()
|
||||
} else {
|
||||
viewModel.handleEvent(
|
||||
AppEvent.ShowMessage(
|
||||
StringValue.StringResource(R.string.turn_on_tunnel)
|
||||
)
|
||||
)
|
||||
}
|
||||
},
|
||||
) {
|
||||
Icon(
|
||||
Icons.Rounded.Info,
|
||||
stringResource(R.string.info),
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
}
|
||||
IconButton(modifier = Modifier.weight(1f), onClick = onCopy) {
|
||||
Icon(
|
||||
Icons.Rounded.CopyAll,
|
||||
stringResource(R.string.copy),
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
}
|
||||
IconButton(
|
||||
modifier = Modifier.weight(1f),
|
||||
onClick = {
|
||||
if (isActive) {
|
||||
viewModel.handleEvent(
|
||||
AppEvent.ShowMessage(
|
||||
StringValue.StringResource(R.string.turn_off_tunnel)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
onDelete()
|
||||
}
|
||||
},
|
||||
) {
|
||||
Icon(
|
||||
Icons.Rounded.Delete,
|
||||
stringResource(R.string.delete_tunnel),
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
}
|
||||
ScaledSwitch(
|
||||
modifier = Modifier.focusRequester(itemFocusRequester).weight(1f),
|
||||
checked = isActive,
|
||||
onClick = onSwitchClick,
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp, Alignment.Start),
|
||||
) {
|
||||
if (isTv) {
|
||||
Checkbox(
|
||||
isSelected,
|
||||
onCheckedChange = { onToggleSelectedTunnel(tunnel) },
|
||||
modifier = Modifier.minimumInteractiveComponentSize().size(12.dp),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
ScaledSwitch(
|
||||
modifier = Modifier.focusRequester(itemFocusRequester),
|
||||
checked = isActive,
|
||||
onClick = onSwitchClick,
|
||||
Icon(
|
||||
leadingIcon,
|
||||
stringResource(R.string.status),
|
||||
tint = leadingIconColor,
|
||||
modifier = Modifier.size(size),
|
||||
)
|
||||
}
|
||||
},
|
||||
text = tunnel.tunName,
|
||||
onHold = { if (!isTv) onToggleSelectedTunnel(tunnel) },
|
||||
onClick = { if (!isTv) onClick() },
|
||||
onDoubleClick = { if (!isTv) onDoubleClick() },
|
||||
expanded = {
|
||||
if (expanded) {
|
||||
TunnelStatisticsRow(tunnelState.statistics, tunnel)
|
||||
} else null
|
||||
},
|
||||
trailing = {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End),
|
||||
) {
|
||||
if (isTv) {
|
||||
IconButton(onClick = onDoubleClick) {
|
||||
Icon(
|
||||
Icons.Rounded.KeyboardArrowDown,
|
||||
contentDescription = stringResource(R.string.info),
|
||||
)
|
||||
}
|
||||
IconButton(onClick = onClick) {
|
||||
Icon(
|
||||
Icons.Rounded.Settings,
|
||||
contentDescription = stringResource(R.string.settings),
|
||||
)
|
||||
}
|
||||
}
|
||||
ScaledSwitch(checked = state.status.isUpOrStarting(), onClick = onSwitchClick)
|
||||
}
|
||||
},
|
||||
isSelected = isSelected,
|
||||
)
|
||||
}
|
||||
|
||||
+5
-2
@@ -27,6 +27,10 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.state.ConfigUi
|
||||
@Composable
|
||||
fun InterfaceSection(uiState: ConfigUiState, viewModel: ConfigViewModel) {
|
||||
var isDropDownExpanded by remember { mutableStateOf(false) }
|
||||
val isAmneziaCompatibilitySet =
|
||||
remember(uiState.configProxy.`interface`) {
|
||||
uiState.configProxy.`interface`.isAmneziaCompatibilityModeSet()
|
||||
}
|
||||
|
||||
Surface(shape = RoundedCornerShape(12.dp), color = MaterialTheme.colorScheme.surface) {
|
||||
Column(
|
||||
@@ -44,8 +48,7 @@ fun InterfaceSection(uiState: ConfigUiState, viewModel: ConfigViewModel) {
|
||||
onExpandedChange = { isDropDownExpanded = it },
|
||||
showScripts = uiState.showScripts,
|
||||
showAmneziaValues = uiState.showAmneziaValues,
|
||||
isAmneziaCompatibilitySet =
|
||||
uiState.configProxy.`interface`.isAmneziaCompatibilityModeSet(),
|
||||
isAmneziaCompatibilitySet = isAmneziaCompatibilitySet,
|
||||
onToggleScripts = viewModel::toggleScripts,
|
||||
onToggleAmneziaValues = viewModel::toggleAmneziaValues,
|
||||
onToggleAmneziaCompatibility = viewModel::toggleAmneziaCompatibility,
|
||||
|
||||
+11
-4
@@ -50,6 +50,7 @@ constructor(
|
||||
tunnelId?.let { loadInitialState(it) }
|
||||
}
|
||||
|
||||
// TODO improve this loading experience
|
||||
private fun loadInitialState(tunnelId: Int) =
|
||||
viewModelScope.launch {
|
||||
val tunnel = tunnelRepository.getById(tunnelId) ?: return@launch
|
||||
@@ -108,6 +109,7 @@ constructor(
|
||||
loading = false,
|
||||
tunnelConf = tunnel,
|
||||
tunneledApps = tunneledApps,
|
||||
queriedApps = tunneledApps,
|
||||
splitOption = splitOption,
|
||||
)
|
||||
}
|
||||
@@ -116,14 +118,14 @@ constructor(
|
||||
fun onSearchQuery(query: String) {
|
||||
val filteredApps =
|
||||
if (query.isBlank()) {
|
||||
allTunneledApps
|
||||
_uiState.value.tunneledApps
|
||||
} else {
|
||||
allTunneledApps.filter {
|
||||
_uiState.value.tunneledApps.filter {
|
||||
it.first.name.contains(query, ignoreCase = true) ||
|
||||
it.first.`package`.contains(query, ignoreCase = true)
|
||||
}
|
||||
}
|
||||
_uiState.update { it.copy(searchQuery = query, tunneledApps = filteredApps) }
|
||||
_uiState.update { it.copy(searchQuery = query, queriedApps = filteredApps) }
|
||||
}
|
||||
|
||||
fun updateSplitOption(newOption: SplitOption) {
|
||||
@@ -136,7 +138,12 @@ constructor(
|
||||
currentState.tunneledApps.map { (app, selected) ->
|
||||
if (app.`package` == packageName) Pair(app, !selected) else Pair(app, selected)
|
||||
}
|
||||
_uiState.value = currentState.copy(tunneledApps = updatedApps)
|
||||
val updatedQueryApps =
|
||||
currentState.queriedApps.map { (app, selected) ->
|
||||
if (app.`package` == packageName) Pair(app, !selected) else Pair(app, selected)
|
||||
}
|
||||
_uiState.value =
|
||||
currentState.copy(tunneledApps = updatedApps, queriedApps = updatedQueryApps)
|
||||
}
|
||||
|
||||
fun saveChanges() =
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ fun SplitTunnelContent(
|
||||
)
|
||||
if (uiState.splitOption != SplitOption.ALL) {
|
||||
AppListSection(
|
||||
apps = uiState.tunneledApps,
|
||||
apps = uiState.queriedApps,
|
||||
onAppSelectionToggle = onAppSelectionToggle,
|
||||
onQueryChange = onQueryChange,
|
||||
uiState.searchQuery,
|
||||
|
||||
+1
@@ -6,6 +6,7 @@ data class SplitTunnelUiState(
|
||||
val loading: Boolean = true,
|
||||
val tunnelConf: TunnelConf? = null,
|
||||
val tunneledApps: SplitTunnelApps = emptyList(),
|
||||
val queriedApps: SplitTunnelApps = emptyList(),
|
||||
val splitOption: SplitOption = SplitOption.ALL,
|
||||
val searchQuery: String = "",
|
||||
val success: Boolean? = null,
|
||||
|
||||
+4
-19
@@ -6,33 +6,18 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.AutoTunnelingItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.PingConfigItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.PingRestartItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.PrimaryTunnelItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.ServerIpv4Item
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.SplitTunnelingItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.components.*
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
|
||||
@Composable
|
||||
fun TunnelOptionsScreen(tunnelConf: TunnelConf, appUiState: AppUiState, viewModel: AppViewModel) {
|
||||
var currentText by remember { mutableStateOf("") }
|
||||
|
||||
LaunchedEffect(tunnelConf.tunnelNetworks) { currentText = "" }
|
||||
fun TunnelOptionsScreen(tunnelConf: TunnelConf, viewModel: AppViewModel) {
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
@@ -52,7 +37,7 @@ fun TunnelOptionsScreen(tunnelConf: TunnelConf, appUiState: AppUiState, viewMode
|
||||
SplitTunnelingItem(tunnelConf),
|
||||
)
|
||||
)
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
||||
SectionDivider()
|
||||
SurfaceSelectionGroupButton(
|
||||
items =
|
||||
buildList {
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
|
||||
@Composable
|
||||
fun AutoTunnelingItem(tunnelConf: TunnelConf): SelectionItem {
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
|
||||
@Composable
|
||||
fun SplitTunnelingItem(tunnelConf: TunnelConf): SelectionItem {
|
||||
|
||||
+4
-5
@@ -3,21 +3,20 @@ package com.zaneschepke.wireguardautotunnel.ui.screens.pin
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
import xyz.teamgravity.pin_lock_compose.PinLock
|
||||
|
||||
@Composable
|
||||
fun PinLockScreen(viewModel: AppViewModel) {
|
||||
val context = LocalContext.current
|
||||
val navController = LocalNavController.current
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
PinLock(
|
||||
title = { pinExists ->
|
||||
Text(
|
||||
@@ -34,7 +33,7 @@ fun PinLockScreen(viewModel: AppViewModel) {
|
||||
textColor = MaterialTheme.colorScheme.onSurface,
|
||||
onPinCorrect = {
|
||||
// pin is correct, navigate or hide pin lock
|
||||
if (context.isRunningOnTv()) {
|
||||
if (isTv) {
|
||||
navController.navigate(Route.Main)
|
||||
} else {
|
||||
val isPopped = navController.popBackStack()
|
||||
|
||||
+12
-20
@@ -8,23 +8,21 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.AdvancedSettingsItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.AlwaysOnVpnItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.AppShortcutsItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.AppearanceItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.ExportTunnelsBottomSheet
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.KernelModeItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.KillSwitchItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.LocalLoggingItem
|
||||
@@ -32,21 +30,15 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.PinLoc
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.ReadLogsItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.RestartAtBootItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppViewState
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
|
||||
@Composable
|
||||
fun SettingsScreen(uiState: AppUiState, appViewState: AppViewState, viewModel: AppViewModel) {
|
||||
val context = LocalContext.current
|
||||
fun SettingsScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
val focusManager = LocalFocusManager.current
|
||||
val navController = LocalNavController.current
|
||||
val isRunningOnTv = remember { context.isRunningOnTv() }
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
|
||||
if (appViewState.showBottomSheet) {
|
||||
ExportTunnelsBottomSheet(viewModel, isRunningOnTv)
|
||||
}
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
@@ -57,7 +49,7 @@ fun SettingsScreen(uiState: AppUiState, appViewState: AppViewState, viewModel: A
|
||||
.padding(vertical = 24.dp)
|
||||
.padding(horizontal = 12.dp)
|
||||
.then(
|
||||
if (!isRunningOnTv) {
|
||||
if (!isTv) {
|
||||
Modifier.clickable(
|
||||
indication = null,
|
||||
interactionSource = interactionSource,
|
||||
@@ -72,12 +64,12 @@ fun SettingsScreen(uiState: AppUiState, appViewState: AppViewState, viewModel: A
|
||||
items =
|
||||
buildList {
|
||||
add(AppShortcutsItem(uiState, viewModel))
|
||||
if (!isRunningOnTv) add(AlwaysOnVpnItem(uiState, viewModel))
|
||||
if (!isTv) add(AlwaysOnVpnItem(uiState, viewModel))
|
||||
add(KillSwitchItem())
|
||||
add(RestartAtBootItem(uiState, viewModel))
|
||||
}
|
||||
)
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
||||
SectionDivider()
|
||||
SurfaceSelectionGroupButton(
|
||||
items =
|
||||
buildList {
|
||||
@@ -87,10 +79,10 @@ fun SettingsScreen(uiState: AppUiState, appViewState: AppViewState, viewModel: A
|
||||
add(PinLockItem(uiState, viewModel))
|
||||
}
|
||||
)
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
||||
if (!isRunningOnTv) {
|
||||
SectionDivider()
|
||||
if (!isTv) {
|
||||
SurfaceSelectionGroupButton(items = listOf(KernelModeItem(uiState, viewModel)))
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
||||
SectionDivider()
|
||||
}
|
||||
SurfaceSelectionGroupButton(
|
||||
items =
|
||||
|
||||
+3
-4
@@ -4,12 +4,11 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.components.DisplayThemeItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.components.LanguageItem
|
||||
@@ -23,9 +22,9 @@ fun AppearanceScreen() {
|
||||
modifier = Modifier.fillMaxSize().padding(vertical = 24.dp).padding(horizontal = 12.dp),
|
||||
) {
|
||||
SurfaceSelectionGroupButton(items = listOf(LanguageItem()))
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
||||
SectionDivider()
|
||||
SurfaceSelectionGroupButton(items = listOf(NotificationsItem()))
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
||||
SectionDivider()
|
||||
SurfaceSelectionGroupButton(items = listOf(DisplayThemeItem()))
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
|
||||
@Composable
|
||||
fun DisplayThemeItem(): SelectionItem {
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
|
||||
@Composable
|
||||
fun LanguageItem(): SelectionItem {
|
||||
|
||||
+4
-7
@@ -8,13 +8,12 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.language.components.AutomaticLanguageItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.language.components.LanguageItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.util.LocaleUtil
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import java.text.Collator
|
||||
import java.util.*
|
||||
@@ -22,9 +21,7 @@ import java.util.*
|
||||
@Composable
|
||||
fun LanguageScreen(appUiState: AppUiState, viewModel: AppViewModel) {
|
||||
val collator = Collator.getInstance(Locale.getDefault())
|
||||
|
||||
val context = LocalContext.current
|
||||
val isAndroidTv = remember { context.isRunningOnTv() }
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
|
||||
val locales =
|
||||
LocaleUtil.supportedLocales.map {
|
||||
@@ -42,9 +39,9 @@ fun LanguageScreen(appUiState: AppUiState, viewModel: AppViewModel) {
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier.padding(horizontal = 12.dp),
|
||||
) {
|
||||
item { AutomaticLanguageItem(appUiState, viewModel, isAndroidTv) }
|
||||
item { AutomaticLanguageItem(appUiState, viewModel, isTv) }
|
||||
items(sortedLocales, key = { it }) { locale ->
|
||||
LanguageItem(locale, appUiState, viewModel, isAndroidTv)
|
||||
LanguageItem(locale, appUiState, viewModel, isTv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
|
||||
@Composable
|
||||
fun AppearanceItem(): SelectionItem {
|
||||
|
||||
-104
@@ -1,104 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.settings.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.FolderZip
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.ModalBottomSheet
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.ConfigType
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ExportTunnelsBottomSheet(viewModel: AppViewModel, isRunningOnTv: Boolean) {
|
||||
var showAuthPrompt by remember { mutableStateOf(false) }
|
||||
var isAuthorized by remember { mutableStateOf(false) }
|
||||
var exportType by remember { mutableStateOf(ConfigType.WG) }
|
||||
|
||||
fun handleExport() {
|
||||
viewModel.handleEvent(AppEvent.ToggleBottomSheet)
|
||||
viewModel.handleEvent(AppEvent.ExportTunnels(exportType))
|
||||
}
|
||||
|
||||
if (showAuthPrompt) {
|
||||
AuthorizationPromptWrapper(
|
||||
onDismiss = { showAuthPrompt = false },
|
||||
onSuccess = {
|
||||
showAuthPrompt = false
|
||||
isAuthorized = true
|
||||
handleExport()
|
||||
},
|
||||
viewModel = viewModel,
|
||||
)
|
||||
}
|
||||
|
||||
ModalBottomSheet(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
onDismissRequest = { viewModel.handleEvent(AppEvent.ToggleBottomSheet) },
|
||||
) {
|
||||
Row(
|
||||
modifier =
|
||||
Modifier.fillMaxWidth()
|
||||
.clickable {
|
||||
exportType = ConfigType.AMNEZIA
|
||||
if (!isAuthorized && !isRunningOnTv) {
|
||||
showAuthPrompt = true
|
||||
return@clickable
|
||||
}
|
||||
handleExport()
|
||||
}
|
||||
.padding(10.dp)
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.FolderZip,
|
||||
contentDescription = stringResource(R.string.export_tunnels_amnezia),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
Text(
|
||||
stringResource(R.string.export_tunnels_amnezia),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
}
|
||||
HorizontalDivider()
|
||||
Row(
|
||||
modifier =
|
||||
Modifier.fillMaxWidth()
|
||||
.clickable {
|
||||
exportType = ConfigType.WG
|
||||
if (!isAuthorized && !isRunningOnTv) {
|
||||
showAuthPrompt = true
|
||||
return@clickable
|
||||
}
|
||||
handleExport()
|
||||
}
|
||||
.padding(10.dp)
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.FolderZip,
|
||||
contentDescription = stringResource(R.string.export_tunnels_wireguard),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
Text(
|
||||
stringResource(R.string.export_tunnels_wireguard),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -10,7 +10,7 @@ import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
|
||||
@Composable
|
||||
fun KillSwitchItem(): SelectionItem {
|
||||
|
||||
+11
-2
@@ -3,10 +3,12 @@ package com.zaneschepke.wireguardautotunnel.ui.screens.settings.components
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.ViewHeadline
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
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.SelectionItemLabel
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionLabelType
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
@@ -15,8 +17,15 @@ import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
fun LocalLoggingItem(uiState: AppUiState, viewModel: AppViewModel): SelectionItem {
|
||||
return SelectionItem(
|
||||
leadingIcon = Icons.Outlined.ViewHeadline,
|
||||
title = { SelectionItemLabel(R.string.local_logging) },
|
||||
description = { SelectionItemLabel(R.string.enable_local_logging, isDescription = true) },
|
||||
title = {
|
||||
SelectionItemLabel(stringResource(R.string.local_logging), SelectionLabelType.TITLE)
|
||||
},
|
||||
description = {
|
||||
SelectionItemLabel(
|
||||
stringResource(R.string.enable_local_logging),
|
||||
SelectionLabelType.DESCRIPTION,
|
||||
)
|
||||
},
|
||||
trailing = {
|
||||
ScaledSwitch(
|
||||
checked = uiState.appState.isLocalLogsEnabled,
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
|
||||
+6
-2
@@ -3,19 +3,23 @@ package com.zaneschepke.wireguardautotunnel.ui.screens.settings.components
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ViewTimeline
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItemLabel
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionLabelType
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
|
||||
@Composable
|
||||
fun ReadLogsItem(): SelectionItem {
|
||||
val navController = LocalNavController.current
|
||||
return SelectionItem(
|
||||
leadingIcon = Icons.Filled.ViewTimeline,
|
||||
title = { SelectionItemLabel(R.string.read_logs) },
|
||||
title = {
|
||||
SelectionItemLabel(stringResource(R.string.read_logs), SelectionLabelType.TITLE)
|
||||
},
|
||||
trailing = { ForwardButton { navController.navigate(Route.Logs) } },
|
||||
onClick = { navController.navigate(Route.Logs) },
|
||||
)
|
||||
|
||||
+5
-7
@@ -4,32 +4,30 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.killswitch.components.VpnKillSwitchItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
|
||||
@Composable
|
||||
fun KillSwitchScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||
val context = LocalContext.current
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp, Alignment.Top),
|
||||
modifier = Modifier.fillMaxSize().padding(vertical = 24.dp).padding(horizontal = 12.dp),
|
||||
) {
|
||||
if (!context.isRunningOnTv()) {
|
||||
if (!isTv) {
|
||||
SurfaceSelectionGroupButton(items = listOf(NativeKillSwitchItem()))
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
||||
SectionDivider()
|
||||
}
|
||||
SurfaceSelectionGroupButton(
|
||||
items =
|
||||
|
||||
+5
-2
@@ -65,8 +65,11 @@ fun LogsScreen(appViewState: AppViewState, viewModel: AppViewModel) {
|
||||
}
|
||||
}
|
||||
|
||||
if (appViewState.showBottomSheet) {
|
||||
LogsBottomSheet(viewModel)
|
||||
when (appViewState.bottomSheet) {
|
||||
AppViewState.BottomSheet.LOGS -> {
|
||||
LogsBottomSheet(viewModel)
|
||||
}
|
||||
else -> Unit
|
||||
}
|
||||
|
||||
if (logs.isEmpty()) {
|
||||
|
||||
+10
-3
@@ -18,6 +18,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppViewState
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
|
||||
@@ -26,13 +27,17 @@ import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
fun LogsBottomSheet(viewModel: AppViewModel) {
|
||||
ModalBottomSheet(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
onDismissRequest = { viewModel.handleEvent(AppEvent.ToggleBottomSheet) },
|
||||
onDismissRequest = {
|
||||
viewModel.handleEvent(AppEvent.SetBottomSheet(AppViewState.BottomSheet.NONE))
|
||||
},
|
||||
) {
|
||||
Row(
|
||||
modifier =
|
||||
Modifier.fillMaxWidth()
|
||||
.clickable {
|
||||
viewModel.handleEvent(AppEvent.ToggleBottomSheet)
|
||||
viewModel.handleEvent(
|
||||
AppEvent.SetBottomSheet(AppViewState.BottomSheet.NONE)
|
||||
)
|
||||
viewModel.handleEvent(AppEvent.ExportLogs)
|
||||
}
|
||||
.padding(10.dp)
|
||||
@@ -49,7 +54,9 @@ fun LogsBottomSheet(viewModel: AppViewModel) {
|
||||
modifier =
|
||||
Modifier.fillMaxWidth()
|
||||
.clickable {
|
||||
viewModel.handleEvent(AppEvent.ToggleBottomSheet)
|
||||
viewModel.handleEvent(
|
||||
AppEvent.SetBottomSheet(AppViewState.BottomSheet.NONE)
|
||||
)
|
||||
viewModel.handleEvent(AppEvent.DeleteLogs)
|
||||
}
|
||||
.padding(10.dp)
|
||||
|
||||
+101
-11
@@ -1,29 +1,111 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.support
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.StrokeCap
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
||||
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.GeneralSupportOptions
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.VersionLabel
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.UpdateSection
|
||||
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.showToast
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
|
||||
@Composable
|
||||
fun SupportScreen() {
|
||||
fun SupportScreen(viewModel: SupportViewModel = hiltViewModel(), appViewModel: AppViewModel) {
|
||||
val context = LocalContext.current
|
||||
|
||||
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||
var showPermissionDialog by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(uiState.error) {
|
||||
uiState.error?.let {
|
||||
viewModel.handleErrorShown()
|
||||
appViewModel.handleEvent(AppEvent.ShowMessage(it))
|
||||
viewModel.handleErrorShown()
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(uiState.isUptoDate) {
|
||||
if (uiState.isUptoDate == true)
|
||||
return@LaunchedEffect context.showToast(R.string.latest_installed)
|
||||
}
|
||||
|
||||
if (uiState.appUpdate != null) {
|
||||
InfoDialog(
|
||||
onDismiss = { viewModel.handleUpdateShown() },
|
||||
onAttest = {
|
||||
if (BuildConfig.FLAVOR != "full") {
|
||||
uiState.appUpdate?.apkUrl?.let { context.openWebUrl(it) }
|
||||
return@InfoDialog
|
||||
}
|
||||
if (context.canInstallPackages()) {
|
||||
viewModel.handleDownloadAndInstallApk()
|
||||
} else {
|
||||
showPermissionDialog = true
|
||||
}
|
||||
},
|
||||
title = { Text(stringResource(R.string.update_available)) },
|
||||
body = {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp, Alignment.Top),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
Text(uiState.appUpdate?.version ?: "")
|
||||
Text(uiState.appUpdate?.releaseNotes ?: "")
|
||||
if (uiState.isLoading) {
|
||||
LinearProgressIndicator(
|
||||
progress = { uiState.downloadProgress },
|
||||
modifier = Modifier.fillMaxWidth().padding(top = 16.dp),
|
||||
trackColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.1f),
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
strokeCap = StrokeCap.Round,
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmText = {
|
||||
Text(
|
||||
if (BuildConfig.FLAVOR != "full") stringResource(R.string.download)
|
||||
else stringResource(R.string.download_and_install)
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
if (showPermissionDialog) {
|
||||
InfoDialog(
|
||||
onDismiss = { showPermissionDialog = false },
|
||||
onAttest = {
|
||||
context.requestInstallPackagesPermission()
|
||||
showPermissionDialog = false
|
||||
},
|
||||
title = { Text(stringResource(R.string.permission_required)) },
|
||||
body = { Text(stringResource(R.string.install_updated_permission)) },
|
||||
confirmText = { Text(stringResource(R.string.allow)) },
|
||||
)
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier =
|
||||
Modifier.fillMaxSize()
|
||||
@@ -35,11 +117,19 @@ fun SupportScreen() {
|
||||
) {
|
||||
GroupLabel(
|
||||
stringResource(R.string.thank_you),
|
||||
modifier = Modifier.padding(horizontal = 12.dp),
|
||||
modifier = Modifier.padding(horizontal = 12.dp).padding(bottom = 12.dp),
|
||||
)
|
||||
UpdateSection(
|
||||
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)
|
||||
viewModel.handleUpdateCheck()
|
||||
}
|
||||
)
|
||||
SectionDivider()
|
||||
GeneralSupportOptions(context)
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline.copy(0.30f))
|
||||
SectionDivider()
|
||||
ContactSupportOptions(context)
|
||||
VersionLabel()
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.support
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppUpdate
|
||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||
|
||||
data class SupportUiState(
|
||||
val appUpdate: AppUpdate? = null,
|
||||
val isLoading: Boolean = false,
|
||||
val error: StringValue? = null,
|
||||
val isUptoDate: Boolean? = null,
|
||||
val downloadProgress: Float = 0f,
|
||||
)
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.support
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppUpdate
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.UpdateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.util.FileUtils
|
||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import jakarta.inject.Inject
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@HiltViewModel
|
||||
class SupportViewModel
|
||||
@Inject
|
||||
constructor(private val updateRepository: UpdateRepository, private val fileUtils: FileUtils) :
|
||||
ViewModel() {
|
||||
|
||||
private val _uiState = MutableStateFlow(SupportUiState())
|
||||
val uiState = _uiState.asStateFlow()
|
||||
|
||||
fun handleUpdateCheck() =
|
||||
viewModelScope.launch {
|
||||
_uiState.update { it.copy(isLoading = true) }
|
||||
updateRepository
|
||||
.checkForUpdate(BuildConfig.VERSION_NAME)
|
||||
.onSuccess { appUpdate ->
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
appUpdate = appUpdate.sanitized(),
|
||||
error = null,
|
||||
isUptoDate = appUpdate == null,
|
||||
)
|
||||
}
|
||||
}
|
||||
.onFailure {
|
||||
_uiState.update {
|
||||
it.copy(error = StringValue.StringResource(R.string.update_check_failed))
|
||||
}
|
||||
}
|
||||
_uiState.update { it.copy(isLoading = false) }
|
||||
}
|
||||
|
||||
private fun AppUpdate?.sanitized(): AppUpdate? {
|
||||
return this?.copy(releaseNotes = releaseNotes.substringBefore(CHANGELOG_START))
|
||||
}
|
||||
|
||||
fun handleErrorShown() = _uiState.update { it.copy(error = null) }
|
||||
|
||||
fun handleUpdateShown() = _uiState.update { it.copy(appUpdate = null) }
|
||||
|
||||
fun handleDownloadAndInstallApk() =
|
||||
viewModelScope.launch {
|
||||
with(uiState.value) {
|
||||
if (appUpdate == null) return@launch
|
||||
if (appUpdate.apkUrl == null || appUpdate.apkFileName == null) return@launch
|
||||
_uiState.update { it.copy(isLoading = true) }
|
||||
updateRepository
|
||||
.downloadApk(appUpdate.apkUrl, appUpdate.apkFileName) { progress ->
|
||||
_uiState.update { it.copy(downloadProgress = progress) }
|
||||
}
|
||||
.onSuccess { apk ->
|
||||
_uiState.update { it.copy(isLoading = false) }
|
||||
fileUtils.installApk(apk)
|
||||
}
|
||||
.onFailure {
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
isLoading = false,
|
||||
error = StringValue.StringResource(R.string.update_download_failed),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val CHANGELOG_START =
|
||||
"SHA-256 fingerprint for the 4096-bit signing certificate:"
|
||||
}
|
||||
}
|
||||
+32
-5
@@ -5,12 +5,14 @@ import androidx.compose.material.icons.filled.Favorite
|
||||
import androidx.compose.material.icons.filled.Mail
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItemLabel
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionLabelType
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.launchSupportEmail
|
||||
@@ -25,7 +27,12 @@ fun ContactSupportOptions(context: android.content.Context) {
|
||||
listOf(
|
||||
SelectionItem(
|
||||
leadingIcon = ImageVector.vectorResource(R.drawable.matrix),
|
||||
title = { SelectionItemLabel(R.string.join_matrix) },
|
||||
title = {
|
||||
SelectionItemLabel(
|
||||
stringResource(R.string.join_matrix),
|
||||
SelectionLabelType.TITLE,
|
||||
)
|
||||
},
|
||||
trailing = {
|
||||
ForwardButton {
|
||||
context.openWebUrl(context.getString(R.string.matrix_url))
|
||||
@@ -35,7 +42,12 @@ fun ContactSupportOptions(context: android.content.Context) {
|
||||
),
|
||||
SelectionItem(
|
||||
leadingIcon = ImageVector.vectorResource(R.drawable.telegram),
|
||||
title = { SelectionItemLabel(R.string.join_telegram) },
|
||||
title = {
|
||||
SelectionItemLabel(
|
||||
stringResource(R.string.join_telegram),
|
||||
SelectionLabelType.TITLE,
|
||||
)
|
||||
},
|
||||
trailing = {
|
||||
ForwardButton {
|
||||
context.openWebUrl(context.getString(R.string.telegram_url))
|
||||
@@ -47,7 +59,12 @@ fun ContactSupportOptions(context: android.content.Context) {
|
||||
),
|
||||
SelectionItem(
|
||||
leadingIcon = ImageVector.vectorResource(R.drawable.github),
|
||||
title = { SelectionItemLabel(R.string.open_issue) },
|
||||
title = {
|
||||
SelectionItemLabel(
|
||||
stringResource(R.string.open_issue),
|
||||
SelectionLabelType.TITLE,
|
||||
)
|
||||
},
|
||||
trailing = {
|
||||
ForwardButton {
|
||||
context.openWebUrl(context.getString(R.string.github_url))
|
||||
@@ -57,7 +74,12 @@ fun ContactSupportOptions(context: android.content.Context) {
|
||||
),
|
||||
SelectionItem(
|
||||
leadingIcon = Icons.Filled.Mail,
|
||||
title = { SelectionItemLabel(R.string.email_description) },
|
||||
title = {
|
||||
SelectionItemLabel(
|
||||
stringResource(R.string.email_description),
|
||||
SelectionLabelType.TITLE,
|
||||
)
|
||||
},
|
||||
trailing = { ForwardButton { context.launchSupportEmail() } },
|
||||
onClick = { context.launchSupportEmail() },
|
||||
),
|
||||
@@ -67,7 +89,12 @@ fun ContactSupportOptions(context: android.content.Context) {
|
||||
add(
|
||||
SelectionItem(
|
||||
leadingIcon = Icons.Filled.Favorite,
|
||||
title = { SelectionItemLabel(R.string.donate) },
|
||||
title = {
|
||||
SelectionItemLabel(
|
||||
stringResource(R.string.donate),
|
||||
SelectionLabelType.TITLE,
|
||||
)
|
||||
},
|
||||
trailing = {
|
||||
ForwardButton {
|
||||
context.openWebUrl(context.getString(R.string.donate_url))
|
||||
|
||||
+31
-2
@@ -1,25 +1,36 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.support.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Balance
|
||||
import androidx.compose.material.icons.filled.Book
|
||||
import androidx.compose.material.icons.filled.Policy
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
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.SurfaceSelectionGroupButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||
|
||||
@Composable
|
||||
fun GeneralSupportOptions(context: android.content.Context) {
|
||||
val navController = LocalNavController.current
|
||||
SurfaceSelectionGroupButton(
|
||||
items =
|
||||
buildList {
|
||||
add(
|
||||
SelectionItem(
|
||||
leadingIcon = Icons.Filled.Book,
|
||||
title = { SelectionItemLabel(R.string.docs_description) },
|
||||
title = {
|
||||
SelectionItemLabel(
|
||||
stringResource(R.string.docs_description),
|
||||
SelectionLabelType.TITLE,
|
||||
)
|
||||
},
|
||||
trailing = {
|
||||
ForwardButton {
|
||||
context.openWebUrl(context.getString(R.string.docs_url))
|
||||
@@ -31,7 +42,12 @@ fun GeneralSupportOptions(context: android.content.Context) {
|
||||
add(
|
||||
SelectionItem(
|
||||
leadingIcon = Icons.Filled.Policy,
|
||||
title = { SelectionItemLabel(R.string.privacy_policy) },
|
||||
title = {
|
||||
SelectionItemLabel(
|
||||
stringResource(R.string.privacy_policy),
|
||||
SelectionLabelType.TITLE,
|
||||
)
|
||||
},
|
||||
trailing = {
|
||||
ForwardButton {
|
||||
context.openWebUrl(context.getString(R.string.privacy_policy_url))
|
||||
@@ -42,6 +58,19 @@ fun GeneralSupportOptions(context: android.content.Context) {
|
||||
},
|
||||
)
|
||||
)
|
||||
add(
|
||||
SelectionItem(
|
||||
leadingIcon = Icons.Filled.Balance,
|
||||
title = {
|
||||
SelectionItemLabel(
|
||||
stringResource(R.string.licenses),
|
||||
SelectionLabelType.TITLE,
|
||||
)
|
||||
},
|
||||
trailing = { ForwardButton { navController.navigate(Route.License) } },
|
||||
onClick = { navController.navigate(Route.License) },
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
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.filled.CloudDownload
|
||||
import androidx.compose.material.icons.rounded.CloudDownload
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItemLabel
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionLabelType
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||
|
||||
@Composable
|
||||
fun UpdateSection(onUpdateCheck: () -> Unit = {}) {
|
||||
SurfaceSelectionGroupButton(
|
||||
listOf(
|
||||
SelectionItem(
|
||||
leadingIcon = Icons.Filled.CloudDownload,
|
||||
title = {
|
||||
SelectionItemLabel(
|
||||
stringResource(R.string.check_for_update),
|
||||
SelectionLabelType.TITLE,
|
||||
)
|
||||
},
|
||||
description = {
|
||||
Column {
|
||||
SelectionItemLabel(
|
||||
stringResource(
|
||||
R.string.version_template,
|
||||
"v${BuildConfig.VERSION_NAME +
|
||||
if(BuildConfig.DEBUG) "-debug" else "" }",
|
||||
),
|
||||
SelectionLabelType.DESCRIPTION,
|
||||
)
|
||||
SelectionItemLabel(
|
||||
stringResource(R.string.flavor_template, BuildConfig.FLAVOR),
|
||||
SelectionLabelType.DESCRIPTION,
|
||||
)
|
||||
}
|
||||
},
|
||||
onClick = onUpdateCheck,
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.support.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||
|
||||
@Composable
|
||||
fun VersionLabel() {
|
||||
val clipboardManager = LocalClipboardManager.current
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Start) {
|
||||
val versionText =
|
||||
if (BuildConfig.BUILD_TYPE == Constants.RELEASE) {
|
||||
BuildConfig.VERSION_NAME
|
||||
} else {
|
||||
"${BuildConfig.VERSION_NAME}-${BuildConfig.BUILD_TYPE}"
|
||||
}
|
||||
Text(
|
||||
"${stringResource(R.string.version)}: $versionText",
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
color = MaterialTheme.colorScheme.outline,
|
||||
modifier =
|
||||
Modifier.clickable {
|
||||
clipboardManager.setText(AnnotatedString(BuildConfig.VERSION_NAME))
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class LicenseFileEntry(
|
||||
val groupId: String,
|
||||
val artifactId: String,
|
||||
val version: String,
|
||||
val name: String,
|
||||
val spdxLicenses: List<SpdxLicense> = emptyList(),
|
||||
val scm: Scm? = null,
|
||||
)
|
||||
|
||||
@Serializable data class SpdxLicense(val identifier: String, val name: String, val url: String)
|
||||
|
||||
@Serializable data class Scm(val url: String)
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.support.license
|
||||
|
||||
import LicenseFileEntry
|
||||
import android.content.Context
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.license.components.LicenseList
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
@Composable
|
||||
fun LicenseScreen() {
|
||||
val context = LocalContext.current
|
||||
var licenses by remember { mutableStateOf<List<LicenseFileEntry>>(emptyList()) }
|
||||
|
||||
LaunchedEffect(Unit) { licenses = loadLicenseeJson(context) }
|
||||
|
||||
if (licenses.isEmpty()) {
|
||||
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
} else {
|
||||
LicenseList(licenses)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun loadLicenseeJson(context: Context): List<LicenseFileEntry> {
|
||||
return withContext(Dispatchers.IO) {
|
||||
val json = Json { ignoreUnknownKeys = true }
|
||||
|
||||
val jsonResult = context.assets.open("licenses.json").bufferedReader().use { it.readText() }
|
||||
json.decodeFromString(jsonResult)
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.support.license.components
|
||||
|
||||
import LicenseFileEntry
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun LicenseList(licenses: List<LicenseFileEntry>) {
|
||||
LazyColumn(modifier = Modifier.fillMaxSize().padding(16.dp)) {
|
||||
items(licenses) { entry ->
|
||||
Column(modifier = Modifier.padding(bottom = 12.dp)) {
|
||||
Text(
|
||||
text = "${entry.name} (${entry.version})",
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
)
|
||||
|
||||
entry.spdxLicenses.forEach { license ->
|
||||
Text(
|
||||
text = license.name,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
}
|
||||
|
||||
entry.scm?.url?.let { scmUrl ->
|
||||
Text(
|
||||
text = scmUrl,
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
modifier = Modifier.padding(top = 4.dp),
|
||||
color = MaterialTheme.colorScheme.secondary,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,5 @@ data class AppUiState(
|
||||
val isAutoTunnelActive: Boolean = false,
|
||||
val appConfigurationChange: Boolean = false,
|
||||
val isAppLoaded: Boolean = false,
|
||||
val selectedTunnel: TunnelConf? = null,
|
||||
val networkStatus: NetworkStatus? = null,
|
||||
)
|
||||
|
||||
@@ -8,8 +8,22 @@ data class AppViewState(
|
||||
val errorMessage: StringValue? = null,
|
||||
val popBackStack: Boolean = false,
|
||||
val isAppReady: Boolean = false,
|
||||
val showBottomSheet: Boolean = false,
|
||||
val selectedTunnel: TunnelConf? = null,
|
||||
val bottomSheet: BottomSheet = BottomSheet.NONE,
|
||||
val selectedTunnels: List<TunnelConf> = emptyList(),
|
||||
val requestVpnPermission: Boolean = false,
|
||||
val requestBatteryPermission: Boolean = false,
|
||||
)
|
||||
val showModal: ModalType = ModalType.NONE,
|
||||
) {
|
||||
enum class ModalType {
|
||||
NONE,
|
||||
DELETE,
|
||||
INFO,
|
||||
}
|
||||
|
||||
enum class BottomSheet {
|
||||
EXPORT_TUNNELS,
|
||||
IMPORT_TUNNELS,
|
||||
LOGS,
|
||||
NONE,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,10 +75,7 @@ data class InterfaceProxy(
|
||||
}
|
||||
|
||||
fun isAmneziaCompatibilityModeSet(): Boolean {
|
||||
return junkPacketCount.toIntOrNull() in 3..<5 &&
|
||||
junkPacketMinSize.toIntOrNull() == 40 &&
|
||||
junkPacketMaxSize.toIntOrNull() == 70 &&
|
||||
with(initPacketJunkSize.toIntOrNull()) { this == 0 || this == null } &&
|
||||
return with(initPacketJunkSize.toIntOrNull()) { this == 0 || this == null } &&
|
||||
with(responsePacketJunkSize.toIntOrNull()) { this == 0 || this == null } &&
|
||||
initPacketMagicHeader.toLongOrNull() == 1L &&
|
||||
responsePacketMagicHeader.toLongOrNull() == 2L &&
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.state
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
|
||||
data class NavBarState(
|
||||
val showTop: Boolean = true,
|
||||
val showBottom: Boolean = true,
|
||||
val topTitle: @Composable (() -> Unit)? = null,
|
||||
val topTrailing: @Composable (() -> Unit)? = null,
|
||||
val route: Route? = null,
|
||||
)
|
||||
@@ -78,6 +78,7 @@ fun WireguardAutoTunnelTheme(theme: Theme = Theme.AUTOMATIC, content: @Composabl
|
||||
|
||||
val view = LocalView.current
|
||||
if (!view.isInEditMode) {
|
||||
@Suppress("DEPRECATION")
|
||||
SideEffect {
|
||||
val window = (view.context as Activity).window
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
|
||||
@@ -14,7 +14,7 @@ object Constants {
|
||||
const val ZIP_FILE_EXTENSION = ".zip"
|
||||
const val URI_CONTENT_SCHEME = "content"
|
||||
private const val TEXT_MIME_TYPE = "text/plain"
|
||||
private const val ZIP_FILE_MIME_TYPE = "application/zip"
|
||||
const val ZIP_FILE_MIME_TYPE = "application/zip"
|
||||
const val ALLOWED_TV_FILE_TYPES = "${TEXT_MIME_TYPE}|${ZIP_FILE_MIME_TYPE}"
|
||||
const val ALL_FILE_TYPES = "*/*"
|
||||
const val GOOGLE_TV_EXPLORER_STUB = "com.google.android.tv.frameworkpackagestubs"
|
||||
@@ -22,6 +22,8 @@ object Constants {
|
||||
const val VPN_SETTINGS_PACKAGE = "android.net.vpn.SETTINGS"
|
||||
const val SYSTEM_EXEMPT_SERVICE_TYPE_ID = 1024
|
||||
|
||||
const val DEFAULT_EXPORT_FILE_NAME = "wgtunnel-export.zip"
|
||||
|
||||
const val SUBSCRIPTION_TIMEOUT = 5_000L
|
||||
|
||||
const val DEFAULT_PING_IP = "1.1.1.1"
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
package com.zaneschepke.wireguardautotunnel.util
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.MediaStore
|
||||
import android.provider.OpenableColumns
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.FileProvider
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.getInputStreamFromUri
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.installApk
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.launchShareFile
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toWgQuickString
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.*
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipInputStream
|
||||
import java.util.zip.ZipOutputStream
|
||||
@@ -26,21 +29,37 @@ class FileUtils(private val context: Context, private val ioDispatcher: Coroutin
|
||||
|
||||
suspend fun createWgFiles(tunnels: List<TunnelConf>): List<File> =
|
||||
withContext(ioDispatcher) {
|
||||
tunnels.map { config ->
|
||||
tunnels.mapNotNull { config ->
|
||||
if (config.wgQuick.isBlank()) {
|
||||
Timber.w("Skipping tunnel ${config.tunName}: empty wgQuick config")
|
||||
return@mapNotNull null
|
||||
}
|
||||
val file = File(context.cacheDir, "${config.tunName}-wg.conf")
|
||||
file.outputStream().use { it.write(config.wgQuick.toByteArray()) }
|
||||
file
|
||||
Timber.d("Created WG file: ${file.path}, size: ${file.length()} bytes")
|
||||
if (file.length() == 0L) {
|
||||
Timber.w("WG file ${file.path} is empty")
|
||||
null
|
||||
} else {
|
||||
file
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun createAmFiles(tunnels: List<TunnelConf>): List<File> =
|
||||
withContext(ioDispatcher) {
|
||||
tunnels
|
||||
.filter { it.amQuick != TunnelConfig.AM_QUICK_DEFAULT }
|
||||
.map { config ->
|
||||
.filter { it.amQuick != TunnelConfig.AM_QUICK_DEFAULT && it.amQuick.isNotBlank() }
|
||||
.mapNotNull { config ->
|
||||
val file = File(context.cacheDir, "${config.tunName}-am.conf")
|
||||
file.outputStream().use { it.write(config.amQuick.toByteArray()) }
|
||||
file
|
||||
Timber.d("Created AM file: ${file.path}, size: ${file.length()} bytes")
|
||||
if (file.length() == 0L) {
|
||||
Timber.w("AM file ${file.path} is empty")
|
||||
null
|
||||
} else {
|
||||
file
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,31 +67,80 @@ class FileUtils(private val context: Context, private val ioDispatcher: Coroutin
|
||||
withContext(ioDispatcher) {
|
||||
ZipOutputStream(BufferedOutputStream(FileOutputStream(zipFile))).use { zos ->
|
||||
files.forEach { file ->
|
||||
val zipFileName =
|
||||
(file.parentFile?.let { parent ->
|
||||
file.absolutePath.removePrefix(parent.absolutePath)
|
||||
} ?: file.absolutePath)
|
||||
.removePrefix("/")
|
||||
val entry = ZipEntry("$zipFileName${(if (file.isDirectory) "/" else "")}")
|
||||
zos.putNextEntry(entry)
|
||||
if (file.isFile) {
|
||||
file.inputStream().use { it.copyTo(zos) }
|
||||
if (!file.exists() || file.length() == 0L) {
|
||||
Timber.w("Skipping file ${file.path}: does not exist or empty")
|
||||
return@forEach
|
||||
}
|
||||
val entryName = file.name // Use file name only, avoid complex path logic
|
||||
val entry = ZipEntry(entryName)
|
||||
zos.putNextEntry(entry)
|
||||
FileInputStream(file).use { fis ->
|
||||
fis.copyTo(zos)
|
||||
Timber.d(
|
||||
"Added ${file.path} to zip as $entryName, size: ${file.length()} bytes"
|
||||
)
|
||||
}
|
||||
zos.closeEntry()
|
||||
}
|
||||
zos.flush()
|
||||
Timber.d("Finished zipping: ${zipFile.path}, size: ${zipFile.length()} bytes")
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun createNewShareFile(name: String): File =
|
||||
withContext(ioDispatcher) {
|
||||
val sharePath = File(context.filesDir, "external_files")
|
||||
if (sharePath.exists()) sharePath.delete()
|
||||
sharePath.mkdir()
|
||||
val file = File("${sharePath.path}/$name")
|
||||
if (sharePath.exists()) sharePath.deleteRecursively()
|
||||
sharePath.mkdirs()
|
||||
val file = File(sharePath, name)
|
||||
if (file.exists()) file.delete()
|
||||
file.createNewFile()
|
||||
Timber.d("Created share file: ${file.path}")
|
||||
file
|
||||
}
|
||||
|
||||
suspend fun copyFileToUri(sourceFile: File, destinationUri: Uri): Result<Unit> =
|
||||
withContext(ioDispatcher) {
|
||||
try {
|
||||
if (!sourceFile.exists()) {
|
||||
Timber.e("Source file does not exist: ${sourceFile.path}")
|
||||
return@withContext Result.failure(IOException("Source file does not exist"))
|
||||
}
|
||||
if (!sourceFile.canRead()) {
|
||||
Timber.e("Source file is not readable: ${sourceFile.path}")
|
||||
return@withContext Result.failure(IOException("Source file is not readable"))
|
||||
}
|
||||
if (sourceFile.length() == 0L) {
|
||||
Timber.e("Source file is empty: ${sourceFile.path}")
|
||||
return@withContext Result.failure(IOException("Source file is empty"))
|
||||
}
|
||||
|
||||
Timber.d("Copying file: ${sourceFile.path}, size: ${sourceFile.length()} bytes")
|
||||
var bytesCopied = 0L
|
||||
FileInputStream(sourceFile).use { inputStream ->
|
||||
context.contentResolver.openOutputStream(destinationUri)?.use { outputStream ->
|
||||
val buffer = ByteArray(1024 * 1024) // 1MB buffer
|
||||
var bytesRead: Int
|
||||
while (inputStream.read(buffer).also { bytesRead = it } != -1) {
|
||||
outputStream.write(buffer, 0, bytesRead)
|
||||
bytesCopied += bytesRead
|
||||
Timber.d("Copied $bytesCopied bytes so far")
|
||||
}
|
||||
outputStream.flush()
|
||||
Timber.d("Total bytes copied: $bytesCopied")
|
||||
Result.success(Unit)
|
||||
}
|
||||
?: run {
|
||||
Timber.e("Failed to open OutputStream for Uri: $destinationUri")
|
||||
Result.failure(IOException("Failed to open OutputStream for Uri"))
|
||||
}
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
Timber.e(e, "Error copying file to Uri: ${e.message}")
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDisplayNameColumnIndex(cursor: Cursor): Int? {
|
||||
val columnIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
|
||||
if (columnIndex == -1) return null
|
||||
@@ -161,4 +229,33 @@ class FileUtils(private val context: Context, private val ioDispatcher: Coroutin
|
||||
FileProvider.getUriForFile(context, context.getString(R.string.provider), shareFile)
|
||||
context.launchShareFile(uri)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.Q)
|
||||
suspend fun saveToDownloadsWithMediaStore(file: File, mimeType: String): Uri? =
|
||||
withContext(ioDispatcher) {
|
||||
val contentValues =
|
||||
ContentValues().apply {
|
||||
put(MediaStore.Downloads.DISPLAY_NAME, file.name)
|
||||
put(MediaStore.Downloads.MIME_TYPE, mimeType)
|
||||
put(MediaStore.Downloads.IS_PENDING, 1)
|
||||
}
|
||||
|
||||
val resolver = context.contentResolver
|
||||
val collection = MediaStore.Downloads.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY)
|
||||
val itemUri = resolver.insert(collection, contentValues) ?: return@withContext null
|
||||
|
||||
resolver.openOutputStream(itemUri)?.use { output ->
|
||||
file.inputStream().use { input -> input.copyTo(output) }
|
||||
}
|
||||
// Mark as finished
|
||||
contentValues.clear()
|
||||
contentValues.put(MediaStore.Downloads.IS_PENDING, 0)
|
||||
resolver.update(itemUri, contentValues, null, null)
|
||||
|
||||
return@withContext itemUri
|
||||
}
|
||||
|
||||
fun installApk(file: File) {
|
||||
context.installApk(file)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.zaneschepke.wireguardautotunnel.util
|
||||
|
||||
import com.vdurmont.semver4j.Semver
|
||||
import java.math.BigDecimal
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
import kotlin.math.pow
|
||||
import timber.log.Timber
|
||||
|
||||
object NumberUtils {
|
||||
private const val BYTES_IN_KB = 1024.0
|
||||
@@ -38,4 +40,15 @@ object NumberUtils {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun compareVersions(newVersion: String, currentVersion: String): Int {
|
||||
try {
|
||||
val newSemver = Semver(newVersion, Semver.SemverType.LOOSE)
|
||||
val currentSemver = Semver(currentVersion, Semver.SemverType.LOOSE)
|
||||
return newSemver.compareTo(currentSemver)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Failed to compare versions $newVersion and $currentVersion")
|
||||
return 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+68
-40
@@ -14,24 +14,21 @@ import android.os.PowerManager
|
||||
import android.provider.Settings
|
||||
import android.service.quicksettings.TileService
|
||||
import android.widget.Toast
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.TextUnit
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.core.location.LocationManagerCompat
|
||||
import androidx.core.net.toUri
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.tile.AutoTunnelControlTile
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.tile.TunnelControlTile
|
||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
|
||||
private const val BASELINE_HEIGHT = 2201
|
||||
private const val BASELINE_WIDTH = 1080
|
||||
private const val BASELINE_DENSITY = 2.625
|
||||
private const val ANDROID_TV_SIZE_MULTIPLIER = 1.5f
|
||||
import timber.log.Timber
|
||||
|
||||
fun Context.openWebUrl(url: String): Result<Unit> {
|
||||
return kotlin
|
||||
.runCatching {
|
||||
val webpage: Uri = Uri.parse(url)
|
||||
val webpage: Uri = url.toUri()
|
||||
val intent =
|
||||
Intent(Intent.ACTION_VIEW, webpage).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
@@ -52,37 +49,6 @@ val Context.actionBarSize
|
||||
attrs.getDimension(0, 0F).toInt().also { attrs.recycle() }
|
||||
}
|
||||
|
||||
fun Context.resizeHeight(dp: Dp): Dp {
|
||||
val displayMetrics = resources.displayMetrics
|
||||
val density = displayMetrics.density
|
||||
val height =
|
||||
(displayMetrics.heightPixels - this.actionBarSize) *
|
||||
(if (isRunningOnTv()) ANDROID_TV_SIZE_MULTIPLIER else 1f)
|
||||
val resizeHeightPercentage =
|
||||
(height.toFloat() / BASELINE_HEIGHT) * (BASELINE_DENSITY.toFloat() / density)
|
||||
return dp * resizeHeightPercentage
|
||||
}
|
||||
|
||||
fun Context.resizeHeight(textUnit: TextUnit): TextUnit {
|
||||
val displayMetrics = resources.displayMetrics
|
||||
val density = displayMetrics.density
|
||||
val height =
|
||||
(displayMetrics.heightPixels - actionBarSize) *
|
||||
(if (isRunningOnTv()) ANDROID_TV_SIZE_MULTIPLIER else 1f)
|
||||
val resizeHeightPercentage =
|
||||
(height.toFloat() / BASELINE_HEIGHT) * (BASELINE_DENSITY.toFloat() / density)
|
||||
return textUnit * resizeHeightPercentage * 1.1
|
||||
}
|
||||
|
||||
fun Context.resizeWidth(dp: Dp): Dp {
|
||||
val displayMetrics = resources.displayMetrics
|
||||
val density = displayMetrics.density
|
||||
val width = displayMetrics.widthPixels
|
||||
val resizeWidthPercentage =
|
||||
(width.toFloat() / BASELINE_WIDTH) * (BASELINE_DENSITY.toFloat() / density)
|
||||
return dp * resizeWidthPercentage
|
||||
}
|
||||
|
||||
fun Context.launchNotificationSettings() {
|
||||
if (isRunningOnTv()) return launchAppSettings()
|
||||
val settingsIntent: Intent =
|
||||
@@ -92,6 +58,43 @@ fun Context.launchNotificationSettings() {
|
||||
this.startActivity(settingsIntent)
|
||||
}
|
||||
|
||||
fun Context.hasSAFSupport(mimeType: String): Boolean {
|
||||
val intent =
|
||||
Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
|
||||
type = mimeType
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
}
|
||||
val activitiesToResolveIntent =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
packageManager.queryIntentActivities(
|
||||
intent,
|
||||
PackageManager.ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong()),
|
||||
)
|
||||
} else {
|
||||
packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
|
||||
}
|
||||
Timber.d(
|
||||
"Found ${activitiesToResolveIntent.size} activities: ${activitiesToResolveIntent.map { it.activityInfo.packageName }}"
|
||||
)
|
||||
|
||||
return if (activitiesToResolveIntent.isEmpty()) {
|
||||
Timber.w("No activities found to handle SAF intent")
|
||||
false
|
||||
} else if (
|
||||
isRunningOnTv() &&
|
||||
activitiesToResolveIntent.all {
|
||||
val name = it.activityInfo.packageName
|
||||
name.startsWith(Constants.GOOGLE_TV_EXPLORER_STUB) ||
|
||||
name.startsWith(Constants.ANDROID_TV_EXPLORER_STUB)
|
||||
}
|
||||
) {
|
||||
Timber.w("Only stub file explorers found on TV")
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.launchShareFile(file: Uri) {
|
||||
val shareIntent =
|
||||
Intent().apply {
|
||||
@@ -99,6 +102,7 @@ fun Context.launchShareFile(file: Uri) {
|
||||
type = Constants.ALL_FILE_TYPES
|
||||
putExtra(Intent.EXTRA_STREAM, file)
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
}
|
||||
val chooserIntent =
|
||||
Intent.createChooser(shareIntent, "").apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) }
|
||||
@@ -117,7 +121,7 @@ fun Context.showToast(resId: Int) {
|
||||
fun Context.launchSupportEmail() {
|
||||
val intent =
|
||||
Intent(Intent.ACTION_SENDTO).apply {
|
||||
data = Uri.parse("mailto:")
|
||||
data = "mailto:".toUri()
|
||||
putExtra(Intent.EXTRA_EMAIL, arrayOf(getString(R.string.my_email)))
|
||||
putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_subject))
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
@@ -197,3 +201,27 @@ fun Context.getAllInternetCapablePackages(): List<PackageInfo> {
|
||||
packageManager.getPackagesHoldingPermissions(permissions, 0)
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.canInstallPackages(): Boolean {
|
||||
return packageManager.canRequestPackageInstalls()
|
||||
}
|
||||
|
||||
fun Context.requestInstallPackagesPermission() {
|
||||
val intent =
|
||||
Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES).apply {
|
||||
data = "package:${packageName}".toUri()
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
fun Context.installApk(apkFile: File) {
|
||||
val apkUri = FileProvider.getUriForFile(this, getString(R.string.provider), apkFile)
|
||||
val intent =
|
||||
Intent(Intent.ACTION_VIEW).apply {
|
||||
setDataAndType(apkUri, "application/vnd.android.package-archive")
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
@@ -20,3 +20,7 @@ typealias Tunnels = List<TunnelConf>
|
||||
typealias TunnelConfigs = List<TunnelConfig>
|
||||
|
||||
typealias Packages = List<PackageInfo>
|
||||
|
||||
fun <T> MutableList<T>.addAllUnique(elements: Collection<T>, comparator: (T, T) -> Boolean) {
|
||||
addAll(elements.filterNot { new -> this.any { existing -> comparator(existing, new) } })
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package com.zaneschepke.wireguardautotunnel.util.extensions
|
||||
|
||||
import androidx.navigation.NavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.isCurrentRoute
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.isCurrentRoute
|
||||
|
||||
fun NavController.goFromRoot(route: Route) {
|
||||
if (currentBackStackEntry?.isCurrentRoute(route::class) == true) return
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.zaneschepke.wireguardautotunnel.viewmodel
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.wireguard.android.backend.WgQuickBackend
|
||||
@@ -28,9 +29,11 @@ import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppViewState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||
import com.zaneschepke.wireguardautotunnel.util.*
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.addAllUnique
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.withFirstState
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import java.io.IOException
|
||||
import java.net.URL
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
@@ -128,8 +131,8 @@ constructor(
|
||||
handleToggleLocalLogging(state.appState.isLocalLogsEnabled)
|
||||
is AppEvent.SetDebounceDelay ->
|
||||
handleSetDebounceDelay(state.appSettings, event.delay)
|
||||
is AppEvent.CopyTunnel -> handleCopyTunnel(event.tunnel, state.tunnels)
|
||||
is AppEvent.DeleteTunnel -> handleDeleteTunnel(event.tunnel, state)
|
||||
is AppEvent.CopySelectedTunnel -> handleCopySelectedTunnel(state.tunnels)
|
||||
is AppEvent.DeleteSelectedTunnels -> handleDeleteSelectedTunnels()
|
||||
is AppEvent.ImportTunnelFromClipboard ->
|
||||
handleClipboardImport(event.text, state.tunnels)
|
||||
is AppEvent.ImportTunnelFromFile ->
|
||||
@@ -142,8 +145,8 @@ constructor(
|
||||
is AppEvent.StartTunnel -> handleStartTunnel(event.tunnel, state.appSettings)
|
||||
is AppEvent.StopTunnel -> handleStopTunnel(event.tunnel)
|
||||
AppEvent.ToggleAutoTunnel -> handleToggleAutoTunnel(state)
|
||||
AppEvent.ToggleTunnelStatsExpanded ->
|
||||
handleToggleExpandTunnelStats(state.appState.isTunnelStatsExpanded)
|
||||
is AppEvent.ToggleTunnelStatsExpanded ->
|
||||
handleToggleTunnelStats(event.tunnelId, state.appState)
|
||||
AppEvent.ToggleAlwaysOn -> handleToggleAlwaysOnVPN(state.appSettings)
|
||||
AppEvent.TogglePinLock -> handlePinLockToggled(state.appState.isPinLockEnabled)
|
||||
AppEvent.SetLocationDisclosureShown -> setLocationDisclosureShown()
|
||||
@@ -183,19 +186,21 @@ constructor(
|
||||
handleToggleStopKillSwitchOnTrusted(state.appSettings)
|
||||
AppEvent.ToggleStopTunnelOnNoInternet ->
|
||||
handleToggleStopOnNoInternet(state.appSettings)
|
||||
is AppEvent.ExportTunnels ->
|
||||
handleExportTunnels(event.configType, state.tunnels)
|
||||
is AppEvent.ExportSelectedTunnels ->
|
||||
handleExportSelectedTunnels(event.configType, event.uri)
|
||||
|
||||
AppEvent.ExportLogs -> handleExportLogs()
|
||||
AppEvent.MessageShown -> handleErrorShown()
|
||||
is AppEvent.TogglePingTunnelEnabled -> handleTogglePingTunnel(event.tunnel)
|
||||
is AppEvent.SetTunnelPingIp ->
|
||||
handleTunnelPingIpChange(event.tunnelConf, event.ip)
|
||||
AppEvent.ToggleBottomSheet -> handleToggleBottomSheet()
|
||||
is AppEvent.SetBottomSheet -> handleSetBottomSheet(event.showSheet)
|
||||
AppEvent.DeleteLogs -> handleDeleteLogs()
|
||||
is AppEvent.SetScreenAction -> _screenCallback.update { event.callback }
|
||||
AppEvent.InvokeScreenAction -> _screenCallback.value?.invoke()
|
||||
is AppEvent.SetSelectedTunnel ->
|
||||
_appViewState.update { it.copy(selectedTunnel = event.tunnel) }
|
||||
is AppEvent.ToggleSelectedTunnel -> handleToggleSelectedTunnel(event.tunnel)
|
||||
is AppEvent.ToggleSelectAllTunnels ->
|
||||
handleToggleSelectAllTunnels(state.tunnels)
|
||||
AppEvent.VpnPermissionRequested -> requestVpnPermission(false)
|
||||
is AppEvent.AppReadyCheck -> handleAppReadyCheck(event.tunnels)
|
||||
is AppEvent.ShowMessage -> handleShowMessage(event.message)
|
||||
@@ -203,10 +208,43 @@ constructor(
|
||||
_appViewState.update { it.copy(popBackStack = event.pop) }
|
||||
is AppEvent.ClearTunnelError -> tunnelManager.clearError(event.tunnel)
|
||||
AppEvent.ToggleRemoteControl -> handleToggleRemoteControl(state.appState)
|
||||
AppEvent.ClearSelectedTunnels -> clearSelectedTunnels()
|
||||
is AppEvent.SetShowModal ->
|
||||
_appViewState.update { it.copy(showModal = event.modalType) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleToggleSelectAllTunnels(tunnels: List<TunnelConf>) =
|
||||
_appViewState.update { it ->
|
||||
val remove = tunnels.size == it.selectedTunnels.size
|
||||
it.copy(
|
||||
selectedTunnels =
|
||||
it.selectedTunnels.toMutableList().apply {
|
||||
if (remove) removeAll(tunnels)
|
||||
else addAllUnique(tunnels) { existing, new -> existing.id == new.id }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun handleToggleSelectedTunnel(tunnel: TunnelConf) =
|
||||
_appViewState.update {
|
||||
it.copy(
|
||||
selectedTunnels =
|
||||
it.selectedTunnels.toMutableList().apply {
|
||||
if (it.selectedTunnels.contains(tunnel)) remove(tunnel) else add(tunnel)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun handleToggleTunnelStats(tunnelId: Int, appState: AppState) {
|
||||
if (appState.expandedTunnelIds.contains(tunnelId)) {
|
||||
appDataRepository.appState.removeTunnelExpanded(tunnelId)
|
||||
} else {
|
||||
appDataRepository.appState.setTunnelExpanded(tunnelId)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun handleToggleRemoteControl(appState: AppState) {
|
||||
val enabled = !appState.isRemoteControlEnabled
|
||||
if (enabled) appDataRepository.appState.setRemoteKey(UUID.randomUUID().toString())
|
||||
@@ -233,8 +271,8 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleToggleBottomSheet() =
|
||||
_appViewState.update { it.copy(showBottomSheet = !it.showBottomSheet) }
|
||||
private fun handleSetBottomSheet(bottomSheet: AppViewState.BottomSheet) =
|
||||
_appViewState.update { it.copy(bottomSheet = bottomSheet) }
|
||||
|
||||
private suspend fun handleTunnelPingIpChange(tunnelConf: TunnelConf, ip: String) =
|
||||
saveTunnel(tunnelConf.copy(pingIp = ip))
|
||||
@@ -261,7 +299,8 @@ constructor(
|
||||
private suspend fun handleSetDebounceDelay(appSettings: AppSettings, delay: Int) =
|
||||
saveSettings(appSettings.copy(debounceDelaySeconds = delay))
|
||||
|
||||
private suspend fun handleCopyTunnel(tunnel: TunnelConf, existingTunnels: List<TunnelConf>) =
|
||||
private suspend fun handleCopySelectedTunnel(existingTunnels: List<TunnelConf>) {
|
||||
val tunnel = _appViewState.value.selectedTunnels.firstOrNull() ?: return
|
||||
saveTunnel(
|
||||
TunnelConf(
|
||||
tunName = tunnel.generateUniqueName(existingTunnels.map { it.tunName }),
|
||||
@@ -269,14 +308,22 @@ constructor(
|
||||
amQuick = tunnel.amQuick,
|
||||
)
|
||||
)
|
||||
|
||||
private suspend fun handleDeleteTunnel(tunnel: TunnelConf, state: AppUiState) {
|
||||
if (state.tunnels.size == 1 || tunnel.isPrimaryTunnel) {
|
||||
serviceManager.stopAutoTunnel()
|
||||
}
|
||||
appDataRepository.tunnels.delete(tunnel)
|
||||
clearSelectedTunnels()
|
||||
}
|
||||
|
||||
private fun clearSelectedTunnels() =
|
||||
_appViewState.update {
|
||||
it.copy(selectedTunnels = it.selectedTunnels.toMutableList().apply { clear() })
|
||||
}
|
||||
|
||||
private suspend fun handleDeleteSelectedTunnels() =
|
||||
_appViewState.value.selectedTunnels
|
||||
.forEach {
|
||||
appDataRepository.tunnels.delete(it)
|
||||
appDataRepository.appState.removeTunnelExpanded(it.id)
|
||||
}
|
||||
.also { clearSelectedTunnels() }
|
||||
|
||||
private fun requestVpnPermission(request: Boolean) =
|
||||
_appViewState.update { it.copy(requestVpnPermission = request) }
|
||||
|
||||
@@ -284,6 +331,7 @@ constructor(
|
||||
_appViewState.update { it.copy(requestBatteryPermission = request) }
|
||||
|
||||
private suspend fun handleStartTunnel(tunnel: TunnelConf, appSettings: AppSettings) {
|
||||
clearSelectedTunnels()
|
||||
tunControlMutex.withLock {
|
||||
if (!tunnelManager.hasVpnPermission() && !appSettings.isKernelEnabled)
|
||||
return@withLock requestVpnPermission(true)
|
||||
@@ -292,6 +340,7 @@ constructor(
|
||||
}
|
||||
|
||||
private suspend fun handleStopTunnel(tunnel: TunnelConf) {
|
||||
clearSelectedTunnels()
|
||||
tunControlMutex.withLock { tunnelManager.stopTunnel(tunnel) }
|
||||
}
|
||||
|
||||
@@ -310,10 +359,6 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun handleToggleExpandTunnelStats(currentlyEnabled: Boolean) {
|
||||
appDataRepository.appState.setTunnelStatsExpanded(!currentlyEnabled)
|
||||
}
|
||||
|
||||
private fun handleErrorShown() {
|
||||
_appViewState.update { it.copy(errorMessage = null) }
|
||||
}
|
||||
@@ -635,31 +680,59 @@ constructor(
|
||||
tunnelMutex.withLock { appDataRepository.tunnels.save(tunnel) }
|
||||
}
|
||||
|
||||
private suspend fun handleExportTunnels(configType: ConfigType, tunnels: List<TunnelConf>) {
|
||||
runCatching {
|
||||
val (files, shareFileName) =
|
||||
when (configType) {
|
||||
ConfigType.AMNEZIA -> {
|
||||
Pair(
|
||||
fileUtils.createAmFiles(tunnels),
|
||||
"am-export_${Instant.now().epochSecond}.zip",
|
||||
)
|
||||
}
|
||||
ConfigType.WG -> {
|
||||
Pair(
|
||||
fileUtils.createWgFiles(tunnels),
|
||||
"wg-export_${Instant.now().epochSecond}.zip",
|
||||
)
|
||||
private suspend fun handleExportSelectedTunnels(configType: ConfigType, uri: Uri?) {
|
||||
val tunnels = _appViewState.value.selectedTunnels
|
||||
try {
|
||||
if (tunnels.isEmpty()) return
|
||||
val (files, shareFileName) =
|
||||
when (configType) {
|
||||
ConfigType.AMNEZIA -> {
|
||||
val amFiles = fileUtils.createAmFiles(tunnels)
|
||||
if (amFiles.isEmpty()) {
|
||||
throw IOException("No valid Amnezia config files created")
|
||||
}
|
||||
Pair(amFiles, "am-export_${Instant.now().epochSecond}.zip")
|
||||
}
|
||||
val shareFile = fileUtils.createNewShareFile(shareFileName)
|
||||
fileUtils.zipAll(shareFile, files)
|
||||
fileUtils.shareFile(shareFile)
|
||||
ConfigType.WG -> {
|
||||
val wgFiles = fileUtils.createWgFiles(tunnels)
|
||||
if (wgFiles.isEmpty()) {
|
||||
throw IOException("No valid WireGuard config files created")
|
||||
}
|
||||
Pair(wgFiles, "wg-export_${Instant.now().epochSecond}.zip")
|
||||
}
|
||||
}
|
||||
|
||||
val shareFile = fileUtils.createNewShareFile(shareFileName)
|
||||
fileUtils.zipAll(shareFile, files)
|
||||
if (!shareFile.exists() || shareFile.length() == 0L) {
|
||||
throw IOException("Zip file is empty or not created: ${shareFile.path}")
|
||||
}
|
||||
.onFailure {
|
||||
Timber.e(it)
|
||||
handleShowMessage(StringValue.StringResource(R.string.export_failed))
|
||||
|
||||
// fall back to save to downloads for older devices
|
||||
if (uri != null) {
|
||||
val copyResult = fileUtils.copyFileToUri(shareFile, uri)
|
||||
copyResult.fold(
|
||||
onSuccess = {
|
||||
handleShowMessage(StringValue.StringResource(R.string.export_success))
|
||||
},
|
||||
onFailure = { error ->
|
||||
Timber.w("User likely cancelled or file write failed: ${error.message}")
|
||||
handleShowMessage(StringValue.StringResource(R.string.export_failed))
|
||||
},
|
||||
)
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
fileUtils.saveToDownloadsWithMediaStore(shareFile, Constants.ZIP_FILE_MIME_TYPE)
|
||||
handleShowMessage(StringValue.StringResource(R.string.export_success))
|
||||
} else throw IOException("File exporting not supported on this device")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Export failed")
|
||||
handleShowMessage(StringValue.StringResource(R.string.export_failed))
|
||||
} finally {
|
||||
handleSetBottomSheet(AppViewState.BottomSheet.NONE)
|
||||
clearSelectedTunnels()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun handleExportLogs() {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.zaneschepke.wireguardautotunnel.viewmodel.event
|
||||
import android.net.Uri
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.ConfigType
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppViewState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||
|
||||
@@ -55,9 +56,9 @@ sealed class AppEvent {
|
||||
|
||||
data class StopTunnel(val tunnel: TunnelConf) : AppEvent()
|
||||
|
||||
data class DeleteTunnel(val tunnel: TunnelConf) : AppEvent()
|
||||
data object DeleteSelectedTunnels : AppEvent()
|
||||
|
||||
data class CopyTunnel(val tunnel: TunnelConf) : AppEvent()
|
||||
data object CopySelectedTunnel : AppEvent()
|
||||
|
||||
data class ImportTunnelFromFile(val data: Uri) : AppEvent()
|
||||
|
||||
@@ -67,7 +68,7 @@ sealed class AppEvent {
|
||||
|
||||
data class ImportTunnelFromQrCode(val qrCode: String) : AppEvent()
|
||||
|
||||
data object ToggleTunnelStatsExpanded : AppEvent()
|
||||
data class ToggleTunnelStatsExpanded(val tunnelId: Int) : AppEvent()
|
||||
|
||||
data object SetBatteryOptimizeDisableShown : AppEvent()
|
||||
|
||||
@@ -95,7 +96,7 @@ sealed class AppEvent {
|
||||
|
||||
data class SaveTrustedSSID(val ssid: String) : AppEvent()
|
||||
|
||||
data class ExportTunnels(val configType: ConfigType) : AppEvent()
|
||||
data class ExportSelectedTunnels(val configType: ConfigType, val uri: Uri?) : AppEvent()
|
||||
|
||||
data object ExportLogs : AppEvent()
|
||||
|
||||
@@ -109,13 +110,19 @@ sealed class AppEvent {
|
||||
|
||||
data class PopBackStack(val pop: Boolean) : AppEvent()
|
||||
|
||||
data object ToggleBottomSheet : AppEvent()
|
||||
data class SetBottomSheet(val showSheet: AppViewState.BottomSheet) : AppEvent()
|
||||
|
||||
data class SetSelectedTunnel(val tunnel: TunnelConf?) : AppEvent()
|
||||
data class ToggleSelectedTunnel(val tunnel: TunnelConf) : AppEvent()
|
||||
|
||||
data object ClearSelectedTunnels : AppEvent()
|
||||
|
||||
data object VpnPermissionRequested : AppEvent()
|
||||
|
||||
data class AppReadyCheck(val tunnels: List<TunnelConf>) : AppEvent()
|
||||
|
||||
data object ToggleRemoteControl : AppEvent()
|
||||
|
||||
data class SetShowModal(val modalType: AppViewState.ModalType) : AppEvent()
|
||||
|
||||
data object ToggleSelectAllTunnels : AppEvent()
|
||||
}
|
||||
|
||||
Binary file not shown.
|
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>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user