mirror of
https://github.com/wgtunnel/android.git
synced 2026-07-03 14:07:49 +02:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| acae5ad33d | |||
| 13b7457881 | |||
| 2bca6de331 | |||
| d9608e073c | |||
| 6417065c32 | |||
| ca946e1cf1 | |||
| 3c0f993584 | |||
| 385c0dfbfc |
@@ -20,7 +20,7 @@ on:
|
|||||||
default: fdroid
|
default: fdroid
|
||||||
options:
|
options:
|
||||||
- fdroid
|
- fdroid
|
||||||
- standalone
|
- full
|
||||||
secrets:
|
secrets:
|
||||||
SIGNING_KEY_ALIAS:
|
SIGNING_KEY_ALIAS:
|
||||||
required: false
|
required: false
|
||||||
@@ -119,10 +119,9 @@ jobs:
|
|||||||
- name: Get release apk path
|
- name: Get release apk path
|
||||||
id: apk-path
|
id: apk-path
|
||||||
run: echo "path=$(find . -regex '^.*/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/.*\.apk$' -type f | head -1 | tail -c+2)" >> $GITHUB_OUTPUT
|
run: echo "path=$(find . -regex '^.*/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/.*\.apk$' -type f | head -1 | tail -c+2)" >> $GITHUB_OUTPUT
|
||||||
- name: Upload APK
|
- name: Upload release apk
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: android_artifacts_${{ inputs.flavor }}
|
name: ${{ env.UPLOAD_DIR_ANDROID }}
|
||||||
path: app/build/outputs/apk/${{ inputs.flavor }}/release/wgtunnel-${{ inputs.flavor }}-release-*.apk
|
path: ${{ github.workspace }}/${{ steps.apk-path.outputs.path }}
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
if-no-files-found: warn
|
|
||||||
@@ -34,17 +34,17 @@ on:
|
|||||||
type: choice
|
type: choice
|
||||||
description: "Product flavor"
|
description: "Product flavor"
|
||||||
required: true
|
required: true
|
||||||
default: standalone
|
default: full
|
||||||
options:
|
options:
|
||||||
- fdroid
|
- fdroid
|
||||||
- standalone
|
- full
|
||||||
workflow_call:
|
workflow_call:
|
||||||
inputs:
|
inputs:
|
||||||
flavor:
|
flavor:
|
||||||
type: string
|
type: string
|
||||||
description: "Product flavor"
|
description: "Product flavor"
|
||||||
required: false
|
required: false
|
||||||
default: standalone
|
default: full
|
||||||
|
|
||||||
env:
|
env:
|
||||||
UPLOAD_DIR_ANDROID: android_artifacts
|
UPLOAD_DIR_ANDROID: android_artifacts
|
||||||
@@ -80,18 +80,18 @@ jobs:
|
|||||||
build_type: ${{ inputs.release_type == '' && 'nightly' || inputs.release_type }}
|
build_type: ${{ inputs.release_type == '' && 'nightly' || inputs.release_type }}
|
||||||
flavor: fdroid
|
flavor: fdroid
|
||||||
|
|
||||||
build-standalone:
|
build-full:
|
||||||
if: ${{ inputs.release_type == 'release' || inputs.release_type == 'nightly' || inputs.release_type == 'prerelease' || inputs.flavor == 'standalone' }}
|
if: ${{ inputs.release_type == 'release' || inputs.release_type == 'nightly' || inputs.release_type == 'prerelease' || inputs.flavor == 'full' }}
|
||||||
uses: ./.github/workflows/build.yml
|
uses: ./.github/workflows/build.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
with:
|
with:
|
||||||
build_type: ${{ inputs.release_type == '' && 'nightly' || inputs.release_type }}
|
build_type: ${{ inputs.release_type == '' && 'nightly' || inputs.release_type }}
|
||||||
flavor: standalone
|
flavor: full
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
needs:
|
needs:
|
||||||
- check_commits
|
- check_commits
|
||||||
- build-standalone
|
- build-full
|
||||||
if: ${{ needs.check_commits.outputs.has_new_commits > 0 && inputs.release_type != 'none' }}
|
if: ${{ needs.check_commits.outputs.has_new_commits > 0 && inputs.release_type != 'none' }}
|
||||||
name: publish-github
|
name: publish-github
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -139,9 +139,8 @@ jobs:
|
|||||||
- name: Download artifacts
|
- name: Download artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
pattern: android_artifacts_*
|
name: ${{ env.UPLOAD_DIR_ANDROID }}
|
||||||
path: ${{ github.workspace }}/temp
|
path: ${{ github.workspace }}/temp
|
||||||
merge-multiple: true
|
|
||||||
- name: Set version release notes
|
- name: Set version release notes
|
||||||
if: ${{ inputs.release_type == 'release' }}
|
if: ${{ inputs.release_type == 'release' }}
|
||||||
run: |
|
run: |
|
||||||
@@ -163,7 +162,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Delete previous release
|
- name: Delete previous release
|
||||||
if: ${{ contains(env.TAG_NAME, 'nightly') || inputs.release_type == 'prerelease' }}
|
if: ${{ contains(env.TAG_NAME, 'nightly') || inputs.release_type == 'prerelease' }}
|
||||||
uses: ClementTsang/delete-tag-and-release@v0.4.0
|
uses: ClementTsang/delete-tag-and-release@v0.3.1
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ env.TAG_NAME }}
|
tag_name: ${{ env.TAG_NAME }}
|
||||||
delete_release: true
|
delete_release: true
|
||||||
@@ -209,69 +208,3 @@ jobs:
|
|||||||
${{ github.workspace }}/temp/*
|
${{ github.workspace }}/temp/*
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
publish-fdroid-public:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs:
|
|
||||||
- build-fdroid
|
|
||||||
if: inputs.release_type == 'release'
|
|
||||||
steps:
|
|
||||||
- name: Dispatch update for fdroid repo
|
|
||||||
uses: peter-evans/repository-dispatch@v3
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
repository: wgtunnel/fdroid
|
|
||||||
event-type: fdroid-update
|
|
||||||
|
|
||||||
publish-play:
|
|
||||||
if: ${{ inputs.track != 'none' && inputs.track != '' }}
|
|
||||||
name: Publish to Google Play
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
env:
|
|
||||||
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
|
|
||||||
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
|
||||||
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
|
|
||||||
KEY_STORE_FILE: 'android_keystore.jks'
|
|
||||||
KEY_STORE_LOCATION: ${{ github.workspace }}/app/keystore/
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Set up JDK 17
|
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
|
||||||
distribution: 'temurin'
|
|
||||||
java-version: '17'
|
|
||||||
cache: gradle
|
|
||||||
|
|
||||||
- name: Grant execute permission for gradlew
|
|
||||||
run: chmod +x gradlew
|
|
||||||
|
|
||||||
# Here we need to decode keystore.jks from base64 string and place it
|
|
||||||
# in the folder specified in the release signing configuration
|
|
||||||
- name: Decode Keystore
|
|
||||||
id: decode_keystore
|
|
||||||
uses: timheuer/base64-to-file@v1.2
|
|
||||||
with:
|
|
||||||
fileName: ${{ env.KEY_STORE_FILE }}
|
|
||||||
fileDir: ${{ env.KEY_STORE_LOCATION }}
|
|
||||||
encodedString: ${{ secrets.KEYSTORE }}
|
|
||||||
|
|
||||||
# create keystore path for gradle to read
|
|
||||||
- name: Create keystore path env var
|
|
||||||
run: |
|
|
||||||
store_path=${{ env.KEY_STORE_LOCATION }}${{ env.KEY_STORE_FILE }}
|
|
||||||
echo "KEY_STORE_PATH=$store_path" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Create service_account.json
|
|
||||||
id: createServiceAccount
|
|
||||||
run: echo '${{ secrets.SERVICE_ACCOUNT_JSON }}' > service_account.json
|
|
||||||
|
|
||||||
- name: Deploy with fastlane
|
|
||||||
uses: ruby/setup-ruby@v1
|
|
||||||
with:
|
|
||||||
ruby-version: '3.2' # Not needed with a .ruby-version file
|
|
||||||
bundler-cache: true
|
|
||||||
|
|
||||||
- name: Distribute app to Prod track 🚀
|
|
||||||
run: (cd ${{ github.workspace }} && bundle install && bundle exec fastlane ${{ inputs.track }})
|
|
||||||
@@ -103,10 +103,7 @@ android {
|
|||||||
dimension = "type"
|
dimension = "type"
|
||||||
buildConfigField("String", "FLAVOR", "\"google\"")
|
buildConfigField("String", "FLAVOR", "\"google\"")
|
||||||
}
|
}
|
||||||
create("standalone") {
|
create("full") { dimension = "type" }
|
||||||
dimension = "type"
|
|
||||||
buildConfigField("String", "FLAVOR", "\"standalone\"")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
|
|||||||
@@ -166,11 +166,15 @@
|
|||||||
<receiver
|
<receiver
|
||||||
android:name=".core.broadcast.RestartReceiver"
|
android:name=".core.broadcast.RestartReceiver"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false">
|
android:exported="false"
|
||||||
|
android:directBootAware="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SCREEN_ON" />
|
||||||
|
<action android:name="android.intent.action.USER_PRESENT" />
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||||
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
|
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
|
||||||
|
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
|
||||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import androidx.navigation.compose.rememberNavController
|
|||||||
import androidx.navigation.toRoute
|
import androidx.navigation.toRoute
|
||||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.VpnDeniedDialog
|
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.VpnDeniedDialog
|
||||||
@@ -109,7 +110,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val isTv = isRunningOnTv()
|
val isTv = isRunningOnTv()
|
||||||
val appUiState by viewModel.uiState.collectAsStateWithLifecycle()
|
val appUiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||||
val appViewState by viewModel.appViewState.collectAsStateWithLifecycle()
|
val appViewState by viewModel.appViewState.collectAsStateWithLifecycle()
|
||||||
val tunnelError by viewModel.tunnelManager.errorEvents.collectAsStateWithLifecycle(null)
|
|
||||||
|
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
val backStackEntry by navController.currentBackStackEntryAsState()
|
val backStackEntry by navController.currentBackStackEntryAsState()
|
||||||
@@ -134,7 +134,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
vpnPermissionDenied = true
|
vpnPermissionDenied = true
|
||||||
} else {
|
} else {
|
||||||
vpnPermissionDenied = false
|
vpnPermissionDenied = false
|
||||||
showVpnPermissionDialog = false
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -152,15 +151,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
viewModel.handleEvent(AppEvent.SetBatteryOptimizeDisableShown)
|
viewModel.handleEvent(AppEvent.SetBatteryOptimizeDisableShown)
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(tunnelError) {
|
|
||||||
if (tunnelError == null) return@LaunchedEffect
|
|
||||||
val message = tunnelError!!.second.toStringRes()
|
|
||||||
val context = this@MainActivity
|
|
||||||
snackbar.showSnackbar(
|
|
||||||
context.getString(R.string.tunnel_error_template, context.getString(message))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
with(appViewState) {
|
with(appViewState) {
|
||||||
LaunchedEffect(isConfigChanged) {
|
LaunchedEffect(isConfigChanged) {
|
||||||
if (isConfigChanged) {
|
if (isConfigChanged) {
|
||||||
@@ -176,6 +166,21 @@ class MainActivity : AppCompatActivity() {
|
|||||||
viewModel.handleEvent(AppEvent.MessageShown)
|
viewModel.handleEvent(AppEvent.MessageShown)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LaunchedEffect(appUiState.activeTunnels) {
|
||||||
|
appUiState.activeTunnels.mapNotNull { (tunnelConf, tunnelState) ->
|
||||||
|
(tunnelState.status as? TunnelStatus.Error)?.let { error ->
|
||||||
|
val message = error.error.toStringRes()
|
||||||
|
val context = this@MainActivity
|
||||||
|
snackbar.showSnackbar(
|
||||||
|
context.getString(
|
||||||
|
R.string.tunnel_error_template,
|
||||||
|
context.getString(message),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
viewModel.handleEvent(AppEvent.ClearTunnelError(tunnelConf))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
LaunchedEffect(popBackStack) {
|
LaunchedEffect(popBackStack) {
|
||||||
if (popBackStack) {
|
if (popBackStack) {
|
||||||
navController.popBackStack()
|
navController.popBackStack()
|
||||||
@@ -209,10 +214,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
WireguardAutoTunnelTheme(theme = appUiState.appState.theme) {
|
WireguardAutoTunnelTheme(theme = appUiState.appState.theme) {
|
||||||
VpnDeniedDialog(
|
VpnDeniedDialog(
|
||||||
showVpnPermissionDialog,
|
showVpnPermissionDialog,
|
||||||
onDismiss = {
|
onDismiss = { showVpnPermissionDialog = false },
|
||||||
showVpnPermissionDialog = false
|
|
||||||
vpnPermissionDenied = false
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
|
|||||||
+6
-7
@@ -3,12 +3,12 @@ package com.zaneschepke.wireguardautotunnel.core.broadcast
|
|||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import com.zaneschepke.logcatter.LogReader
|
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
@@ -26,20 +26,20 @@ class RestartReceiver : BroadcastReceiver() {
|
|||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
@Inject lateinit var tunnelManager: TunnelManager
|
||||||
|
|
||||||
@Inject lateinit var logReader: LogReader
|
|
||||||
|
|
||||||
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
Timber.d("RestartReceiver triggered with action: ${intent.action}")
|
Timber.d("RestartReceiver triggered with action: ${intent.action}")
|
||||||
|
// screen on for Android TV only to help with sleep shutdowns
|
||||||
|
val isTv = context.isRunningOnTv()
|
||||||
|
if (intent.action == Intent.ACTION_SCREEN_ON && !isTv) return
|
||||||
|
if (intent.action == Intent.ACTION_USER_PRESENT && !isTv) return
|
||||||
serviceManager.updateTunnelTile()
|
serviceManager.updateTunnelTile()
|
||||||
serviceManager.updateAutoTunnelTile()
|
serviceManager.updateAutoTunnelTile()
|
||||||
applicationScope.launch(ioDispatcher) {
|
applicationScope.launch(ioDispatcher) {
|
||||||
val settings = appDataRepository.settings.get()
|
val settings = appDataRepository.settings.get()
|
||||||
if (settings.isRestoreOnBootEnabled) {
|
if (settings.isRestoreOnBootEnabled) {
|
||||||
if (
|
if (settings.isAutoTunnelEnabled && !serviceManager.autoTunnelActive.value) {
|
||||||
settings.isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null
|
|
||||||
) {
|
|
||||||
Timber.d("Starting auto-tunnel on boot/update")
|
Timber.d("Starting auto-tunnel on boot/update")
|
||||||
serviceManager.startAutoTunnel()
|
serviceManager.startAutoTunnel()
|
||||||
} else {
|
} else {
|
||||||
@@ -49,7 +49,6 @@ class RestartReceiver : BroadcastReceiver() {
|
|||||||
} else {
|
} else {
|
||||||
Timber.d("Restore on boot disabled, skipping")
|
Timber.d("Restore on boot disabled, skipping")
|
||||||
}
|
}
|
||||||
if (intent.action == Intent.ACTION_MY_PACKAGE_REPLACED) logReader.deleteAndClearLogs()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+54
-70
@@ -1,11 +1,10 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.service
|
package com.zaneschepke.wireguardautotunnel.core.service
|
||||||
|
|
||||||
import android.content.ComponentName
|
import android.app.Service
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.ServiceConnection
|
|
||||||
import android.net.VpnService
|
import android.net.VpnService
|
||||||
import android.os.IBinder
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.AutoTunnelService
|
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.AutoTunnelService
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
@@ -14,6 +13,7 @@ import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
|||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestAutoTunnelTileServiceUpdate
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestAutoTunnelTileServiceUpdate
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestTunnelTileServiceStateUpdate
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestTunnelTileServiceStateUpdate
|
||||||
import jakarta.inject.Inject
|
import jakarta.inject.Inject
|
||||||
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
@@ -37,37 +37,23 @@ constructor(
|
|||||||
|
|
||||||
private val autoTunnelMutex = Mutex()
|
private val autoTunnelMutex = Mutex()
|
||||||
|
|
||||||
private val _tunnelService = MutableStateFlow<TunnelForegroundService?>(null)
|
private val _autoTunnelActive = MutableStateFlow(false)
|
||||||
private val _autoTunnelService = MutableStateFlow<AutoTunnelService?>(null)
|
val autoTunnelActive = _autoTunnelActive.asStateFlow()
|
||||||
val autoTunnelService = _autoTunnelService.asStateFlow()
|
|
||||||
|
|
||||||
private val tunnelServiceConnection =
|
var autoTunnelService = CompletableDeferred<AutoTunnelService>()
|
||||||
object : ServiceConnection {
|
var backgroundService = CompletableDeferred<TunnelForegroundService>()
|
||||||
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
|
||||||
val binder = service as? TunnelForegroundService.LocalBinder
|
|
||||||
_tunnelService.value = binder?.service
|
|
||||||
Timber.d("TunnelForegroundService connected")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onServiceDisconnected(name: ComponentName) {
|
private fun <T : Service> startService(cls: Class<T>, background: Boolean) {
|
||||||
_tunnelService.value = null
|
runCatching {
|
||||||
Timber.d("TunnelForegroundService disconnected")
|
val intent = Intent(context, cls)
|
||||||
|
if (background) {
|
||||||
|
context.startForegroundService(intent)
|
||||||
|
} else {
|
||||||
|
context.startService(intent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
.onFailure { Timber.e(it) }
|
||||||
|
}
|
||||||
private val autoTunnelServiceConnection =
|
|
||||||
object : ServiceConnection {
|
|
||||||
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
|
||||||
val binder = service as? AutoTunnelService.LocalBinder
|
|
||||||
_autoTunnelService.value = binder?.service
|
|
||||||
Timber.d("AutoTunnelService connected")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onServiceDisconnected(name: ComponentName) {
|
|
||||||
_autoTunnelService.value = null
|
|
||||||
Timber.d("AutoTunnelService disconnected")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun hasVpnPermission(): Boolean {
|
fun hasVpnPermission(): Boolean {
|
||||||
return VpnService.prepare(context) == null
|
return VpnService.prepare(context) == null
|
||||||
@@ -77,13 +63,20 @@ constructor(
|
|||||||
autoTunnelMutex.withLock {
|
autoTunnelMutex.withLock {
|
||||||
val settings = appDataRepository.settings.get()
|
val settings = appDataRepository.settings.get()
|
||||||
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = true))
|
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = true))
|
||||||
if (_autoTunnelService.value != null) return
|
if (autoTunnelService.isCompleted) {
|
||||||
withContext(ioDispatcher) {
|
_autoTunnelActive.update { true }
|
||||||
val intent = Intent(context, AutoTunnelService::class.java)
|
return
|
||||||
context.startForegroundService(intent)
|
|
||||||
context.bindService(intent, autoTunnelServiceConnection, Context.BIND_AUTO_CREATE)
|
|
||||||
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
|
||||||
}
|
}
|
||||||
|
runCatching {
|
||||||
|
autoTunnelService = CompletableDeferred()
|
||||||
|
startService(AutoTunnelService::class.java, !WireGuardAutoTunnel.isForeground())
|
||||||
|
_autoTunnelActive.update { true }
|
||||||
|
}
|
||||||
|
.onFailure {
|
||||||
|
Timber.e(it)
|
||||||
|
_autoTunnelActive.update { false }
|
||||||
|
}
|
||||||
|
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,44 +84,43 @@ constructor(
|
|||||||
autoTunnelMutex.withLock {
|
autoTunnelMutex.withLock {
|
||||||
val settings = appDataRepository.settings.get()
|
val settings = appDataRepository.settings.get()
|
||||||
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = false))
|
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = false))
|
||||||
if (_autoTunnelService.value == null) return
|
if (!autoTunnelService.isCompleted) return
|
||||||
_autoTunnelService.value?.let { service ->
|
runCatching {
|
||||||
service.stop()
|
val service = autoTunnelService.await()
|
||||||
try {
|
service.stop()
|
||||||
context.unbindService(autoTunnelServiceConnection)
|
_autoTunnelActive.update { false }
|
||||||
} finally {
|
autoTunnelService = CompletableDeferred()
|
||||||
_tunnelService.value = null
|
|
||||||
}
|
}
|
||||||
}
|
.onFailure { Timber.e(it) }
|
||||||
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun startTunnelForegroundService() {
|
fun startTunnelForegroundService() {
|
||||||
if (_tunnelService.value != null) return
|
if (backgroundService.isCompleted) return
|
||||||
withContext(ioDispatcher) {
|
runCatching {
|
||||||
applicationScope.launch(ioDispatcher) {
|
backgroundService = CompletableDeferred()
|
||||||
val intent = Intent(context, TunnelForegroundService::class.java)
|
startService(
|
||||||
context.startForegroundService(intent)
|
TunnelForegroundService::class.java,
|
||||||
context.bindService(intent, tunnelServiceConnection, Context.BIND_AUTO_CREATE)
|
!WireGuardAutoTunnel.isForeground(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
.onFailure { Timber.e(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stopTunnelForegroundService() {
|
suspend fun stopTunnelForegroundService() {
|
||||||
_tunnelService.value?.let { service ->
|
if (!backgroundService.isCompleted) return
|
||||||
service.stop()
|
runCatching {
|
||||||
try {
|
val service = backgroundService.await()
|
||||||
context.unbindService(tunnelServiceConnection)
|
service.stop()
|
||||||
} finally {
|
backgroundService = CompletableDeferred()
|
||||||
_tunnelService.value = null
|
|
||||||
}
|
}
|
||||||
}
|
.onFailure { Timber.e(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleAutoTunnel() {
|
fun toggleAutoTunnel() {
|
||||||
applicationScope.launch(ioDispatcher) {
|
applicationScope.launch(ioDispatcher) {
|
||||||
if (_autoTunnelService.value != null) stopAutoTunnel() else startAutoTunnel()
|
if (_autoTunnelActive.value) stopAutoTunnel() else startAutoTunnel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,12 +131,4 @@ constructor(
|
|||||||
fun updateTunnelTile() {
|
fun updateTunnelTile() {
|
||||||
context.requestTunnelTileServiceStateUpdate()
|
context.requestTunnelTileServiceStateUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleTunnelServiceDestroy() {
|
|
||||||
_tunnelService.update { null }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun handleAutoTunnelServiceDestroy() {
|
|
||||||
_autoTunnelService.update { null }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-14
@@ -2,7 +2,6 @@ package com.zaneschepke.wireguardautotunnel.core.service
|
|||||||
|
|
||||||
import android.app.Notification
|
import android.app.Notification
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Binder
|
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import androidx.core.app.ServiceCompat
|
import androidx.core.app.ServiceCompat
|
||||||
import androidx.lifecycle.LifecycleService
|
import androidx.lifecycle.LifecycleService
|
||||||
@@ -24,6 +23,7 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.distinctByKeys
|
|||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.NonCancellable
|
import kotlinx.coroutines.NonCancellable
|
||||||
@@ -64,12 +64,9 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
|
|
||||||
private val jobsMutex = Mutex()
|
private val jobsMutex = Mutex()
|
||||||
|
|
||||||
class LocalBinder(val service: TunnelForegroundService) : Binder()
|
|
||||||
|
|
||||||
private val binder = LocalBinder(this)
|
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
serviceManager.backgroundService.complete(this)
|
||||||
ServiceCompat.startForeground(
|
ServiceCompat.startForeground(
|
||||||
this@TunnelForegroundService,
|
this@TunnelForegroundService,
|
||||||
NotificationManager.VPN_NOTIFICATION_ID,
|
NotificationManager.VPN_NOTIFICATION_ID,
|
||||||
@@ -78,13 +75,14 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBind(intent: Intent): IBinder {
|
override fun onBind(intent: Intent): IBinder? {
|
||||||
super.onBind(intent)
|
super.onBind(intent)
|
||||||
return binder
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
super.onStartCommand(intent, flags, startId)
|
super.onStartCommand(intent, flags, startId)
|
||||||
|
serviceManager.backgroundService.complete(this)
|
||||||
ServiceCompat.startForeground(
|
ServiceCompat.startForeground(
|
||||||
this@TunnelForegroundService,
|
this@TunnelForegroundService,
|
||||||
NotificationManager.VPN_NOTIFICATION_ID,
|
NotificationManager.VPN_NOTIFICATION_ID,
|
||||||
@@ -165,12 +163,8 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
} else {
|
} else {
|
||||||
pingJobs[tun]?.cancel() // Cancel any stale job
|
pingJobs[tun]?.cancel() // Cancel any stale job
|
||||||
if (tun.isPingEnabled) {
|
if (tun.isPingEnabled) {
|
||||||
if (tun.isStaticallyConfigured()) {
|
pingJobs[tun] = startPingJob(tun)
|
||||||
Timber.d("Skipping ping for statically configured tunnel")
|
Timber.d("Started ping job for ${tun.tunName}")
|
||||||
} else {
|
|
||||||
pingJobs[tun] = startPingJob(tun)
|
|
||||||
Timber.d("Started ping job for ${tun.tunName}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,7 +273,7 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
serviceManager.handleTunnelServiceDestroy()
|
serviceManager.backgroundService = CompletableDeferred()
|
||||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-8
@@ -1,7 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.service.autotunnel
|
package com.zaneschepke.wireguardautotunnel.core.service.autotunnel
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Binder
|
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import androidx.core.app.ServiceCompat
|
import androidx.core.app.ServiceCompat
|
||||||
@@ -29,6 +28,7 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
|||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Provider
|
import javax.inject.Provider
|
||||||
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.FlowPreview
|
import kotlinx.coroutines.FlowPreview
|
||||||
@@ -68,23 +68,21 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
|
|
||||||
private var killSwitchJob: Job? = null
|
private var killSwitchJob: Job? = null
|
||||||
|
|
||||||
class LocalBinder(val service: AutoTunnelService) : Binder()
|
|
||||||
|
|
||||||
private val binder = LocalBinder(this)
|
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
serviceManager.autoTunnelService.complete(this)
|
||||||
launchWatcherNotification()
|
launchWatcherNotification()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBind(intent: Intent): IBinder {
|
override fun onBind(intent: Intent): IBinder? {
|
||||||
super.onBind(intent)
|
super.onBind(intent)
|
||||||
return binder
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
super.onStartCommand(intent, flags, startId)
|
super.onStartCommand(intent, flags, startId)
|
||||||
Timber.d("onStartCommand executed with startId: $startId")
|
Timber.d("onStartCommand executed with startId: $startId")
|
||||||
|
serviceManager.autoTunnelService.complete(this)
|
||||||
start()
|
start()
|
||||||
return START_STICKY
|
return START_STICKY
|
||||||
}
|
}
|
||||||
@@ -107,7 +105,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
serviceManager.handleAutoTunnelServiceDestroy()
|
serviceManager.autoTunnelService = CompletableDeferred()
|
||||||
restoreVpnKillSwitch()
|
restoreVpnKillSwitch()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -38,8 +38,8 @@ class AutoTunnelControlTile : TileService(), LifecycleOwner {
|
|||||||
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
Timber.d("Start listening called for auto tunnel tile")
|
Timber.d("Start listening called for auto tunnel tile")
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
serviceManager.autoTunnelService.collect {
|
serviceManager.autoTunnelActive.collect {
|
||||||
if (it != null) return@collect setActive()
|
if (it) return@collect setActive()
|
||||||
setInactive()
|
setInactive()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ class AutoTunnelControlTile : TileService(), LifecycleOwner {
|
|||||||
super.onClick()
|
super.onClick()
|
||||||
unlockAndRun {
|
unlockAndRun {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
if (serviceManager.autoTunnelService.value != null) {
|
if (serviceManager.autoTunnelActive.value) {
|
||||||
serviceManager.stopAutoTunnel()
|
serviceManager.stopAutoTunnel()
|
||||||
setInactive()
|
setInactive()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
|
import com.wireguard.android.backend.BackendException
|
||||||
import com.wireguard.android.backend.Tunnel
|
import com.wireguard.android.backend.Tunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
@@ -10,11 +11,14 @@ import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
|||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendError
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
@@ -27,10 +31,6 @@ abstract class BaseTunnel(
|
|||||||
private val serviceManager: ServiceManager,
|
private val serviceManager: ServiceManager,
|
||||||
) : TunnelProvider {
|
) : TunnelProvider {
|
||||||
|
|
||||||
private val _errorEvents =
|
|
||||||
MutableSharedFlow<Pair<TunnelConf, BackendError>>(replay = 0, extraBufferCapacity = 1)
|
|
||||||
override val errorEvents = _errorEvents.asSharedFlow()
|
|
||||||
|
|
||||||
private val activeTuns = MutableStateFlow<Map<TunnelConf, TunnelState>>(emptyMap())
|
private val activeTuns = MutableStateFlow<Map<TunnelConf, TunnelState>>(emptyMap())
|
||||||
private val tunThreads = ConcurrentHashMap<Int, Thread>()
|
private val tunThreads = ConcurrentHashMap<Int, Thread>()
|
||||||
override val activeTunnels = activeTuns.asStateFlow()
|
override val activeTunnels = activeTuns.asStateFlow()
|
||||||
@@ -45,34 +45,37 @@ abstract class BaseTunnel(
|
|||||||
|
|
||||||
abstract fun stopBackend(tunnel: TunnelConf)
|
abstract fun stopBackend(tunnel: TunnelConf)
|
||||||
|
|
||||||
|
override suspend fun clearError(tunnelConf: TunnelConf) =
|
||||||
|
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
||||||
|
|
||||||
override fun hasVpnPermission(): Boolean {
|
override fun hasVpnPermission(): Boolean {
|
||||||
return serviceManager.hasVpnPermission()
|
return serviceManager.hasVpnPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected suspend fun updateTunnelStatus(
|
protected suspend fun updateTunnelStatus(
|
||||||
tunnelConf: TunnelConf,
|
tunnelConf: TunnelConf,
|
||||||
status: TunnelStatus? = null,
|
state: TunnelStatus? = null,
|
||||||
stats: TunnelStatistics? = null,
|
stats: TunnelStatistics? = null,
|
||||||
) {
|
) {
|
||||||
tunStatusMutex.withLock {
|
tunStatusMutex.withLock {
|
||||||
activeTuns.update { currentTuns ->
|
activeTuns.update { current ->
|
||||||
val originalConf = currentTuns.getKeyById(tunnelConf.id) ?: tunnelConf
|
val originalConf = current.getKeyById(tunnelConf.id) ?: tunnelConf
|
||||||
val existingState = currentTuns.getValueById(tunnelConf.id) ?: TunnelState()
|
val existingState = current.getValueById(tunnelConf.id) ?: TunnelState()
|
||||||
val newState = status ?: existingState.status
|
val newState = state ?: existingState.status
|
||||||
if (newState == TunnelStatus.Down) {
|
if (newState == TunnelStatus.Down) {
|
||||||
Timber.d("Removing tunnel ${tunnelConf.id} from activeTunnels as state is DOWN")
|
Timber.d("Removing tunnel ${tunnelConf.id} from activeTunnels as state is DOWN")
|
||||||
cleanUpTunThread(tunnelConf)
|
cleanUpTunThread(tunnelConf)
|
||||||
currentTuns - originalConf
|
current - originalConf
|
||||||
} else if (existingState.status == newState && stats == null) {
|
} else if (existingState.status == newState && stats == null) {
|
||||||
Timber.d("Skipping redundant state update for ${tunnelConf.id}: $newState")
|
Timber.d("Skipping redundant state update for ${tunnelConf.id}: $newState")
|
||||||
currentTuns
|
current
|
||||||
} else {
|
} else {
|
||||||
val updated =
|
val updated =
|
||||||
existingState.copy(
|
existingState.copy(
|
||||||
status = newState,
|
status = newState,
|
||||||
statistics = stats ?: existingState.statistics,
|
statistics = stats ?: existingState.statistics,
|
||||||
)
|
)
|
||||||
currentTuns + (originalConf to updated)
|
current + (originalConf to updated)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,17 +117,23 @@ abstract class BaseTunnel(
|
|||||||
if (this@BaseTunnel is UserspaceTunnel) stopActiveTunnels()
|
if (this@BaseTunnel is UserspaceTunnel) stopActiveTunnels()
|
||||||
tunMutex.withLock {
|
tunMutex.withLock {
|
||||||
tunThreads[tunnelConf.id] = thread {
|
tunThreads[tunnelConf.id] = thread {
|
||||||
runBlocking {
|
runCatching {
|
||||||
try {
|
runBlocking {
|
||||||
Timber.d("Starting tunnel ${tunnelConf.id}...")
|
try {
|
||||||
startTunnelInner(tunnelConf)
|
Timber.d("Starting tunnel ${tunnelConf.id}...")
|
||||||
Timber.d("Started complete for tunnel ${tunnelConf.name}...")
|
startTunnelInner(tunnelConf)
|
||||||
} catch (e: InterruptedException) {
|
Timber.d("Started complete for tunnel ${tunnelConf.name}...")
|
||||||
Timber.w(
|
} catch (e: BackendError) {
|
||||||
"Tunnel start has been interrupted as ${tunnelConf.name} failed to start"
|
Timber.e(e, "Failed to start tunnel ${tunnelConf.name} userspace")
|
||||||
)
|
updateTunnelStatus(tunnelConf, TunnelStatus.Error(e))
|
||||||
|
} catch (e: InterruptedException) {
|
||||||
|
Timber.w(
|
||||||
|
"Tunnel start has been interrupted as ${tunnelConf.name} failed to start"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
.onFailure { Timber.w("Tunnel start has been interrupted") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,10 +147,11 @@ abstract class BaseTunnel(
|
|||||||
Timber.d("Started for tun ${tunnelConf.id}...")
|
Timber.d("Started for tun ${tunnelConf.id}...")
|
||||||
saveTunnelActiveState(tunnelConf, true)
|
saveTunnelActiveState(tunnelConf, true)
|
||||||
serviceManager.startTunnelForegroundService()
|
serviceManager.startTunnelForegroundService()
|
||||||
} catch (e: BackendError) {
|
} catch (e: BackendException) {
|
||||||
Timber.e(e, "Failed to start backend for ${tunnelConf.name}")
|
Timber.e(e, "Failed to start backend for ${tunnelConf.name}")
|
||||||
_errorEvents.emit(tunnelConf to e)
|
val backendError = e.toBackendError()
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
updateTunnelStatus(tunnelConf, TunnelStatus.Error(backendError))
|
||||||
|
throw backendError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,27 +163,26 @@ abstract class BaseTunnel(
|
|||||||
override suspend fun stopTunnel(tunnelConf: TunnelConf?, reason: TunnelStatus.StopReason) {
|
override suspend fun stopTunnel(tunnelConf: TunnelConf?, reason: TunnelStatus.StopReason) {
|
||||||
if (tunnelConf == null) return stopActiveTunnels()
|
if (tunnelConf == null) return stopActiveTunnels()
|
||||||
tunMutex.withLock {
|
tunMutex.withLock {
|
||||||
if (activeTuns.isStarting(tunnelConf.id))
|
try {
|
||||||
return handleStuckStartingTunnelShutdown(tunnelConf)
|
if (activeTuns.isStarting(tunnelConf.id))
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Stopping(reason))
|
return handleStuckStartingTunnelShutdown(tunnelConf)
|
||||||
stopTunnelInner(tunnelConf)
|
updateTunnelStatus(tunnelConf, TunnelStatus.Stopping(reason))
|
||||||
|
stopTunnelInner(tunnelConf)
|
||||||
|
} catch (e: BackendError) {
|
||||||
|
Timber.e(e, "Failed to stop tunnel ${tunnelConf.id}")
|
||||||
|
updateTunnelStatus(tunnelConf, TunnelStatus.Error(e))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun stopTunnelInner(tunnelConf: TunnelConf) {
|
private suspend fun stopTunnelInner(tunnelConf: TunnelConf) {
|
||||||
try {
|
val tunnel = activeTuns.findTunnel(tunnelConf.id) ?: return
|
||||||
val tunnel = activeTuns.findTunnel(tunnelConf.id) ?: return
|
stopBackend(tunnel)
|
||||||
stopBackend(tunnel)
|
saveTunnelActiveState(tunnelConf, false)
|
||||||
saveTunnelActiveState(tunnelConf, false)
|
removeActiveTunnel(tunnel)
|
||||||
removeActiveTunnel(tunnel)
|
|
||||||
} catch (e: BackendError) {
|
|
||||||
Timber.e(e, "Failed to stop tunnel ${tunnelConf.id}")
|
|
||||||
_errorEvents.emit(tunnelConf to e)
|
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleServiceStateOnChange() {
|
private suspend fun handleServiceStateOnChange() {
|
||||||
if (activeTuns.value.isEmpty() && bouncingTunnelIds.isEmpty())
|
if (activeTuns.value.isEmpty() && bouncingTunnelIds.isEmpty())
|
||||||
serviceManager.stopTunnelForegroundService()
|
serviceManager.stopTunnelForegroundService()
|
||||||
}
|
}
|
||||||
@@ -184,15 +193,15 @@ abstract class BaseTunnel(
|
|||||||
tunThreads[tunnel.id]?.let {
|
tunThreads[tunnel.id]?.let {
|
||||||
if (it.state != Thread.State.TERMINATED) {
|
if (it.state != Thread.State.TERMINATED) {
|
||||||
it.interrupt()
|
it.interrupt()
|
||||||
|
updateTunnelStatus(tunnel, TunnelStatus.Down)
|
||||||
} else {
|
} else {
|
||||||
Timber.d("Thread already terminated")
|
Timber.d("Thread already terminated")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "Failed to stop tunnel thread for ${tunnel.name}")
|
Timber.e(e, "Failed to stop tunnel thread for ${tunnel.name}")
|
||||||
} finally {
|
|
||||||
updateTunnelStatus(tunnel, TunnelStatus.Down)
|
|
||||||
}
|
}
|
||||||
|
cleanUpTunThread(tunnel)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cleanUpTunThread(tunnel: TunnelConf) {
|
private fun cleanUpTunThread(tunnel: TunnelConf) {
|
||||||
@@ -212,7 +221,7 @@ abstract class BaseTunnel(
|
|||||||
bouncingTunnelIds[tunnelConf.id] = reason
|
bouncingTunnelIds[tunnelConf.id] = reason
|
||||||
try {
|
try {
|
||||||
stopTunnel(tunnelConf, reason)
|
stopTunnel(tunnelConf, reason)
|
||||||
delay(BOUNCE_DELAY)
|
delay(300L)
|
||||||
startTunnel(tunnelConf)
|
startTunnel(tunnelConf)
|
||||||
} finally {
|
} finally {
|
||||||
bouncingTunnelIds.remove(tunnelConf.id)
|
bouncingTunnelIds.remove(tunnelConf.id)
|
||||||
@@ -226,8 +235,4 @@ abstract class BaseTunnel(
|
|||||||
|
|
||||||
override suspend fun runningTunnelNames(): Set<String> =
|
override suspend fun runningTunnelNames(): Set<String> =
|
||||||
activeTuns.value.keys.map { it.tunName }.toSet()
|
activeTuns.value.keys.map { it.tunName }.toSet()
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val BOUNCE_DELAY = 300L
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|||||||
import com.zaneschepke.wireguardautotunnel.di.Kernel
|
import com.zaneschepke.wireguardautotunnel.di.Kernel
|
||||||
import com.zaneschepke.wireguardautotunnel.di.Userspace
|
import com.zaneschepke.wireguardautotunnel.di.Userspace
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendError
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
@@ -16,7 +15,6 @@ import kotlinx.coroutines.CoroutineDispatcher
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharedFlow
|
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.filterNotNull
|
import kotlinx.coroutines.flow.filterNotNull
|
||||||
import kotlinx.coroutines.flow.flatMapLatest
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
@@ -64,9 +62,6 @@ constructor(
|
|||||||
initialValue = emptyMap(),
|
initialValue = emptyMap(),
|
||||||
)
|
)
|
||||||
|
|
||||||
override val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
|
||||||
get() = tunnelProviderFlow.value.errorEvents
|
|
||||||
|
|
||||||
override val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason> =
|
override val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason> =
|
||||||
tunnelProviderFlow.value.bouncingTunnelIds
|
tunnelProviderFlow.value.bouncingTunnelIds
|
||||||
|
|
||||||
@@ -74,6 +69,10 @@ constructor(
|
|||||||
return userspaceTunnel.hasVpnPermission()
|
return userspaceTunnel.hasVpnPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun clearError(tunnelConf: TunnelConf) {
|
||||||
|
tunnelProviderFlow.value.clearError(tunnelConf)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun updateTunnelStatistics(tunnel: TunnelConf) {
|
override suspend fun updateTunnelStatistics(tunnel: TunnelConf) {
|
||||||
tunnelProviderFlow.value.updateTunnelStatistics(tunnel)
|
tunnelProviderFlow.value.updateTunnelStatistics(tunnel)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendError
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import kotlinx.coroutines.flow.SharedFlow
|
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
|
||||||
interface TunnelProvider {
|
interface TunnelProvider {
|
||||||
@@ -48,11 +46,11 @@ interface TunnelProvider {
|
|||||||
|
|
||||||
val activeTunnels: StateFlow<Map<TunnelConf, TunnelState>>
|
val activeTunnels: StateFlow<Map<TunnelConf, TunnelState>>
|
||||||
|
|
||||||
val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
|
||||||
|
|
||||||
val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason>
|
val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason>
|
||||||
|
|
||||||
fun hasVpnPermission(): Boolean
|
fun hasVpnPermission(): Boolean
|
||||||
|
|
||||||
|
suspend fun clearError(tunnelConf: TunnelConf)
|
||||||
|
|
||||||
suspend fun updateTunnelStatistics(tunnel: TunnelConf)
|
suspend fun updateTunnelStatistics(tunnel: TunnelConf)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -50,9 +50,8 @@ constructor(
|
|||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
Timber.e(e, "Failed to stop tunnel ${tunnel.id}")
|
Timber.e(e, "Failed to stop tunnel ${tunnel.id}")
|
||||||
throw e.toBackendError()
|
throw e.toBackendError()
|
||||||
} finally {
|
|
||||||
handlePreviouslyEnabledVpnKillSwitch()
|
|
||||||
}
|
}
|
||||||
|
handlePreviouslyEnabledVpnKillSwitch()
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop vpn kill switch if we need to resolve DNS for peer endpoints
|
// stop vpn kill switch if we need to resolve DNS for peer endpoints
|
||||||
@@ -70,7 +69,7 @@ constructor(
|
|||||||
// restore vpn kill switch if needed
|
// restore vpn kill switch if needed
|
||||||
private fun handlePreviouslyEnabledVpnKillSwitch() {
|
private fun handlePreviouslyEnabledVpnKillSwitch() {
|
||||||
// let auto tunnel handle this if it is active
|
// let auto tunnel handle this if it is active
|
||||||
if (serviceManager.autoTunnelService.value == null) {
|
if (!serviceManager.autoTunnelActive.value) {
|
||||||
previousBackendState?.let { (state, lanEnabled) ->
|
previousBackendState?.let { (state, lanEnabled) ->
|
||||||
Timber.d("Restoring kill switch configuration")
|
Timber.d("Restoring kill switch configuration")
|
||||||
val lan = if (lanEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS else emptyList()
|
val lan = if (lanEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS else emptyList()
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ constructor(
|
|||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
Timber.i("Service worker started")
|
Timber.i("Service worker started")
|
||||||
with(appDataRepository.settings.get()) {
|
with(appDataRepository.settings.get()) {
|
||||||
if (isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null)
|
if (isAutoTunnelEnabled && !serviceManager.autoTunnelActive.value)
|
||||||
return@with serviceManager.startAutoTunnel()
|
return@with serviceManager.startAutoTunnel()
|
||||||
if (tunnelManager.activeTunnels.value.isEmpty())
|
if (tunnelManager.activeTunnels.value.isEmpty())
|
||||||
tunnelManager.restorePreviousState()
|
tunnelManager.restorePreviousState()
|
||||||
|
|||||||
@@ -60,10 +60,6 @@ data class TunnelConf(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isStaticallyConfigured(): Boolean {
|
|
||||||
return toAmConfig().peers.all { it.endpoint.get().host.isValidIpv4orIpv6Address() }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun copyWithCallback(
|
fun copyWithCallback(
|
||||||
id: Int = this.id,
|
id: Int = this.id,
|
||||||
tunName: String = this.tunName,
|
tunName: String = this.tunName,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.enums
|
package com.zaneschepke.wireguardautotunnel.domain.enums
|
||||||
|
|
||||||
sealed class TunnelStatus {
|
sealed class TunnelStatus {
|
||||||
|
data class Error(val error: BackendError) : TunnelStatus()
|
||||||
|
|
||||||
data object Up : TunnelStatus()
|
data object Up : TunnelStatus()
|
||||||
|
|
||||||
|
|||||||
-1
@@ -12,7 +12,6 @@ class AmneziaStatistics(private val statistics: Statistics) : TunnelStatistics()
|
|||||||
rxBytes = stats.rxBytes,
|
rxBytes = stats.rxBytes,
|
||||||
txBytes = stats.txBytes,
|
txBytes = stats.txBytes,
|
||||||
latestHandshakeEpochMillis = stats.latestHandshakeEpochMillis,
|
latestHandshakeEpochMillis = stats.latestHandshakeEpochMillis,
|
||||||
resolvedEndpoint = stats.resolvedEndpoint,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ abstract class TunnelStatistics {
|
|||||||
val rxBytes: Long,
|
val rxBytes: Long,
|
||||||
val txBytes: Long,
|
val txBytes: Long,
|
||||||
val latestHandshakeEpochMillis: Long,
|
val latestHandshakeEpochMillis: Long,
|
||||||
val resolvedEndpoint: String,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
abstract fun peerStats(peer: Key): PeerStats?
|
abstract fun peerStats(peer: Key): PeerStats?
|
||||||
|
|||||||
-1
@@ -12,7 +12,6 @@ class WireGuardStatistics(private val statistics: Statistics) : TunnelStatistics
|
|||||||
txBytes = peerStats.txBytes,
|
txBytes = peerStats.txBytes,
|
||||||
rxBytes = peerStats.rxBytes,
|
rxBytes = peerStats.rxBytes,
|
||||||
latestHandshakeEpochMillis = peerStats.latestHandshakeEpochMillis,
|
latestHandshakeEpochMillis = peerStats.latestHandshakeEpochMillis,
|
||||||
resolvedEndpoint = peerStats.resolvedEndpoint,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-15
@@ -2,21 +2,22 @@ package com.zaneschepke.wireguardautotunnel.ui.common
|
|||||||
|
|
||||||
import androidx.compose.animation.animateContentSize
|
import androidx.compose.animation.animateContentSize
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.combinedClickable
|
import androidx.compose.foundation.combinedClickable
|
||||||
import androidx.compose.foundation.indication
|
import androidx.compose.foundation.indication
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
|
import androidx.compose.foundation.interaction.PressInteraction
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.ripple
|
import androidx.compose.material3.ripple
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
@@ -43,25 +44,32 @@ fun ExpandingRowListItem(
|
|||||||
modifier =
|
modifier =
|
||||||
Modifier.animateContentSize()
|
Modifier.animateContentSize()
|
||||||
.clip(RoundedCornerShape(8.dp))
|
.clip(RoundedCornerShape(8.dp))
|
||||||
.background(
|
|
||||||
if (isSelected) MaterialTheme.colorScheme.primary.copy(alpha = 0.1f)
|
|
||||||
else Color.Transparent
|
|
||||||
)
|
|
||||||
.then(
|
.then(
|
||||||
if (!isTv) {
|
if (!isTv) {
|
||||||
Modifier.combinedClickable(
|
Modifier.combinedClickable(
|
||||||
interactionSource = interactionSource,
|
onClick = onClick,
|
||||||
indication = ripple(),
|
onLongClick = {
|
||||||
onClick = onClick,
|
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
onLongClick = {
|
onHold()
|
||||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
},
|
||||||
onHold()
|
onDoubleClick = onDoubleClick,
|
||||||
},
|
)
|
||||||
onDoubleClick = onDoubleClick,
|
.indication(
|
||||||
)
|
interactionSource = interactionSource,
|
||||||
|
indication = ripple(),
|
||||||
|
)
|
||||||
} else Modifier
|
} else Modifier
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
LaunchedEffect(isSelected) {
|
||||||
|
if (isSelected) {
|
||||||
|
interactionSource.emit(PressInteraction.Press(Offset.Zero))
|
||||||
|
} else {
|
||||||
|
interactionSource.emit(
|
||||||
|
PressInteraction.Release(PressInteraction.Press(Offset.Zero))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Column {
|
Column {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),
|
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),
|
||||||
|
|||||||
-42
@@ -1,42 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common.functions
|
|
||||||
|
|
||||||
import android.content.ClipData
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
|
||||||
import androidx.compose.ui.platform.ClipEntry
|
|
||||||
import androidx.compose.ui.platform.Clipboard
|
|
||||||
import androidx.compose.ui.platform.LocalClipboard
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
class ClipboardHelper(
|
|
||||||
private val clipboard: Clipboard,
|
|
||||||
private val coroutineScope: CoroutineScope,
|
|
||||||
private val dispatcher: CoroutineDispatcher = Dispatchers.Main,
|
|
||||||
) {
|
|
||||||
fun copy(text: String, label: String = "") {
|
|
||||||
coroutineScope.launch(dispatcher) {
|
|
||||||
val clipData = ClipData.newPlainText(label, text)
|
|
||||||
clipboard.setClipEntry(ClipEntry(clipData))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun paste(onResult: (String?) -> Unit) {
|
|
||||||
coroutineScope.launch(dispatcher) {
|
|
||||||
val entry = clipboard.getClipEntry()
|
|
||||||
val text = entry?.clipData?.getItemAt(0)?.text?.toString()
|
|
||||||
onResult(text)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun rememberClipboardHelper(
|
|
||||||
coroutineScope: CoroutineScope = rememberCoroutineScope()
|
|
||||||
): ClipboardHelper {
|
|
||||||
val clipboard = LocalClipboard.current
|
|
||||||
return remember(clipboard, coroutineScope) { ClipboardHelper(clipboard, coroutineScope) }
|
|
||||||
}
|
|
||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components
|
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components
|
||||||
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.PublicOff
|
import androidx.compose.material.icons.outlined.AirplanemodeActive
|
||||||
import androidx.compose.material.icons.outlined.SettingsEthernet
|
import androidx.compose.material.icons.outlined.SettingsEthernet
|
||||||
import androidx.compose.material.icons.outlined.SignalCellular4Bar
|
import androidx.compose.material.icons.outlined.SignalCellular4Bar
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@@ -95,7 +95,7 @@ fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<Se
|
|||||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnEthernet) },
|
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnEthernet) },
|
||||||
),
|
),
|
||||||
SelectionItem(
|
SelectionItem(
|
||||||
leadingIcon = Icons.Outlined.PublicOff,
|
leadingIcon = Icons.Outlined.AirplanemodeActive,
|
||||||
title = {
|
title = {
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.stop_on_no_internet),
|
stringResource(R.string.stop_on_no_internet),
|
||||||
|
|||||||
+20
-31
@@ -22,15 +22,16 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalClipboardManager
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.networkmonitor.NetworkStatus
|
import com.zaneschepke.networkmonitor.NetworkStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.LearnMoreLinkLabel
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.LearnMoreLinkLabel
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||||
@@ -47,7 +48,7 @@ fun WifiTunnelingItems(
|
|||||||
isWifiNameReadable: () -> Boolean,
|
isWifiNameReadable: () -> Boolean,
|
||||||
): List<SelectionItem> {
|
): List<SelectionItem> {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val clipboardHelper = rememberClipboardHelper()
|
val clipboard = LocalClipboardManager.current
|
||||||
|
|
||||||
val baseItems =
|
val baseItems =
|
||||||
listOf(
|
listOf(
|
||||||
@@ -70,41 +71,29 @@ fun WifiTunnelingItems(
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
description = {
|
description = {
|
||||||
val wifiInfo by
|
val wifiName by
|
||||||
remember(uiState.networkStatus) {
|
remember(uiState.networkStatus) {
|
||||||
derivedStateOf {
|
derivedStateOf {
|
||||||
(uiState.networkStatus as? NetworkStatus.Connected)
|
(uiState.networkStatus as? NetworkStatus.Connected)
|
||||||
?.takeIf { it.wifiConnected }
|
?.takeIf { it.wifiConnected }
|
||||||
.let { Pair(it?.wifiSsid, it?.securityType) }
|
?.wifiSsid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val (wifiName, securityType) = wifiInfo
|
Text(
|
||||||
Column {
|
text =
|
||||||
Text(
|
wifiName?.let { stringResource(R.string.wifi_name_template, it) }
|
||||||
text =
|
?: stringResource(R.string.inactive),
|
||||||
wifiName?.let { stringResource(R.string.wifi_name_template, it) }
|
style =
|
||||||
?: stringResource(R.string.inactive),
|
MaterialTheme.typography.bodySmall.copy(
|
||||||
style =
|
color = MaterialTheme.colorScheme.outline
|
||||||
MaterialTheme.typography.bodySmall.copy(
|
),
|
||||||
color = MaterialTheme.colorScheme.outline
|
maxLines = 1,
|
||||||
),
|
overflow = TextOverflow.Ellipsis,
|
||||||
maxLines = 1,
|
modifier =
|
||||||
overflow = TextOverflow.Ellipsis,
|
Modifier.clickable {
|
||||||
modifier =
|
wifiName?.let { clipboard.setText(AnnotatedString(it)) }
|
||||||
Modifier.clickable { wifiName?.let { clipboardHelper.copy(it) } },
|
},
|
||||||
)
|
)
|
||||||
securityType?.let {
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.security_template, it.name),
|
|
||||||
style =
|
|
||||||
MaterialTheme.typography.bodySmall.copy(
|
|
||||||
color = MaterialTheme.colorScheme.outline
|
|
||||||
),
|
|
||||||
maxLines = 1,
|
|
||||||
overflow = TextOverflow.Ellipsis,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnWifi) },
|
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnWifi) },
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalClipboardManager
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileImportLauncherForResult
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileImportLauncherForResult
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ExportTunnelsBottomSheet
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ExportTunnelsBottomSheet
|
||||||
@@ -29,7 +29,7 @@ import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
|||||||
@Composable
|
@Composable
|
||||||
fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: AppViewModel) {
|
fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: AppViewModel) {
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val clipboard = rememberClipboardHelper()
|
val clipboard = LocalClipboardManager.current
|
||||||
|
|
||||||
var showUrlImportDialog by remember { mutableStateOf(false) }
|
var showUrlImportDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
@@ -90,9 +90,8 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
|||||||
requestPermissionLauncher.launch(android.Manifest.permission.CAMERA)
|
requestPermissionLauncher.launch(android.Manifest.permission.CAMERA)
|
||||||
},
|
},
|
||||||
onClipboardClick = {
|
onClipboardClick = {
|
||||||
clipboard.paste { result ->
|
clipboard.getText()?.text?.let {
|
||||||
if (result != null)
|
viewModel.handleEvent(AppEvent.ImportTunnelFromClipboard(it))
|
||||||
viewModel.handleEvent(AppEvent.ImportTunnelFromClipboard(result))
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onManualImportClick = {
|
onManualImportClick = {
|
||||||
|
|||||||
+4
-18
@@ -7,7 +7,6 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.overscroll
|
import androidx.compose.foundation.overscroll
|
||||||
import androidx.compose.foundation.rememberOverscrollEffect
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@@ -19,7 +18,6 @@ import com.zaneschepke.wireguardautotunnel.core.tunnel.getValueById
|
|||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||||
@@ -37,19 +35,12 @@ fun TunnelList(
|
|||||||
onToggleTunnel: (TunnelConf, Boolean) -> Unit,
|
onToggleTunnel: (TunnelConf, Boolean) -> Unit,
|
||||||
viewModel: AppViewModel,
|
viewModel: AppViewModel,
|
||||||
) {
|
) {
|
||||||
val isTv = LocalIsAndroidTV.current
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val collator = Collator.getInstance(Locale.getDefault())
|
val collator = Collator.getInstance(Locale.getDefault())
|
||||||
val sortedTunnels =
|
val sortedTunnels =
|
||||||
remember(appUiState.tunnels) {
|
remember(appUiState.tunnels) {
|
||||||
appUiState.tunnels.sortedWith(
|
appUiState.tunnels.sortedWith(compareBy(collator) { it.tunName })
|
||||||
compareBy(
|
|
||||||
// primary tunnel first
|
|
||||||
{ !it.isPrimaryTunnel },
|
|
||||||
{ collator.compare(it.tunName, "") },
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
@@ -58,7 +49,7 @@ fun TunnelList(
|
|||||||
modifier =
|
modifier =
|
||||||
modifier
|
modifier
|
||||||
.pointerInput(Unit) { if (appUiState.tunnels.isEmpty()) return@pointerInput }
|
.pointerInput(Unit) { if (appUiState.tunnels.isEmpty()) return@pointerInput }
|
||||||
.overscroll(rememberOverscrollEffect()),
|
.overscroll(ScrollableDefaults.overscrollEffect()),
|
||||||
state = rememberLazyListState(0, appUiState.tunnels.count()),
|
state = rememberLazyListState(0, appUiState.tunnels.count()),
|
||||||
userScrollEnabled = true,
|
userScrollEnabled = true,
|
||||||
reverseLayout = false,
|
reverseLayout = false,
|
||||||
@@ -80,12 +71,8 @@ fun TunnelList(
|
|||||||
tunnel = tunnel,
|
tunnel = tunnel,
|
||||||
tunnelState = tunnelState,
|
tunnelState = tunnelState,
|
||||||
onClick = {
|
onClick = {
|
||||||
if (selectedTunnels.isNotEmpty() && !isTv) {
|
navController.navigate(Route.TunnelOptions(tunnel.id))
|
||||||
viewModel.handleEvent(AppEvent.ToggleSelectedTunnel(tunnel))
|
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
||||||
} else {
|
|
||||||
navController.navigate(Route.TunnelOptions(tunnel.id))
|
|
||||||
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onDoubleClick = {
|
onDoubleClick = {
|
||||||
viewModel.handleEvent(AppEvent.ToggleTunnelStatsExpanded(tunnel.id))
|
viewModel.handleEvent(AppEvent.ToggleTunnelStatsExpanded(tunnel.id))
|
||||||
@@ -94,7 +81,6 @@ fun TunnelList(
|
|||||||
viewModel.handleEvent(AppEvent.ToggleSelectedTunnel(it))
|
viewModel.handleEvent(AppEvent.ToggleSelectedTunnel(it))
|
||||||
},
|
},
|
||||||
onSwitchClick = { checked -> onToggleTunnel(tunnel, checked) },
|
onSwitchClick = { checked -> onToggleTunnel(tunnel, checked) },
|
||||||
isTv = isTv,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -26,6 +26,7 @@ import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
|||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.ExpandingRowListItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.ExpandingRowListItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asColor
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asColor
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -39,8 +40,9 @@ fun TunnelRowItem(
|
|||||||
onDoubleClick: () -> Unit,
|
onDoubleClick: () -> Unit,
|
||||||
onToggleSelectedTunnel: (TunnelConf) -> Unit,
|
onToggleSelectedTunnel: (TunnelConf) -> Unit,
|
||||||
onSwitchClick: (Boolean) -> Unit,
|
onSwitchClick: (Boolean) -> Unit,
|
||||||
isTv: Boolean,
|
|
||||||
) {
|
) {
|
||||||
|
val isTv = LocalIsAndroidTV.current
|
||||||
|
|
||||||
val leadingIconColor =
|
val leadingIconColor =
|
||||||
remember(state) {
|
remember(state) {
|
||||||
if (state.status.isUp()) tunnelState.statistics.asColor() else Color.Gray
|
if (state.status.isUp()) tunnelState.statistics.asColor() else Color.Gray
|
||||||
|
|||||||
+23
-67
@@ -8,9 +8,6 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.derivedStateOf
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
@@ -24,90 +21,49 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.toThreeDecimalPlaceSt
|
|||||||
@Composable
|
@Composable
|
||||||
fun TunnelStatisticsRow(statistics: TunnelStatistics?, tunnelConf: TunnelConf) {
|
fun TunnelStatisticsRow(statistics: TunnelStatistics?, tunnelConf: TunnelConf) {
|
||||||
val config = TunnelConf.configFromAmQuick(tunnelConf.wgQuick)
|
val config = TunnelConf.configFromAmQuick(tunnelConf.wgQuick)
|
||||||
Column(
|
config.peers.forEach { peer ->
|
||||||
modifier = Modifier.fillMaxWidth().padding(start = 45.dp, bottom = 10.dp, end = 10.dp),
|
Row(
|
||||||
verticalArrangement = Arrangement.spacedBy(10.dp, Alignment.CenterVertically),
|
modifier = Modifier.fillMaxWidth().padding(end = 10.dp, bottom = 10.dp, start = 45.dp),
|
||||||
horizontalAlignment = Alignment.Start,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
horizontalArrangement = Arrangement.spacedBy(5.dp, Alignment.Start),
|
||||||
config.peers.forEach { peer ->
|
) {
|
||||||
val peerId = remember { peer.publicKey.toBase64().subSequence(0, 3).toString() + "***" }
|
val peerId = peer.publicKey.toBase64().subSequence(0, 3).toString() + "***"
|
||||||
val endpoint =
|
val peerRx = statistics?.peerStats(peer.publicKey)?.rxBytes ?: 0
|
||||||
remember(statistics) { statistics?.peerStats(peer.publicKey)?.resolvedEndpoint }
|
val peerTx = statistics?.peerStats(peer.publicKey)?.txBytes ?: 0
|
||||||
val peerRxMB by
|
val peerTxMB = NumberUtils.bytesToMB(peerTx).toThreeDecimalPlaceString()
|
||||||
remember(statistics) {
|
val peerRxMB = NumberUtils.bytesToMB(peerRx).toThreeDecimalPlaceString()
|
||||||
derivedStateOf {
|
val handshake =
|
||||||
statistics
|
statistics?.peerStats(peer.publicKey)?.latestHandshakeEpochMillis?.let {
|
||||||
?.peerStats(peer.publicKey)
|
if (it == 0L) {
|
||||||
?.rxBytes
|
stringResource(R.string.never)
|
||||||
?.let { NumberUtils.bytesToMB(it) }
|
} else {
|
||||||
?.toThreeDecimalPlaceString()
|
"${NumberUtils.getSecondsBetweenTimestampAndNow(it)} ${stringResource(R.string.sec)}"
|
||||||
}
|
}
|
||||||
}
|
} ?: stringResource(R.string.never)
|
||||||
val peerTxMB by
|
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
remember(statistics) {
|
|
||||||
derivedStateOf {
|
|
||||||
statistics
|
|
||||||
?.peerStats(peer.publicKey)
|
|
||||||
?.txBytes
|
|
||||||
?.let { NumberUtils.bytesToMB(it) }
|
|
||||||
?.toThreeDecimalPlaceString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val handshake by
|
|
||||||
remember(statistics) {
|
|
||||||
derivedStateOf {
|
|
||||||
statistics?.peerStats(peer.publicKey)?.latestHandshakeEpochMillis?.let {
|
|
||||||
if (it == 0L) {
|
|
||||||
null
|
|
||||||
} else {
|
|
||||||
"${NumberUtils.getSecondsBetweenTimestampAndNow(it)}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start),
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.peer).lowercase() + ": $peerId",
|
stringResource(R.string.peer).lowercase() + ": $peerId",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.handshake) +
|
"tx: $peerTxMB MB",
|
||||||
": ${if(handshake == null) stringResource(R.string.never) else handshake + " " + stringResource(R.string.sec)}",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Row(
|
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start),
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
"rx: ${peerRxMB ?: 0.00} MB",
|
stringResource(R.string.handshake) + ": $handshake",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
"tx: ${peerTxMB ?: 0.00} MB",
|
"rx: $peerRxMB MB",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (endpoint != null) {
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start),
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
"endpoint: $endpoint",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.outline,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-5
@@ -16,15 +16,16 @@ import androidx.compose.material3.OutlinedTextField
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalClipboardManager
|
||||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||||
import androidx.compose.ui.text.input.VisualTransformation
|
import androidx.compose.ui.text.input.VisualTransformation
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationTextBox
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationTextBox
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.InterfaceProxy
|
import com.zaneschepke.wireguardautotunnel.ui.state.InterfaceProxy
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -37,7 +38,7 @@ fun InterfaceFields(
|
|||||||
onInterfaceChange: (InterfaceProxy) -> Unit,
|
onInterfaceChange: (InterfaceProxy) -> Unit,
|
||||||
) {
|
) {
|
||||||
val keyboardController = LocalSoftwareKeyboardController.current
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
val clipboardManager = rememberClipboardHelper()
|
val clipboardManager = LocalClipboardManager.current
|
||||||
val keyboardActions = KeyboardActions(onDone = { keyboardController?.hide() })
|
val keyboardActions = KeyboardActions(onDone = { keyboardController?.hide() })
|
||||||
val keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done)
|
val keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done)
|
||||||
|
|
||||||
@@ -52,9 +53,8 @@ fun InterfaceFields(
|
|||||||
if (isAuthenticated) VisualTransformation.None else PasswordVisualTransformation(),
|
if (isAuthenticated) VisualTransformation.None else PasswordVisualTransformation(),
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
IconButton(
|
IconButton(
|
||||||
enabled = true,
|
enabled = isAuthenticated,
|
||||||
onClick = {
|
onClick = {
|
||||||
if (!isAuthenticated) return@IconButton showAuthPrompt()
|
|
||||||
val keypair = com.wireguard.crypto.KeyPair()
|
val keypair = com.wireguard.crypto.KeyPair()
|
||||||
onInterfaceChange(
|
onInterfaceChange(
|
||||||
interfaceState.copy(
|
interfaceState.copy(
|
||||||
@@ -88,7 +88,9 @@ fun InterfaceFields(
|
|||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
IconButton(onClick = { clipboardManager.copy(interfaceState.publicKey) }) {
|
IconButton(
|
||||||
|
onClick = { clipboardManager.setText(AnnotatedString(interfaceState.publicKey)) }
|
||||||
|
) {
|
||||||
Icon(Icons.Rounded.ContentCopy, stringResource(R.string.copy_public_key))
|
Icon(Icons.Rounded.ContentCopy, stringResource(R.string.copy_public_key))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+17
-15
@@ -1,15 +1,12 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.animation.Crossfade
|
||||||
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
@@ -37,16 +34,21 @@ fun SplitTunnelScreen(
|
|||||||
appViewModel.handleEvent(AppEvent.PopBackStack(true))
|
appViewModel.handleEvent(AppEvent.PopBackStack(true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (uiState.loading) {
|
|
||||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
Crossfade(
|
||||||
CircularProgressIndicator(modifier = Modifier.size(30.dp), strokeWidth = 5.dp)
|
targetState = uiState.loading,
|
||||||
|
animationSpec = tween(200),
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
) { isLoading ->
|
||||||
|
if (isLoading) {
|
||||||
|
SplitTunnelSkeleton()
|
||||||
|
} else {
|
||||||
|
SplitTunnelContent(
|
||||||
|
uiState = uiState,
|
||||||
|
onSplitOptionChange = viewModel::updateSplitOption,
|
||||||
|
onAppSelectionToggle = viewModel::toggleAppSelection,
|
||||||
|
onQueryChange = viewModel::onSearchQuery,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
SplitTunnelContent(
|
|
||||||
uiState = uiState,
|
|
||||||
onSplitOptionChange = viewModel::updateSplitOption,
|
|
||||||
onAppSelectionToggle = viewModel::toggleAppSelection,
|
|
||||||
onQueryChange = viewModel::onSearchQuery,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+92
@@ -0,0 +1,92 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.animation.ShimmerEffect
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SplitTunnelSkeleton() {
|
||||||
|
val shimmerBrush = ShimmerEffect()
|
||||||
|
|
||||||
|
Column(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(24.dp, Alignment.CenterVertically),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(top = 24.dp),
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp).height(45.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
) {
|
||||||
|
repeat(3) {
|
||||||
|
Box(
|
||||||
|
modifier =
|
||||||
|
Modifier.weight(1f)
|
||||||
|
.height(45.dp)
|
||||||
|
.clip(RoundedCornerShape(8.dp))
|
||||||
|
.background(shimmerBrush)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp).height(45.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier =
|
||||||
|
Modifier.height(45.dp)
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clip(RoundedCornerShape(8.dp))
|
||||||
|
.background(shimmerBrush)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
LazyColumn(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Top,
|
||||||
|
contentPadding = PaddingValues(top = 10.dp),
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
items(20) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp, vertical = 8.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier =
|
||||||
|
Modifier.size(iconSize).clip(CircleShape).background(shimmerBrush)
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
|
Box(
|
||||||
|
modifier =
|
||||||
|
Modifier.height(20.dp)
|
||||||
|
.weight(1f)
|
||||||
|
.clip(RoundedCornerShape(4.dp))
|
||||||
|
.background(shimmerBrush)
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
|
Box(modifier = Modifier.size(24.dp).clip(CircleShape).background(shimmerBrush))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-5
@@ -18,6 +18,7 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
|||||||
import java.text.Collator
|
import java.text.Collator
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
@@ -49,6 +50,7 @@ constructor(
|
|||||||
tunnelId?.let { loadInitialState(it) }
|
tunnelId?.let { loadInitialState(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO improve this loading experience
|
||||||
private fun loadInitialState(tunnelId: Int) =
|
private fun loadInitialState(tunnelId: Int) =
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val tunnel = tunnelRepository.getById(tunnelId) ?: return@launch
|
val tunnel = tunnelRepository.getById(tunnelId) ?: return@launch
|
||||||
@@ -64,7 +66,7 @@ constructor(
|
|||||||
|
|
||||||
val installedPackages = packages.map { it.packageName }.toSet()
|
val installedPackages = packages.map { it.packageName }.toSet()
|
||||||
|
|
||||||
// Remove uninstalled apps
|
// remove uninstalled apps
|
||||||
proxyInterface.includedApplications.retainAll { it in installedPackages }
|
proxyInterface.includedApplications.retainAll { it in installedPackages }
|
||||||
proxyInterface.excludedApplications.retainAll { it in installedPackages }
|
proxyInterface.excludedApplications.retainAll { it in installedPackages }
|
||||||
|
|
||||||
@@ -96,13 +98,12 @@ constructor(
|
|||||||
selected,
|
selected,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.sortedWith(
|
.sortedWith(compareBy(collator) { it.first.name })
|
||||||
compareByDescending<Pair<TunnelApp, Boolean>> { it.second }
|
|
||||||
.thenBy(collator) { it.first.name }
|
|
||||||
)
|
|
||||||
|
|
||||||
allTunneledApps = tunneledApps
|
allTunneledApps = tunneledApps
|
||||||
|
|
||||||
|
delay(500)
|
||||||
|
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
SplitTunnelUiState(
|
SplitTunnelUiState(
|
||||||
loading = false,
|
loading = false,
|
||||||
|
|||||||
+5
-3
@@ -8,19 +8,20 @@ import androidx.compose.material3.MaterialTheme
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalClipboardManager
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun RemoteControlItem(uiState: AppUiState, viewModel: AppViewModel): SelectionItem {
|
fun RemoteControlItem(uiState: AppUiState, viewModel: AppViewModel): SelectionItem {
|
||||||
val clipboardManager = rememberClipboardHelper()
|
val clipboardManager = LocalClipboardManager.current
|
||||||
|
|
||||||
return SelectionItem(
|
return SelectionItem(
|
||||||
leadingIcon = Icons.Filled.SmartToy,
|
leadingIcon = Icons.Filled.SmartToy,
|
||||||
@@ -41,7 +42,8 @@ fun RemoteControlItem(uiState: AppUiState, viewModel: AppViewModel): SelectionIt
|
|||||||
),
|
),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
modifier = Modifier.clickable { clipboardManager.copy(key) },
|
modifier =
|
||||||
|
Modifier.clickable { clipboardManager.setText(AnnotatedString(key)) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-16
@@ -23,21 +23,25 @@ fun DisplayScreen(appUiState: AppUiState, viewModel: AppViewModel) {
|
|||||||
verticalArrangement = Arrangement.spacedBy(24.dp, Alignment.Top),
|
verticalArrangement = Arrangement.spacedBy(24.dp, Alignment.Top),
|
||||||
modifier = Modifier.fillMaxSize().padding(top = 24.dp).padding(horizontal = 24.dp),
|
modifier = Modifier.fillMaxSize().padding(top = 24.dp).padding(horizontal = 24.dp),
|
||||||
) {
|
) {
|
||||||
enumValues<Theme>().forEach {
|
IconSurfaceButton(
|
||||||
val title =
|
title = stringResource(R.string.automatic),
|
||||||
when (it) {
|
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.AUTOMATIC)) },
|
||||||
Theme.DARK -> stringResource(R.string.dark)
|
selected = appUiState.appState.theme == Theme.AUTOMATIC,
|
||||||
Theme.LIGHT -> stringResource(R.string.light)
|
)
|
||||||
Theme.AUTOMATIC -> stringResource(R.string.automatic)
|
IconSurfaceButton(
|
||||||
Theme.DYNAMIC -> stringResource(R.string.dynamic)
|
title = stringResource(R.string.light),
|
||||||
Theme.DARKER -> stringResource(R.string.darker)
|
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.LIGHT)) },
|
||||||
Theme.AMOLED -> stringResource(R.string.amoled)
|
selected = appUiState.appState.theme == Theme.LIGHT,
|
||||||
}
|
)
|
||||||
IconSurfaceButton(
|
IconSurfaceButton(
|
||||||
title = title,
|
title = stringResource(R.string.dark),
|
||||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(it)) },
|
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.DARK)) },
|
||||||
selected = appUiState.appState.theme == it,
|
selected = appUiState.appState.theme == Theme.DARK,
|
||||||
)
|
)
|
||||||
}
|
IconSurfaceButton(
|
||||||
|
title = stringResource(R.string.dynamic),
|
||||||
|
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.DYNAMIC)) },
|
||||||
|
selected = appUiState.appState.theme == Theme.DYNAMIC,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -11,16 +11,17 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalClipboardManager
|
||||||
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.zaneschepke.logcatter.model.LogMessage
|
import com.zaneschepke.logcatter.model.LogMessage
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.text.LogTypeLabel
|
import com.zaneschepke.wireguardautotunnel.ui.common.text.LogTypeLabel
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LogItem(log: LogMessage) {
|
fun LogItem(log: LogMessage) {
|
||||||
val clipboardManager = rememberClipboardHelper()
|
val clipboardManager = LocalClipboardManager.current
|
||||||
val fontSize = 10.sp
|
val fontSize = 10.sp
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
@@ -31,7 +32,7 @@ fun LogItem(log: LogMessage) {
|
|||||||
.clickable(
|
.clickable(
|
||||||
interactionSource = remember { MutableInteractionSource() },
|
interactionSource = remember { MutableInteractionSource() },
|
||||||
indication = null,
|
indication = null,
|
||||||
onClick = { clipboardManager.copy(log.toString()) },
|
onClick = { clipboardManager.setText(AnnotatedString(log.toString())) },
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
Text(text = log.tag, modifier = Modifier.fillMaxSize(0.3f), fontSize = fontSize)
|
Text(text = log.tag, modifier = Modifier.fillMaxSize(0.3f), fontSize = fontSize)
|
||||||
|
|||||||
+3
-8
@@ -23,7 +23,6 @@ import com.zaneschepke.wireguardautotunnel.ui.common.label.GroupLabel
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.ContactSupportOptions
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.ContactSupportOptions
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.GeneralSupportOptions
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.GeneralSupportOptions
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.UpdateSection
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.UpdateSection
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.canInstallPackages
|
import com.zaneschepke.wireguardautotunnel.util.extensions.canInstallPackages
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestInstallPackagesPermission
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestInstallPackagesPermission
|
||||||
@@ -55,7 +54,7 @@ fun SupportScreen(viewModel: SupportViewModel = hiltViewModel(), appViewModel: A
|
|||||||
InfoDialog(
|
InfoDialog(
|
||||||
onDismiss = { viewModel.handleUpdateShown() },
|
onDismiss = { viewModel.handleUpdateShown() },
|
||||||
onAttest = {
|
onAttest = {
|
||||||
if (BuildConfig.FLAVOR != Constants.STANDALONE_FLAVOR) {
|
if (BuildConfig.FLAVOR != "full") {
|
||||||
uiState.appUpdate?.apkUrl?.let { context.openWebUrl(it) }
|
uiState.appUpdate?.apkUrl?.let { context.openWebUrl(it) }
|
||||||
return@InfoDialog
|
return@InfoDialog
|
||||||
}
|
}
|
||||||
@@ -87,7 +86,7 @@ fun SupportScreen(viewModel: SupportViewModel = hiltViewModel(), appViewModel: A
|
|||||||
},
|
},
|
||||||
confirmText = {
|
confirmText = {
|
||||||
Text(
|
Text(
|
||||||
if (BuildConfig.FLAVOR != Constants.STANDALONE_FLAVOR) stringResource(R.string.download)
|
if (BuildConfig.FLAVOR != "full") stringResource(R.string.download)
|
||||||
else stringResource(R.string.download_and_install)
|
else stringResource(R.string.download_and_install)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -122,11 +121,7 @@ fun SupportScreen(viewModel: SupportViewModel = hiltViewModel(), appViewModel: A
|
|||||||
)
|
)
|
||||||
UpdateSection(
|
UpdateSection(
|
||||||
onUpdateCheck = {
|
onUpdateCheck = {
|
||||||
if (
|
if (BuildConfig.DEBUG || BuildConfig.VERSION_NAME.contains("beta"))
|
||||||
BuildConfig.DEBUG ||
|
|
||||||
BuildConfig.VERSION_NAME.contains("beta") ||
|
|
||||||
BuildConfig.FLAVOR == Constants.GOOGLE_PLAY_FLAVOR
|
|
||||||
)
|
|
||||||
return@UpdateSection context.showToast(R.string.update_check_unsupported)
|
return@UpdateSection context.showToast(R.string.update_check_unsupported)
|
||||||
context.showToast(R.string.checking_for_update)
|
context.showToast(R.string.checking_for_update)
|
||||||
viewModel.handleUpdateCheck()
|
viewModel.handleUpdateCheck()
|
||||||
|
|||||||
+1
-1
@@ -85,7 +85,7 @@ fun ContactSupportOptions(context: android.content.Context) {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if (BuildConfig.FLAVOR != Constants.GOOGLE_PLAY_FLAVOR) {
|
if (BuildConfig.FLAVOR == Constants.FDROID_FLAVOR) {
|
||||||
add(
|
add(
|
||||||
SelectionItem(
|
SelectionItem(
|
||||||
leadingIcon = Icons.Filled.Favorite,
|
leadingIcon = Icons.Filled.Favorite,
|
||||||
|
|||||||
@@ -10,9 +10,6 @@ val Plantation = Color(0xFF264A49)
|
|||||||
val Shark = Color(0xFF21272A)
|
val Shark = Color(0xFF21272A)
|
||||||
val BalticSea = Color(0xFF1C1B1F)
|
val BalticSea = Color(0xFF1C1B1F)
|
||||||
|
|
||||||
// amoled
|
|
||||||
val ElectricTeal = Color(0xFF4DD0E1)
|
|
||||||
|
|
||||||
// Status colors
|
// Status colors
|
||||||
val SilverTree = Color(0xFF6DB58B)
|
val SilverTree = Color(0xFF6DB58B)
|
||||||
val Brick = Color(0xFFCE4257)
|
val Brick = Color(0xFFCE4257)
|
||||||
|
|||||||
@@ -44,8 +44,6 @@ enum class Theme {
|
|||||||
AUTOMATIC,
|
AUTOMATIC,
|
||||||
LIGHT,
|
LIGHT,
|
||||||
DARK,
|
DARK,
|
||||||
DARKER,
|
|
||||||
AMOLED,
|
|
||||||
DYNAMIC,
|
DYNAMIC,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,18 +59,6 @@ fun WireguardAutoTunnelTheme(theme: Theme = Theme.AUTOMATIC, content: @Composabl
|
|||||||
isDark = true
|
isDark = true
|
||||||
DarkColorScheme
|
DarkColorScheme
|
||||||
}
|
}
|
||||||
Theme.DARKER -> {
|
|
||||||
isDark = true
|
|
||||||
DarkColorScheme.copy(surface = BalticSea, background = BalticSea)
|
|
||||||
}
|
|
||||||
Theme.AMOLED -> {
|
|
||||||
isDark = true
|
|
||||||
DarkColorScheme.copy(
|
|
||||||
surface = Color.Black,
|
|
||||||
background = Color.Black,
|
|
||||||
primary = ElectricTeal,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Theme.LIGHT -> {
|
Theme.LIGHT -> {
|
||||||
isDark = false
|
isDark = false
|
||||||
LightColorScheme
|
LightColorScheme
|
||||||
|
|||||||
@@ -35,7 +35,5 @@ object Constants {
|
|||||||
const val QR_CODE_NAME_PROPERTY = "# Name ="
|
const val QR_CODE_NAME_PROPERTY = "# Name ="
|
||||||
|
|
||||||
const val FDROID_FLAVOR = "fdroid"
|
const val FDROID_FLAVOR = "fdroid"
|
||||||
const val GOOGLE_PLAY_FLAVOR = "google"
|
|
||||||
const val STANDALONE_FLAVOR = "standalone"
|
|
||||||
const val RELEASE = "release"
|
const val RELEASE = "release"
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-19
@@ -1,29 +1,14 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.util.extensions
|
package com.zaneschepke.wireguardautotunnel.util.extensions
|
||||||
|
|
||||||
|
import java.util.regex.Pattern
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
val hasNumberInParentheses = """^(.+?)\((\d+)\)$""".toRegex()
|
val hasNumberInParentheses = """^(.+?)\((\d+)\)$""".toRegex()
|
||||||
|
|
||||||
fun String.isValidIpv4orIpv6Address(): Boolean {
|
fun String.isValidIpv4orIpv6Address(): Boolean {
|
||||||
val sanitized = removeSurrounding("[", "]")
|
val ipv4Pattern = Pattern.compile("^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\$")
|
||||||
val ipv6Pattern =
|
val ipv6Pattern = Pattern.compile("^([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\$")
|
||||||
Regex(
|
return ipv4Pattern.matcher(this).matches() || ipv6Pattern.matcher(this).matches()
|
||||||
"(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:)" +
|
|
||||||
"{1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]" +
|
|
||||||
"{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:" +
|
|
||||||
"[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4})" +
|
|
||||||
"{1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}" +
|
|
||||||
":((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]" +
|
|
||||||
"{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}" +
|
|
||||||
"[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:)" +
|
|
||||||
"{1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))"
|
|
||||||
)
|
|
||||||
val ipv4Pattern =
|
|
||||||
Regex(
|
|
||||||
"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}" +
|
|
||||||
"(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
|
|
||||||
)
|
|
||||||
return ipv4Pattern.matches(sanitized) || ipv6Pattern.matches(sanitized)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.hasNumberInParentheses(): Boolean {
|
fun String.hasNumberInParentheses(): Boolean {
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ import java.time.Instant
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Provider
|
import javax.inject.Provider
|
||||||
import kotlin.collections.component1
|
|
||||||
import kotlin.collections.component2
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
@@ -58,7 +56,7 @@ constructor(
|
|||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||||
@MainDispatcher private val mainDispatcher: CoroutineDispatcher,
|
@MainDispatcher private val mainDispatcher: CoroutineDispatcher,
|
||||||
@AppShell private val rootShell: Provider<RootShell>,
|
@AppShell private val rootShell: Provider<RootShell>,
|
||||||
val tunnelManager: TunnelManager,
|
private val tunnelManager: TunnelManager,
|
||||||
private val serviceManager: ServiceManager,
|
private val serviceManager: ServiceManager,
|
||||||
private val logReader: LogReader,
|
private val logReader: LogReader,
|
||||||
private val fileUtils: FileUtils,
|
private val fileUtils: FileUtils,
|
||||||
@@ -88,7 +86,7 @@ constructor(
|
|||||||
appDataRepository.tunnels.flow,
|
appDataRepository.tunnels.flow,
|
||||||
appDataRepository.appState.flow,
|
appDataRepository.appState.flow,
|
||||||
tunnelManager.activeTunnels,
|
tunnelManager.activeTunnels,
|
||||||
serviceManager.autoTunnelService.map { it != null },
|
serviceManager.autoTunnelActive,
|
||||||
networkMonitor.networkStatusFlow,
|
networkMonitor.networkStatusFlow,
|
||||||
) { array ->
|
) { array ->
|
||||||
val settings = array[0] as AppSettings
|
val settings = array[0] as AppSettings
|
||||||
@@ -208,6 +206,7 @@ constructor(
|
|||||||
is AppEvent.ShowMessage -> handleShowMessage(event.message)
|
is AppEvent.ShowMessage -> handleShowMessage(event.message)
|
||||||
is AppEvent.PopBackStack ->
|
is AppEvent.PopBackStack ->
|
||||||
_appViewState.update { it.copy(popBackStack = event.pop) }
|
_appViewState.update { it.copy(popBackStack = event.pop) }
|
||||||
|
is AppEvent.ClearTunnelError -> tunnelManager.clearError(event.tunnel)
|
||||||
AppEvent.ToggleRemoteControl -> handleToggleRemoteControl(state.appState)
|
AppEvent.ToggleRemoteControl -> handleToggleRemoteControl(state.appState)
|
||||||
AppEvent.ClearSelectedTunnels -> clearSelectedTunnels()
|
AppEvent.ClearSelectedTunnels -> clearSelectedTunnels()
|
||||||
is AppEvent.SetShowModal ->
|
is AppEvent.SetShowModal ->
|
||||||
@@ -266,9 +265,6 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleTunnelErrors() =
|
|
||||||
viewModelScope.launch { tunnelManager.errorEvents.collect { errorEvent -> } }
|
|
||||||
|
|
||||||
private suspend fun handleAppReadyCheck(tunnels: List<TunnelConf>) {
|
private suspend fun handleAppReadyCheck(tunnels: List<TunnelConf>) {
|
||||||
if (tunnels.size == appDataRepository.tunnels.count()) {
|
if (tunnels.size == appDataRepository.tunnels.count()) {
|
||||||
_appViewState.update { it.copy(isAppReady = true) }
|
_appViewState.update { it.copy(isAppReady = true) }
|
||||||
|
|||||||
@@ -106,6 +106,8 @@ sealed class AppEvent {
|
|||||||
|
|
||||||
data class ShowMessage(val message: StringValue) : AppEvent()
|
data class ShowMessage(val message: StringValue) : AppEvent()
|
||||||
|
|
||||||
|
data class ClearTunnelError(val tunnel: TunnelConf) : AppEvent()
|
||||||
|
|
||||||
data class PopBackStack(val pop: Boolean) : AppEvent()
|
data class PopBackStack(val pop: Boolean) : AppEvent()
|
||||||
|
|
||||||
data class SetBottomSheet(val showSheet: AppViewState.BottomSheet) : AppEvent()
|
data class SetBottomSheet(val showSheet: AppViewState.BottomSheet) : AppEvent()
|
||||||
|
|||||||
@@ -221,7 +221,6 @@
|
|||||||
<string name="wifi_name_template">Active: %1$s</string>
|
<string name="wifi_name_template">Active: %1$s</string>
|
||||||
<string name="remote_key_template">Key: %1$s</string>
|
<string name="remote_key_template">Key: %1$s</string>
|
||||||
<string name="version_template">Version: %1$s</string>
|
<string name="version_template">Version: %1$s</string>
|
||||||
<string name="security_template">Security: %1$s</string>
|
|
||||||
<string name="flavor_template">Flavor: %1$s</string>
|
<string name="flavor_template">Flavor: %1$s</string>
|
||||||
<string name="config_error">config error</string>
|
<string name="config_error">config error</string>
|
||||||
<string name="dns_resolve_error">dns resolution error</string>
|
<string name="dns_resolve_error">dns resolution error</string>
|
||||||
@@ -256,6 +255,4 @@
|
|||||||
<string name="allow">Allow</string>
|
<string name="allow">Allow</string>
|
||||||
<string name="licenses">Licenses</string>
|
<string name="licenses">Licenses</string>
|
||||||
<string name="update_check_unsupported">Update check not supported this build type.</string>
|
<string name="update_check_unsupported">Update check not supported this build type.</string>
|
||||||
<string name="darker">Darker</string>
|
|
||||||
<string name="amoled">AMOLED</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
object Constants {
|
object Constants {
|
||||||
const val VERSION_NAME = "3.9.0"
|
const val VERSION_NAME = "3.8.3"
|
||||||
const val JVM_TARGET = "17"
|
const val JVM_TARGET = "17"
|
||||||
const val VERSION_CODE = 38900
|
const val VERSION_CODE = 38300
|
||||||
const val TARGET_SDK = 35
|
const val TARGET_SDK = 35
|
||||||
const val MIN_SDK = 26
|
const val MIN_SDK = 26
|
||||||
const val APP_ID = "com.zaneschepke.wireguardautotunnel"
|
const val APP_ID = "com.zaneschepke.wireguardautotunnel"
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ fun Project.computeVersionName(): String {
|
|||||||
// Bump minor for pre-release
|
// Bump minor for pre-release
|
||||||
val preReleaseVersion = Semver.of(
|
val preReleaseVersion = Semver.of(
|
||||||
baseVersion.major,
|
baseVersion.major,
|
||||||
baseVersion.minor,
|
baseVersion.minor + 1,
|
||||||
0 + 1,
|
0
|
||||||
)
|
)
|
||||||
"${preReleaseVersion}-beta+git.${getGitCommitHash()}"
|
"${preReleaseVersion}-beta+git.${getGitCommitHash()}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
What's new:
|
|
||||||
- Fix Android TV Banners
|
|
||||||
- Add multi-select for tunnels
|
|
||||||
- Add in-app update checker
|
|
||||||
- Add license screen
|
|
||||||
- Various bug fixes
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
[versions]
|
[versions]
|
||||||
accompanist = "0.37.2"
|
accompanist = "0.37.2"
|
||||||
activityCompose = "1.10.1"
|
activityCompose = "1.10.1"
|
||||||
amneziawgAndroid = "1.3.10"
|
amneziawgAndroid = "1.3.8"
|
||||||
androidx-junit = "1.2.1"
|
androidx-junit = "1.2.1"
|
||||||
appcompat = "1.7.0"
|
appcompat = "1.7.0"
|
||||||
biometricKtx = "1.2.0-alpha05"
|
biometricKtx = "1.2.0-alpha05"
|
||||||
coreKtx = "1.16.0"
|
coreKtx = "1.16.0"
|
||||||
datastorePreferences = "1.2.0-alpha01"
|
datastorePreferences = "1.1.4"
|
||||||
desugar_jdk_libs = "2.1.5"
|
desugar_jdk_libs = "2.1.5"
|
||||||
espressoCore = "3.6.1"
|
espressoCore = "3.6.1"
|
||||||
hiltAndroid = "2.56.2"
|
hiltAndroid = "2.56.2"
|
||||||
@@ -19,18 +19,17 @@ material3 = "1.3.2"
|
|||||||
navigationCompose = "2.8.9"
|
navigationCompose = "2.8.9"
|
||||||
pinLockCompose = "1.0.4"
|
pinLockCompose = "1.0.4"
|
||||||
qrcodeKotlin = "4.4.1"
|
qrcodeKotlin = "4.4.1"
|
||||||
roomVersion = "2.7.1"
|
roomVersion = "2.7.0"
|
||||||
semver4j = "3.1.0"
|
semver4j = "3.1.0"
|
||||||
slf4jAndroid = "1.7.36"
|
slf4jAndroid = "1.7.36"
|
||||||
timber = "5.0.1"
|
timber = "5.0.1"
|
||||||
tunnel = "1.2.16"
|
tunnel = "1.2.14"
|
||||||
androidGradlePlugin = "8.9.2"
|
androidGradlePlugin = "8.9.2"
|
||||||
kotlin = "2.1.20"
|
kotlin = "2.1.20"
|
||||||
ksp = "2.1.20-2.0.0"
|
ksp = "2.1.20-2.0.0"
|
||||||
composeBom = "2025.04.01"
|
composeBom = "2025.04.00"
|
||||||
compose = "1.8.0"
|
compose = "1.7.8"
|
||||||
icons = "1.7.8"
|
workRuntimeKtxVersion = "2.10.0"
|
||||||
workRuntimeKtxVersion = "2.10.1"
|
|
||||||
zxingAndroidEmbedded = "4.3.0"
|
zxingAndroidEmbedded = "4.3.0"
|
||||||
coreSplashscreen = "1.0.1"
|
coreSplashscreen = "1.0.1"
|
||||||
gradlePlugins-grgit = "5.3.0"
|
gradlePlugins-grgit = "5.3.0"
|
||||||
@@ -96,7 +95,7 @@ ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktorCli
|
|||||||
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktorClientCore" }
|
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktorClientCore" }
|
||||||
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktorClientCore" }
|
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktorClientCore" }
|
||||||
lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle-runtime-compose" }
|
lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle-runtime-compose" }
|
||||||
material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "icons" }
|
material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "compose" }
|
||||||
|
|
||||||
pin-lock-compose = { module = "com.zaneschepke:pin_lock_compose", version.ref = "pinLockCompose" }
|
pin-lock-compose = { module = "com.zaneschepke:pin_lock_compose", version.ref = "pinLockCompose" }
|
||||||
qrcode-kotlin = { module = "io.github.g0dkar:qrcode-kotlin", version.ref = "qrcodeKotlin" }
|
qrcode-kotlin = { module = "io.github.g0dkar:qrcode-kotlin", version.ref = "qrcodeKotlin" }
|
||||||
|
|||||||
+8
-34
@@ -12,7 +12,6 @@ import android.net.NetworkRequest
|
|||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import com.wireguard.android.util.RootShell
|
import com.wireguard.android.util.RootShell
|
||||||
import java.util.Collections
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.channels.awaitClose
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
@@ -46,18 +45,10 @@ class AndroidNetworkMonitor(
|
|||||||
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||||
|
|
||||||
@get:Synchronized @set:Synchronized var currentSsid: String? = null
|
@get:Synchronized @set:Synchronized var currentSsid: String? = null
|
||||||
@get:Synchronized @set:Synchronized var securityType: WifiSecurityType? = null
|
|
||||||
|
|
||||||
@get:Synchronized @set:Synchronized var wifiConnected = false
|
@get:Synchronized @set:Synchronized var wifiConnected = false
|
||||||
|
|
||||||
// Track active Wi-Fi networks and last active network ID
|
data class WifiState(val connected: Boolean = false, val ssid: String? = null)
|
||||||
private val activeNetworks = Collections.synchronizedSet(mutableSetOf<Network>())
|
|
||||||
|
|
||||||
data class WifiState(
|
|
||||||
val connected: Boolean = false,
|
|
||||||
val ssid: String? = null,
|
|
||||||
val securityType: WifiSecurityType? = null,
|
|
||||||
)
|
|
||||||
|
|
||||||
data class TransportState(val connected: Boolean = false)
|
data class TransportState(val connected: Boolean = false)
|
||||||
|
|
||||||
@@ -81,15 +72,15 @@ class AndroidNetworkMonitor(
|
|||||||
|
|
||||||
suspend fun handleUnknownWifi() {
|
suspend fun handleUnknownWifi() {
|
||||||
val newSsid = getWifiSsid()
|
val newSsid = getWifiSsid()
|
||||||
val securityType = wifiManager?.getCurrentSecurityType()
|
|
||||||
// Only update if new SSID is valid; preserve existing valid SSID otherwise
|
// Only update if new SSID is valid; preserve existing valid SSID otherwise
|
||||||
if (newSsid != null && newSsid != WifiManager.UNKNOWN_SSID) {
|
if (newSsid != null && newSsid != WifiManager.UNKNOWN_SSID) {
|
||||||
currentSsid = newSsid
|
currentSsid = newSsid
|
||||||
trySend(WifiState(wifiConnected, currentSsid, securityType))
|
trySend(WifiState(connected = wifiConnected, ssid = currentSsid))
|
||||||
} else if (currentSsid == null || currentSsid == WifiManager.UNKNOWN_SSID) {
|
} else if (currentSsid == null || currentSsid == WifiManager.UNKNOWN_SSID) {
|
||||||
currentSsid = newSsid
|
currentSsid = newSsid
|
||||||
trySend(WifiState(wifiConnected, currentSsid, securityType))
|
trySend(WifiState(connected = wifiConnected, ssid = currentSsid))
|
||||||
}
|
}
|
||||||
|
Timber.d("handleUnknownWifi: currentSsid=$currentSsid")
|
||||||
}
|
}
|
||||||
|
|
||||||
val locationPermissionReceiver =
|
val locationPermissionReceiver =
|
||||||
@@ -148,34 +139,18 @@ class AndroidNetworkMonitor(
|
|||||||
object : ConnectivityManager.NetworkCallback() {
|
object : ConnectivityManager.NetworkCallback() {
|
||||||
override fun onAvailable(network: Network) {
|
override fun onAvailable(network: Network) {
|
||||||
Timber.d("Wi-Fi onAvailable: network=$network")
|
Timber.d("Wi-Fi onAvailable: network=$network")
|
||||||
activeNetworks.add(network)
|
|
||||||
launch {
|
launch {
|
||||||
currentSsid = getWifiSsid()
|
currentSsid = getWifiSsid()
|
||||||
securityType = wifiManager?.getCurrentSecurityType()
|
|
||||||
wifiConnected = true
|
wifiConnected = true
|
||||||
trySend(
|
trySend(WifiState(connected = true, ssid = currentSsid))
|
||||||
WifiState(
|
|
||||||
connected = true,
|
|
||||||
ssid = currentSsid,
|
|
||||||
securityType = securityType,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLost(network: Network) {
|
override fun onLost(network: Network) {
|
||||||
Timber.d("Wi-Fi onLost: network=$network")
|
Timber.d("Wi-Fi onLost: network=$network")
|
||||||
activeNetworks.remove(network)
|
currentSsid = null
|
||||||
if (activeNetworks.isEmpty()) {
|
wifiConnected = false
|
||||||
Timber.d(
|
trySend(WifiState(connected = false, ssid = null))
|
||||||
"All Wi-Fi networks disconnected, clearing currentSsid and wifiConnected"
|
|
||||||
)
|
|
||||||
currentSsid = null
|
|
||||||
wifiConnected = false
|
|
||||||
trySend(WifiState(connected = false, ssid = null, securityType = null))
|
|
||||||
} else {
|
|
||||||
Timber.d("Wi-Fi onLost, but still connected to other networks, ignoring")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,7 +228,6 @@ class AndroidNetworkMonitor(
|
|||||||
if (hasAnyConnection) {
|
if (hasAnyConnection) {
|
||||||
NetworkStatus.Connected(
|
NetworkStatus.Connected(
|
||||||
wifiSsid = wifi.ssid,
|
wifiSsid = wifi.ssid,
|
||||||
securityType = wifi.securityType,
|
|
||||||
wifiConnected = wifi.connected,
|
wifiConnected = wifi.connected,
|
||||||
cellularConnected = cellular.connected,
|
cellularConnected = cellular.connected,
|
||||||
ethernetConnected = ethernet.connected,
|
ethernetConnected = ethernet.connected,
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.zaneschepke.networkmonitor
|
package com.zaneschepke.networkmonitor
|
||||||
|
|
||||||
import android.net.wifi.WifiManager
|
|
||||||
import android.os.Build
|
|
||||||
import com.wireguard.android.util.RootShell
|
import com.wireguard.android.util.RootShell
|
||||||
|
|
||||||
fun RootShell.getCurrentWifiName(): String? {
|
fun RootShell.getCurrentWifiName(): String? {
|
||||||
@@ -12,12 +10,3 @@ fun RootShell.getCurrentWifiName(): String? {
|
|||||||
)
|
)
|
||||||
return response.firstOrNull()
|
return response.firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
fun WifiManager.getCurrentSecurityType(): WifiSecurityType? {
|
|
||||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
||||||
WifiSecurityType.from(connectionInfo.currentSecurityType)
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ sealed class NetworkStatus {
|
|||||||
|
|
||||||
data class Connected(
|
data class Connected(
|
||||||
val wifiSsid: String? = null,
|
val wifiSsid: String? = null,
|
||||||
val securityType: WifiSecurityType? = null,
|
|
||||||
override val wifiConnected: Boolean = false,
|
override val wifiConnected: Boolean = false,
|
||||||
override val ethernetConnected: Boolean = false,
|
override val ethernetConnected: Boolean = false,
|
||||||
override val cellularConnected: Boolean = false,
|
override val cellularConnected: Boolean = false,
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
package com.zaneschepke.networkmonitor
|
|
||||||
|
|
||||||
import android.net.wifi.WifiInfo
|
|
||||||
|
|
||||||
enum class WifiSecurityType {
|
|
||||||
UNKNOWN,
|
|
||||||
OPEN,
|
|
||||||
WEP,
|
|
||||||
WPA2, // WPA and WPA2
|
|
||||||
WPA3, // WPA3-Personal (SAE)
|
|
||||||
OWE,
|
|
||||||
WAPI, // All WAPI_PSK and WAPI_CERT
|
|
||||||
EAP, // All EAP (covers both WPA3 and others)
|
|
||||||
PASSPOINT, // All Passpoint versions
|
|
||||||
DPP;
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun from(securityType: Int): WifiSecurityType {
|
|
||||||
return when (securityType) {
|
|
||||||
WifiInfo.SECURITY_TYPE_OPEN -> OPEN
|
|
||||||
WifiInfo.SECURITY_TYPE_WEP -> WEP
|
|
||||||
WifiInfo.SECURITY_TYPE_PSK -> WPA2
|
|
||||||
WifiInfo.SECURITY_TYPE_EAP -> EAP
|
|
||||||
WifiInfo.SECURITY_TYPE_SAE -> WPA3
|
|
||||||
WifiInfo.SECURITY_TYPE_OWE -> OWE
|
|
||||||
WifiInfo.SECURITY_TYPE_WAPI_PSK,
|
|
||||||
WifiInfo.SECURITY_TYPE_WAPI_CERT -> WAPI
|
|
||||||
WifiInfo.SECURITY_TYPE_EAP_WPA3_ENTERPRISE -> EAP
|
|
||||||
WifiInfo.SECURITY_TYPE_EAP_WPA3_ENTERPRISE_192_BIT -> EAP
|
|
||||||
WifiInfo.SECURITY_TYPE_PASSPOINT_R1_R2,
|
|
||||||
WifiInfo.SECURITY_TYPE_PASSPOINT_R3 -> PASSPOINT
|
|
||||||
WifiInfo.SECURITY_TYPE_DPP -> DPP
|
|
||||||
WifiInfo.SECURITY_TYPE_UNKNOWN -> UNKNOWN
|
|
||||||
else -> UNKNOWN
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user