mirror of
https://github.com/wgtunnel/android.git
synced 2026-07-03 14:07:49 +02:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 47f619ff07 | |||
| 791b532d85 | |||
| 57d096ebb1 | |||
| cfb4f85ded | |||
| d330fa4c28 | |||
| a362327fa3 | |||
| 9c72390398 | |||
| d1d59aaf5c | |||
| 03fdb82c24 | |||
| 4355e2e9ce | |||
| d7b4fbecb9 | |||
| 7fee0b3768 | |||
| bd76ee5392 | |||
| 911ed140e0 | |||
| a9d7648425 | |||
| 230f505806 | |||
| e58dad00ea | |||
| 8ddf5cf537 | |||
| d86fa782cc | |||
| fe7b9072d6 | |||
| 9895ed1061 | |||
| 34066ea182 | |||
| b99b116fdb | |||
| 9d42e7299b | |||
| b782cdeb35 | |||
| e40515c138 | |||
| d62df80682 | |||
| 71284b5a9c |
@@ -1,4 +1,4 @@
|
|||||||
name: Issue Updates Workflow
|
name: on-issue
|
||||||
|
|
||||||
on:
|
on:
|
||||||
issues:
|
issues:
|
||||||
@@ -7,8 +7,8 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
build:
|
on-issue:
|
||||||
name: Build
|
name: On new issue
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Send Telegram Message
|
- name: Send Telegram Message
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
name: Release Updates Workflow
|
name: on-publish
|
||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
@@ -7,8 +7,8 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
build:
|
on-publish:
|
||||||
name: Build
|
name: On publish
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Send Telegram Message
|
- name: Send Telegram Message
|
||||||
@@ -2,7 +2,7 @@ name: release-android
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "4 3 * * *"
|
- cron: "4 3 * * *"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
track:
|
track:
|
||||||
@@ -14,7 +14,7 @@ on:
|
|||||||
- alpha
|
- alpha
|
||||||
- beta
|
- beta
|
||||||
- production
|
- production
|
||||||
default: alpha
|
default: none
|
||||||
required: true
|
required: true
|
||||||
release_type:
|
release_type:
|
||||||
type: choice
|
type: choice
|
||||||
@@ -30,13 +30,30 @@ on:
|
|||||||
description: "Tag name for release"
|
description: "Tag name for release"
|
||||||
required: false
|
required: false
|
||||||
default: nightly
|
default: nightly
|
||||||
|
workflow_call:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
check_date:
|
||||||
name: Build Signed APK
|
runs-on: ubuntu-latest
|
||||||
if: ${{ inputs.release_type != 'none' }}
|
name: Check latest commit
|
||||||
|
outputs:
|
||||||
|
should_run: ${{ steps.should_run.outputs.should_run }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: print latest_commit
|
||||||
|
run: echo ${{ github.sha }}
|
||||||
|
- id: should_run
|
||||||
|
continue-on-error: true
|
||||||
|
name: check latest commit is less than a day
|
||||||
|
if: ${{ github.event_name == 'schedule' }}
|
||||||
|
run: test -z $(git rev-list --after="23 hours" ${{ github.sha }}) && echo "::set-output name=should_run::false"
|
||||||
|
build:
|
||||||
|
needs: check_date
|
||||||
|
if: |
|
||||||
|
github.event_name != 'schedule' ||
|
||||||
|
(needs.check_date.outputs.should_run == 'true' && github.event_name == 'schedule')
|
||||||
|
name: Build Signed APK
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
env:
|
env:
|
||||||
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
|
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
|
||||||
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
||||||
@@ -110,9 +127,24 @@ jobs:
|
|||||||
version_code=$(grep "VERSION_CODE" buildSrc/src/main/kotlin/Constants.kt | awk '{print $5}' | tr -d '\n')
|
version_code=$(grep "VERSION_CODE" buildSrc/src/main/kotlin/Constants.kt | awk '{print $5}' | tr -d '\n')
|
||||||
echo "VERSION_CODE=$version_code" >> $GITHUB_ENV
|
echo "VERSION_CODE=$version_code" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Commit and push versionCode changes
|
||||||
|
if: ${{ inputs.release_type == '' || inputs.release_type == 'nightly' || inputs.release_type == 'prerelease' }}
|
||||||
|
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"
|
||||||
|
|
||||||
|
- 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.GITHUB_TOKEN }}
|
||||||
|
branch: ${{ github.ref }}
|
||||||
|
|
||||||
# Save the APK after the Build job is complete to publish it as a Github release in the next job
|
# Save the APK after the Build job is complete to publish it as a Github release in the next job
|
||||||
- name: Upload APK
|
- name: Upload APK
|
||||||
uses: actions/upload-artifact@v4.3.6
|
uses: actions/upload-artifact@v4.4.0
|
||||||
with:
|
with:
|
||||||
name: wgtunnel
|
name: wgtunnel
|
||||||
path: ${{ env.APK_PATH }}
|
path: ${{ env.APK_PATH }}
|
||||||
|
|||||||
+32
-13
@@ -8,6 +8,21 @@ plugins {
|
|||||||
alias(libs.plugins.grgit)
|
alias(libs.plugins.grgit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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().toInt() + 1
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = Constants.APP_ID
|
namespace = Constants.APP_ID
|
||||||
compileSdk = Constants.TARGET_SDK
|
compileSdk = Constants.TARGET_SDK
|
||||||
@@ -20,7 +35,7 @@ android {
|
|||||||
applicationId = Constants.APP_ID
|
applicationId = Constants.APP_ID
|
||||||
minSdk = Constants.MIN_SDK
|
minSdk = Constants.MIN_SDK
|
||||||
targetSdk = Constants.TARGET_SDK
|
targetSdk = Constants.TARGET_SDK
|
||||||
versionCode = determineVersionCode()
|
versionCode = Constants.VERSION_CODE + versionCodeIncrement
|
||||||
versionName = determineVersionName()
|
versionName = determineVersionName()
|
||||||
|
|
||||||
ksp { arg("room.schemaLocation", "$projectDir/schemas") }
|
ksp { arg("room.schemaLocation", "$projectDir/schemas") }
|
||||||
@@ -157,8 +172,6 @@ dependencies {
|
|||||||
implementation(libs.androidx.navigation.compose)
|
implementation(libs.androidx.navigation.compose)
|
||||||
implementation(libs.androidx.hilt.navigation.compose)
|
implementation(libs.androidx.hilt.navigation.compose)
|
||||||
|
|
||||||
implementation(libs.zaneschepke.multifab)
|
|
||||||
|
|
||||||
// hilt
|
// hilt
|
||||||
implementation(libs.hilt.android)
|
implementation(libs.hilt.android)
|
||||||
ksp(libs.hilt.android.compiler)
|
ksp(libs.hilt.android.compiler)
|
||||||
@@ -199,16 +212,6 @@ dependencies {
|
|||||||
implementation(libs.androidx.core.splashscreen)
|
implementation(libs.androidx.core.splashscreen)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun determineVersionCode(): Int {
|
|
||||||
return with(getBuildTaskName().lowercase()) {
|
|
||||||
when {
|
|
||||||
contains(Constants.NIGHTLY) -> Constants.VERSION_CODE + Constants.NIGHTLY_CODE
|
|
||||||
contains(Constants.PRERELEASE) -> Constants.VERSION_CODE + Constants.PRERELEASE_CODE
|
|
||||||
else -> Constants.VERSION_CODE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun determineVersionName(): String {
|
fun determineVersionName(): String {
|
||||||
return with(getBuildTaskName().lowercase()) {
|
return with(getBuildTaskName().lowercase()) {
|
||||||
when {
|
when {
|
||||||
@@ -219,3 +222,19 @@ fun determineVersionName(): String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ data class GeneralState(
|
|||||||
val isLocationDisclosureShown: Boolean = LOCATION_DISCLOSURE_SHOWN_DEFAULT,
|
val isLocationDisclosureShown: Boolean = LOCATION_DISCLOSURE_SHOWN_DEFAULT,
|
||||||
val isBatteryOptimizationDisableShown: Boolean = BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT,
|
val isBatteryOptimizationDisableShown: Boolean = BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT,
|
||||||
val isPinLockEnabled: Boolean = PIN_LOCK_ENABLED_DEFAULT,
|
val isPinLockEnabled: Boolean = PIN_LOCK_ENABLED_DEFAULT,
|
||||||
val lastActiveTunnelId: Int? = null,
|
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
const val LOCATION_DISCLOSURE_SHOWN_DEFAULT = false
|
const val LOCATION_DISCLOSURE_SHOWN_DEFAULT = false
|
||||||
|
|||||||
@@ -58,6 +58,11 @@ data class TunnelConfig(
|
|||||||
)
|
)
|
||||||
var pingIp: String? = null,
|
var pingIp: String? = null,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
fun toAmConfig(): org.amnezia.awg.config.Config {
|
||||||
|
return configFromAmQuick(if (amQuick != "") amQuick else wgQuick)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun configFromWgQuick(wgQuick: String): Config {
|
fun configFromWgQuick(wgQuick: String): Config {
|
||||||
|
|||||||
+11
-21
@@ -2,57 +2,47 @@ package com.zaneschepke.wireguardautotunnel.data.repository
|
|||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.datastore.DataStoreManager
|
import com.zaneschepke.wireguardautotunnel.data.datastore.DataStoreManager
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.GeneralState
|
import com.zaneschepke.wireguardautotunnel.data.domain.GeneralState
|
||||||
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class DataStoreAppStateRepository(
|
class DataStoreAppStateRepository(
|
||||||
private val dataStoreManager: DataStoreManager,
|
private val dataStoreManager: DataStoreManager,
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
|
||||||
) :
|
) :
|
||||||
AppStateRepository {
|
AppStateRepository {
|
||||||
override suspend fun isLocationDisclosureShown(): Boolean {
|
override suspend fun isLocationDisclosureShown(): Boolean {
|
||||||
return withContext(ioDispatcher) {
|
return dataStoreManager.getFromStore(DataStoreManager.LOCATION_DISCLOSURE_SHOWN)
|
||||||
dataStoreManager.getFromStore(DataStoreManager.LOCATION_DISCLOSURE_SHOWN)
|
?: GeneralState.LOCATION_DISCLOSURE_SHOWN_DEFAULT
|
||||||
?: GeneralState.LOCATION_DISCLOSURE_SHOWN_DEFAULT
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun setLocationDisclosureShown(shown: Boolean) {
|
override suspend fun setLocationDisclosureShown(shown: Boolean) {
|
||||||
withContext(ioDispatcher) { dataStoreManager.saveToDataStore(DataStoreManager.LOCATION_DISCLOSURE_SHOWN, shown) }
|
dataStoreManager.saveToDataStore(DataStoreManager.LOCATION_DISCLOSURE_SHOWN, shown)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun isPinLockEnabled(): Boolean {
|
override suspend fun isPinLockEnabled(): Boolean {
|
||||||
return withContext(ioDispatcher) {
|
return dataStoreManager.getFromStore(DataStoreManager.IS_PIN_LOCK_ENABLED)
|
||||||
dataStoreManager.getFromStore(DataStoreManager.IS_PIN_LOCK_ENABLED)
|
?: GeneralState.PIN_LOCK_ENABLED_DEFAULT
|
||||||
?: GeneralState.PIN_LOCK_ENABLED_DEFAULT
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun setPinLockEnabled(enabled: Boolean) {
|
override suspend fun setPinLockEnabled(enabled: Boolean) {
|
||||||
withContext(ioDispatcher) { dataStoreManager.saveToDataStore(DataStoreManager.IS_PIN_LOCK_ENABLED, enabled) }
|
dataStoreManager.saveToDataStore(DataStoreManager.IS_PIN_LOCK_ENABLED, enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun isBatteryOptimizationDisableShown(): Boolean {
|
override suspend fun isBatteryOptimizationDisableShown(): Boolean {
|
||||||
return withContext(ioDispatcher) {
|
return dataStoreManager.getFromStore(DataStoreManager.BATTERY_OPTIMIZE_DISABLE_SHOWN)
|
||||||
dataStoreManager.getFromStore(DataStoreManager.BATTERY_OPTIMIZE_DISABLE_SHOWN)
|
?: GeneralState.BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT
|
||||||
?: GeneralState.BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun setBatteryOptimizationDisableShown(shown: Boolean) {
|
override suspend fun setBatteryOptimizationDisableShown(shown: Boolean) {
|
||||||
withContext(ioDispatcher) { dataStoreManager.saveToDataStore(DataStoreManager.BATTERY_OPTIMIZE_DISABLE_SHOWN, shown) }
|
dataStoreManager.saveToDataStore(DataStoreManager.BATTERY_OPTIMIZE_DISABLE_SHOWN, shown)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getCurrentSsid(): String? {
|
override suspend fun getCurrentSsid(): String? {
|
||||||
return withContext(ioDispatcher) { dataStoreManager.getFromStore(DataStoreManager.CURRENT_SSID) }
|
return dataStoreManager.getFromStore(DataStoreManager.CURRENT_SSID)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun setCurrentSsid(ssid: String) {
|
override suspend fun setCurrentSsid(ssid: String) {
|
||||||
withContext(ioDispatcher) { dataStoreManager.saveToDataStore(DataStoreManager.CURRENT_SSID, ssid) }
|
dataStoreManager.saveToDataStore(DataStoreManager.CURRENT_SSID, ssid)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val generalStateFlow: Flow<GeneralState> =
|
override val generalStateFlow: Flow<GeneralState> =
|
||||||
|
|||||||
@@ -72,8 +72,8 @@ class RepositoryModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideGeneralStateRepository(dataStoreManager: DataStoreManager, @IoDispatcher ioDispatcher: CoroutineDispatcher): AppStateRepository {
|
fun provideGeneralStateRepository(dataStoreManager: DataStoreManager): AppStateRepository {
|
||||||
return DataStoreAppStateRepository(dataStoreManager, ioDispatcher)
|
return DataStoreAppStateRepository(dataStoreManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|||||||
@@ -4,8 +4,11 @@ import android.content.Context
|
|||||||
import com.wireguard.android.backend.Backend
|
import com.wireguard.android.backend.Backend
|
||||||
import com.wireguard.android.backend.GoBackend
|
import com.wireguard.android.backend.GoBackend
|
||||||
import com.wireguard.android.backend.RootTunnelActionHandler
|
import com.wireguard.android.backend.RootTunnelActionHandler
|
||||||
|
import com.wireguard.android.backend.WgQuickBackend
|
||||||
import com.wireguard.android.util.RootShell
|
import com.wireguard.android.util.RootShell
|
||||||
|
import com.wireguard.android.util.ToolsInstaller
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.TunnelConfigRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.WireGuardTunnel
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.WireGuardTunnel
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
@@ -43,8 +46,8 @@ class TunnelModule {
|
|||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Kernel
|
@Kernel
|
||||||
fun provideKernelBackend(@ApplicationContext context: Context, rootShell: org.amnezia.awg.util.RootShell): org.amnezia.awg.backend.Backend {
|
fun provideKernelBackend(@ApplicationContext context: Context, rootShell: RootShell): Backend {
|
||||||
return org.amnezia.awg.backend.AwgQuickBackend(context, rootShell, org.amnezia.awg.util.ToolsInstaller(context, rootShell))
|
return WgQuickBackend(context, rootShell, ToolsInstaller(context, rootShell), RootTunnelActionHandler(rootShell))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@@ -57,15 +60,15 @@ class TunnelModule {
|
|||||||
@Singleton
|
@Singleton
|
||||||
fun provideVpnService(
|
fun provideVpnService(
|
||||||
amneziaBackend: Provider<org.amnezia.awg.backend.Backend>,
|
amneziaBackend: Provider<org.amnezia.awg.backend.Backend>,
|
||||||
@Userspace userspaceBackend: Provider<Backend>,
|
@Kernel kernelBackend: Provider<Backend>,
|
||||||
@Kernel kernelBackend: Provider<org.amnezia.awg.backend.Backend>,
|
|
||||||
appDataRepository: AppDataRepository,
|
appDataRepository: AppDataRepository,
|
||||||
|
tunnelConfigRepository: TunnelConfigRepository,
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
@ApplicationScope applicationScope: CoroutineScope,
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||||
): TunnelService {
|
): TunnelService {
|
||||||
return WireGuardTunnel(
|
return WireGuardTunnel(
|
||||||
amneziaBackend,
|
amneziaBackend,
|
||||||
userspaceBackend,
|
tunnelConfigRepository,
|
||||||
kernelBackend,
|
kernelBackend,
|
||||||
appDataRepository,
|
appDataRepository,
|
||||||
applicationScope,
|
applicationScope,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
|||||||
import com.zaneschepke.wireguardautotunnel.module.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.module.ApplicationScope
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.startTunnelBackground
|
import com.zaneschepke.wireguardautotunnel.util.extensions.startTunnelBackground
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@@ -33,7 +34,9 @@ class BootReceiver : BroadcastReceiver() {
|
|||||||
with(appDataRepository.settings.getSettings()) {
|
with(appDataRepository.settings.getSettings()) {
|
||||||
if (isRestoreOnBootEnabled) {
|
if (isRestoreOnBootEnabled) {
|
||||||
val activeTunnels = appDataRepository.tunnels.getActive()
|
val activeTunnels = appDataRepository.tunnels.getActive()
|
||||||
if (activeTunnels.isNotEmpty()) {
|
val tunState = tunnelService.get().vpnState.value.status
|
||||||
|
if (activeTunnels.isNotEmpty() && tunState != TunnelState.UP) {
|
||||||
|
Timber.i("Starting previously active tunnel")
|
||||||
context.startTunnelBackground(activeTunnels.first().id)
|
context.startTunnelBackground(activeTunnels.first().id)
|
||||||
}
|
}
|
||||||
if (isAutoTunnelEnabled) {
|
if (isAutoTunnelEnabled) {
|
||||||
|
|||||||
+48
-36
@@ -33,6 +33,7 @@ import kotlinx.coroutines.delay
|
|||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -71,7 +72,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
@MainImmediateDispatcher
|
@MainImmediateDispatcher
|
||||||
lateinit var mainImmediateDispatcher: CoroutineDispatcher
|
lateinit var mainImmediateDispatcher: CoroutineDispatcher
|
||||||
|
|
||||||
private val networkEventsFlow = MutableStateFlow(AutoTunnelState())
|
private val autoTunnelStateFlow = MutableStateFlow(AutoTunnelState())
|
||||||
|
|
||||||
private var wakeLock: PowerManager.WakeLock? = null
|
private var wakeLock: PowerManager.WakeLock? = null
|
||||||
|
|
||||||
@@ -132,6 +133,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
initWakeLock()
|
initWakeLock()
|
||||||
}
|
}
|
||||||
startSettingsJob()
|
startSettingsJob()
|
||||||
|
startVpnStateJob()
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
Timber.e(it)
|
Timber.e(it)
|
||||||
}
|
}
|
||||||
@@ -191,6 +193,10 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
watchForSettingsChanges()
|
watchForSettingsChanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun startVpnStateJob() = lifecycleScope.launch {
|
||||||
|
watchForVpnStateChanges()
|
||||||
|
}
|
||||||
|
|
||||||
private fun startWifiJob() = lifecycleScope.launch {
|
private fun startWifiJob() = lifecycleScope.launch {
|
||||||
watchForWifiConnectivityChanges()
|
watchForWifiConnectivityChanges()
|
||||||
}
|
}
|
||||||
@@ -218,7 +224,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
when (status) {
|
when (status) {
|
||||||
is NetworkStatus.Available -> {
|
is NetworkStatus.Available -> {
|
||||||
Timber.i("Gained Mobile data connection")
|
Timber.i("Gained Mobile data connection")
|
||||||
networkEventsFlow.update {
|
autoTunnelStateFlow.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
isMobileDataConnected = true,
|
isMobileDataConnected = true,
|
||||||
)
|
)
|
||||||
@@ -226,7 +232,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
is NetworkStatus.CapabilitiesChanged -> {
|
is NetworkStatus.CapabilitiesChanged -> {
|
||||||
networkEventsFlow.update {
|
autoTunnelStateFlow.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
isMobileDataConnected = true,
|
isMobileDataConnected = true,
|
||||||
)
|
)
|
||||||
@@ -235,7 +241,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
is NetworkStatus.Unavailable -> {
|
is NetworkStatus.Unavailable -> {
|
||||||
networkEventsFlow.update {
|
autoTunnelStateFlow.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
isMobileDataConnected = false,
|
isMobileDataConnected = false,
|
||||||
)
|
)
|
||||||
@@ -253,7 +259,8 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
runCatching {
|
runCatching {
|
||||||
do {
|
do {
|
||||||
val vpnState = tunnelService.get().vpnState.value
|
val vpnState = tunnelService.get().vpnState.value
|
||||||
if (vpnState.status == TunnelState.UP) {
|
val settings = appDataRepository.settings.getSettings()
|
||||||
|
if (vpnState.status == TunnelState.UP && !settings.isAutoTunnelPaused) {
|
||||||
if (vpnState.tunnelConfig != null) {
|
if (vpnState.tunnelConfig != null) {
|
||||||
val config = TunnelConfig.configFromWgQuick(vpnState.tunnelConfig.wgQuick)
|
val config = TunnelConfig.configFromWgQuick(vpnState.tunnelConfig.wgQuick)
|
||||||
val results = if (vpnState.tunnelConfig.pingIp != null) {
|
val results = if (vpnState.tunnelConfig.pingIp != null) {
|
||||||
@@ -283,16 +290,8 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSettings(settings: Settings) {
|
|
||||||
networkEventsFlow.update {
|
|
||||||
it.copy(
|
|
||||||
settings = settings,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onAutoTunnelPause(paused: Boolean) {
|
private fun onAutoTunnelPause(paused: Boolean) {
|
||||||
if (networkEventsFlow.value.settings.isAutoTunnelPaused
|
if (autoTunnelStateFlow.value.settings.isAutoTunnelPaused
|
||||||
!= paused
|
!= paused
|
||||||
) {
|
) {
|
||||||
when (paused) {
|
when (paused) {
|
||||||
@@ -306,19 +305,36 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
Timber.i("Starting settings watcher")
|
Timber.i("Starting settings watcher")
|
||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
appDataRepository.settings.getSettingsFlow().combine(
|
appDataRepository.settings.getSettingsFlow().combine(
|
||||||
appDataRepository.tunnels.getTunnelConfigsFlow(),
|
// ignore isActive changes to allow manual tunnel overrides
|
||||||
|
appDataRepository.tunnels.getTunnelConfigsFlow().distinctUntilChanged { old, new ->
|
||||||
|
old.map { it.isActive } != new.map { it.isActive }
|
||||||
|
},
|
||||||
) { settings, tunnels ->
|
) { settings, tunnels ->
|
||||||
val activeTunnel = tunnels.firstOrNull { it.isActive }
|
autoTunnelStateFlow.value.copy(
|
||||||
if (!settings.isPingEnabled) {
|
settings = settings,
|
||||||
settings.copy(isPingEnabled = activeTunnel?.isPingEnabled ?: false)
|
tunnels = tunnels,
|
||||||
} else {
|
)
|
||||||
settings
|
|
||||||
}
|
|
||||||
}.collect {
|
}.collect {
|
||||||
Timber.d("Settings change: $it")
|
onAutoTunnelPause(it.settings.isAutoTunnelPaused)
|
||||||
onAutoTunnelPause(it.isAutoTunnelPaused)
|
manageJobsBySettings(it.settings)
|
||||||
updateSettings(it)
|
autoTunnelStateFlow.emit(it)
|
||||||
manageJobsBySettings(it)
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun watchForVpnStateChanges() {
|
||||||
|
Timber.i("Starting vpn state watcher")
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
tunnelService.get().vpnState.collect { state ->
|
||||||
|
state.tunnelConfig?.let {
|
||||||
|
val settings = appDataRepository.settings.getSettings()
|
||||||
|
if (it.isPingEnabled && !settings.isPingEnabled) {
|
||||||
|
pingJob.onNotRunning { pingJob = startPingJob() }
|
||||||
|
}
|
||||||
|
if (!it.isPingEnabled && !settings.isPingEnabled) {
|
||||||
|
cancelAndResetPingJob()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -374,7 +390,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateEthernet(connected: Boolean) {
|
private fun updateEthernet(connected: Boolean) {
|
||||||
networkEventsFlow.update {
|
autoTunnelStateFlow.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
isEthernetConnected = connected,
|
isEthernetConnected = connected,
|
||||||
)
|
)
|
||||||
@@ -412,7 +428,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
when (status) {
|
when (status) {
|
||||||
is NetworkStatus.Available -> {
|
is NetworkStatus.Available -> {
|
||||||
Timber.i("Gained Wi-Fi connection")
|
Timber.i("Gained Wi-Fi connection")
|
||||||
networkEventsFlow.update {
|
autoTunnelStateFlow.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
isWifiConnected = true,
|
isWifiConnected = true,
|
||||||
)
|
)
|
||||||
@@ -421,7 +437,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
|
|
||||||
is NetworkStatus.CapabilitiesChanged -> {
|
is NetworkStatus.CapabilitiesChanged -> {
|
||||||
Timber.i("Wifi capabilities changed")
|
Timber.i("Wifi capabilities changed")
|
||||||
networkEventsFlow.update {
|
autoTunnelStateFlow.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
isWifiConnected = true,
|
isWifiConnected = true,
|
||||||
)
|
)
|
||||||
@@ -434,7 +450,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
Timber.i("Detected valid SSID")
|
Timber.i("Detected valid SSID")
|
||||||
}
|
}
|
||||||
appDataRepository.appState.setCurrentSsid(name)
|
appDataRepository.appState.setCurrentSsid(name)
|
||||||
networkEventsFlow.update {
|
autoTunnelStateFlow.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
currentNetworkSSID = name,
|
currentNetworkSSID = name,
|
||||||
)
|
)
|
||||||
@@ -443,7 +459,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
is NetworkStatus.Unavailable -> {
|
is NetworkStatus.Unavailable -> {
|
||||||
networkEventsFlow.update {
|
autoTunnelStateFlow.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
isWifiConnected = false,
|
isWifiConnected = false,
|
||||||
)
|
)
|
||||||
@@ -459,10 +475,6 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
return appDataRepository.tunnels.findByMobileDataTunnel().firstOrNull()
|
return appDataRepository.tunnels.findByMobileDataTunnel().firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getSsidTunnel(ssid: String): TunnelConfig? {
|
|
||||||
return appDataRepository.tunnels.findByTunnelNetworksName(ssid).firstOrNull()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isTunnelDown(): Boolean {
|
private fun isTunnelDown(): Boolean {
|
||||||
return tunnelService.get().vpnState.value.status == TunnelState.DOWN
|
return tunnelService.get().vpnState.value.status == TunnelState.DOWN
|
||||||
}
|
}
|
||||||
@@ -470,7 +482,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
private suspend fun handleNetworkEventChanges() {
|
private suspend fun handleNetworkEventChanges() {
|
||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
Timber.i("Starting network event watcher")
|
Timber.i("Starting network event watcher")
|
||||||
networkEventsFlow.collectLatest { watcherState ->
|
autoTunnelStateFlow.collectLatest { watcherState ->
|
||||||
val autoTunnel = "Auto-tunnel watcher"
|
val autoTunnel = "Auto-tunnel watcher"
|
||||||
if (!watcherState.settings.isAutoTunnelPaused) {
|
if (!watcherState.settings.isAutoTunnelPaused) {
|
||||||
// delay for rapid network state changes and then collect latest
|
// delay for rapid network state changes and then collect latest
|
||||||
@@ -516,7 +528,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
Timber.i(
|
Timber.i(
|
||||||
"$autoTunnel - tunnel on ssid not associated with current tunnel condition met",
|
"$autoTunnel - tunnel on ssid not associated with current tunnel condition met",
|
||||||
)
|
)
|
||||||
getSsidTunnel(watcherState.currentNetworkSSID)?.let {
|
watcherState.tunnels.firstOrNull { it.tunnelNetworks.isMatchingToWildcardList(watcherState.currentNetworkSSID) }?.let {
|
||||||
Timber.i("Found tunnel associated with this SSID, bringing tunnel up: ${it.name}")
|
Timber.i("Found tunnel associated with this SSID, bringing tunnel up: ${it.name}")
|
||||||
if (isTunnelDown() || activeTunnel?.id != it.id) {
|
if (isTunnelDown() || activeTunnel?.id != it.id) {
|
||||||
tunnelService.get().startTunnel(it)
|
tunnelService.get().startTunnel(it)
|
||||||
|
|||||||
+2
@@ -1,6 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.service.foreground
|
package com.zaneschepke.wireguardautotunnel.service.foreground
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.TunnelConfigs
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isMatchingToWildcardList
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isMatchingToWildcardList
|
||||||
|
|
||||||
data class AutoTunnelState(
|
data class AutoTunnelState(
|
||||||
@@ -9,6 +10,7 @@ data class AutoTunnelState(
|
|||||||
val isMobileDataConnected: Boolean = false,
|
val isMobileDataConnected: Boolean = false,
|
||||||
val currentNetworkSSID: String = "",
|
val currentNetworkSSID: String = "",
|
||||||
val settings: Settings = Settings(),
|
val settings: Settings = Settings(),
|
||||||
|
val tunnels: TunnelConfigs = emptyList(),
|
||||||
) {
|
) {
|
||||||
fun isEthernetConditionMet(): Boolean {
|
fun isEthernetConditionMet(): Boolean {
|
||||||
return (
|
return (
|
||||||
|
|||||||
+69
-39
@@ -2,25 +2,24 @@ package com.zaneschepke.wireguardautotunnel.service.tunnel
|
|||||||
|
|
||||||
import com.wireguard.android.backend.Backend
|
import com.wireguard.android.backend.Backend
|
||||||
import com.wireguard.android.backend.Tunnel.State
|
import com.wireguard.android.backend.Tunnel.State
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.TunnelConfigRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.module.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.module.ApplicationScope
|
||||||
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.module.Kernel
|
import com.zaneschepke.wireguardautotunnel.module.Kernel
|
||||||
import com.zaneschepke.wireguardautotunnel.module.Userspace
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.AmneziaStatistics
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.AmneziaStatistics
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.TunnelStatistics
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.WireGuardStatistics
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.WireGuardStatistics
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestTunnelTileServiceStateUpdate
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.amnezia.awg.backend.Tunnel
|
import org.amnezia.awg.backend.Tunnel
|
||||||
@@ -32,15 +31,30 @@ class WireGuardTunnel
|
|||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val amneziaBackend: Provider<org.amnezia.awg.backend.Backend>,
|
private val amneziaBackend: Provider<org.amnezia.awg.backend.Backend>,
|
||||||
@Userspace private val userspaceBackend: Provider<Backend>,
|
tunnelConfigRepository: TunnelConfigRepository,
|
||||||
@Kernel private val kernelBackend: Provider<org.amnezia.awg.backend.Backend>,
|
@Kernel private val kernelBackend: Provider<Backend>,
|
||||||
private val appDataRepository: AppDataRepository,
|
private val appDataRepository: AppDataRepository,
|
||||||
@ApplicationScope private val applicationScope: CoroutineScope,
|
@ApplicationScope private val applicationScope: CoroutineScope,
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||||
) : TunnelService {
|
) : TunnelService {
|
||||||
|
|
||||||
private val _vpnState = MutableStateFlow(VpnState())
|
private val _vpnState = MutableStateFlow(VpnState())
|
||||||
override val vpnState: StateFlow<VpnState> = _vpnState.asStateFlow()
|
override val vpnState: StateFlow<VpnState> = _vpnState.combine(
|
||||||
|
tunnelConfigRepository.getTunnelConfigsFlow(),
|
||||||
|
) {
|
||||||
|
vpnState, tunnels ->
|
||||||
|
vpnState.copy(
|
||||||
|
tunnelConfig = tunnels.firstOrNull { it.id == vpnState.tunnelConfig?.id },
|
||||||
|
)
|
||||||
|
}.stateIn(applicationScope, SharingStarted.Lazily, VpnState())
|
||||||
|
|
||||||
|
private var statsJob: Job? = null
|
||||||
|
|
||||||
|
private suspend fun backend(): Any {
|
||||||
|
val settings = appDataRepository.settings.getSettings()
|
||||||
|
if (settings.isKernelEnabled) return kernelBackend.get()
|
||||||
|
return amneziaBackend.get()
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun runningTunnelNames(): Set<String> {
|
override suspend fun runningTunnelNames(): Set<String> {
|
||||||
return when (val backend = backend()) {
|
return when (val backend = backend()) {
|
||||||
@@ -50,8 +64,6 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var statsJob: Job? = null
|
|
||||||
|
|
||||||
private suspend fun setState(tunnelConfig: TunnelConfig, tunnelState: TunnelState): Result<TunnelState> {
|
private suspend fun setState(tunnelConfig: TunnelConfig, tunnelState: TunnelState): Result<TunnelState> {
|
||||||
return runCatching {
|
return runCatching {
|
||||||
when (val backend = backend()) {
|
when (val backend = backend()) {
|
||||||
@@ -75,34 +87,26 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun backend(): Any {
|
|
||||||
val settings = appDataRepository.settings.getSettings()
|
|
||||||
if (settings.isKernelEnabled) return kernelBackend.get()
|
|
||||||
if (settings.isAmneziaEnabled) return amneziaBackend.get()
|
|
||||||
return userspaceBackend.get()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun startTunnel(tunnelConfig: TunnelConfig): Result<TunnelState> {
|
override suspend fun startTunnel(tunnelConfig: TunnelConfig): Result<TunnelState> {
|
||||||
return withContext(ioDispatcher) {
|
return withContext(ioDispatcher) {
|
||||||
if (_vpnState.value.status == TunnelState.UP) vpnState.value.tunnelConfig?.let { stopTunnel(it) }
|
onBeforeStart(tunnelConfig)
|
||||||
emitTunnelConfig(tunnelConfig)
|
|
||||||
setState(tunnelConfig, TunnelState.UP).onSuccess {
|
setState(tunnelConfig, TunnelState.UP).onSuccess {
|
||||||
emitTunnelState(it)
|
emitTunnelState(it)
|
||||||
appDataRepository.tunnels.save(tunnelConfig.copy(isActive = true))
|
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
Timber.e(it)
|
Timber.e(it)
|
||||||
|
onStartFailed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun stopTunnel(tunnelConfig: TunnelConfig): Result<TunnelState> {
|
override suspend fun stopTunnel(tunnelConfig: TunnelConfig): Result<TunnelState> {
|
||||||
return withContext(ioDispatcher) {
|
return withContext(ioDispatcher) {
|
||||||
|
onBeforeStop(tunnelConfig)
|
||||||
setState(tunnelConfig, TunnelState.DOWN).onSuccess {
|
setState(tunnelConfig, TunnelState.DOWN).onSuccess {
|
||||||
emitTunnelState(it)
|
emitTunnelState(it)
|
||||||
appDataRepository.tunnels.save(tunnelConfig.copy(isActive = false))
|
|
||||||
resetBackendStatistics()
|
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
Timber.e(it)
|
Timber.e(it)
|
||||||
|
onStopFailed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,7 +114,7 @@ constructor(
|
|||||||
// use this when we just want to bounce tunnel and not change tunnelConfig active state
|
// use this when we just want to bounce tunnel and not change tunnelConfig active state
|
||||||
override suspend fun bounceTunnel(tunnelConfig: TunnelConfig): Result<TunnelState> {
|
override suspend fun bounceTunnel(tunnelConfig: TunnelConfig): Result<TunnelState> {
|
||||||
toggleTunnel(tunnelConfig)
|
toggleTunnel(tunnelConfig)
|
||||||
delay(Constants.VPN_RESTART_DELAY)
|
delay(VPN_RESTART_DELAY)
|
||||||
return toggleTunnel(tunnelConfig)
|
return toggleTunnel(tunnelConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,6 +129,34 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun onStopFailed() {
|
||||||
|
_vpnState.value.tunnelConfig?.let {
|
||||||
|
appDataRepository.tunnels.save(it.copy(isActive = true))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun onStartFailed() {
|
||||||
|
_vpnState.value.tunnelConfig?.let {
|
||||||
|
appDataRepository.tunnels.save(it.copy(isActive = false))
|
||||||
|
}
|
||||||
|
cancelStatsJob()
|
||||||
|
resetBackendStatistics()
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun onBeforeStart(tunnelConfig: TunnelConfig) {
|
||||||
|
if (_vpnState.value.status == TunnelState.UP) vpnState.value.tunnelConfig?.let { stopTunnel(it) }
|
||||||
|
resetBackendStatistics()
|
||||||
|
appDataRepository.tunnels.save(tunnelConfig.copy(isActive = true))
|
||||||
|
emitVpnStateConfig(tunnelConfig)
|
||||||
|
startStatsJob()
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun onBeforeStop(tunnelConfig: TunnelConfig) {
|
||||||
|
cancelStatsJob()
|
||||||
|
resetBackendStatistics()
|
||||||
|
appDataRepository.tunnels.save(tunnelConfig.copy(isActive = false))
|
||||||
|
}
|
||||||
|
|
||||||
private fun emitTunnelState(state: TunnelState) {
|
private fun emitTunnelState(state: TunnelState) {
|
||||||
_vpnState.tryEmit(
|
_vpnState.tryEmit(
|
||||||
_vpnState.value.copy(
|
_vpnState.value.copy(
|
||||||
@@ -141,7 +173,7 @@ constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun emitTunnelConfig(tunnelConfig: TunnelConfig?) {
|
private fun emitVpnStateConfig(tunnelConfig: TunnelConfig) {
|
||||||
_vpnState.tryEmit(
|
_vpnState.tryEmit(
|
||||||
_vpnState.value.copy(
|
_vpnState.value.copy(
|
||||||
tunnelConfig = tunnelConfig,
|
tunnelConfig = tunnelConfig,
|
||||||
@@ -177,21 +209,9 @@ constructor(
|
|||||||
return _vpnState.value.tunnelConfig?.name ?: ""
|
return _vpnState.value.tunnelConfig?.name ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStateChange(newState: Tunnel.State) {
|
|
||||||
handleStateChange(TunnelState.from(newState))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleStateChange(state: TunnelState) {
|
|
||||||
emitTunnelState(state)
|
|
||||||
WireGuardAutoTunnel.instance.requestTunnelTileServiceStateUpdate()
|
|
||||||
when (state) {
|
|
||||||
TunnelState.UP -> startStatsJob()
|
|
||||||
else -> cancelStatsJob()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun startTunnelStatisticsJob() = applicationScope.launch(ioDispatcher) {
|
private fun startTunnelStatisticsJob() = applicationScope.launch(ioDispatcher) {
|
||||||
val backend = backend()
|
val backend = backend()
|
||||||
|
delay(STATS_START_DELAY)
|
||||||
while (true) {
|
while (true) {
|
||||||
when (backend) {
|
when (backend) {
|
||||||
is Backend -> emitBackendStatistics(
|
is Backend -> emitBackendStatistics(
|
||||||
@@ -205,11 +225,21 @@ constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delay(Constants.VPN_STATISTIC_CHECK_INTERVAL)
|
delay(VPN_STATISTIC_CHECK_INTERVAL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onStateChange(newState: Tunnel.State) {
|
||||||
|
emitTunnelState(TunnelState.from(newState))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onStateChange(state: State) {
|
override fun onStateChange(state: State) {
|
||||||
handleStateChange(TunnelState.from(state))
|
emitTunnelState(TunnelState.from(state))
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val STATS_START_DELAY = 5_000L
|
||||||
|
const val VPN_STATISTIC_CHECK_INTERVAL = 1_000L
|
||||||
|
const val VPN_RESTART_DELAY = 1_000L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,18 @@ import androidx.lifecycle.ViewModel
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.TunnelConfigs
|
import com.zaneschepke.wireguardautotunnel.util.extensions.TunnelConfigs
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.plus
|
||||||
import xyz.teamgravity.pin_lock_compose.PinManager
|
import xyz.teamgravity.pin_lock_compose.PinManager
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -21,8 +24,9 @@ class AppViewModel
|
|||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val appDataRepository: AppDataRepository,
|
private val appDataRepository: AppDataRepository,
|
||||||
private val tunnelService: TunnelService,
|
tunnelService: TunnelService,
|
||||||
val navHostController: NavHostController,
|
val navHostController: NavHostController,
|
||||||
|
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
private val _appUiState = MutableStateFlow(AppUiState())
|
private val _appUiState = MutableStateFlow(AppUiState())
|
||||||
@@ -42,12 +46,12 @@ constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
.stateIn(
|
.stateIn(
|
||||||
viewModelScope,
|
viewModelScope + ioDispatcher,
|
||||||
SharingStarted.WhileSubscribed(Constants.SUBSCRIPTION_TIMEOUT),
|
SharingStarted.WhileSubscribed(Constants.SUBSCRIPTION_TIMEOUT),
|
||||||
_appUiState.value,
|
_appUiState.value,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun setTunnels(tunnels: TunnelConfigs) = viewModelScope.launch {
|
fun setTunnels(tunnels: TunnelConfigs) = viewModelScope.launch(ioDispatcher) {
|
||||||
_appUiState.emit(
|
_appUiState.emit(
|
||||||
_appUiState.value.copy(
|
_appUiState.value.copy(
|
||||||
tunnels = tunnels,
|
tunnels = tunnels,
|
||||||
@@ -55,7 +59,7 @@ constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onPinLockDisabled() = viewModelScope.launch {
|
fun onPinLockDisabled() = viewModelScope.launch(ioDispatcher) {
|
||||||
PinManager.clearPin()
|
PinManager.clearPin()
|
||||||
appDataRepository.appState.setPinLockEnabled(false)
|
appDataRepository.appState.setPinLockEnabled(false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ import androidx.compose.animation.fadeOut
|
|||||||
import androidx.compose.foundation.focusable
|
import androidx.compose.foundation.focusable
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.rounded.Home
|
||||||
|
import androidx.compose.material.icons.rounded.QuestionMark
|
||||||
|
import androidx.compose.material.icons.rounded.Settings
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.SnackbarData
|
import androidx.compose.material3.SnackbarData
|
||||||
@@ -25,23 +29,25 @@ import androidx.compose.ui.focus.FocusRequester
|
|||||||
import androidx.compose.ui.focus.focusProperties
|
import androidx.compose.ui.focus.focusProperties
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.toArgb
|
import androidx.compose.ui.graphics.toArgb
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.navigation.NavType
|
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
import androidx.navigation.navArgument
|
import androidx.navigation.toRoute
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppStateRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppStateRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavBar
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavBar
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavItem
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.isCurrentRoute
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.CustomSnackBar
|
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.CustomSnackBar
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarControllerProvider
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarControllerProvider
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.config.ConfigScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.config.ConfigScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.ConfigType
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.options.OptionsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.options.OptionsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.pinlock.PinLockScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.pinlock.PinLockScreen
|
||||||
@@ -110,18 +116,31 @@ class MainActivity : AppCompatActivity() {
|
|||||||
Modifier
|
Modifier
|
||||||
.focusable()
|
.focusable()
|
||||||
.focusProperties {
|
.focusProperties {
|
||||||
when (navBackStackEntry?.destination?.route) {
|
if (navBackStackEntry?.isCurrentRoute(Route.Lock) == true) {
|
||||||
Screen.Lock.route -> Unit
|
Unit
|
||||||
else -> up = focusRequester
|
} else {
|
||||||
|
up = focusRequester
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
bottomBar = {
|
bottomBar = {
|
||||||
BottomNavBar(
|
BottomNavBar(
|
||||||
navController,
|
navController,
|
||||||
listOf(
|
listOf(
|
||||||
Screen.Main.navItem,
|
BottomNavItem(
|
||||||
Screen.Settings.navItem,
|
name = stringResource(R.string.tunnels),
|
||||||
Screen.Support.navItem,
|
route = Route.Main,
|
||||||
|
icon = Icons.Rounded.Home,
|
||||||
|
),
|
||||||
|
BottomNavItem(
|
||||||
|
name = stringResource(R.string.settings),
|
||||||
|
route = Route.Settings,
|
||||||
|
icon = Icons.Rounded.Settings,
|
||||||
|
),
|
||||||
|
BottomNavItem(
|
||||||
|
name = stringResource(R.string.support),
|
||||||
|
route = Route.Support,
|
||||||
|
icon = Icons.Rounded.QuestionMark,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -131,20 +150,16 @@ class MainActivity : AppCompatActivity() {
|
|||||||
navController,
|
navController,
|
||||||
enterTransition = { fadeIn(tween(Constants.TRANSITION_ANIMATION_TIME)) },
|
enterTransition = { fadeIn(tween(Constants.TRANSITION_ANIMATION_TIME)) },
|
||||||
exitTransition = { fadeOut(tween(Constants.TRANSITION_ANIMATION_TIME)) },
|
exitTransition = { fadeOut(tween(Constants.TRANSITION_ANIMATION_TIME)) },
|
||||||
startDestination = (if (isPinLockEnabled == true) Screen.Lock.route else Screen.Main.route),
|
startDestination = (if (isPinLockEnabled == true) Route.Lock else Route.Main),
|
||||||
) {
|
) {
|
||||||
composable(
|
composable<Route.Main> {
|
||||||
Screen.Main.route,
|
|
||||||
) {
|
|
||||||
MainScreen(
|
MainScreen(
|
||||||
focusRequester = focusRequester,
|
focusRequester = focusRequester,
|
||||||
uiState = appUiState,
|
uiState = appUiState,
|
||||||
navController = navController,
|
navController = navController,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
composable(
|
composable<Route.Settings> {
|
||||||
Screen.Settings.route,
|
|
||||||
) {
|
|
||||||
SettingsScreen(
|
SettingsScreen(
|
||||||
appViewModel = appViewModel,
|
appViewModel = appViewModel,
|
||||||
uiState = appUiState,
|
uiState = appUiState,
|
||||||
@@ -152,58 +167,33 @@ class MainActivity : AppCompatActivity() {
|
|||||||
focusRequester = focusRequester,
|
focusRequester = focusRequester,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
composable(
|
composable<Route.Support> {
|
||||||
Screen.Support.route,
|
|
||||||
) {
|
|
||||||
SupportScreen(
|
SupportScreen(
|
||||||
focusRequester = focusRequester,
|
focusRequester = focusRequester,
|
||||||
navController = navController,
|
navController = navController,
|
||||||
appUiState = appUiState,
|
appUiState = appUiState,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
composable(Screen.Support.Logs.route) {
|
composable<Route.Logs> {
|
||||||
LogsScreen()
|
LogsScreen()
|
||||||
}
|
}
|
||||||
composable(
|
composable<Route.Config> {
|
||||||
"${Screen.Config.route}/{id}?configType={configType}",
|
val args = it.toRoute<Route.Config>()
|
||||||
arguments =
|
ConfigScreen(
|
||||||
listOf(
|
focusRequester = focusRequester,
|
||||||
navArgument("id") {
|
tunnelId = args.id,
|
||||||
type = NavType.StringType
|
)
|
||||||
defaultValue = "0"
|
|
||||||
},
|
|
||||||
navArgument("configType") {
|
|
||||||
type = NavType.StringType
|
|
||||||
defaultValue = ConfigType.WIREGUARD.name
|
|
||||||
},
|
|
||||||
),
|
|
||||||
) {
|
|
||||||
val id = it.arguments?.getString("id")
|
|
||||||
val configType =
|
|
||||||
ConfigType.valueOf(
|
|
||||||
it.arguments?.getString("configType") ?: ConfigType.WIREGUARD.name,
|
|
||||||
)
|
|
||||||
if (!id.isNullOrBlank()) {
|
|
||||||
ConfigScreen(
|
|
||||||
navController = navController,
|
|
||||||
tunnelId = id,
|
|
||||||
focusRequester = focusRequester,
|
|
||||||
configType = configType,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
composable("${Screen.Option.route}/{id}") {
|
composable<Route.Option> {
|
||||||
val id = it.arguments?.getString("id")
|
val args = it.toRoute<Route.Option>()
|
||||||
if (!id.isNullOrBlank()) {
|
OptionsScreen(
|
||||||
OptionsScreen(
|
navController = navController,
|
||||||
navController = navController,
|
tunnelId = args.id,
|
||||||
tunnelId = id.toInt(),
|
focusRequester = focusRequester,
|
||||||
focusRequester = focusRequester,
|
appUiState = appUiState,
|
||||||
appUiState = appUiState,
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
composable(Screen.Lock.route) {
|
composable<Route.Lock> {
|
||||||
PinLockScreen(
|
PinLockScreen(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
appViewModel = appViewModel,
|
appViewModel = appViewModel,
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
sealed class Route {
|
||||||
|
@Serializable
|
||||||
|
data object Support : Route()
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data object Settings : Route()
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data object Main : Route()
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class Option(
|
||||||
|
val id: Int,
|
||||||
|
) : Route()
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data object Lock : Route()
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class Config(
|
||||||
|
val id: Int,
|
||||||
|
) : Route()
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data object Logs : Route()
|
||||||
|
}
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui
|
|
||||||
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.rounded.Home
|
|
||||||
import androidx.compose.material.icons.rounded.QuestionMark
|
|
||||||
import androidx.compose.material.icons.rounded.Settings
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavItem
|
|
||||||
|
|
||||||
sealed class Screen(val route: String) {
|
|
||||||
data object Main : Screen("main") {
|
|
||||||
val navItem =
|
|
||||||
BottomNavItem(
|
|
||||||
name = WireGuardAutoTunnel.instance.getString(R.string.tunnels),
|
|
||||||
route = route,
|
|
||||||
icon = Icons.Rounded.Home,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
data object Settings : Screen("settings") {
|
|
||||||
val navItem =
|
|
||||||
BottomNavItem(
|
|
||||||
name = WireGuardAutoTunnel.instance.getString(R.string.settings),
|
|
||||||
route = route,
|
|
||||||
icon = Icons.Rounded.Settings,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
data object Support : Screen("support") {
|
|
||||||
val navItem =
|
|
||||||
BottomNavItem(
|
|
||||||
name = WireGuardAutoTunnel.instance.getString(R.string.support),
|
|
||||||
route = route,
|
|
||||||
icon = Icons.Rounded.QuestionMark,
|
|
||||||
)
|
|
||||||
|
|
||||||
data object Logs : Screen("support/logs")
|
|
||||||
}
|
|
||||||
|
|
||||||
data object Config : Screen("config")
|
|
||||||
|
|
||||||
data object Lock : Screen("lock")
|
|
||||||
|
|
||||||
data object Option : Screen("option")
|
|
||||||
}
|
|
||||||
+2
-2
@@ -18,7 +18,7 @@ fun ConfigurationToggle(
|
|||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
checked: Boolean,
|
checked: Boolean,
|
||||||
padding: Dp,
|
padding: Dp,
|
||||||
onCheckChanged: () -> Unit,
|
onCheckChanged: (checked: Boolean) -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
@@ -44,7 +44,7 @@ fun ConfigurationToggle(
|
|||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
checked = checked,
|
checked = checked,
|
||||||
onCheckedChange = { onCheckChanged() },
|
onCheckedChange = { onCheckChanged(it) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-13
@@ -3,12 +3,15 @@ package com.zaneschepke.wireguardautotunnel.ui.common.config
|
|||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.interaction.collectIsFocusedAsState
|
import androidx.compose.foundation.interaction.collectIsFocusedAsState
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.Save
|
import androidx.compose.material.icons.outlined.Save
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@@ -42,25 +45,31 @@ fun SubmitConfigurationTextBox(
|
|||||||
val isFocused by interactionSource.collectIsFocusedAsState()
|
val isFocused by interactionSource.collectIsFocusedAsState()
|
||||||
val keyboardController = LocalSoftwareKeyboardController.current
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
|
|
||||||
var stateValue by remember { mutableStateOf(value) }
|
var stateValue by remember { mutableStateOf(value ?: "") }
|
||||||
|
|
||||||
ConfigurationTextBox(
|
OutlinedTextField(
|
||||||
isError = isErrorValue(stateValue),
|
isError = isErrorValue(stateValue),
|
||||||
interactionSource = interactionSource,
|
|
||||||
value = stateValue ?: "",
|
|
||||||
onValueChange = {
|
|
||||||
stateValue = it
|
|
||||||
},
|
|
||||||
keyboardOptions = keyboardOptions,
|
|
||||||
label = label,
|
|
||||||
hint = hint,
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.focusRequester(focusRequester),
|
.focusRequester(focusRequester),
|
||||||
trailing = {
|
value = stateValue,
|
||||||
if (!stateValue.isNullOrBlank() && !isErrorValue(stateValue) && isFocused) {
|
singleLine = true,
|
||||||
|
interactionSource = interactionSource,
|
||||||
|
onValueChange = { stateValue = it },
|
||||||
|
label = { Text(label) },
|
||||||
|
maxLines = 1,
|
||||||
|
placeholder = { Text(hint) },
|
||||||
|
keyboardOptions = keyboardOptions,
|
||||||
|
keyboardActions = KeyboardActions(
|
||||||
|
onDone = {
|
||||||
|
onSubmit(stateValue)
|
||||||
|
keyboardController?.hide()
|
||||||
|
},
|
||||||
|
),
|
||||||
|
trailingIcon = {
|
||||||
|
if (!isErrorValue(stateValue) && isFocused) {
|
||||||
IconButton(onClick = {
|
IconButton(onClick = {
|
||||||
onSubmit(stateValue!!)
|
onSubmit(stateValue)
|
||||||
keyboardController?.hide()
|
keyboardController?.hide()
|
||||||
focusManager.clearFocus()
|
focusManager.clearFocus()
|
||||||
}) {
|
}) {
|
||||||
|
|||||||
+9
-4
@@ -12,6 +12,8 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
|
import androidx.navigation.NavDestination.Companion.hasRoute
|
||||||
|
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
|
|
||||||
@@ -20,19 +22,22 @@ fun BottomNavBar(navController: NavController, bottomNavItems: List<BottomNavIte
|
|||||||
var showBottomBar by rememberSaveable { mutableStateOf(true) }
|
var showBottomBar by rememberSaveable { mutableStateOf(true) }
|
||||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||||
|
|
||||||
showBottomBar = bottomNavItems.firstOrNull { navBackStackEntry?.destination?.route?.contains(it.route) == true } != null
|
showBottomBar = bottomNavItems.firstOrNull {
|
||||||
|
navBackStackEntry?.destination?.hierarchy?.any { dest ->
|
||||||
|
bottomNavItems.map { dest.hasRoute(route = it.route::class) }.contains(true)
|
||||||
|
} == true
|
||||||
|
} != null
|
||||||
|
|
||||||
if (showBottomBar) {
|
if (showBottomBar) {
|
||||||
NavigationBar(
|
NavigationBar(
|
||||||
containerColor = MaterialTheme.colorScheme.surface,
|
containerColor = MaterialTheme.colorScheme.surface,
|
||||||
) {
|
) {
|
||||||
bottomNavItems.forEach { item ->
|
bottomNavItems.forEach { item ->
|
||||||
val selected = navBackStackEntry?.destination?.route?.contains(item.route) == true
|
val selected = navBackStackEntry.isCurrentRoute(item.route)
|
||||||
|
|
||||||
NavigationBarItem(
|
NavigationBarItem(
|
||||||
selected = selected,
|
selected = selected,
|
||||||
onClick = {
|
onClick = {
|
||||||
if (navBackStackEntry?.destination?.route == item.route) return@NavigationBarItem
|
if (selected) return@NavigationBarItem
|
||||||
navController.navigate(item.route) {
|
navController.navigate(item.route) {
|
||||||
// Pop up to the start destination of the graph to
|
// Pop up to the start destination of the graph to
|
||||||
// avoid building up a large stack of destinations
|
// avoid building up a large stack of destinations
|
||||||
|
|||||||
+2
-1
@@ -1,9 +1,10 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||||
|
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
|
|
||||||
data class BottomNavItem(
|
data class BottomNavItem(
|
||||||
val name: String,
|
val name: String,
|
||||||
val route: String,
|
val route: Route,
|
||||||
val icon: ImageVector,
|
val icon: ImageVector,
|
||||||
)
|
)
|
||||||
|
|||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||||
|
|
||||||
|
import androidx.navigation.NavBackStackEntry
|
||||||
|
import androidx.navigation.NavDestination.Companion.hasRoute
|
||||||
|
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
|
|
||||||
|
fun NavBackStackEntry?.isCurrentRoute(route: Route): Boolean {
|
||||||
|
return this?.destination?.hierarchy?.any {
|
||||||
|
it.hasRoute(route = route::class)
|
||||||
|
} == true
|
||||||
|
}
|
||||||
+56
-273
@@ -1,36 +1,27 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.config
|
package com.zaneschepke.wireguardautotunnel.ui.screens.config
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import androidx.compose.foundation.Image
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.focusGroup
|
import androidx.compose.foundation.focusGroup
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.IntrinsicSize
|
import androidx.compose.foundation.layout.IntrinsicSize
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxHeight
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
|
||||||
import androidx.compose.foundation.lazy.items
|
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.rounded.Android
|
|
||||||
import androidx.compose.material.icons.rounded.ContentCopy
|
import androidx.compose.material.icons.rounded.ContentCopy
|
||||||
import androidx.compose.material.icons.rounded.Delete
|
import androidx.compose.material.icons.rounded.Delete
|
||||||
import androidx.compose.material.icons.rounded.Refresh
|
import androidx.compose.material.icons.rounded.Refresh
|
||||||
import androidx.compose.material.icons.rounded.Save
|
import androidx.compose.material.icons.rounded.Save
|
||||||
import androidx.compose.material3.BasicAlertDialog
|
|
||||||
import androidx.compose.material3.Checkbox
|
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
||||||
import androidx.compose.material3.FabPosition
|
import androidx.compose.material3.FabPosition
|
||||||
import androidx.compose.material3.FloatingActionButton
|
import androidx.compose.material3.FloatingActionButton
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
@@ -39,10 +30,8 @@ import androidx.compose.material3.MaterialTheme
|
|||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Switch
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.material3.surfaceColorAtElevation
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
@@ -53,7 +42,6 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.focus.focusRequester
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.focus.onFocusChanged
|
|
||||||
import androidx.compose.ui.platform.ClipboardManager
|
import androidx.compose.ui.platform.ClipboardManager
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
import androidx.compose.ui.platform.LocalClipboardManager
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
@@ -67,34 +55,25 @@ import androidx.compose.ui.text.input.VisualTransformation
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.navigation.NavController
|
|
||||||
import com.google.accompanist.drawablepainter.DrawablePainter
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Screen
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.SearchBar
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationTextBox
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationTextBox
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationToggle
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt
|
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.screen.LoadingScreen
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.config.components.ApplicationSelectionDialog
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.ConfigType
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.ConfigType
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.getMessage
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
||||||
@OptIn(
|
|
||||||
ExperimentalMaterial3Api::class,
|
|
||||||
)
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ConfigScreen(
|
fun ConfigScreen(tunnelId: Int, focusRequester: FocusRequester) {
|
||||||
viewModel: ConfigViewModel = hiltViewModel(),
|
val viewModel = hiltViewModel<ConfigViewModel, ConfigViewModel.ConfigViewModelFactory> { factory ->
|
||||||
focusRequester: FocusRequester,
|
factory.create(tunnelId)
|
||||||
navController: NavController,
|
}
|
||||||
tunnelId: String,
|
|
||||||
configType: ConfigType,
|
|
||||||
) {
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val snackbar = SnackbarController.current
|
val snackbar = SnackbarController.current
|
||||||
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
||||||
@@ -102,12 +81,11 @@ fun ConfigScreen(
|
|||||||
var showApplicationsDialog by remember { mutableStateOf(false) }
|
var showApplicationsDialog by remember { mutableStateOf(false) }
|
||||||
var showAuthPrompt by remember { mutableStateOf(false) }
|
var showAuthPrompt by remember { mutableStateOf(false) }
|
||||||
var isAuthenticated by remember { mutableStateOf(false) }
|
var isAuthenticated by remember { mutableStateOf(false) }
|
||||||
|
var configType by remember { mutableStateOf(ConfigType.WIREGUARD) }
|
||||||
|
|
||||||
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
|
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
LaunchedEffect(Unit) { viewModel.init(tunnelId) }
|
LaunchedEffect(Unit) {
|
||||||
|
|
||||||
LaunchedEffect(uiState.loading) {
|
|
||||||
if (!uiState.loading && context.isRunningOnTv()) {
|
if (!uiState.loading && context.isRunningOnTv()) {
|
||||||
delay(Constants.FOCUS_REQUEST_DELAY)
|
delay(Constants.FOCUS_REQUEST_DELAY)
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
@@ -119,13 +97,12 @@ fun ConfigScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uiState.loading) {
|
LaunchedEffect(Unit) {
|
||||||
LoadingScreen()
|
delay(2_000L)
|
||||||
return
|
viewModel.cleanUpUninstalledApps()
|
||||||
}
|
}
|
||||||
|
|
||||||
val keyboardActions = KeyboardActions(onDone = { keyboardController?.hide() })
|
val keyboardActions = KeyboardActions(onDone = { keyboardController?.hide() })
|
||||||
|
|
||||||
val keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done)
|
val keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done)
|
||||||
|
|
||||||
val fillMaxHeight = .85f
|
val fillMaxHeight = .85f
|
||||||
@@ -174,182 +151,19 @@ fun ConfigScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (showApplicationsDialog) {
|
if (showApplicationsDialog) {
|
||||||
val sortedPackages =
|
ApplicationSelectionDialog(viewModel, uiState) {
|
||||||
remember(uiState.packages) {
|
showApplicationsDialog = false
|
||||||
uiState.packages.sortedBy { viewModel.getPackageLabel(it) }
|
|
||||||
}
|
|
||||||
BasicAlertDialog(onDismissRequest = { showApplicationsDialog = false }) {
|
|
||||||
Surface(
|
|
||||||
tonalElevation = 2.dp,
|
|
||||||
shadowElevation = 2.dp,
|
|
||||||
shape = RoundedCornerShape(12.dp),
|
|
||||||
color = MaterialTheme.colorScheme.surface,
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.fillMaxHeight(if (uiState.isAllApplicationsEnabled) 1 / 5f else 4 / 5f),
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.fillMaxWidth(),
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 20.dp, vertical = 7.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
) {
|
|
||||||
Text(stringResource(id = R.string.tunnel_all))
|
|
||||||
Switch(
|
|
||||||
checked = uiState.isAllApplicationsEnabled,
|
|
||||||
onCheckedChange = { viewModel.onAllApplicationsChange(it) },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (!uiState.isAllApplicationsEnabled) {
|
|
||||||
Row(
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 20.dp, vertical = 7.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
) {
|
|
||||||
Text(stringResource(id = R.string.include))
|
|
||||||
Checkbox(
|
|
||||||
checked = uiState.include,
|
|
||||||
onCheckedChange = {
|
|
||||||
viewModel.onIncludeChange(!uiState.include)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
) {
|
|
||||||
Text(stringResource(id = R.string.exclude))
|
|
||||||
Checkbox(
|
|
||||||
checked = !uiState.include,
|
|
||||||
onCheckedChange = {
|
|
||||||
viewModel.onIncludeChange(!uiState.include)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Row(
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 20.dp, vertical = 7.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
) {
|
|
||||||
SearchBar(viewModel::emitQueriedPackages)
|
|
||||||
}
|
|
||||||
Spacer(Modifier.padding(5.dp))
|
|
||||||
LazyColumn(
|
|
||||||
horizontalAlignment = Alignment.Start,
|
|
||||||
verticalArrangement = Arrangement.Top,
|
|
||||||
modifier = Modifier.fillMaxHeight(4 / 5f),
|
|
||||||
) {
|
|
||||||
items(sortedPackages, key = { it.packageName }) { pack ->
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(5.dp),
|
|
||||||
) {
|
|
||||||
Row(modifier = Modifier.fillMaxWidth(fillMaxWidth)) {
|
|
||||||
val drawable =
|
|
||||||
pack.applicationInfo?.loadIcon(context.packageManager)
|
|
||||||
if (drawable != null) {
|
|
||||||
Image(
|
|
||||||
painter = DrawablePainter(drawable),
|
|
||||||
stringResource(id = R.string.icon),
|
|
||||||
modifier = Modifier.size(50.dp, 50.dp),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
val icon = Icons.Rounded.Android
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
icon.name,
|
|
||||||
modifier = Modifier.size(50.dp, 50.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Text(
|
|
||||||
viewModel.getPackageLabel(pack),
|
|
||||||
modifier = Modifier.padding(5.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Checkbox(
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
checked =
|
|
||||||
(
|
|
||||||
uiState.checkedPackageNames.contains(
|
|
||||||
pack.packageName,
|
|
||||||
)
|
|
||||||
),
|
|
||||||
onCheckedChange = {
|
|
||||||
if (it) {
|
|
||||||
viewModel.onAddCheckedPackage(pack.packageName)
|
|
||||||
} else {
|
|
||||||
viewModel.onRemoveCheckedPackage(pack.packageName)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(top = 5.dp),
|
|
||||||
horizontalArrangement = Arrangement.Center,
|
|
||||||
) {
|
|
||||||
TextButton(onClick = { showApplicationsDialog = false }) {
|
|
||||||
Text(stringResource(R.string.done))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
floatingActionButtonPosition = FabPosition.End,
|
floatingActionButtonPosition = FabPosition.End,
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
val secondaryColor = MaterialTheme.colorScheme.secondary
|
|
||||||
val hoverColor = MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp)
|
|
||||||
var fobColor by remember { mutableStateOf(secondaryColor) }
|
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
modifier =
|
|
||||||
Modifier.onFocusChanged {
|
|
||||||
if (context.isRunningOnTv()) {
|
|
||||||
fobColor = if (it.isFocused) hoverColor else secondaryColor
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onClick = {
|
onClick = {
|
||||||
viewModel.onSaveAllChanges(configType).onSuccess {
|
viewModel.onSaveAllChanges()
|
||||||
snackbar.showMessage(
|
|
||||||
context.getString(R.string.config_changes_saved),
|
|
||||||
)
|
|
||||||
navController.navigate(Screen.Main.route)
|
|
||||||
}.onFailure {
|
|
||||||
snackbar.showMessage(it.getMessage(context))
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
containerColor = fobColor,
|
containerColor = MaterialTheme.colorScheme.primary,
|
||||||
shape = RoundedCornerShape(16.dp),
|
shape = RoundedCornerShape(16.dp),
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
@@ -399,9 +213,16 @@ fun ConfigScreen(
|
|||||||
stringResource(R.string.interface_),
|
stringResource(R.string.interface_),
|
||||||
padding = screenPadding,
|
padding = screenPadding,
|
||||||
)
|
)
|
||||||
|
ConfigurationToggle(
|
||||||
|
stringResource(id = R.string.show_amnezia_properties),
|
||||||
|
checked = configType == ConfigType.AMNEZIA,
|
||||||
|
padding = screenPadding,
|
||||||
|
onCheckChanged = { configType = if (it) ConfigType.AMNEZIA else ConfigType.WIREGUARD },
|
||||||
|
modifier = Modifier.focusRequester(focusRequester),
|
||||||
|
)
|
||||||
ConfigurationTextBox(
|
ConfigurationTextBox(
|
||||||
value = uiState.tunnelName,
|
value = uiState.tunnelName,
|
||||||
onValueChange = { value -> viewModel.onTunnelNameChange(value) },
|
onValueChange = viewModel::onTunnelNameChange,
|
||||||
keyboardActions = keyboardActions,
|
keyboardActions = keyboardActions,
|
||||||
label = stringResource(R.string.name),
|
label = stringResource(R.string.name),
|
||||||
hint = stringResource(R.string.tunnel_name).lowercase(),
|
hint = stringResource(R.string.tunnel_name).lowercase(),
|
||||||
@@ -417,12 +238,12 @@ fun ConfigScreen(
|
|||||||
.clickable { showAuthPrompt = true },
|
.clickable { showAuthPrompt = true },
|
||||||
value = uiState.interfaceProxy.privateKey,
|
value = uiState.interfaceProxy.privateKey,
|
||||||
visualTransformation =
|
visualTransformation =
|
||||||
if ((tunnelId == Constants.MANUAL_TUNNEL_CONFIG_ID) || isAuthenticated) {
|
if ((tunnelId == Constants.MANUAL_TUNNEL_CONFIG_ID.toInt()) || isAuthenticated) {
|
||||||
VisualTransformation.None
|
VisualTransformation.None
|
||||||
} else {
|
} else {
|
||||||
PasswordVisualTransformation()
|
PasswordVisualTransformation()
|
||||||
},
|
},
|
||||||
enabled = (tunnelId == Constants.MANUAL_TUNNEL_CONFIG_ID) || isAuthenticated,
|
enabled = (tunnelId == Constants.MANUAL_TUNNEL_CONFIG_ID.toInt()) || isAuthenticated,
|
||||||
onValueChange = { value -> viewModel.onPrivateKeyChange(value) },
|
onValueChange = { value -> viewModel.onPrivateKeyChange(value) },
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
IconButton(
|
IconButton(
|
||||||
@@ -472,31 +293,29 @@ fun ConfigScreen(
|
|||||||
keyboardOptions = keyboardOptions,
|
keyboardOptions = keyboardOptions,
|
||||||
keyboardActions = keyboardActions,
|
keyboardActions = keyboardActions,
|
||||||
)
|
)
|
||||||
Row(modifier = Modifier.fillMaxWidth()) {
|
ConfigurationTextBox(
|
||||||
ConfigurationTextBox(
|
value = uiState.interfaceProxy.addresses,
|
||||||
value = uiState.interfaceProxy.addresses,
|
onValueChange = viewModel::onAddressesChanged,
|
||||||
onValueChange = { value -> viewModel.onAddressesChanged(value) },
|
keyboardActions = keyboardActions,
|
||||||
keyboardActions = keyboardActions,
|
label = stringResource(R.string.addresses),
|
||||||
label = stringResource(R.string.addresses),
|
hint = stringResource(R.string.comma_separated_list),
|
||||||
hint = stringResource(R.string.comma_separated_list),
|
modifier =
|
||||||
modifier =
|
Modifier
|
||||||
Modifier
|
.fillMaxWidth()
|
||||||
.fillMaxWidth(3 / 5f)
|
.padding(end = 5.dp),
|
||||||
.padding(end = 5.dp),
|
)
|
||||||
)
|
ConfigurationTextBox(
|
||||||
ConfigurationTextBox(
|
value = uiState.interfaceProxy.listenPort,
|
||||||
value = uiState.interfaceProxy.listenPort,
|
onValueChange = viewModel::onListenPortChanged,
|
||||||
onValueChange = { value -> viewModel.onListenPortChanged(value) },
|
keyboardActions = keyboardActions,
|
||||||
keyboardActions = keyboardActions,
|
label = stringResource(R.string.listen_port),
|
||||||
label = stringResource(R.string.listen_port),
|
hint = stringResource(R.string.random),
|
||||||
hint = stringResource(R.string.random),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
modifier = Modifier.width(IntrinsicSize.Min),
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
Row(modifier = Modifier.fillMaxWidth()) {
|
Row(modifier = Modifier.fillMaxWidth()) {
|
||||||
ConfigurationTextBox(
|
ConfigurationTextBox(
|
||||||
value = uiState.interfaceProxy.dnsServers,
|
value = uiState.interfaceProxy.dnsServers,
|
||||||
onValueChange = { value -> viewModel.onDnsServersChanged(value) },
|
onValueChange = viewModel::onDnsServersChanged,
|
||||||
keyboardActions = keyboardActions,
|
keyboardActions = keyboardActions,
|
||||||
label = stringResource(R.string.dns_servers),
|
label = stringResource(R.string.dns_servers),
|
||||||
hint = stringResource(R.string.comma_separated_list),
|
hint = stringResource(R.string.comma_separated_list),
|
||||||
@@ -507,7 +326,7 @@ fun ConfigScreen(
|
|||||||
)
|
)
|
||||||
ConfigurationTextBox(
|
ConfigurationTextBox(
|
||||||
value = uiState.interfaceProxy.mtu,
|
value = uiState.interfaceProxy.mtu,
|
||||||
onValueChange = { value -> viewModel.onMtuChanged(value) },
|
onValueChange = viewModel::onMtuChanged,
|
||||||
keyboardActions = keyboardActions,
|
keyboardActions = keyboardActions,
|
||||||
label = stringResource(R.string.mtu),
|
label = stringResource(R.string.mtu),
|
||||||
hint = stringResource(R.string.auto),
|
hint = stringResource(R.string.auto),
|
||||||
@@ -517,10 +336,7 @@ fun ConfigScreen(
|
|||||||
if (configType == ConfigType.AMNEZIA) {
|
if (configType == ConfigType.AMNEZIA) {
|
||||||
ConfigurationTextBox(
|
ConfigurationTextBox(
|
||||||
value = uiState.interfaceProxy.junkPacketCount,
|
value = uiState.interfaceProxy.junkPacketCount,
|
||||||
onValueChange = {
|
onValueChange = viewModel::onJunkPacketCountChanged,
|
||||||
value ->
|
|
||||||
viewModel.onJunkPacketCountChanged(value)
|
|
||||||
},
|
|
||||||
keyboardActions = keyboardActions,
|
keyboardActions = keyboardActions,
|
||||||
label = stringResource(R.string.junk_packet_count),
|
label = stringResource(R.string.junk_packet_count),
|
||||||
hint = stringResource(R.string.junk_packet_count).lowercase(),
|
hint = stringResource(R.string.junk_packet_count).lowercase(),
|
||||||
@@ -531,11 +347,7 @@ fun ConfigScreen(
|
|||||||
)
|
)
|
||||||
ConfigurationTextBox(
|
ConfigurationTextBox(
|
||||||
value = uiState.interfaceProxy.junkPacketMinSize,
|
value = uiState.interfaceProxy.junkPacketMinSize,
|
||||||
onValueChange = { value ->
|
onValueChange = viewModel::onJunkPacketMinSizeChanged,
|
||||||
viewModel.onJunkPacketMinSizeChanged(
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
keyboardActions = keyboardActions,
|
keyboardActions = keyboardActions,
|
||||||
label = stringResource(R.string.junk_packet_minimum_size),
|
label = stringResource(R.string.junk_packet_minimum_size),
|
||||||
hint =
|
hint =
|
||||||
@@ -549,11 +361,7 @@ fun ConfigScreen(
|
|||||||
)
|
)
|
||||||
ConfigurationTextBox(
|
ConfigurationTextBox(
|
||||||
value = uiState.interfaceProxy.junkPacketMaxSize,
|
value = uiState.interfaceProxy.junkPacketMaxSize,
|
||||||
onValueChange = { value ->
|
onValueChange = viewModel::onJunkPacketMaxSizeChanged,
|
||||||
viewModel.onJunkPacketMaxSizeChanged(
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
keyboardActions = keyboardActions,
|
keyboardActions = keyboardActions,
|
||||||
label = stringResource(R.string.junk_packet_maximum_size),
|
label = stringResource(R.string.junk_packet_maximum_size),
|
||||||
hint =
|
hint =
|
||||||
@@ -567,11 +375,7 @@ fun ConfigScreen(
|
|||||||
)
|
)
|
||||||
ConfigurationTextBox(
|
ConfigurationTextBox(
|
||||||
value = uiState.interfaceProxy.initPacketJunkSize,
|
value = uiState.interfaceProxy.initPacketJunkSize,
|
||||||
onValueChange = { value ->
|
onValueChange = viewModel::onInitPacketJunkSizeChanged,
|
||||||
viewModel.onInitPacketJunkSizeChanged(
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
keyboardActions = keyboardActions,
|
keyboardActions = keyboardActions,
|
||||||
label = stringResource(R.string.init_packet_junk_size),
|
label = stringResource(R.string.init_packet_junk_size),
|
||||||
hint = stringResource(R.string.init_packet_junk_size).lowercase(),
|
hint = stringResource(R.string.init_packet_junk_size).lowercase(),
|
||||||
@@ -582,10 +386,7 @@ fun ConfigScreen(
|
|||||||
)
|
)
|
||||||
ConfigurationTextBox(
|
ConfigurationTextBox(
|
||||||
value = uiState.interfaceProxy.responsePacketJunkSize,
|
value = uiState.interfaceProxy.responsePacketJunkSize,
|
||||||
onValueChange = {
|
onValueChange = viewModel::onResponsePacketJunkSize,
|
||||||
value ->
|
|
||||||
viewModel.onResponsePacketJunkSize(value)
|
|
||||||
},
|
|
||||||
keyboardActions = keyboardActions,
|
keyboardActions = keyboardActions,
|
||||||
label = stringResource(R.string.response_packet_junk_size),
|
label = stringResource(R.string.response_packet_junk_size),
|
||||||
hint =
|
hint =
|
||||||
@@ -599,10 +400,7 @@ fun ConfigScreen(
|
|||||||
)
|
)
|
||||||
ConfigurationTextBox(
|
ConfigurationTextBox(
|
||||||
value = uiState.interfaceProxy.initPacketMagicHeader,
|
value = uiState.interfaceProxy.initPacketMagicHeader,
|
||||||
onValueChange = {
|
onValueChange = viewModel::onInitPacketMagicHeader,
|
||||||
value ->
|
|
||||||
viewModel.onInitPacketMagicHeader(value)
|
|
||||||
},
|
|
||||||
keyboardActions = keyboardActions,
|
keyboardActions = keyboardActions,
|
||||||
label = stringResource(R.string.init_packet_magic_header),
|
label = stringResource(R.string.init_packet_magic_header),
|
||||||
hint =
|
hint =
|
||||||
@@ -616,11 +414,7 @@ fun ConfigScreen(
|
|||||||
)
|
)
|
||||||
ConfigurationTextBox(
|
ConfigurationTextBox(
|
||||||
value = uiState.interfaceProxy.responsePacketMagicHeader,
|
value = uiState.interfaceProxy.responsePacketMagicHeader,
|
||||||
onValueChange = { value ->
|
onValueChange = viewModel::onResponsePacketMagicHeader,
|
||||||
viewModel.onResponsePacketMagicHeader(
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
keyboardActions = keyboardActions,
|
keyboardActions = keyboardActions,
|
||||||
label = stringResource(R.string.response_packet_magic_header),
|
label = stringResource(R.string.response_packet_magic_header),
|
||||||
hint =
|
hint =
|
||||||
@@ -634,11 +428,7 @@ fun ConfigScreen(
|
|||||||
)
|
)
|
||||||
ConfigurationTextBox(
|
ConfigurationTextBox(
|
||||||
value = uiState.interfaceProxy.underloadPacketMagicHeader,
|
value = uiState.interfaceProxy.underloadPacketMagicHeader,
|
||||||
onValueChange = { value ->
|
onValueChange = viewModel::onUnderloadPacketMagicHeader,
|
||||||
viewModel.onUnderloadPacketMagicHeader(
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
keyboardActions = keyboardActions,
|
keyboardActions = keyboardActions,
|
||||||
label = stringResource(R.string.underload_packet_magic_header),
|
label = stringResource(R.string.underload_packet_magic_header),
|
||||||
hint =
|
hint =
|
||||||
@@ -652,11 +442,7 @@ fun ConfigScreen(
|
|||||||
)
|
)
|
||||||
ConfigurationTextBox(
|
ConfigurationTextBox(
|
||||||
value = uiState.interfaceProxy.transportPacketMagicHeader,
|
value = uiState.interfaceProxy.transportPacketMagicHeader,
|
||||||
onValueChange = { value ->
|
onValueChange = viewModel::onTransportPacketMagicHeader,
|
||||||
viewModel.onTransportPacketMagicHeader(
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
keyboardActions = keyboardActions,
|
keyboardActions = keyboardActions,
|
||||||
label = stringResource(R.string.transport_packet_magic_header),
|
label = stringResource(R.string.transport_packet_magic_header),
|
||||||
hint =
|
hint =
|
||||||
@@ -814,9 +600,6 @@ fun ConfigScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (context.isRunningOnTv()) {
|
|
||||||
Spacer(modifier = Modifier.weight(.17f))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-2
@@ -15,7 +15,7 @@ data class ConfigUiState(
|
|||||||
val isAllApplicationsEnabled: Boolean = false,
|
val isAllApplicationsEnabled: Boolean = false,
|
||||||
val loading: Boolean = true,
|
val loading: Boolean = true,
|
||||||
val tunnel: TunnelConfig? = null,
|
val tunnel: TunnelConfig? = null,
|
||||||
val tunnelName: String = "",
|
var tunnelName: String = "",
|
||||||
val isAmneziaEnabled: Boolean = false,
|
val isAmneziaEnabled: Boolean = false,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -45,7 +45,6 @@ data class ConfigUiState(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun from(config: org.amnezia.awg.config.Config): ConfigUiState {
|
fun from(config: org.amnezia.awg.config.Config): ConfigUiState {
|
||||||
// TODO update with new values
|
|
||||||
val proxyPeers = config.peers.map { PeerProxy.from(it) }
|
val proxyPeers = config.peers.map { PeerProxy.from(it) }
|
||||||
val proxyInterface = InterfaceProxy.from(config.`interface`)
|
val proxyInterface = InterfaceProxy.from(config.`interface`)
|
||||||
var include = true
|
var include = true
|
||||||
@@ -69,5 +68,13 @@ data class ConfigUiState(
|
|||||||
isAllApplicationsEnabled,
|
isAllApplicationsEnabled,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun from(tunnel: TunnelConfig): ConfigUiState {
|
||||||
|
val config = tunnel.toAmConfig()
|
||||||
|
return from(config).copy(
|
||||||
|
tunnelName = tunnel.name,
|
||||||
|
tunnel = tunnel,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+216
-192
@@ -6,6 +6,7 @@ import android.content.pm.PackageManager
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import androidx.navigation.NavHostController
|
||||||
import com.wireguard.config.Config
|
import com.wireguard.config.Config
|
||||||
import com.wireguard.config.Interface
|
import com.wireguard.config.Interface
|
||||||
import com.wireguard.config.Peer
|
import com.wireguard.config.Peer
|
||||||
@@ -15,100 +16,116 @@ import com.zaneschepke.wireguardautotunnel.R
|
|||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.SettingsRepository
|
|
||||||
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.config.model.PeerProxy
|
import com.zaneschepke.wireguardautotunnel.ui.screens.config.model.PeerProxy
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.ConfigType
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
import com.zaneschepke.wireguardautotunnel.util.WgTunnelExceptions
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.removeAt
|
import com.zaneschepke.wireguardautotunnel.util.extensions.removeAt
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.update
|
import com.zaneschepke.wireguardautotunnel.util.extensions.update
|
||||||
|
import dagger.assisted.Assisted
|
||||||
|
import dagger.assisted.AssistedFactory
|
||||||
|
import dagger.assisted.AssistedInject
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.onStart
|
||||||
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.plus
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel(assistedFactory = ConfigViewModel.ConfigViewModelFactory::class)
|
||||||
class ConfigViewModel
|
class ConfigViewModel
|
||||||
@Inject
|
@AssistedInject
|
||||||
constructor(
|
constructor(
|
||||||
private val settingsRepository: SettingsRepository,
|
|
||||||
private val appDataRepository: AppDataRepository,
|
private val appDataRepository: AppDataRepository,
|
||||||
|
private val navController: NavHostController,
|
||||||
|
@Assisted val id: Int,
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
private val packageManager = WireGuardAutoTunnel.instance.packageManager
|
private val packageManager = WireGuardAutoTunnel.instance.packageManager
|
||||||
|
|
||||||
private val _uiState = MutableStateFlow(ConfigUiState())
|
private val _uiState = MutableStateFlow(ConfigUiState())
|
||||||
val uiState = _uiState.asStateFlow()
|
val uiState = _uiState.onStart {
|
||||||
|
appDataRepository.tunnels.getById(id)?.let {
|
||||||
fun init(tunnelId: String) = viewModelScope.launch(ioDispatcher) {
|
val packages = getQueriedPackages()
|
||||||
val packages = getQueriedPackages("")
|
_uiState.value = ConfigUiState.from(it).copy(
|
||||||
val state =
|
packages = packages,
|
||||||
if (tunnelId != Constants.MANUAL_TUNNEL_CONFIG_ID) {
|
)
|
||||||
val tunnelConfig =
|
}
|
||||||
appDataRepository.tunnels.getAll()
|
}.stateIn(
|
||||||
.firstOrNull { it.id.toString() == tunnelId }
|
viewModelScope + ioDispatcher,
|
||||||
val isAmneziaEnabled = settingsRepository.getSettings().isAmneziaEnabled
|
SharingStarted.WhileSubscribed(Constants.SUBSCRIPTION_TIMEOUT),
|
||||||
if (tunnelConfig != null) {
|
ConfigUiState(),
|
||||||
(
|
)
|
||||||
if (isAmneziaEnabled) {
|
|
||||||
val amConfig =
|
|
||||||
if (tunnelConfig.amQuick == "") tunnelConfig.wgQuick else tunnelConfig.amQuick
|
|
||||||
ConfigUiState.from(TunnelConfig.configFromAmQuick(amConfig))
|
|
||||||
} else {
|
|
||||||
ConfigUiState.from(
|
|
||||||
TunnelConfig.configFromWgQuick(tunnelConfig.wgQuick),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
).copy(
|
|
||||||
packages = packages,
|
|
||||||
loading = false,
|
|
||||||
tunnel = tunnelConfig,
|
|
||||||
tunnelName = tunnelConfig.name,
|
|
||||||
isAmneziaEnabled = isAmneziaEnabled,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
ConfigUiState(loading = false, packages = packages)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ConfigUiState(loading = false, packages = packages)
|
|
||||||
}
|
|
||||||
_uiState.value = state
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onTunnelNameChange(name: String) {
|
fun onTunnelNameChange(name: String) {
|
||||||
_uiState.value = _uiState.value.copy(tunnelName = name)
|
_uiState.update {
|
||||||
|
it.copy(tunnelName = name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onIncludeChange(include: Boolean) {
|
fun onIncludeChange(include: Boolean) {
|
||||||
_uiState.value = _uiState.value.copy(include = include)
|
_uiState.update {
|
||||||
|
it.copy(include = include)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun cleanUpUninstalledApps() = viewModelScope.launch(ioDispatcher) {
|
||||||
|
uiState.value.tunnel?.let {
|
||||||
|
val config = it.toAmConfig()
|
||||||
|
val packages = getQueriedPackages()
|
||||||
|
val packageSet = packages.map { pack -> pack.packageName }.toSet()
|
||||||
|
val includedApps = config.`interface`.includedApplications.toMutableList()
|
||||||
|
val excludedApps = config.`interface`.excludedApplications.toMutableList()
|
||||||
|
if (includedApps.isEmpty() && excludedApps.isEmpty()) return@launch
|
||||||
|
if (includedApps.retainAll(packageSet) || excludedApps.retainAll(packageSet)) {
|
||||||
|
Timber.i("Removing split tunnel package name that no longer exists on the device")
|
||||||
|
_uiState.update { state ->
|
||||||
|
state.copy(
|
||||||
|
checkedPackageNames = if (_uiState.value.include) includedApps else excludedApps,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val wgQuick = buildConfig().toWgQuickString(true)
|
||||||
|
val amQuick = buildAmConfig().toAwgQuickString(true)
|
||||||
|
saveConfig(
|
||||||
|
it.copy(
|
||||||
|
amQuick = amQuick,
|
||||||
|
wgQuick = wgQuick,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onAddCheckedPackage(packageName: String) {
|
fun onAddCheckedPackage(packageName: String) {
|
||||||
_uiState.value =
|
_uiState.update {
|
||||||
_uiState.value.copy(
|
it.copy(
|
||||||
checkedPackageNames = _uiState.value.checkedPackageNames + packageName,
|
checkedPackageNames = it.checkedPackageNames + packageName,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onAllApplicationsChange(isAllApplicationsEnabled: Boolean) {
|
fun onAllApplicationsChange(isAllApplicationsEnabled: Boolean) {
|
||||||
_uiState.value = _uiState.value.copy(isAllApplicationsEnabled = isAllApplicationsEnabled)
|
_uiState.update {
|
||||||
|
it.copy(isAllApplicationsEnabled = isAllApplicationsEnabled)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onRemoveCheckedPackage(packageName: String) {
|
fun onRemoveCheckedPackage(packageName: String) {
|
||||||
_uiState.value =
|
_uiState.update {
|
||||||
_uiState.value.copy(
|
it.copy(
|
||||||
checkedPackageNames = _uiState.value.checkedPackageNames - packageName,
|
checkedPackageNames = it.checkedPackageNames - packageName,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getQueriedPackages(query: String): List<PackageInfo> {
|
private fun getQueriedPackages(query: String = ""): List<PackageInfo> {
|
||||||
return getAllInternetCapablePackages().filter {
|
return getAllInternetCapablePackages().filter {
|
||||||
getPackageLabel(it).lowercase().contains(query.lowercase())
|
getPackageLabel(it).lowercase().contains(query.lowercase())
|
||||||
}
|
}
|
||||||
@@ -137,7 +154,9 @@ constructor(
|
|||||||
return _uiState.value.isAllApplicationsEnabled
|
return _uiState.value.isAllApplicationsEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveConfig(tunnelConfig: TunnelConfig) = viewModelScope.launch { appDataRepository.tunnels.save(tunnelConfig) }
|
private fun saveConfig(tunnelConfig: TunnelConfig) = viewModelScope.launch {
|
||||||
|
appDataRepository.tunnels.save(tunnelConfig)
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateTunnelConfig(tunnelConfig: TunnelConfig?) = viewModelScope.launch {
|
private fun updateTunnelConfig(tunnelConfig: TunnelConfig?) = viewModelScope.launch {
|
||||||
if (tunnelConfig != null) {
|
if (tunnelConfig != null) {
|
||||||
@@ -174,105 +193,113 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun emptyCheckedPackagesList() {
|
private fun emptyCheckedPackagesList() {
|
||||||
_uiState.value = _uiState.value.copy(checkedPackageNames = emptyList())
|
_uiState.update {
|
||||||
|
it.copy(checkedPackageNames = emptyList())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildInterfaceListFromProxyInterface(): Interface {
|
private fun buildInterfaceListFromProxyInterface(): Interface {
|
||||||
val builder = Interface.Builder()
|
val builder = Interface.Builder()
|
||||||
builder.parsePrivateKey(_uiState.value.interfaceProxy.privateKey.trim())
|
with(_uiState.value.interfaceProxy) {
|
||||||
builder.parseAddresses(_uiState.value.interfaceProxy.addresses.trim())
|
builder.parsePrivateKey(this.privateKey.trim())
|
||||||
if (_uiState.value.interfaceProxy.dnsServers.isNotEmpty()) {
|
builder.parseAddresses(this.addresses.trim())
|
||||||
builder.parseDnsServers(_uiState.value.interfaceProxy.dnsServers.trim())
|
if (this.dnsServers.isNotEmpty()) {
|
||||||
}
|
builder.parseDnsServers(this.dnsServers.trim())
|
||||||
if (_uiState.value.interfaceProxy.mtu.isNotEmpty()) {
|
}
|
||||||
builder.parseMtu(_uiState.value.interfaceProxy.mtu.trim())
|
if (this.mtu.isNotEmpty()) {
|
||||||
}
|
builder.parseMtu(this.mtu.trim())
|
||||||
if (_uiState.value.interfaceProxy.listenPort.isNotEmpty()) {
|
}
|
||||||
builder.parseListenPort(_uiState.value.interfaceProxy.listenPort.trim())
|
if (this.listenPort.isNotEmpty()) {
|
||||||
}
|
builder.parseListenPort(this.listenPort.trim())
|
||||||
if (isAllApplicationsEnabled()) emptyCheckedPackagesList()
|
}
|
||||||
if (_uiState.value.include) {
|
if (isAllApplicationsEnabled()) emptyCheckedPackagesList()
|
||||||
builder.includeApplications(
|
if (_uiState.value.include) {
|
||||||
_uiState.value.checkedPackageNames,
|
builder.includeApplications(
|
||||||
)
|
_uiState.value.checkedPackageNames,
|
||||||
}
|
)
|
||||||
if (!_uiState.value.include) {
|
}
|
||||||
builder.excludeApplications(
|
if (!_uiState.value.include) {
|
||||||
_uiState.value.checkedPackageNames,
|
builder.excludeApplications(
|
||||||
)
|
_uiState.value.checkedPackageNames,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build()
|
return builder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildAmInterfaceListFromProxyInterface(): org.amnezia.awg.config.Interface {
|
private fun buildAmInterfaceListFromProxyInterface(): org.amnezia.awg.config.Interface {
|
||||||
val builder = org.amnezia.awg.config.Interface.Builder()
|
val builder = org.amnezia.awg.config.Interface.Builder()
|
||||||
builder.parsePrivateKey(_uiState.value.interfaceProxy.privateKey.trim())
|
with(_uiState.value.interfaceProxy) {
|
||||||
builder.parseAddresses(_uiState.value.interfaceProxy.addresses.trim())
|
builder.parsePrivateKey(this.privateKey.trim())
|
||||||
if (_uiState.value.interfaceProxy.dnsServers.isNotEmpty()) {
|
builder.parseAddresses(this.addresses.trim())
|
||||||
builder.parseDnsServers(_uiState.value.interfaceProxy.dnsServers.trim())
|
if (this.dnsServers.isNotEmpty()) {
|
||||||
}
|
builder.parseDnsServers(this.dnsServers.trim())
|
||||||
if (_uiState.value.interfaceProxy.mtu.isNotEmpty()) {
|
}
|
||||||
builder.parseMtu(_uiState.value.interfaceProxy.mtu.trim())
|
if (this.mtu.isNotEmpty()) {
|
||||||
}
|
builder.parseMtu(this.mtu.trim())
|
||||||
if (_uiState.value.interfaceProxy.listenPort.isNotEmpty()) {
|
}
|
||||||
builder.parseListenPort(_uiState.value.interfaceProxy.listenPort.trim())
|
if (this.listenPort.isNotEmpty()) {
|
||||||
}
|
builder.parseListenPort(this.listenPort.trim())
|
||||||
if (isAllApplicationsEnabled()) emptyCheckedPackagesList()
|
}
|
||||||
if (_uiState.value.include) {
|
if (isAllApplicationsEnabled()) emptyCheckedPackagesList()
|
||||||
builder.includeApplications(
|
if (_uiState.value.include) {
|
||||||
_uiState.value.checkedPackageNames,
|
builder.includeApplications(
|
||||||
)
|
_uiState.value.checkedPackageNames,
|
||||||
}
|
)
|
||||||
if (!_uiState.value.include) {
|
}
|
||||||
builder.excludeApplications(
|
if (!_uiState.value.include) {
|
||||||
_uiState.value.checkedPackageNames,
|
builder.excludeApplications(
|
||||||
)
|
_uiState.value.checkedPackageNames,
|
||||||
}
|
)
|
||||||
if (_uiState.value.interfaceProxy.junkPacketCount.isNotEmpty()) {
|
}
|
||||||
builder.setJunkPacketCount(
|
if (this.junkPacketCount.isNotEmpty()) {
|
||||||
_uiState.value.interfaceProxy.junkPacketCount.trim().toInt(),
|
builder.setJunkPacketCount(
|
||||||
)
|
this.junkPacketCount.trim().toInt(),
|
||||||
}
|
)
|
||||||
if (_uiState.value.interfaceProxy.junkPacketMinSize.isNotEmpty()) {
|
}
|
||||||
builder.setJunkPacketMinSize(
|
if (this.junkPacketMinSize.isNotEmpty()) {
|
||||||
_uiState.value.interfaceProxy.junkPacketMinSize.trim().toInt(),
|
builder.setJunkPacketMinSize(
|
||||||
)
|
this.junkPacketMinSize.trim().toInt(),
|
||||||
}
|
)
|
||||||
if (_uiState.value.interfaceProxy.junkPacketMaxSize.isNotEmpty()) {
|
}
|
||||||
builder.setJunkPacketMaxSize(
|
if (this.junkPacketMaxSize.isNotEmpty()) {
|
||||||
_uiState.value.interfaceProxy.junkPacketMaxSize.trim().toInt(),
|
builder.setJunkPacketMaxSize(
|
||||||
)
|
this.junkPacketMaxSize.trim().toInt(),
|
||||||
}
|
)
|
||||||
if (_uiState.value.interfaceProxy.initPacketJunkSize.isNotEmpty()) {
|
}
|
||||||
builder.setInitPacketJunkSize(
|
if (this.initPacketJunkSize.isNotEmpty()) {
|
||||||
_uiState.value.interfaceProxy.initPacketJunkSize.trim().toInt(),
|
builder.setInitPacketJunkSize(
|
||||||
)
|
this.initPacketJunkSize.trim().toInt(),
|
||||||
}
|
)
|
||||||
if (_uiState.value.interfaceProxy.responsePacketJunkSize.isNotEmpty()) {
|
}
|
||||||
builder.setResponsePacketJunkSize(
|
if (this.responsePacketJunkSize.isNotEmpty()) {
|
||||||
_uiState.value.interfaceProxy.responsePacketJunkSize.trim().toInt(),
|
builder.setResponsePacketJunkSize(
|
||||||
)
|
this.responsePacketJunkSize.trim().toInt(),
|
||||||
}
|
)
|
||||||
if (_uiState.value.interfaceProxy.initPacketMagicHeader.isNotEmpty()) {
|
}
|
||||||
builder.setInitPacketMagicHeader(
|
if (this.initPacketMagicHeader.isNotEmpty()) {
|
||||||
_uiState.value.interfaceProxy.initPacketMagicHeader.trim().toLong(),
|
builder.setInitPacketMagicHeader(
|
||||||
)
|
this.initPacketMagicHeader.trim().toLong(),
|
||||||
}
|
)
|
||||||
if (_uiState.value.interfaceProxy.responsePacketMagicHeader.isNotEmpty()) {
|
}
|
||||||
builder.setResponsePacketMagicHeader(
|
if (this.responsePacketMagicHeader.isNotEmpty()) {
|
||||||
_uiState.value.interfaceProxy.responsePacketMagicHeader.trim().toLong(),
|
builder.setResponsePacketMagicHeader(
|
||||||
)
|
this.responsePacketMagicHeader.trim().toLong(),
|
||||||
}
|
)
|
||||||
if (_uiState.value.interfaceProxy.transportPacketMagicHeader.isNotEmpty()) {
|
}
|
||||||
builder.setTransportPacketMagicHeader(
|
if (this.transportPacketMagicHeader.isNotEmpty()) {
|
||||||
_uiState.value.interfaceProxy.transportPacketMagicHeader.trim().toLong(),
|
builder.setTransportPacketMagicHeader(
|
||||||
)
|
this.transportPacketMagicHeader.trim().toLong(),
|
||||||
}
|
)
|
||||||
if (_uiState.value.interfaceProxy.underloadPacketMagicHeader.isNotEmpty()) {
|
}
|
||||||
builder.setUnderloadPacketMagicHeader(
|
if (this.underloadPacketMagicHeader.isNotEmpty()) {
|
||||||
_uiState.value.interfaceProxy.underloadPacketMagicHeader.trim().toLong(),
|
builder.setUnderloadPacketMagicHeader(
|
||||||
)
|
this.underloadPacketMagicHeader.trim().toLong(),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build()
|
return builder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,41 +318,33 @@ constructor(
|
|||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onSaveAllChanges(configType: ConfigType): Result<Unit> {
|
fun onSaveAllChanges() = viewModelScope.launch {
|
||||||
return try {
|
kotlin.runCatching {
|
||||||
val wgQuick = buildConfig().toWgQuickString(true)
|
val wgQuick = buildConfig().toWgQuickString(true)
|
||||||
val amQuick =
|
val amQuick = buildAmConfig().toAwgQuickString(true)
|
||||||
if (configType == ConfigType.AMNEZIA) {
|
val tunnelConfig = uiState.value.tunnel?.copy(
|
||||||
buildAmConfig().toAwgQuickString(true)
|
name = _uiState.value.tunnelName,
|
||||||
} else {
|
amQuick = amQuick,
|
||||||
TunnelConfig.AM_QUICK_DEFAULT
|
wgQuick = wgQuick,
|
||||||
}
|
) ?: TunnelConfig(
|
||||||
val tunnelConfig =
|
name = _uiState.value.tunnelName,
|
||||||
when (uiState.value.tunnel) {
|
wgQuick = wgQuick,
|
||||||
null ->
|
amQuick = amQuick,
|
||||||
TunnelConfig(
|
)
|
||||||
name = _uiState.value.tunnelName,
|
|
||||||
wgQuick = wgQuick,
|
|
||||||
amQuick = amQuick,
|
|
||||||
)
|
|
||||||
|
|
||||||
else ->
|
|
||||||
uiState.value.tunnel!!.copy(
|
|
||||||
name = _uiState.value.tunnelName,
|
|
||||||
wgQuick = wgQuick,
|
|
||||||
amQuick = amQuick,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
updateTunnelConfig(tunnelConfig)
|
updateTunnelConfig(tunnelConfig)
|
||||||
Result.success(Unit)
|
SnackbarController.showMessage(
|
||||||
} catch (e: Exception) {
|
StringValue.StringResource(R.string.config_changes_saved),
|
||||||
Timber.e(e)
|
)
|
||||||
val message = e.message?.substringAfter(":", missingDelimiterValue = "")
|
navController.navigate(Route.Main)
|
||||||
val stringValue =
|
}.onFailure {
|
||||||
message?.let {
|
Timber.e(it)
|
||||||
StringValue.DynamicString(message)
|
val message = it.message?.substringAfter(":", missingDelimiterValue = "")
|
||||||
} ?: StringValue.StringResource(R.string.unknown_error)
|
val stringValue = if (message.isNullOrBlank()) {
|
||||||
Result.failure(WgTunnelExceptions.ConfigParseError(stringValue))
|
StringValue.StringResource(R.string.unknown_error)
|
||||||
|
} else {
|
||||||
|
StringValue.DynamicString(message)
|
||||||
|
}
|
||||||
|
SnackbarController.showMessage(stringValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,7 +427,7 @@ constructor(
|
|||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
interfaceProxy =
|
interfaceProxy =
|
||||||
_uiState.value.interfaceProxy.copy(
|
it.interfaceProxy.copy(
|
||||||
privateKey = keyPair.privateKey.toBase64(),
|
privateKey = keyPair.privateKey.toBase64(),
|
||||||
publicKey = keyPair.publicKey.toBase64(),
|
publicKey = keyPair.publicKey.toBase64(),
|
||||||
),
|
),
|
||||||
@@ -419,7 +438,7 @@ constructor(
|
|||||||
fun onAddressesChanged(value: String) {
|
fun onAddressesChanged(value: String) {
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(addresses = value),
|
interfaceProxy = it.interfaceProxy.copy(addresses = value),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -427,7 +446,7 @@ constructor(
|
|||||||
fun onListenPortChanged(value: String) {
|
fun onListenPortChanged(value: String) {
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(listenPort = value),
|
interfaceProxy = it.interfaceProxy.copy(listenPort = value),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -435,21 +454,21 @@ constructor(
|
|||||||
fun onDnsServersChanged(value: String) {
|
fun onDnsServersChanged(value: String) {
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(dnsServers = value),
|
interfaceProxy = it.interfaceProxy.copy(dnsServers = value),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMtuChanged(value: String) {
|
fun onMtuChanged(value: String) {
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(interfaceProxy = _uiState.value.interfaceProxy.copy(mtu = value))
|
it.copy(interfaceProxy = it.interfaceProxy.copy(mtu = value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onInterfacePublicKeyChange(value: String) {
|
private fun onInterfacePublicKeyChange(value: String) {
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(publicKey = value),
|
interfaceProxy = it.interfaceProxy.copy(publicKey = value),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -457,7 +476,7 @@ constructor(
|
|||||||
fun onPrivateKeyChange(value: String) {
|
fun onPrivateKeyChange(value: String) {
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(privateKey = value),
|
interfaceProxy = it.interfaceProxy.copy(privateKey = value),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (NumberUtils.isValidKey(value)) {
|
if (NumberUtils.isValidKey(value)) {
|
||||||
@@ -479,7 +498,7 @@ constructor(
|
|||||||
fun onJunkPacketCountChanged(value: String) {
|
fun onJunkPacketCountChanged(value: String) {
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(junkPacketCount = value),
|
interfaceProxy = it.interfaceProxy.copy(junkPacketCount = value),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -487,7 +506,7 @@ constructor(
|
|||||||
fun onJunkPacketMinSizeChanged(value: String) {
|
fun onJunkPacketMinSizeChanged(value: String) {
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(junkPacketMinSize = value),
|
interfaceProxy = it.interfaceProxy.copy(junkPacketMinSize = value),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -495,7 +514,7 @@ constructor(
|
|||||||
fun onJunkPacketMaxSizeChanged(value: String) {
|
fun onJunkPacketMaxSizeChanged(value: String) {
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(junkPacketMaxSize = value),
|
interfaceProxy = it.interfaceProxy.copy(junkPacketMaxSize = value),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -503,7 +522,7 @@ constructor(
|
|||||||
fun onInitPacketJunkSizeChanged(value: String) {
|
fun onInitPacketJunkSizeChanged(value: String) {
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(initPacketJunkSize = value),
|
interfaceProxy = it.interfaceProxy.copy(initPacketJunkSize = value),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -512,7 +531,7 @@ constructor(
|
|||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
interfaceProxy =
|
interfaceProxy =
|
||||||
_uiState.value.interfaceProxy.copy(
|
it.interfaceProxy.copy(
|
||||||
responsePacketJunkSize = value,
|
responsePacketJunkSize = value,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -523,7 +542,7 @@ constructor(
|
|||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
interfaceProxy =
|
interfaceProxy =
|
||||||
_uiState.value.interfaceProxy.copy(
|
it.interfaceProxy.copy(
|
||||||
initPacketMagicHeader = value,
|
initPacketMagicHeader = value,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -534,7 +553,7 @@ constructor(
|
|||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
interfaceProxy =
|
interfaceProxy =
|
||||||
_uiState.value.interfaceProxy.copy(
|
it.interfaceProxy.copy(
|
||||||
responsePacketMagicHeader = value,
|
responsePacketMagicHeader = value,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -545,7 +564,7 @@ constructor(
|
|||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
interfaceProxy =
|
interfaceProxy =
|
||||||
_uiState.value.interfaceProxy.copy(
|
it.interfaceProxy.copy(
|
||||||
transportPacketMagicHeader = value,
|
transportPacketMagicHeader = value,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -556,10 +575,15 @@ constructor(
|
|||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
interfaceProxy =
|
interfaceProxy =
|
||||||
_uiState.value.interfaceProxy.copy(
|
it.interfaceProxy.copy(
|
||||||
underloadPacketMagicHeader = value,
|
underloadPacketMagicHeader = value,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AssistedFactory
|
||||||
|
interface ConfigViewModelFactory {
|
||||||
|
fun create(id: Int): ConfigViewModel
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+199
@@ -0,0 +1,199 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.screens.config.components
|
||||||
|
|
||||||
|
import android.content.pm.PackageInfo
|
||||||
|
import androidx.compose.foundation.Image
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.rounded.Android
|
||||||
|
import androidx.compose.material3.BasicAlertDialog
|
||||||
|
import androidx.compose.material3.Checkbox
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Switch
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
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.unit.dp
|
||||||
|
import com.google.accompanist.drawablepainter.DrawablePainter
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.SearchBar
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.config.ConfigUiState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.config.ConfigViewModel
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun ApplicationSelectionDialog(viewModel: ConfigViewModel, uiState: ConfigUiState, onDismiss: () -> Unit) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val licenseComparator = compareBy<PackageInfo> { viewModel.getPackageLabel(it) }
|
||||||
|
|
||||||
|
val sortedPackages = remember(uiState.packages, licenseComparator) {
|
||||||
|
uiState.packages.sortedWith(licenseComparator)
|
||||||
|
}
|
||||||
|
BasicAlertDialog(
|
||||||
|
onDismissRequest = { onDismiss() },
|
||||||
|
) {
|
||||||
|
Surface(
|
||||||
|
tonalElevation = 2.dp,
|
||||||
|
shadowElevation = 2.dp,
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
color = MaterialTheme.colorScheme.surface,
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.fillMaxHeight(if (uiState.isAllApplicationsEnabled) 1 / 5f else 4 / 5f),
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 20.dp, vertical = 7.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
) {
|
||||||
|
Text(stringResource(id = R.string.tunnel_all))
|
||||||
|
Switch(
|
||||||
|
checked = uiState.isAllApplicationsEnabled,
|
||||||
|
onCheckedChange = viewModel::onAllApplicationsChange,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (!uiState.isAllApplicationsEnabled) {
|
||||||
|
Row(
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 20.dp, vertical = 7.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
) {
|
||||||
|
Text(stringResource(id = R.string.include))
|
||||||
|
Checkbox(
|
||||||
|
checked = uiState.include,
|
||||||
|
onCheckedChange = {
|
||||||
|
viewModel.onIncludeChange(!uiState.include)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
) {
|
||||||
|
Text(stringResource(id = R.string.exclude))
|
||||||
|
Checkbox(
|
||||||
|
checked = !uiState.include,
|
||||||
|
onCheckedChange = {
|
||||||
|
viewModel.onIncludeChange(!uiState.include)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Row(
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 20.dp, vertical = 7.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
) {
|
||||||
|
SearchBar(viewModel::emitQueriedPackages)
|
||||||
|
}
|
||||||
|
Spacer(Modifier.padding(5.dp))
|
||||||
|
LazyColumn(
|
||||||
|
horizontalAlignment = Alignment.Start,
|
||||||
|
verticalArrangement = Arrangement.Top,
|
||||||
|
modifier = Modifier.fillMaxHeight(19 / 22f),
|
||||||
|
) {
|
||||||
|
items(sortedPackages, key = { it.packageName }) { pack ->
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(5.dp).padding(end = 25.dp),
|
||||||
|
) {
|
||||||
|
Row(modifier = Modifier.fillMaxWidth().padding(start = 5.dp)) {
|
||||||
|
val drawable =
|
||||||
|
pack.applicationInfo?.loadIcon(context.packageManager)
|
||||||
|
val iconSize = 35.dp
|
||||||
|
if (drawable != null) {
|
||||||
|
Image(
|
||||||
|
painter = DrawablePainter(drawable),
|
||||||
|
stringResource(id = R.string.icon),
|
||||||
|
modifier = Modifier.size(iconSize),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
val icon = Icons.Rounded.Android
|
||||||
|
Icon(
|
||||||
|
icon,
|
||||||
|
icon.name,
|
||||||
|
modifier = Modifier.size(iconSize),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
viewModel.getPackageLabel(pack),
|
||||||
|
modifier = Modifier.padding(5.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Checkbox(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
checked =
|
||||||
|
(
|
||||||
|
uiState.checkedPackageNames.contains(
|
||||||
|
pack.packageName,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
onCheckedChange = {
|
||||||
|
if (it) {
|
||||||
|
viewModel.onAddCheckedPackage(pack.packageName)
|
||||||
|
} else {
|
||||||
|
viewModel.onRemoveCheckedPackage(pack.packageName)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(top = 5.dp),
|
||||||
|
horizontalArrangement = Arrangement.Center,
|
||||||
|
) {
|
||||||
|
TextButton(onClick = { onDismiss() }) {
|
||||||
|
Text(stringResource(R.string.done))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+31
-53
@@ -18,6 +18,7 @@ import androidx.compose.foundation.lazy.items
|
|||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.overscroll
|
import androidx.compose.foundation.overscroll
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Add
|
||||||
import androidx.compose.material.icons.rounded.Bolt
|
import androidx.compose.material.icons.rounded.Bolt
|
||||||
import androidx.compose.material.icons.rounded.Circle
|
import androidx.compose.material.icons.rounded.Circle
|
||||||
import androidx.compose.material.icons.rounded.CopyAll
|
import androidx.compose.material.icons.rounded.CopyAll
|
||||||
@@ -29,6 +30,7 @@ import androidx.compose.material.icons.rounded.Star
|
|||||||
import androidx.compose.material3.FabPosition
|
import androidx.compose.material3.FabPosition
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Switch
|
import androidx.compose.material3.Switch
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@@ -38,7 +40,6 @@ import androidx.compose.runtime.LaunchedEffect
|
|||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@@ -67,26 +68,24 @@ import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
|||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.HandshakeStatus
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.HandshakeStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Screen
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.RowListItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.RowListItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileImportLauncherForResult
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileImportLauncherForResult
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.GettingStartedLabel
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.GettingStartedLabel
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ScrollDismissMultiFab
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ScrollDismissFab
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.TunnelImportSheet
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.TunnelImportSheet
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.VpnDeniedDialog
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.VpnDeniedDialog
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.corn
|
import com.zaneschepke.wireguardautotunnel.ui.theme.corn
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.mint
|
import com.zaneschepke.wireguardautotunnel.ui.theme.mint
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.getMessage
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.handshakeStatus
|
import com.zaneschepke.wireguardautotunnel.util.extensions.handshakeStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.mapPeerStats
|
import com.zaneschepke.wireguardautotunnel.util.extensions.mapPeerStats
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.startTunnelBackground
|
import com.zaneschepke.wireguardautotunnel.util.extensions.startTunnelBackground
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
||||||
@@ -96,10 +95,8 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState,
|
|||||||
val haptic = LocalHapticFeedback.current
|
val haptic = LocalHapticFeedback.current
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val snackbar = SnackbarController.current
|
val snackbar = SnackbarController.current
|
||||||
val scope = rememberCoroutineScope()
|
|
||||||
|
|
||||||
var showBottomSheet by remember { mutableStateOf(false) }
|
var showBottomSheet by remember { mutableStateOf(false) }
|
||||||
var configType by remember { mutableStateOf(ConfigType.WIREGUARD) }
|
|
||||||
var showVpnPermissionDialog by remember { mutableStateOf(false) }
|
var showVpnPermissionDialog by remember { mutableStateOf(false) }
|
||||||
val isVisible = rememberSaveable { mutableStateOf(true) }
|
val isVisible = rememberSaveable { mutableStateOf(true) }
|
||||||
var showDeleteTunnelAlertDialog by remember { mutableStateOf(false) }
|
var showDeleteTunnelAlertDialog by remember { mutableStateOf(false) }
|
||||||
@@ -152,11 +149,7 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState,
|
|||||||
context.getString(R.string.error_no_file_explorer),
|
context.getString(R.string.error_no_file_explorer),
|
||||||
)
|
)
|
||||||
}, onData = { data ->
|
}, onData = { data ->
|
||||||
scope.launch {
|
viewModel.onTunnelFileSelected(data, context)
|
||||||
viewModel.onTunnelFileSelected(data, configType, context).onFailure {
|
|
||||||
snackbar.showMessage(it.getMessage(context))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
val scanLauncher =
|
val scanLauncher =
|
||||||
@@ -164,11 +157,7 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState,
|
|||||||
contract = ScanContract(),
|
contract = ScanContract(),
|
||||||
onResult = {
|
onResult = {
|
||||||
if (it.contents != null) {
|
if (it.contents != null) {
|
||||||
scope.launch {
|
viewModel.onTunnelQrResult(it.contents)
|
||||||
viewModel.onTunnelQrResult(it.contents, configType).onFailure { error ->
|
|
||||||
snackbar.showMessage(error.getMessage(context))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -227,9 +216,15 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState,
|
|||||||
},
|
},
|
||||||
floatingActionButtonPosition = FabPosition.End,
|
floatingActionButtonPosition = FabPosition.End,
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
ScrollDismissMultiFab(R.drawable.add, focusRequester, isVisible = isVisible.value, onFabItemClicked = {
|
ScrollDismissFab(icon = {
|
||||||
|
val icon = Icons.Filled.Add
|
||||||
|
Icon(
|
||||||
|
imageVector = icon,
|
||||||
|
contentDescription = icon.name,
|
||||||
|
tint = MaterialTheme.colorScheme.onPrimary,
|
||||||
|
)
|
||||||
|
}, focusRequester, isVisible = isVisible.value, onClick = {
|
||||||
showBottomSheet = true
|
showBottomSheet = true
|
||||||
configType = ConfigType.valueOf(it.value)
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
@@ -240,7 +235,7 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState,
|
|||||||
onQrClick = { launchQrScanner() },
|
onQrClick = { launchQrScanner() },
|
||||||
onManualImportClick = {
|
onManualImportClick = {
|
||||||
navController.navigate(
|
navController.navigate(
|
||||||
"${Screen.Config.route}/${Constants.MANUAL_TUNNEL_CONFIG_ID}?configType=$configType",
|
Route.Config(Constants.MANUAL_TUNNEL_CONFIG_ID),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -331,20 +326,22 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState,
|
|||||||
uiState.tunnels,
|
uiState.tunnels,
|
||||||
key = { tunnel -> tunnel.id },
|
key = { tunnel -> tunnel.id },
|
||||||
) { tunnel ->
|
) { tunnel ->
|
||||||
val isActive = uiState.tunnels.any { it.id == tunnel.id && it.isActive }
|
val isActive = uiState.tunnels.any {
|
||||||
|
it.id == tunnel.id &&
|
||||||
|
it.isActive
|
||||||
|
}
|
||||||
val leadingIconColor =
|
val leadingIconColor =
|
||||||
(
|
(
|
||||||
if (
|
if (
|
||||||
isActive
|
isActive && uiState.vpnState.statistics != null
|
||||||
) {
|
) {
|
||||||
uiState.vpnState.statistics
|
uiState.vpnState.statistics.mapPeerStats()
|
||||||
?.mapPeerStats()
|
.map { it.value?.handshakeStatus() }
|
||||||
?.map { it.value?.handshakeStatus() }
|
|
||||||
.let { statuses ->
|
.let { statuses ->
|
||||||
when {
|
when {
|
||||||
statuses?.all { it == HandshakeStatus.HEALTHY } == true -> mint
|
statuses.all { it == HandshakeStatus.HEALTHY } -> mint
|
||||||
statuses?.any { it == HandshakeStatus.STALE } == true -> corn
|
statuses.any { it == HandshakeStatus.STALE } -> corn
|
||||||
statuses?.all { it == HandshakeStatus.NOT_STARTED } == true ->
|
statuses.all { it == HandshakeStatus.NOT_STARTED } ->
|
||||||
Color.Gray
|
Color.Gray
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
@@ -384,15 +381,6 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState,
|
|||||||
},
|
},
|
||||||
text = tunnel.name,
|
text = tunnel.name,
|
||||||
onHold = {
|
onHold = {
|
||||||
if (
|
|
||||||
(uiState.vpnState.status == TunnelState.UP) &&
|
|
||||||
(tunnel.name == uiState.vpnState.tunnelConfig?.name)
|
|
||||||
) {
|
|
||||||
snackbar.showMessage(
|
|
||||||
context.getString(R.string.turn_off_tunnel),
|
|
||||||
)
|
|
||||||
return@RowListItem
|
|
||||||
}
|
|
||||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
selectedTunnel = tunnel
|
selectedTunnel = tunnel
|
||||||
},
|
},
|
||||||
@@ -419,16 +407,9 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState,
|
|||||||
Row {
|
Row {
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
if (
|
selectedTunnel?.let {
|
||||||
uiState.settings.isAutoTunnelEnabled &&
|
|
||||||
!uiState.settings.isAutoTunnelPaused
|
|
||||||
) {
|
|
||||||
snackbar.showMessage(
|
|
||||||
context.getString(R.string.turn_off_tunnel),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
navController.navigate(
|
navController.navigate(
|
||||||
"${Screen.Option.route}/${selectedTunnel?.id}",
|
Route.Option(it.id),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -447,6 +428,7 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState,
|
|||||||
Icon(icon, icon.name)
|
Icon(icon, icon.name)
|
||||||
}
|
}
|
||||||
IconButton(
|
IconButton(
|
||||||
|
enabled = !isActive,
|
||||||
modifier = Modifier.focusable(),
|
modifier = Modifier.focusable(),
|
||||||
onClick = { showDeleteTunnelAlertDialog = true },
|
onClick = { showDeleteTunnelAlertDialog = true },
|
||||||
) {
|
) {
|
||||||
@@ -471,14 +453,10 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState,
|
|||||||
Row {
|
Row {
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
if (uiState.settings.isAutoTunnelEnabled && !uiState.settings.isAutoTunnelPaused) {
|
selectedTunnel = tunnel
|
||||||
snackbar.showMessage(
|
selectedTunnel?.let {
|
||||||
context.getString(R.string.turn_off_auto),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
selectedTunnel = tunnel
|
|
||||||
navController.navigate(
|
navController.navigate(
|
||||||
"${Screen.Option.route}/${selectedTunnel?.id}",
|
Route.Option(it.id),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+81
-181
@@ -6,16 +6,19 @@ import android.net.Uri
|
|||||||
import android.provider.OpenableColumns
|
import android.provider.OpenableColumns
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.wireguard.config.Config
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.FileReadException
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.InvalidFileExtensionException
|
||||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||||
import com.zaneschepke.wireguardautotunnel.util.WgTunnelExceptions
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toWgQuickString
|
import com.zaneschepke.wireguardautotunnel.util.extensions.toWgQuickString
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
@@ -70,32 +73,17 @@ constructor(
|
|||||||
tunnelService.stopTunnel(tunnel)
|
tunnelService.stopTunnel(tunnel)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun validateConfigString(config: String, configType: ConfigType) {
|
private fun generateQrCodeDefaultName(config: String): String {
|
||||||
when (configType) {
|
|
||||||
ConfigType.AMNEZIA -> TunnelConfig.configFromAmQuick(config)
|
|
||||||
ConfigType.WIREGUARD -> TunnelConfig.configFromWgQuick(config)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun generateQrCodeDefaultName(config: String, configType: ConfigType): String {
|
|
||||||
return try {
|
return try {
|
||||||
when (configType) {
|
TunnelConfig.configFromAmQuick(config).peers[0].endpoint.get().host
|
||||||
ConfigType.AMNEZIA -> {
|
|
||||||
TunnelConfig.configFromAmQuick(config).peers[0].endpoint.get().host
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigType.WIREGUARD -> {
|
|
||||||
TunnelConfig.configFromWgQuick(config).peers[0].endpoint.get().host
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
NumberUtils.generateRandomTunnelName()
|
NumberUtils.generateRandomTunnelName()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateQrCodeTunnelName(config: String, configType: ConfigType): String {
|
private fun generateQrCodeTunnelName(config: String): String {
|
||||||
var defaultName = generateQrCodeDefaultName(config, configType)
|
var defaultName = generateQrCodeDefaultName(config)
|
||||||
val lines = config.lines().toMutableList()
|
val lines = config.lines().toMutableList()
|
||||||
val linesIterator = lines.iterator()
|
val linesIterator = lines.iterator()
|
||||||
while (linesIterator.hasNext()) {
|
while (linesIterator.hasNext()) {
|
||||||
@@ -108,37 +96,18 @@ constructor(
|
|||||||
return defaultName
|
return defaultName
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun onTunnelQrResult(result: String, configType: ConfigType): Result<Unit> {
|
fun onTunnelQrResult(result: String) = viewModelScope.launch(ioDispatcher) {
|
||||||
return withContext(ioDispatcher) {
|
kotlin.runCatching {
|
||||||
try {
|
val amConfig = TunnelConfig.configFromAmQuick(result)
|
||||||
validateConfigString(result, configType)
|
val amQuick = amConfig.toAwgQuickString(true)
|
||||||
val tunnelName =
|
val wgQuick = amConfig.toWgQuickString()
|
||||||
makeTunnelNameUnique(generateQrCodeTunnelName(result, configType))
|
|
||||||
val tunnelConfig =
|
|
||||||
when (configType) {
|
|
||||||
ConfigType.AMNEZIA -> {
|
|
||||||
TunnelConfig(
|
|
||||||
name = tunnelName,
|
|
||||||
amQuick = result,
|
|
||||||
wgQuick =
|
|
||||||
TunnelConfig.configFromAmQuick(
|
|
||||||
result,
|
|
||||||
).toWgQuickString(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigType.WIREGUARD ->
|
val tunnelName = makeTunnelNameUnique(generateQrCodeTunnelName(result))
|
||||||
TunnelConfig(
|
val tunnelConfig = TunnelConfig(name = tunnelName, wgQuick = wgQuick, amQuick = amQuick)
|
||||||
name = tunnelName,
|
saveTunnel(tunnelConfig)
|
||||||
wgQuick = result,
|
}.onFailure {
|
||||||
)
|
Timber.e(it)
|
||||||
}
|
SnackbarController.showMessage(StringValue.StringResource(R.string.error_invalid_code))
|
||||||
addTunnel(tunnelConfig)
|
|
||||||
Result.success(Unit)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.e(e)
|
|
||||||
Result.failure(WgTunnelExceptions.InvalidQrCode())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,130 +124,70 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveTunnelConfigFromStream(stream: InputStream, fileName: String, type: ConfigType) {
|
private suspend fun saveTunnelConfigFromStream(stream: InputStream, fileName: String) {
|
||||||
var amQuick: String? = null
|
val amConfig = stream.use { org.amnezia.awg.config.Config.parse(it) }
|
||||||
val wgQuick =
|
val tunnelName = makeTunnelNameUnique(getNameFromFileName(fileName))
|
||||||
stream.use {
|
saveTunnel(
|
||||||
when (type) {
|
TunnelConfig(
|
||||||
ConfigType.AMNEZIA -> {
|
name = tunnelName,
|
||||||
val config = org.amnezia.awg.config.Config.parse(it)
|
wgQuick = amConfig.toWgQuickString(),
|
||||||
amQuick = config.toAwgQuickString(true)
|
amQuick = amConfig.toAwgQuickString(true),
|
||||||
config.toWgQuickString()
|
),
|
||||||
}
|
)
|
||||||
|
|
||||||
ConfigType.WIREGUARD -> {
|
|
||||||
Config.parse(it).toWgQuickString(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
viewModelScope.launch {
|
|
||||||
val tunnelName = makeTunnelNameUnique(getNameFromFileName(fileName))
|
|
||||||
addTunnel(
|
|
||||||
TunnelConfig(
|
|
||||||
name = tunnelName,
|
|
||||||
wgQuick = wgQuick,
|
|
||||||
amQuick = amQuick ?: TunnelConfig.AM_QUICK_DEFAULT,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getInputStreamFromUri(uri: Uri, context: Context): InputStream? {
|
private fun getInputStreamFromUri(uri: Uri, context: Context): InputStream? {
|
||||||
return context.applicationContext.contentResolver.openInputStream(uri)
|
return context.applicationContext.contentResolver.openInputStream(uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun onTunnelFileSelected(uri: Uri, configType: ConfigType, context: Context): Result<Unit> {
|
fun onTunnelFileSelected(uri: Uri, context: Context) = viewModelScope.launch(ioDispatcher) {
|
||||||
return withContext(ioDispatcher) {
|
kotlin.runCatching {
|
||||||
try {
|
if (!isValidUriContentScheme(uri)) throw InvalidFileExtensionException
|
||||||
if (isValidUriContentScheme(uri)) {
|
val fileName = getFileName(context, uri)
|
||||||
val fileName = getFileName(context, uri)
|
when (getFileExtensionFromFileName(fileName)) {
|
||||||
return@withContext when (getFileExtensionFromFileName(fileName)) {
|
Constants.CONF_FILE_EXTENSION ->
|
||||||
Constants.CONF_FILE_EXTENSION ->
|
saveTunnelFromConfUri(fileName, uri, context)
|
||||||
saveTunnelFromConfUri(fileName, uri, configType, context)
|
Constants.ZIP_FILE_EXTENSION ->
|
||||||
|
saveTunnelsFromZipUri(
|
||||||
Constants.ZIP_FILE_EXTENSION ->
|
uri,
|
||||||
saveTunnelsFromZipUri(
|
context,
|
||||||
uri,
|
)
|
||||||
configType,
|
else -> throw InvalidFileExtensionException
|
||||||
context,
|
|
||||||
)
|
|
||||||
|
|
||||||
else -> Result.failure(WgTunnelExceptions.InvalidFileExtension())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Result.failure(WgTunnelExceptions.InvalidFileExtension())
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.e(e)
|
|
||||||
Result.failure(WgTunnelExceptions.FileReadFailed())
|
|
||||||
}
|
}
|
||||||
}
|
}.onFailure {
|
||||||
}
|
Timber.e(it)
|
||||||
|
if (it is InvalidFileExtensionException) {
|
||||||
private suspend fun saveTunnelsFromZipUri(uri: Uri, configType: ConfigType, context: Context): Result<Unit> {
|
SnackbarController.showMessage(StringValue.StringResource(R.string.error_file_extension))
|
||||||
return withContext(ioDispatcher) {
|
|
||||||
ZipInputStream(getInputStreamFromUri(uri, context)).use { zip ->
|
|
||||||
generateSequence { zip.nextEntry }
|
|
||||||
.filterNot {
|
|
||||||
it.isDirectory ||
|
|
||||||
getFileExtensionFromFileName(it.name) != Constants.CONF_FILE_EXTENSION
|
|
||||||
}
|
|
||||||
.forEach {
|
|
||||||
val name = getNameFromFileName(it.name)
|
|
||||||
withContext(viewModelScope.coroutineContext) {
|
|
||||||
try {
|
|
||||||
var amQuick: String? = null
|
|
||||||
val wgQuick =
|
|
||||||
when (configType) {
|
|
||||||
ConfigType.AMNEZIA -> {
|
|
||||||
val config =
|
|
||||||
org.amnezia.awg.config.Config.parse(
|
|
||||||
zip,
|
|
||||||
)
|
|
||||||
amQuick = config.toAwgQuickString(true)
|
|
||||||
config.toWgQuickString()
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigType.WIREGUARD -> {
|
|
||||||
Config.parse(zip).toWgQuickString(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addTunnel(
|
|
||||||
TunnelConfig(
|
|
||||||
name = makeTunnelNameUnique(name),
|
|
||||||
wgQuick = wgQuick,
|
|
||||||
amQuick = amQuick ?: TunnelConfig.AM_QUICK_DEFAULT,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
Result.success(Unit)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Result.failure(WgTunnelExceptions.FileReadFailed())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Result.success(Unit)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun saveTunnelFromConfUri(name: String, uri: Uri, configType: ConfigType, context: Context): Result<Unit> {
|
|
||||||
return withContext(ioDispatcher) {
|
|
||||||
val stream = getInputStreamFromUri(uri, context)
|
|
||||||
return@withContext if (stream != null) {
|
|
||||||
try {
|
|
||||||
saveTunnelConfigFromStream(stream, name, configType)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
return@withContext Result.failure(WgTunnelExceptions.ConfigParseError())
|
|
||||||
}
|
|
||||||
Result.success(Unit)
|
|
||||||
} else {
|
} else {
|
||||||
Result.failure(WgTunnelExceptions.FileReadFailed())
|
SnackbarController.showMessage(StringValue.StringResource(R.string.error_file_format))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addTunnel(tunnelConfig: TunnelConfig) = viewModelScope.launch {
|
private suspend fun saveTunnelsFromZipUri(uri: Uri, context: Context) {
|
||||||
saveTunnel(tunnelConfig)
|
ZipInputStream(getInputStreamFromUri(uri, context)).use { zip ->
|
||||||
|
generateSequence { zip.nextEntry }
|
||||||
|
.filterNot {
|
||||||
|
it.isDirectory ||
|
||||||
|
getFileExtensionFromFileName(it.name) != Constants.CONF_FILE_EXTENSION
|
||||||
|
}
|
||||||
|
.forEach { entry ->
|
||||||
|
val name = getNameFromFileName(entry.name)
|
||||||
|
val amConf = org.amnezia.awg.config.Config.parse(zip.bufferedReader())
|
||||||
|
saveTunnel(
|
||||||
|
TunnelConfig(
|
||||||
|
name = makeTunnelNameUnique(name),
|
||||||
|
wgQuick = amConf.toWgQuickString(),
|
||||||
|
amQuick = amConf.toAwgQuickString(true),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun saveTunnelFromConfUri(name: String, uri: Uri, context: Context) {
|
||||||
|
val stream = getInputStreamFromUri(uri, context) ?: throw FileReadException
|
||||||
|
saveTunnelConfigFromStream(stream, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pauseAutoTunneling() = viewModelScope.launch {
|
fun pauseAutoTunneling() = viewModelScope.launch {
|
||||||
@@ -300,32 +209,23 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getFileNameByCursor(context: Context, uri: Uri): String? {
|
private fun getFileNameByCursor(context: Context, uri: Uri): String? {
|
||||||
context.contentResolver.query(uri, null, null, null, null)?.use {
|
return context.contentResolver.query(uri, null, null, null, null)?.use {
|
||||||
return getDisplayNameByCursor(it)
|
getDisplayNameByCursor(it)
|
||||||
}
|
}
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDisplayNameColumnIndex(cursor: Cursor): Int? {
|
private fun getDisplayNameColumnIndex(cursor: Cursor): Int? {
|
||||||
val columnIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
|
val columnIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
|
||||||
return if (columnIndex != -1) {
|
if (columnIndex == -1) return null
|
||||||
return columnIndex
|
return columnIndex
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDisplayNameByCursor(cursor: Cursor): String? {
|
private fun getDisplayNameByCursor(cursor: Cursor): String? {
|
||||||
return if (cursor.moveToFirst()) {
|
val move = cursor.moveToFirst()
|
||||||
val index = getDisplayNameColumnIndex(cursor)
|
if (!move) return null
|
||||||
if (index != null) {
|
val index = getDisplayNameColumnIndex(cursor)
|
||||||
cursor.getString(index)
|
if (index == null) return index
|
||||||
} else {
|
return cursor.getString(index)
|
||||||
null
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isValidUriContentScheme(uri: Uri): Boolean {
|
private fun isValidUriContentScheme(uri: Uri): Boolean {
|
||||||
|
|||||||
+9
-80
@@ -1,41 +1,20 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main.components
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main.components
|
||||||
|
|
||||||
import androidx.annotation.DrawableRes
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.slideInVertically
|
import androidx.compose.animation.slideInVertically
|
||||||
import androidx.compose.animation.slideOutVertically
|
import androidx.compose.animation.slideOutVertically
|
||||||
import androidx.compose.foundation.focusGroup
|
import androidx.compose.foundation.focusGroup
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material3.FloatingActionButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.focus.focusRequester
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.iamageo.multifablibrary.FabIcon
|
|
||||||
import com.iamageo.multifablibrary.FabOption
|
|
||||||
import com.iamageo.multifablibrary.MultiFabItem
|
|
||||||
import com.iamageo.multifablibrary.MultiFloatingActionButton
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.ConfigType
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ScrollDismissMultiFab(
|
fun ScrollDismissFab(icon: @Composable () -> Unit, focusRequester: FocusRequester, isVisible: Boolean, onClick: () -> Unit) {
|
||||||
@DrawableRes res: Int,
|
|
||||||
focusRequester: FocusRequester,
|
|
||||||
isVisible: Boolean,
|
|
||||||
onFabItemClicked: (fabItem: MultiFabItem) -> Unit,
|
|
||||||
) {
|
|
||||||
// Nested scroll for control FAB
|
|
||||||
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
AnimatedVisibility(
|
AnimatedVisibility(
|
||||||
visible = isVisible,
|
visible = isVisible,
|
||||||
enter = slideInVertically(initialOffsetY = { it * 2 }),
|
enter = slideInVertically(initialOffsetY = { it * 2 }),
|
||||||
@@ -45,64 +24,14 @@ fun ScrollDismissMultiFab(
|
|||||||
.focusRequester(focusRequester)
|
.focusRequester(focusRequester)
|
||||||
.focusGroup(),
|
.focusGroup(),
|
||||||
) {
|
) {
|
||||||
val fobColor = MaterialTheme.colorScheme.secondary
|
FloatingActionButton(
|
||||||
val fobIconColor = MaterialTheme.colorScheme.background
|
onClick = {
|
||||||
MultiFloatingActionButton(
|
onClick()
|
||||||
fabIcon =
|
|
||||||
FabIcon(
|
|
||||||
iconRes = res,
|
|
||||||
iconResAfterRotate = R.drawable.close,
|
|
||||||
iconRotate = 180f,
|
|
||||||
),
|
|
||||||
fabOption =
|
|
||||||
FabOption(
|
|
||||||
iconTint = fobIconColor,
|
|
||||||
backgroundTint = fobColor,
|
|
||||||
),
|
|
||||||
itemsMultiFab =
|
|
||||||
listOf(
|
|
||||||
MultiFabItem(
|
|
||||||
label = {
|
|
||||||
Text(
|
|
||||||
stringResource(id = R.string.amnezia),
|
|
||||||
color = MaterialTheme.colorScheme.onBackground,
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(end = 10.dp),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.size(40.dp),
|
|
||||||
icon = res,
|
|
||||||
value = ConfigType.AMNEZIA.name,
|
|
||||||
miniFabOption =
|
|
||||||
FabOption(
|
|
||||||
backgroundTint = fobColor,
|
|
||||||
fobIconColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
MultiFabItem(
|
|
||||||
label = {
|
|
||||||
Text(
|
|
||||||
stringResource(id = R.string.wireguard),
|
|
||||||
color = MaterialTheme.colorScheme.onBackground,
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(end = 10.dp),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
icon = res,
|
|
||||||
value = ConfigType.WIREGUARD.name,
|
|
||||||
miniFabOption =
|
|
||||||
FabOption(
|
|
||||||
backgroundTint = fobColor,
|
|
||||||
fobIconColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onFabItemClicked = {
|
|
||||||
onFabItemClicked(it)
|
|
||||||
},
|
},
|
||||||
shape = RoundedCornerShape(16.dp),
|
shape = RoundedCornerShape(16.dp),
|
||||||
)
|
containerColor = MaterialTheme.colorScheme.primary,
|
||||||
|
) {
|
||||||
|
icon()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-10
@@ -19,6 +19,7 @@ import androidx.compose.foundation.text.KeyboardOptions
|
|||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Close
|
import androidx.compose.material.icons.filled.Close
|
||||||
|
import androidx.compose.material.icons.filled.Edit
|
||||||
import androidx.compose.material.icons.outlined.Add
|
import androidx.compose.material.icons.outlined.Add
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
@@ -49,16 +50,17 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
|||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Screen
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.ClickableIconButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.ClickableIconButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationToggle
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationToggle
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.SubmitConfigurationTextBox
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.SubmitConfigurationTextBox
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.ConfigType
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ScrollDismissFab
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ScrollDismissMultiFab
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.WildcardSupportingLabel
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isValidIpv4orIpv6Address
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isValidIpv4orIpv6Address
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
||||||
@@ -103,10 +105,16 @@ fun OptionsScreen(
|
|||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
ScrollDismissMultiFab(R.drawable.edit, focusRequester, isVisible = true, onFabItemClicked = {
|
ScrollDismissFab(icon = {
|
||||||
val configType = ConfigType.valueOf(it.value)
|
val icon = Icons.Filled.Edit
|
||||||
|
Icon(
|
||||||
|
imageVector = icon,
|
||||||
|
contentDescription = icon.name,
|
||||||
|
tint = MaterialTheme.colorScheme.onPrimary,
|
||||||
|
)
|
||||||
|
}, focusRequester, isVisible = true, onClick = {
|
||||||
navController.navigate(
|
navController.navigate(
|
||||||
"${Screen.Config.route}/${config.id}?configType=${configType.name}",
|
Route.Config(config.id),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -240,6 +248,7 @@ fun OptionsScreen(
|
|||||||
value = currentText,
|
value = currentText,
|
||||||
onValueChange = { currentText = it },
|
onValueChange = { currentText = it },
|
||||||
label = { Text(stringResource(id = R.string.use_tunnel_on_wifi_name)) },
|
label = { Text(stringResource(id = R.string.use_tunnel_on_wifi_name)) },
|
||||||
|
supportingText = { WildcardSupportingLabel { context.openWebUrl(it) } },
|
||||||
modifier =
|
modifier =
|
||||||
Modifier
|
Modifier
|
||||||
.padding(
|
.padding(
|
||||||
@@ -279,10 +288,10 @@ fun OptionsScreen(
|
|||||||
stringResource(R.string.set_custom_ping_ip),
|
stringResource(R.string.set_custom_ping_ip),
|
||||||
stringResource(R.string.default_ping_ip),
|
stringResource(R.string.default_ping_ip),
|
||||||
focusRequester,
|
focusRequester,
|
||||||
isErrorValue = { !(it?.isValidIpv4orIpv6Address() ?: true) },
|
isErrorValue = { !it.isNullOrBlank() && !it.isValidIpv4orIpv6Address() },
|
||||||
onSubmit = {
|
onSubmit = {
|
||||||
optionsViewModel.saveTunnelChanges(
|
optionsViewModel.saveTunnelChanges(
|
||||||
config.copy(pingIp = it),
|
config.copy(pingIp = it.ifBlank { null }),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -296,11 +305,12 @@ fun OptionsScreen(
|
|||||||
focusRequester,
|
focusRequester,
|
||||||
keyboardOptions = KeyboardOptions(
|
keyboardOptions = KeyboardOptions(
|
||||||
keyboardType = KeyboardType.Number,
|
keyboardType = KeyboardType.Number,
|
||||||
|
imeAction = ImeAction.Done,
|
||||||
),
|
),
|
||||||
isErrorValue = ::isSecondsError,
|
isErrorValue = ::isSecondsError,
|
||||||
onSubmit = {
|
onSubmit = {
|
||||||
optionsViewModel.saveTunnelChanges(
|
optionsViewModel.saveTunnelChanges(
|
||||||
config.copy(pingInterval = it.toLong() * 1000),
|
config.copy(pingInterval = if (it.isBlank()) null else it.toLong() * 1000),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -315,7 +325,7 @@ fun OptionsScreen(
|
|||||||
isErrorValue = ::isSecondsError,
|
isErrorValue = ::isSecondsError,
|
||||||
onSubmit = {
|
onSubmit = {
|
||||||
optionsViewModel.saveTunnelChanges(
|
optionsViewModel.saveTunnelChanges(
|
||||||
config.copy(pingCooldown = it.toLong() * 1000),
|
config.copy(pingCooldown = if (it.isBlank()) null else it.toLong() * 1000),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
+3
-3
@@ -8,7 +8,7 @@ import androidx.compose.ui.res.stringResource
|
|||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.ui.AppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Screen
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||||
@@ -36,11 +36,11 @@ fun PinLockScreen(navController: NavController, appViewModel: AppViewModel) {
|
|||||||
onPinCorrect = {
|
onPinCorrect = {
|
||||||
// pin is correct, navigate or hide pin lock
|
// pin is correct, navigate or hide pin lock
|
||||||
if (context.isRunningOnTv()) {
|
if (context.isRunningOnTv()) {
|
||||||
navController.navigate(Screen.Main.route)
|
navController.navigate(Route.Main)
|
||||||
} else {
|
} else {
|
||||||
val isPopped = navController.popBackStack()
|
val isPopped = navController.popBackStack()
|
||||||
if (!isPopped) {
|
if (!isPopped) {
|
||||||
navController.navigate(Screen.Main.route)
|
navController.navigate(Route.Main)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+27
-52
@@ -5,6 +5,7 @@ import android.app.Activity
|
|||||||
import android.content.Context.POWER_SERVICE
|
import android.content.Context.POWER_SERVICE
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.net.VpnService
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
@@ -68,7 +69,7 @@ import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
|||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.ui.AppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Screen
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.ClickableIconButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.ClickableIconButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationToggle
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationToggle
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt
|
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt
|
||||||
@@ -111,7 +112,7 @@ fun SettingsScreen(
|
|||||||
var isBackgroundLocationGranted by remember { mutableStateOf(true) }
|
var isBackgroundLocationGranted by remember { mutableStateOf(true) }
|
||||||
var showVpnPermissionDialog by remember { mutableStateOf(false) }
|
var showVpnPermissionDialog by remember { mutableStateOf(false) }
|
||||||
var showLocationServicesAlertDialog by remember { mutableStateOf(false) }
|
var showLocationServicesAlertDialog by remember { mutableStateOf(false) }
|
||||||
var didExportFiles by remember { mutableStateOf(false) }
|
val didExportFiles by remember { mutableStateOf(false) }
|
||||||
var showAuthPrompt by remember { mutableStateOf(false) }
|
var showAuthPrompt by remember { mutableStateOf(false) }
|
||||||
var showLocationDialog by remember { mutableStateOf(false) }
|
var showLocationDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
@@ -126,13 +127,6 @@ fun SettingsScreen(
|
|||||||
currentText = ""
|
currentText = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
val notificationPermissionState =
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
||||||
rememberPermissionState(Manifest.permission.POST_NOTIFICATIONS)
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
val startForResult =
|
val startForResult =
|
||||||
rememberLauncherForActivityResult(
|
rememberLauncherForActivityResult(
|
||||||
ActivityResultContracts.StartActivityForResult(),
|
ActivityResultContracts.StartActivityForResult(),
|
||||||
@@ -165,22 +159,20 @@ fun SettingsScreen(
|
|||||||
fun requestBatteryOptimizationsDisabled() {
|
fun requestBatteryOptimizationsDisabled() {
|
||||||
val intent =
|
val intent =
|
||||||
Intent().apply {
|
Intent().apply {
|
||||||
this.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
||||||
data = Uri.fromParts("package", context.packageName, null)
|
data = Uri.parse("package:${context.packageName}")
|
||||||
}
|
}
|
||||||
startForResult.launch(intent)
|
startForResult.launch(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleAutoTunnelToggle() {
|
fun handleAutoTunnelToggle() {
|
||||||
if (!uiState.generalState.isBatteryOptimizationDisableShown || !isBatteryOptimizationsDisabled()) return requestBatteryOptimizationsDisabled()
|
if (!uiState.generalState.isBatteryOptimizationDisableShown &&
|
||||||
if (notificationPermissionState != null && !notificationPermissionState.status.isGranted) {
|
!isBatteryOptimizationsDisabled() && !context.isRunningOnTv()
|
||||||
snackbar.showMessage(
|
) {
|
||||||
context.getString(R.string.notification_permission_required),
|
return requestBatteryOptimizationsDisabled()
|
||||||
)
|
|
||||||
return notificationPermissionState.launchPermissionRequest()
|
|
||||||
}
|
}
|
||||||
val intent = if (!uiState.settings.isKernelEnabled) {
|
val intent = if (!uiState.settings.isKernelEnabled) {
|
||||||
com.wireguard.android.backend.GoBackend.VpnService.prepare(context)
|
VpnService.prepare(context)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
@@ -322,7 +314,20 @@ fun SettingsScreen(
|
|||||||
enabled = !uiState.settings.isAlwaysOnVpnEnabled,
|
enabled = !uiState.settings.isAlwaysOnVpnEnabled,
|
||||||
checked = uiState.settings.isTunnelOnWifiEnabled,
|
checked = uiState.settings.isTunnelOnWifiEnabled,
|
||||||
padding = screenPadding,
|
padding = screenPadding,
|
||||||
onCheckChanged = { viewModel.onToggleTunnelOnWifi() },
|
onCheckChanged = { checked ->
|
||||||
|
if (!checked) viewModel.onToggleTunnelOnWifi()
|
||||||
|
if (checked) {
|
||||||
|
when (false) {
|
||||||
|
isBackgroundLocationGranted -> showLocationDialog = true
|
||||||
|
fineLocationState.status.isGranted -> showLocationDialog = true
|
||||||
|
viewModel.isLocationEnabled(context) ->
|
||||||
|
showLocationServicesAlertDialog = true
|
||||||
|
else -> {
|
||||||
|
viewModel.onToggleTunnelOnWifi()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
modifier =
|
modifier =
|
||||||
if (uiState.settings.isAutoTunnelEnabled) {
|
if (uiState.settings.isAutoTunnelEnabled) {
|
||||||
Modifier
|
Modifier
|
||||||
@@ -450,23 +455,7 @@ fun SettingsScreen(
|
|||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
if (uiState.tunnels.isEmpty()) return@TextButton context.showToast(R.string.tunnel_required)
|
if (uiState.tunnels.isEmpty()) return@TextButton context.showToast(R.string.tunnel_required)
|
||||||
if (
|
handleAutoTunnelToggle()
|
||||||
uiState.settings.isTunnelOnWifiEnabled &&
|
|
||||||
!uiState.settings.isAutoTunnelEnabled
|
|
||||||
) {
|
|
||||||
when (false) {
|
|
||||||
isBackgroundLocationGranted -> showLocationDialog = true
|
|
||||||
fineLocationState.status.isGranted -> showLocationDialog = true
|
|
||||||
viewModel.isLocationEnabled(context) ->
|
|
||||||
showLocationServicesAlertDialog = true
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
handleAutoTunnelToggle()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
handleAutoTunnelToggle()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
val autoTunnelButtonText =
|
val autoTunnelButtonText =
|
||||||
@@ -499,20 +488,6 @@ fun SettingsScreen(
|
|||||||
title = stringResource(id = R.string.backend),
|
title = stringResource(id = R.string.backend),
|
||||||
padding = screenPadding,
|
padding = screenPadding,
|
||||||
)
|
)
|
||||||
ConfigurationToggle(
|
|
||||||
stringResource(R.string.use_amnezia),
|
|
||||||
enabled =
|
|
||||||
!(
|
|
||||||
uiState.settings.isAutoTunnelEnabled ||
|
|
||||||
uiState.settings.isAlwaysOnVpnEnabled ||
|
|
||||||
(uiState.vpnState.status == TunnelState.UP) || uiState.settings.isKernelEnabled
|
|
||||||
),
|
|
||||||
checked = uiState.settings.isAmneziaEnabled,
|
|
||||||
padding = screenPadding,
|
|
||||||
onCheckChanged = {
|
|
||||||
viewModel.onToggleAmnezia()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
ConfigurationToggle(
|
ConfigurationToggle(
|
||||||
stringResource(R.string.use_kernel),
|
stringResource(R.string.use_kernel),
|
||||||
enabled =
|
enabled =
|
||||||
@@ -520,7 +495,7 @@ fun SettingsScreen(
|
|||||||
uiState.settings.isAutoTunnelEnabled ||
|
uiState.settings.isAutoTunnelEnabled ||
|
||||||
uiState.settings.isAlwaysOnVpnEnabled ||
|
uiState.settings.isAlwaysOnVpnEnabled ||
|
||||||
(uiState.vpnState.status == TunnelState.UP) ||
|
(uiState.vpnState.status == TunnelState.UP) ||
|
||||||
kernelSupport
|
!kernelSupport
|
||||||
),
|
),
|
||||||
checked = uiState.settings.isKernelEnabled,
|
checked = uiState.settings.isKernelEnabled,
|
||||||
padding = screenPadding,
|
padding = screenPadding,
|
||||||
@@ -606,7 +581,7 @@ fun SettingsScreen(
|
|||||||
} else {
|
} else {
|
||||||
// TODO may want to show a dialog before proceeding in the future
|
// TODO may want to show a dialog before proceeding in the future
|
||||||
PinManager.initialize(WireGuardAutoTunnel.instance)
|
PinManager.initialize(WireGuardAutoTunnel.instance)
|
||||||
navController.navigate(Screen.Lock.route)
|
navController.navigate(Route.Lock)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ fun WildcardSupportingLabel(onClick: (url: String) -> Unit) {
|
|||||||
buildAnnotatedString {
|
buildAnnotatedString {
|
||||||
pushStringAnnotation(
|
pushStringAnnotation(
|
||||||
tag = "details",
|
tag = "details",
|
||||||
annotation = stringResource(id = R.string.docs_features),
|
annotation = stringResource(id = R.string.docs_wildcards),
|
||||||
)
|
)
|
||||||
withStyle(
|
withStyle(
|
||||||
style = SpanStyle(color = MaterialTheme.colorScheme.primary),
|
style = SpanStyle(color = MaterialTheme.colorScheme.primary),
|
||||||
|
|||||||
+2
-2
@@ -46,7 +46,7 @@ import androidx.navigation.NavController
|
|||||||
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Screen
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.launchSupportEmail
|
import com.zaneschepke.wireguardautotunnel.util.extensions.launchSupportEmail
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||||
@@ -244,7 +244,7 @@ fun SupportScreen(navController: NavController, focusRequester: FocusRequester,
|
|||||||
color = MaterialTheme.colorScheme.onBackground,
|
color = MaterialTheme.colorScheme.onBackground,
|
||||||
)
|
)
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = { navController.navigate(Screen.Support.Logs.route) },
|
onClick = { navController.navigate(Route.Logs) },
|
||||||
modifier = Modifier.padding(vertical = 5.dp),
|
modifier = Modifier.padding(vertical = 5.dp),
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ object Constants {
|
|||||||
const val BASE_LOG_FILE_NAME = "wg_tunnel_logs"
|
const val BASE_LOG_FILE_NAME = "wg_tunnel_logs"
|
||||||
const val LOG_BUFFER_SIZE = 3_000L
|
const val LOG_BUFFER_SIZE = 3_000L
|
||||||
|
|
||||||
const val MANUAL_TUNNEL_CONFIG_ID = "0"
|
const val MANUAL_TUNNEL_CONFIG_ID = 0
|
||||||
const val BATTERY_SAVER_WATCHER_WAKE_LOCK_TIMEOUT = 10 * 60 * 1_000L // 10 minutes
|
const val BATTERY_SAVER_WATCHER_WAKE_LOCK_TIMEOUT = 10 * 60 * 1_000L // 10 minutes
|
||||||
const val VPN_STATISTIC_CHECK_INTERVAL = 1_000L
|
|
||||||
const val WATCHER_COLLECTION_DELAY = 3_000L
|
const val WATCHER_COLLECTION_DELAY = 3_000L
|
||||||
|
|
||||||
const val CONF_FILE_EXTENSION = ".conf"
|
const val CONF_FILE_EXTENSION = ".conf"
|
||||||
const val ZIP_FILE_EXTENSION = ".zip"
|
const val ZIP_FILE_EXTENSION = ".zip"
|
||||||
const val URI_CONTENT_SCHEME = "content"
|
const val URI_CONTENT_SCHEME = "content"
|
||||||
@@ -16,7 +16,6 @@ object Constants {
|
|||||||
const val ZIP_FILE_MIME_TYPE = "application/zip"
|
const val ZIP_FILE_MIME_TYPE = "application/zip"
|
||||||
const val GOOGLE_TV_EXPLORER_STUB = "com.google.android.tv.frameworkpackagestubs"
|
const val GOOGLE_TV_EXPLORER_STUB = "com.google.android.tv.frameworkpackagestubs"
|
||||||
const val ANDROID_TV_EXPLORER_STUB = "com.android.tv.frameworkpackagestubs"
|
const val ANDROID_TV_EXPLORER_STUB = "com.android.tv.frameworkpackagestubs"
|
||||||
const val ALWAYS_ON_VPN_ACTION = "android.net.VpnService"
|
|
||||||
const val VPN_SETTINGS_PACKAGE = "android.net.vpn.SETTINGS"
|
const val VPN_SETTINGS_PACKAGE = "android.net.vpn.SETTINGS"
|
||||||
const val EMAIL_MIME_TYPE = "plain/text"
|
const val EMAIL_MIME_TYPE = "plain/text"
|
||||||
const val SYSTEM_EXEMPT_SERVICE_TYPE_ID = 1024
|
const val SYSTEM_EXEMPT_SERVICE_TYPE_ID = 1024
|
||||||
@@ -28,12 +27,11 @@ object Constants {
|
|||||||
|
|
||||||
const val DEFAULT_PING_IP = "1.1.1.1"
|
const val DEFAULT_PING_IP = "1.1.1.1"
|
||||||
const val PING_TIMEOUT = 5_000L
|
const val PING_TIMEOUT = 5_000L
|
||||||
const val VPN_RESTART_DELAY = 1_000L
|
|
||||||
const val PING_INTERVAL = 60_000L
|
const val PING_INTERVAL = 60_000L
|
||||||
const val PING_COOLDOWN = PING_INTERVAL * 60 // one hour
|
const val PING_COOLDOWN = PING_INTERVAL * 60 // one hour
|
||||||
|
|
||||||
const val UNREADABLE_SSID = "<unknown ssid>"
|
const val UNREADABLE_SSID = "<unknown ssid>"
|
||||||
|
|
||||||
val amneziaProperties = listOf("Jc", "Jmin", "Jmax", "S1", "S2", "H1", "H2", "H3", "H4")
|
val amProperties = listOf("Jc", "Jmin", "Jmax", "S1", "S2", "H1", "H2", "H3", "H4")
|
||||||
const val QR_CODE_NAME_PROPERTY = "# Name ="
|
const val QR_CODE_NAME_PROPERTY = "# Name ="
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.util
|
||||||
|
|
||||||
|
object InvalidFileExtensionException : Exception() {
|
||||||
|
private fun readResolve(): Any = InvalidFileExtensionException
|
||||||
|
}
|
||||||
|
|
||||||
|
object FileReadException : Exception() {
|
||||||
|
private fun readResolve(): Any = FileReadException
|
||||||
|
}
|
||||||
|
|
||||||
|
object ConfigExportException : Exception() {
|
||||||
|
private fun readResolve(): Any = ConfigExportException
|
||||||
|
}
|
||||||
@@ -118,7 +118,7 @@ class FileUtils(
|
|||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
Result.failure(WgTunnelExceptions.ConfigExportFailed())
|
Result.failure(ConfigExportException)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.util
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
|
|
||||||
sealed class WgTunnelExceptions : Exception() {
|
|
||||||
abstract fun getMessage(context: Context): String
|
|
||||||
|
|
||||||
data class ConfigExportFailed(
|
|
||||||
private val userMessage: StringValue =
|
|
||||||
StringValue.StringResource(
|
|
||||||
R.string.export_configs_failed,
|
|
||||||
),
|
|
||||||
) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context): String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class ConfigParseError(private val appendMessage: StringValue = StringValue.Empty) :
|
|
||||||
WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context): String {
|
|
||||||
return StringValue.StringResource(R.string.config_parse_error).asString(context) + (
|
|
||||||
if (appendMessage != StringValue.Empty) ": ${appendMessage.asString(context)}" else ""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class InvalidQrCode(
|
|
||||||
private val userMessage: StringValue =
|
|
||||||
StringValue.StringResource(
|
|
||||||
R.string.error_invalid_code,
|
|
||||||
),
|
|
||||||
) :
|
|
||||||
WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context): String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class InvalidFileExtension(
|
|
||||||
private val userMessage: StringValue =
|
|
||||||
StringValue.StringResource(
|
|
||||||
R.string.error_file_extension,
|
|
||||||
),
|
|
||||||
) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context): String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class FileReadFailed(
|
|
||||||
private val userMessage: StringValue =
|
|
||||||
StringValue.StringResource(
|
|
||||||
R.string.error_file_format,
|
|
||||||
),
|
|
||||||
) :
|
|
||||||
WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context): String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.util.extensions
|
package com.zaneschepke.wireguardautotunnel.util.extensions
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.pm.PackageInfo
|
import android.content.pm.PackageInfo
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.WgTunnelExceptions
|
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
|
|
||||||
@@ -21,10 +17,3 @@ fun <T> List<T>.removeAt(index: Int): List<T> = toMutableList().apply { this.rem
|
|||||||
typealias TunnelConfigs = List<TunnelConfig>
|
typealias TunnelConfigs = List<TunnelConfig>
|
||||||
|
|
||||||
typealias Packages = List<PackageInfo>
|
typealias Packages = List<PackageInfo>
|
||||||
|
|
||||||
fun Throwable.getMessage(context: Context): String {
|
|
||||||
return when (this) {
|
|
||||||
is WgTunnelExceptions -> this.getMessage(context)
|
|
||||||
else -> this.message ?: StringValue.StringResource(R.string.unknown_error).asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ fun Config.toWgQuickString(): String {
|
|||||||
val linesIterator = lines.iterator()
|
val linesIterator = lines.iterator()
|
||||||
while (linesIterator.hasNext()) {
|
while (linesIterator.hasNext()) {
|
||||||
val next = linesIterator.next()
|
val next = linesIterator.next()
|
||||||
Constants.amneziaProperties.forEach {
|
Constants.amProperties.forEach {
|
||||||
if (next.startsWith(it, ignoreCase = true)) {
|
if (next.startsWith(it, ignoreCase = true)) {
|
||||||
linesIterator.remove()
|
linesIterator.remove()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
<string name="docs_url" translatable="false">https://zaneschepke.com/wgtunnel-docs/overview.html</string>
|
<string name="docs_url" translatable="false">https://zaneschepke.com/wgtunnel-docs/overview.html</string>
|
||||||
<string name="docs_features" translatable="false">https://zaneschepke.com/wgtunnel-docs/features.html</string>
|
<string name="docs_features" translatable="false">https://zaneschepke.com/wgtunnel-docs/features.html</string>
|
||||||
<string name="privacy_policy_url" translatable="false">https://zaneschepke.com/wgtunnel-docs/privacypolicy.html</string>
|
<string name="privacy_policy_url" translatable="false">https://zaneschepke.com/wgtunnel-docs/privacypolicy.html</string>
|
||||||
<string name="error_file_extension">File is not a .conf or .zip</string>
|
<string name="docs_wildcards" translatable="false" >https://zaneschepke.com/wgtunnel-docs/features.html#wildcard-wi-fi-name-support</string>
|
||||||
|
<string name="error_file_extension">File is not a .conf or .zip</string>
|
||||||
<string name="turn_off_tunnel">Action requires tunnel off</string>
|
<string name="turn_off_tunnel">Action requires tunnel off</string>
|
||||||
<string name="no_tunnels">No tunnels added yet!</string>
|
<string name="no_tunnels">No tunnels added yet!</string>
|
||||||
<string name="discord_url" translatable="false">https://discord.gg/rbRRNh6H7V</string>
|
<string name="discord_url" translatable="false">https://discord.gg/rbRRNh6H7V</string>
|
||||||
@@ -194,4 +195,5 @@
|
|||||||
<string name="set_custom_ping_cooldown">Ping restart cooldown (sec)</string>
|
<string name="set_custom_ping_cooldown">Ping restart cooldown (sec)</string>
|
||||||
<string name="wildcard_supported">Learn about supported wildcards.</string>
|
<string name="wildcard_supported">Learn about supported wildcards.</string>
|
||||||
<string name="details">details</string>
|
<string name="details">details</string>
|
||||||
|
<string name="show_amnezia_properties">Show Amnezia properties</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
object Constants {
|
object Constants {
|
||||||
const val VERSION_NAME = "3.5.1"
|
const val VERSION_NAME = "3.5.2"
|
||||||
const val JVM_TARGET = "17"
|
const val JVM_TARGET = "17"
|
||||||
const val VERSION_CODE = 35103
|
const val VERSION_CODE = 35200
|
||||||
const val TARGET_SDK = 34
|
const val TARGET_SDK = 34
|
||||||
const val MIN_SDK = 26
|
const val MIN_SDK = 26
|
||||||
const val APP_ID = "com.zaneschepke.wireguardautotunnel"
|
const val APP_ID = "com.zaneschepke.wireguardautotunnel"
|
||||||
@@ -15,9 +15,5 @@ object Constants {
|
|||||||
const val RELEASE = "release"
|
const val RELEASE = "release"
|
||||||
const val NIGHTLY = "nightly"
|
const val NIGHTLY = "nightly"
|
||||||
const val PRERELEASE = "prerelease"
|
const val PRERELEASE = "prerelease"
|
||||||
const val DEBUG = "debug"
|
|
||||||
const val TYPE = "type"
|
const val TYPE = "type"
|
||||||
|
|
||||||
const val NIGHTLY_CODE = 42
|
|
||||||
const val PRERELEASE_CODE = 54
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
What's new:
|
||||||
|
- Added wildcard support for wifi names
|
||||||
|
- Fix slowness on mobile data
|
||||||
|
- Various bug fixes and improvements
|
||||||
|
- UI optimizations
|
||||||
@@ -13,20 +13,19 @@ espressoCore = "3.6.1"
|
|||||||
hiltAndroid = "2.52"
|
hiltAndroid = "2.52"
|
||||||
hiltNavigationCompose = "1.2.0"
|
hiltNavigationCompose = "1.2.0"
|
||||||
junit = "4.13.2"
|
junit = "4.13.2"
|
||||||
kotlinx-serialization-json = "1.7.2"
|
kotlinx-serialization-json = "1.7.3"
|
||||||
lifecycle-runtime-compose = "2.8.5"
|
lifecycle-runtime-compose = "2.8.6"
|
||||||
material3 = "1.3.0"
|
material3 = "1.3.0"
|
||||||
multifabVersion = "1.1.1"
|
navigationCompose = "2.8.1"
|
||||||
navigationCompose = "2.8.0"
|
|
||||||
pinLockCompose = "1.0.3"
|
pinLockCompose = "1.0.3"
|
||||||
roomVersion = "2.6.1"
|
roomVersion = "2.6.1"
|
||||||
timber = "5.0.1"
|
timber = "5.0.1"
|
||||||
tunnel = "1.2.4"
|
tunnel = "1.2.1"
|
||||||
androidGradlePlugin = "8.6.0"
|
androidGradlePlugin = "8.6.1"
|
||||||
kotlin = "2.0.20"
|
kotlin = "2.0.20"
|
||||||
ksp = "2.0.20-1.0.24"
|
ksp = "2.0.20-1.0.25"
|
||||||
composeBom = "2024.09.00"
|
composeBom = "2024.09.02"
|
||||||
compose = "1.7.1"
|
compose = "1.7.2"
|
||||||
zxingAndroidEmbedded = "4.3.0"
|
zxingAndroidEmbedded = "4.3.0"
|
||||||
coreSplashscreen = "1.0.1"
|
coreSplashscreen = "1.0.1"
|
||||||
gradlePlugins-grgit = "5.2.2"
|
gradlePlugins-grgit = "5.2.2"
|
||||||
@@ -90,7 +89,6 @@ pin-lock-compose = { module = "com.zaneschepke:pin_lock_compose", version.ref =
|
|||||||
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
|
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
|
||||||
tunnel = { module = "com.zaneschepke:wireguard-android", version.ref = "tunnel" }
|
tunnel = { module = "com.zaneschepke:wireguard-android", version.ref = "tunnel" }
|
||||||
|
|
||||||
zaneschepke-multifab = { module = "com.zaneschepke:multifab", version.ref = "multifabVersion" }
|
|
||||||
zxing-android-embedded = { module = "com.journeyapps:zxing-android-embedded", version.ref = "zxingAndroidEmbedded" }
|
zxing-android-embedded = { module = "com.journeyapps:zxing-android-embedded", version.ref = "zxingAndroidEmbedded" }
|
||||||
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
9
|
||||||
Reference in New Issue
Block a user