mirror of
https://github.com/wgtunnel/android.git
synced 2026-07-03 14:07:49 +02:00
Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 205493092b | |||
| 47472f088f | |||
| f5a62cba1b | |||
| 89f6dec357 | |||
| ab7499a616 | |||
| 105c753c66 | |||
| d9f0de2dd4 | |||
| 82280091ad | |||
| b97b7cf989 | |||
| f83e40f6cc | |||
| 1fab9dfdf2 | |||
| a670931b06 | |||
| 2c0c88baf2 | |||
| 05e7cb7c04 | |||
| bc811f74ef | |||
| 09b669f54b | |||
| f08d73cbb7 | |||
| 7ca23d3ef5 | |||
| 7fdd95ea51 | |||
| e11f0f794a | |||
| fea31437cd | |||
| 1306fdc8b2 | |||
| d2e5d6d3bc | |||
| 960af02beb | |||
| 3f1ff22488 | |||
| d6b032845b | |||
| ffad6b331f | |||
| 1fb953e2fe | |||
| 893a03d3b1 | |||
| 30b577a03d |
@@ -1,2 +1,3 @@
|
|||||||
ko_fi: zaneschepke
|
ko_fi: zaneschepke
|
||||||
liberapay: zaneschepke
|
liberapay: zaneschepke
|
||||||
|
github: zaneschepke
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ A clear and concise description of what the bug is.
|
|||||||
- Device: [e.g. Pixel 4a]
|
- Device: [e.g. Pixel 4a]
|
||||||
- Android Version: [e.g. Android 13]
|
- Android Version: [e.g. Android 13]
|
||||||
- App Version [e.g. 3.3.3]
|
- App Version [e.g. 3.3.3]
|
||||||
|
- Backend: [e.g. Kernel, Userspace]
|
||||||
|
|
||||||
**To Reproduce**
|
**To Reproduce**
|
||||||
Steps to reproduce the behavior:
|
Steps to reproduce the behavior:
|
||||||
|
|||||||
@@ -33,25 +33,29 @@ on:
|
|||||||
workflow_call:
|
workflow_call:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check_date:
|
check_commits:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Check latest commit
|
|
||||||
outputs:
|
outputs:
|
||||||
should_run: ${{ steps.should_run.outputs.should_run }}
|
new_commits: ${{ steps.check_last_commit.outputs.new_commits }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Checkout repository
|
||||||
- name: print latest_commit
|
uses: actions/checkout@v3
|
||||||
run: echo ${{ github.sha }}
|
with:
|
||||||
- id: should_run
|
fetch-depth: 0
|
||||||
continue-on-error: true
|
|
||||||
name: check latest commit is less than a day
|
- name: Check for new commits in the last 23 hours
|
||||||
if: ${{ github.event_name == 'schedule' }}
|
id: check_last_commit
|
||||||
run: test -z $(git rev-list --after="23 hours" ${{ github.sha }}) && echo "::set-output name=should_run::false"
|
run: |
|
||||||
|
if git log --since="23 hours ago" --oneline | grep -q .; then
|
||||||
|
echo "New commits found in the last 23 hours."
|
||||||
|
echo "new_commits=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "No new commits in the last 23 hours."
|
||||||
|
echo "new_commits=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
build:
|
build:
|
||||||
needs: check_date
|
needs: check_commits
|
||||||
if: |
|
if: needs.check_commits.outputs.new_commits == 'true'
|
||||||
github.event_name != 'schedule' ||
|
|
||||||
(needs.check_date.outputs.should_run == 'true' && github.event_name == 'schedule')
|
|
||||||
name: Build Signed APK
|
name: Build Signed APK
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
@@ -144,7 +148,7 @@ jobs:
|
|||||||
|
|
||||||
# Save the APK after the Build job is complete to publish it as a Github release in the next job
|
# Save the APK after the Build job is complete to publish it as a Github release in the next job
|
||||||
- name: Upload APK
|
- name: Upload APK
|
||||||
uses: actions/upload-artifact@v4.4.0
|
uses: actions/upload-artifact@v4.4.3
|
||||||
with:
|
with:
|
||||||
name: wgtunnel
|
name: wgtunnel
|
||||||
path: ${{ env.APK_PATH }}
|
path: ${{ env.APK_PATH }}
|
||||||
|
|||||||
@@ -72,12 +72,14 @@ android {
|
|||||||
"proguard-rules.pro",
|
"proguard-rules.pro",
|
||||||
)
|
)
|
||||||
signingConfig = signingConfigs.getByName(Constants.RELEASE)
|
signingConfig = signingConfigs.getByName(Constants.RELEASE)
|
||||||
|
resValue("string", "provider", "\"${Constants.APP_NAME}.provider\"")
|
||||||
}
|
}
|
||||||
debug {
|
debug {
|
||||||
applicationIdSuffix = ".debug"
|
applicationIdSuffix = ".debug"
|
||||||
versionNameSuffix = "-debug"
|
versionNameSuffix = "-debug"
|
||||||
resValue("string", "app_name", "WG Tunnel - Debug")
|
resValue("string", "app_name", "WG Tunnel - Debug")
|
||||||
isDebuggable = true
|
isDebuggable = true
|
||||||
|
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.debug\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
create(Constants.PRERELEASE) {
|
create(Constants.PRERELEASE) {
|
||||||
@@ -85,6 +87,7 @@ android {
|
|||||||
applicationIdSuffix = ".prerelease"
|
applicationIdSuffix = ".prerelease"
|
||||||
versionNameSuffix = "-pre"
|
versionNameSuffix = "-pre"
|
||||||
resValue("string", "app_name", "WG Tunnel - Pre")
|
resValue("string", "app_name", "WG Tunnel - Pre")
|
||||||
|
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.pre\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
create(Constants.NIGHTLY) {
|
create(Constants.NIGHTLY) {
|
||||||
@@ -92,6 +95,7 @@ android {
|
|||||||
applicationIdSuffix = ".nightly"
|
applicationIdSuffix = ".nightly"
|
||||||
versionNameSuffix = "-nightly"
|
versionNameSuffix = "-nightly"
|
||||||
resValue("string", "app_name", "WG Tunnel - Nightly")
|
resValue("string", "app_name", "WG Tunnel - Nightly")
|
||||||
|
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.nightly\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationVariants.all {
|
applicationVariants.all {
|
||||||
@@ -129,8 +133,6 @@ android {
|
|||||||
packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" } }
|
packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" } }
|
||||||
}
|
}
|
||||||
|
|
||||||
val generalImplementation by configurations
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
implementation(project(":logcatter"))
|
implementation(project(":logcatter"))
|
||||||
|
|||||||
@@ -10,10 +10,7 @@
|
|||||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||||
android:maxSdkVersion="32"
|
android:maxSdkVersion="32"
|
||||||
tools:ignore="ScopedStorage" />
|
tools:ignore="ScopedStorage" />
|
||||||
<uses-permission
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
android:name="android.permission.ACCESS_WIFI_STATE"
|
|
||||||
android:maxSdkVersion="30"
|
|
||||||
tools:ignore="LeanbackUsesWifi" />
|
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
@@ -66,12 +63,12 @@
|
|||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.AppSplashScreen"
|
android:theme="@style/Theme.App.Start"
|
||||||
tools:targetApi="tiramisu">
|
tools:targetApi="tiramisu">
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.SplashActivity"
|
android:name=".ui.MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:theme="@style/Theme.AppSplashScreen">
|
android:theme="@style/Theme.WireguardAutoTunnel">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
@@ -83,11 +80,6 @@
|
|||||||
android:name="android.app.shortcuts"
|
android:name="android.app.shortcuts"
|
||||||
android:resource="@xml/shortcuts" />
|
android:resource="@xml/shortcuts" />
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
|
||||||
android:name=".ui.MainActivity"
|
|
||||||
android:exported="true"
|
|
||||||
android:theme="@style/Theme.WireguardAutoTunnel">
|
|
||||||
</activity>
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
@@ -103,6 +95,16 @@
|
|||||||
android:launchMode="singleInstance"
|
android:launchMode="singleInstance"
|
||||||
android:theme="@android:style/Theme.NoDisplay" />
|
android:theme="@android:style/Theme.NoDisplay" />
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="androidx.core.content.FileProvider"
|
||||||
|
android:authorities="@string/provider"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/file_paths" />
|
||||||
|
</provider>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".service.tile.TunnelControlTile"
|
android:name=".service.tile.TunnelControlTile"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.zaneschepke.wireguardautotunnel
|
|||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.os.StrictMode
|
import android.os.StrictMode
|
||||||
import android.os.StrictMode.ThreadPolicy
|
import android.os.StrictMode.ThreadPolicy
|
||||||
import com.zaneschepke.logcatter.LocalLogCollector
|
import com.zaneschepke.logcatter.LogReader
|
||||||
import com.zaneschepke.wireguardautotunnel.module.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.module.ApplicationScope
|
||||||
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.util.ReleaseTree
|
import com.zaneschepke.wireguardautotunnel.util.ReleaseTree
|
||||||
@@ -23,7 +23,7 @@ class WireGuardAutoTunnel : Application() {
|
|||||||
lateinit var applicationScope: CoroutineScope
|
lateinit var applicationScope: CoroutineScope
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var localLogCollector: LocalLogCollector
|
lateinit var logReader: LogReader
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@IoDispatcher
|
@IoDispatcher
|
||||||
@@ -47,7 +47,7 @@ class WireGuardAutoTunnel : Application() {
|
|||||||
}
|
}
|
||||||
if (!isRunningOnTv()) {
|
if (!isRunningOnTv()) {
|
||||||
applicationScope.launch(ioDispatcher) {
|
applicationScope.launch(ioDispatcher) {
|
||||||
localLogCollector.start()
|
logReader.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -25,6 +25,7 @@ class DataStoreManager(
|
|||||||
val BATTERY_OPTIMIZE_DISABLE_SHOWN = booleanPreferencesKey("BATTERY_OPTIMIZE_DISABLE_SHOWN")
|
val BATTERY_OPTIMIZE_DISABLE_SHOWN = booleanPreferencesKey("BATTERY_OPTIMIZE_DISABLE_SHOWN")
|
||||||
val CURRENT_SSID = stringPreferencesKey("CURRENT_SSID")
|
val CURRENT_SSID = stringPreferencesKey("CURRENT_SSID")
|
||||||
val IS_PIN_LOCK_ENABLED = booleanPreferencesKey("PIN_LOCK_ENABLED")
|
val IS_PIN_LOCK_ENABLED = booleanPreferencesKey("PIN_LOCK_ENABLED")
|
||||||
|
val IS_TUNNEL_STATS_EXPANDED = booleanPreferencesKey("TUNNEL_STATS_EXPANDED")
|
||||||
}
|
}
|
||||||
|
|
||||||
// preferences
|
// preferences
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ data class GeneralState(
|
|||||||
val isLocationDisclosureShown: Boolean = LOCATION_DISCLOSURE_SHOWN_DEFAULT,
|
val isLocationDisclosureShown: Boolean = LOCATION_DISCLOSURE_SHOWN_DEFAULT,
|
||||||
val isBatteryOptimizationDisableShown: Boolean = BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT,
|
val isBatteryOptimizationDisableShown: Boolean = BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT,
|
||||||
val isPinLockEnabled: Boolean = PIN_LOCK_ENABLED_DEFAULT,
|
val isPinLockEnabled: Boolean = PIN_LOCK_ENABLED_DEFAULT,
|
||||||
|
val isTunnelStatsExpanded: Boolean = IS_TUNNEL_STATS_EXPANDED,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
const val LOCATION_DISCLOSURE_SHOWN_DEFAULT = false
|
const val LOCATION_DISCLOSURE_SHOWN_DEFAULT = false
|
||||||
const val BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT = false
|
const val BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT = false
|
||||||
const val PIN_LOCK_ENABLED_DEFAULT = false
|
const val PIN_LOCK_ENABLED_DEFAULT = false
|
||||||
|
const val IS_TUNNEL_STATS_EXPANDED = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -20,5 +20,9 @@ interface AppStateRepository {
|
|||||||
|
|
||||||
suspend fun setCurrentSsid(ssid: String)
|
suspend fun setCurrentSsid(ssid: String)
|
||||||
|
|
||||||
|
suspend fun isTunnelStatsExpanded(): Boolean
|
||||||
|
|
||||||
|
suspend fun setTunnelStatsExpanded(expanded: Boolean)
|
||||||
|
|
||||||
val generalStateFlow: Flow<GeneralState>
|
val generalStateFlow: Flow<GeneralState>
|
||||||
}
|
}
|
||||||
|
|||||||
+10
@@ -45,6 +45,15 @@ class DataStoreAppStateRepository(
|
|||||||
dataStoreManager.saveToDataStore(DataStoreManager.CURRENT_SSID, ssid)
|
dataStoreManager.saveToDataStore(DataStoreManager.CURRENT_SSID, ssid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun isTunnelStatsExpanded(): Boolean {
|
||||||
|
return dataStoreManager.getFromStore(DataStoreManager.IS_TUNNEL_STATS_EXPANDED)
|
||||||
|
?: GeneralState.IS_TUNNEL_STATS_EXPANDED
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun setTunnelStatsExpanded(expanded: Boolean) {
|
||||||
|
dataStoreManager.saveToDataStore(DataStoreManager.IS_TUNNEL_STATS_EXPANDED, expanded)
|
||||||
|
}
|
||||||
|
|
||||||
override val generalStateFlow: Flow<GeneralState> =
|
override val generalStateFlow: Flow<GeneralState> =
|
||||||
dataStoreManager.preferencesFlow.map { prefs ->
|
dataStoreManager.preferencesFlow.map { prefs ->
|
||||||
prefs?.let { pref ->
|
prefs?.let { pref ->
|
||||||
@@ -59,6 +68,7 @@ class DataStoreAppStateRepository(
|
|||||||
isPinLockEnabled =
|
isPinLockEnabled =
|
||||||
pref[DataStoreManager.IS_PIN_LOCK_ENABLED]
|
pref[DataStoreManager.IS_PIN_LOCK_ENABLED]
|
||||||
?: GeneralState.PIN_LOCK_ENABLED_DEFAULT,
|
?: GeneralState.PIN_LOCK_ENABLED_DEFAULT,
|
||||||
|
isTunnelStatsExpanded = pref[DataStoreManager.IS_TUNNEL_STATS_EXPANDED] ?: GeneralState.IS_TUNNEL_STATS_EXPANDED,
|
||||||
)
|
)
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.module
|
package com.zaneschepke.wireguardautotunnel.module
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.zaneschepke.logcatter.LocalLogCollector
|
import com.zaneschepke.logcatter.LogReader
|
||||||
import com.zaneschepke.logcatter.LogcatUtil
|
import com.zaneschepke.logcatter.LogcatCollector
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
@@ -24,7 +24,7 @@ class AppModule {
|
|||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
fun provideLogCollect(@ApplicationContext context: Context): LocalLogCollector {
|
fun provideLogCollect(@ApplicationContext context: Context): LogReader {
|
||||||
return LogcatUtil.init(context = context)
|
return LogcatCollector.init(context = context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.module
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.navigation.NavHostController
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.NavigationService
|
|
||||||
import dagger.Module
|
|
||||||
import dagger.Provides
|
|
||||||
import dagger.hilt.InstallIn
|
|
||||||
import dagger.hilt.android.components.ActivityRetainedComponent
|
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import dagger.hilt.android.scopes.ActivityRetainedScoped
|
|
||||||
|
|
||||||
@Module
|
|
||||||
@InstallIn(ActivityRetainedComponent::class)
|
|
||||||
object NavigationModule {
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@ActivityRetainedScoped
|
|
||||||
fun provideNestedNavController(@ApplicationContext context: Context): NavHostController {
|
|
||||||
return NavigationService(context).navController
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+28
-16
@@ -2,11 +2,13 @@ package com.zaneschepke.wireguardautotunnel.service.foreground
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
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
|
||||||
import androidx.lifecycle.LifecycleService
|
import androidx.lifecycle.LifecycleService
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import com.wireguard.android.util.RootShell
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
||||||
@@ -23,6 +25,7 @@ import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
|||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.cancelWithMessage
|
import com.zaneschepke.wireguardautotunnel.util.extensions.cancelWithMessage
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.getCurrentWifiName
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isMatchingToWildcardList
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isMatchingToWildcardList
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isReachable
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isReachable
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.onNotRunning
|
import com.zaneschepke.wireguardautotunnel.util.extensions.onNotRunning
|
||||||
@@ -46,6 +49,9 @@ import javax.inject.Provider
|
|||||||
class AutoTunnelService : LifecycleService() {
|
class AutoTunnelService : LifecycleService() {
|
||||||
private val foregroundId = 122
|
private val foregroundId = 122
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var rootShell: Provider<RootShell>
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var wifiService: NetworkService<WifiService>
|
lateinit var wifiService: NetworkService<WifiService>
|
||||||
|
|
||||||
@@ -397,6 +403,14 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateWifi(connected: Boolean) {
|
||||||
|
autoTunnelStateFlow.update {
|
||||||
|
it.copy(
|
||||||
|
isWifiConnected = connected,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun watchForEthernetConnectivityChanges() {
|
private suspend fun watchForEthernetConnectivityChanges() {
|
||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
Timber.i("Starting ethernet data watcher")
|
Timber.i("Starting ethernet data watcher")
|
||||||
@@ -428,21 +442,13 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
when (status) {
|
when (status) {
|
||||||
is NetworkStatus.Available -> {
|
is NetworkStatus.Available -> {
|
||||||
Timber.i("Gained Wi-Fi connection")
|
Timber.i("Gained Wi-Fi connection")
|
||||||
autoTunnelStateFlow.update {
|
updateWifi(true)
|
||||||
it.copy(
|
|
||||||
isWifiConnected = true,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is NetworkStatus.CapabilitiesChanged -> {
|
is NetworkStatus.CapabilitiesChanged -> {
|
||||||
Timber.i("Wifi capabilities changed")
|
Timber.i("Wifi capabilities changed")
|
||||||
autoTunnelStateFlow.update {
|
updateWifi(true)
|
||||||
it.copy(
|
val ssid = getWifiSSID(status.networkCapabilities)
|
||||||
isWifiConnected = true,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
val ssid = wifiService.getNetworkName(status.networkCapabilities)
|
|
||||||
ssid?.let { name ->
|
ssid?.let { name ->
|
||||||
if (name.contains(Constants.UNREADABLE_SSID)) {
|
if (name.contains(Constants.UNREADABLE_SSID)) {
|
||||||
Timber.w("SSID unreadable: missing permissions")
|
Timber.w("SSID unreadable: missing permissions")
|
||||||
@@ -459,11 +465,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
is NetworkStatus.Unavailable -> {
|
is NetworkStatus.Unavailable -> {
|
||||||
autoTunnelStateFlow.update {
|
updateWifi(false)
|
||||||
it.copy(
|
|
||||||
isWifiConnected = false,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Timber.i("Lost Wi-Fi connection")
|
Timber.i("Lost Wi-Fi connection")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -471,6 +473,16 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun getWifiSSID(networkCapabilities: NetworkCapabilities): String? {
|
||||||
|
return withContext(ioDispatcher) {
|
||||||
|
try {
|
||||||
|
rootShell.get().getCurrentWifiName()
|
||||||
|
} catch (_: Exception) {
|
||||||
|
wifiService.getNetworkName(networkCapabilities)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun getMobileDataTunnel(): TunnelConfig? {
|
private suspend fun getMobileDataTunnel(): TunnelConfig? {
|
||||||
return appDataRepository.tunnels.findByMobileDataTunnel().firstOrNull()
|
return appDataRepository.tunnels.findByMobileDataTunnel().firstOrNull()
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-27
@@ -5,8 +5,6 @@ import android.net.ConnectivityManager
|
|||||||
import android.net.Network
|
import android.net.Network
|
||||||
import android.net.NetworkCapabilities
|
import android.net.NetworkCapabilities
|
||||||
import android.net.NetworkRequest
|
import android.net.NetworkRequest
|
||||||
import android.net.wifi.SupplicantState
|
|
||||||
import android.net.wifi.WifiInfo
|
|
||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import kotlinx.coroutines.channels.awaitClose
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
@@ -21,7 +19,7 @@ abstract class BaseNetworkService<T : BaseNetworkService<T>>(
|
|||||||
private val connectivityManager =
|
private val connectivityManager =
|
||||||
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
|
||||||
private val wifiManager =
|
val wifiManager =
|
||||||
context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
||||||
|
|
||||||
override val networkStatus =
|
override val networkStatus =
|
||||||
@@ -83,30 +81,6 @@ abstract class BaseNetworkService<T : BaseNetworkService<T>>(
|
|||||||
|
|
||||||
awaitClose { connectivityManager.unregisterNetworkCallback(networkStatusCallback) }
|
awaitClose { connectivityManager.unregisterNetworkCallback(networkStatusCallback) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getNetworkName(networkCapabilities: NetworkCapabilities): String? {
|
|
||||||
var ssid: String? = getWifiNameFromCapabilities(networkCapabilities)
|
|
||||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
|
|
||||||
val info = wifiManager.connectionInfo
|
|
||||||
if (info.supplicantState === SupplicantState.COMPLETED) {
|
|
||||||
ssid = info.ssid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ssid?.trim('"')
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private fun getWifiNameFromCapabilities(networkCapabilities: NetworkCapabilities): String? {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
val info: WifiInfo
|
|
||||||
if (networkCapabilities.transportInfo is WifiInfo) {
|
|
||||||
info = networkCapabilities.transportInfo as WifiInfo
|
|
||||||
return info.ssid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <Result> Flow<NetworkStatus>.map(
|
inline fun <Result> Flow<NetworkStatus>.map(
|
||||||
|
|||||||
+6
-1
@@ -10,4 +10,9 @@ class EthernetService
|
|||||||
constructor(
|
constructor(
|
||||||
@ApplicationContext context: Context,
|
@ApplicationContext context: Context,
|
||||||
) :
|
) :
|
||||||
BaseNetworkService<EthernetService>(context, NetworkCapabilities.TRANSPORT_ETHERNET)
|
BaseNetworkService<EthernetService>(context, NetworkCapabilities.TRANSPORT_ETHERNET) {
|
||||||
|
|
||||||
|
override fun isNetworkSecure(): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+5
-1
@@ -10,4 +10,8 @@ class MobileDataService
|
|||||||
constructor(
|
constructor(
|
||||||
@ApplicationContext context: Context,
|
@ApplicationContext context: Context,
|
||||||
) :
|
) :
|
||||||
BaseNetworkService<MobileDataService>(context, NetworkCapabilities.TRANSPORT_CELLULAR)
|
BaseNetworkService<MobileDataService>(context, NetworkCapabilities.TRANSPORT_CELLULAR) {
|
||||||
|
override fun isNetworkSecure(): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.service.network
|
||||||
|
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
|
import android.net.wifi.WifiInfo
|
||||||
|
import android.os.Build
|
||||||
|
|
||||||
|
fun NetworkCapabilities.getWifiName(): String? {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
val info: WifiInfo
|
||||||
|
if (transportInfo is WifiInfo) {
|
||||||
|
info = transportInfo as WifiInfo
|
||||||
|
return info.ssid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
+5
-1
@@ -4,7 +4,11 @@ import android.net.NetworkCapabilities
|
|||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
interface NetworkService<T> {
|
interface NetworkService<T> {
|
||||||
fun getNetworkName(networkCapabilities: NetworkCapabilities): String?
|
fun getNetworkName(networkCapabilities: NetworkCapabilities): String? {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isNetworkSecure(): Boolean
|
||||||
|
|
||||||
val networkStatus: Flow<NetworkStatus>
|
val networkStatus: Flow<NetworkStatus>
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-1
@@ -2,6 +2,8 @@ package com.zaneschepke.wireguardautotunnel.service.network
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.NetworkCapabilities
|
import android.net.NetworkCapabilities
|
||||||
|
import android.net.wifi.SupplicantState
|
||||||
|
import android.os.Build
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -10,4 +12,21 @@ class WifiService
|
|||||||
constructor(
|
constructor(
|
||||||
@ApplicationContext context: Context,
|
@ApplicationContext context: Context,
|
||||||
) :
|
) :
|
||||||
BaseNetworkService<WifiService>(context, NetworkCapabilities.TRANSPORT_WIFI)
|
BaseNetworkService<WifiService>(context, NetworkCapabilities.TRANSPORT_WIFI) {
|
||||||
|
|
||||||
|
override fun getNetworkName(networkCapabilities: NetworkCapabilities): String? {
|
||||||
|
var ssid = networkCapabilities.getWifiName()
|
||||||
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S) {
|
||||||
|
val info = wifiManager.connectionInfo
|
||||||
|
if (info.supplicantState === SupplicantState.COMPLETED) {
|
||||||
|
ssid = info.ssid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ssid?.trim('"')
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isNetworkSecure(): Boolean {
|
||||||
|
// TODO
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+2
-2
@@ -9,7 +9,7 @@ import android.content.Intent
|
|||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.SplashActivity
|
import com.zaneschepke.wireguardautotunnel.ui.MainActivity
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ constructor(
|
|||||||
}
|
}
|
||||||
notificationManager.createNotificationChannel(channel)
|
notificationManager.createNotificationChannel(channel)
|
||||||
val pendingIntent: PendingIntent =
|
val pendingIntent: PendingIntent =
|
||||||
Intent(context, SplashActivity::class.java).let { notificationIntent ->
|
Intent(context, MainActivity::class.java).let { notificationIntent ->
|
||||||
PendingIntent.getActivity(
|
PendingIntent.getActivity(
|
||||||
context,
|
context,
|
||||||
0,
|
0,
|
||||||
|
|||||||
@@ -2,30 +2,36 @@ package com.zaneschepke.wireguardautotunnel.ui
|
|||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import androidx.navigation.NavHostController
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.TunnelConfigs
|
import com.zaneschepke.wireguardautotunnel.util.extensions.TunnelConfigs
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.collect
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.onCompletion
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.flow.takeWhile
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.plus
|
import kotlinx.coroutines.plus
|
||||||
import xyz.teamgravity.pin_lock_compose.PinManager
|
import xyz.teamgravity.pin_lock_compose.PinManager
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Provider
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class AppViewModel
|
class AppViewModel
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val appDataRepository: AppDataRepository,
|
private val appDataRepository: AppDataRepository,
|
||||||
tunnelService: TunnelService,
|
private val tunnelService: Provider<TunnelService>,
|
||||||
val navHostController: NavHostController,
|
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
@@ -35,7 +41,7 @@ constructor(
|
|||||||
combine(
|
combine(
|
||||||
appDataRepository.settings.getSettingsFlow(),
|
appDataRepository.settings.getSettingsFlow(),
|
||||||
appDataRepository.tunnels.getTunnelConfigsFlow(),
|
appDataRepository.tunnels.getTunnelConfigsFlow(),
|
||||||
tunnelService.vpnState,
|
tunnelService.get().vpnState,
|
||||||
appDataRepository.appState.generalStateFlow,
|
appDataRepository.appState.generalStateFlow,
|
||||||
) { settings, tunnels, tunnelState, generalState ->
|
) { settings, tunnels, tunnelState, generalState ->
|
||||||
AppUiState(
|
AppUiState(
|
||||||
@@ -44,12 +50,51 @@ constructor(
|
|||||||
tunnelState,
|
tunnelState,
|
||||||
generalState,
|
generalState,
|
||||||
)
|
)
|
||||||
|
}.stateIn(
|
||||||
|
viewModelScope + ioDispatcher,
|
||||||
|
SharingStarted.WhileSubscribed(Constants.SUBSCRIPTION_TIMEOUT),
|
||||||
|
_appUiState.value,
|
||||||
|
)
|
||||||
|
|
||||||
|
private val _isAppReady = MutableStateFlow<Boolean>(false)
|
||||||
|
val isAppReady = _isAppReady.asStateFlow()
|
||||||
|
|
||||||
|
init {
|
||||||
|
|
||||||
|
viewModelScope.launch {
|
||||||
|
initPin()
|
||||||
|
initAutoTunnel()
|
||||||
|
initTunnel()
|
||||||
|
appReadyCheck()
|
||||||
}
|
}
|
||||||
.stateIn(
|
}
|
||||||
viewModelScope + ioDispatcher,
|
|
||||||
SharingStarted.WhileSubscribed(Constants.SUBSCRIPTION_TIMEOUT),
|
private suspend fun appReadyCheck() {
|
||||||
_appUiState.value,
|
val tunnelCount = appDataRepository.tunnels.count()
|
||||||
)
|
uiState.takeWhile { it.tunnels.size != tunnelCount }.onCompletion {
|
||||||
|
_isAppReady.emit(true)
|
||||||
|
}.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun initTunnel() {
|
||||||
|
if (tunnelService.get().getState() == TunnelState.UP) tunnelService.get().startStatsJob()
|
||||||
|
val activeTunnels = appDataRepository.tunnels.getActive()
|
||||||
|
if (activeTunnels.isNotEmpty() &&
|
||||||
|
tunnelService.get().getState() == TunnelState.DOWN
|
||||||
|
) {
|
||||||
|
tunnelService.get().startTunnel(activeTunnels.first())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun initPin() {
|
||||||
|
val isPinEnabled = appDataRepository.appState.isPinLockEnabled()
|
||||||
|
if (isPinEnabled) PinManager.initialize(WireGuardAutoTunnel.instance)
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun initAutoTunnel() {
|
||||||
|
val settings = appDataRepository.settings.getSettings()
|
||||||
|
if (settings.isAutoTunnelEnabled) ServiceManager.startWatcherService(WireGuardAutoTunnel.instance)
|
||||||
|
}
|
||||||
|
|
||||||
fun setTunnels(tunnels: TunnelConfigs) = viewModelScope.launch(ioDispatcher) {
|
fun setTunnels(tunnels: TunnelConfigs) = viewModelScope.launch(ioDispatcher) {
|
||||||
_appUiState.emit(
|
_appUiState.emit(
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ import android.os.Bundle
|
|||||||
import androidx.activity.SystemBarStyle
|
import androidx.activity.SystemBarStyle
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
|
import androidx.activity.viewModels
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.fadeIn
|
||||||
import androidx.compose.animation.fadeOut
|
import androidx.compose.animation.fadeOut
|
||||||
import androidx.compose.foundation.focusable
|
import androidx.compose.foundation.focusable
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
@@ -19,8 +21,8 @@ import androidx.compose.material3.MaterialTheme
|
|||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.SnackbarData
|
import androidx.compose.material3.SnackbarData
|
||||||
import androidx.compose.material3.SnackbarHost
|
import androidx.compose.material3.SnackbarHost
|
||||||
import androidx.compose.material3.Surface
|
|
||||||
import androidx.compose.material3.surfaceColorAtElevation
|
import androidx.compose.material3.surfaceColorAtElevation
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@@ -31,11 +33,12 @@ import androidx.compose.ui.graphics.Color
|
|||||||
import androidx.compose.ui.graphics.toArgb
|
import androidx.compose.ui.graphics.toArgb
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
|
import androidx.navigation.compose.rememberNavController
|
||||||
import androidx.navigation.toRoute
|
import androidx.navigation.toRoute
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppStateRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppStateRepository
|
||||||
@@ -44,6 +47,7 @@ import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
|||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavBar
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavBar
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavItem
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.isCurrentRoute
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.isCurrentRoute
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.CustomSnackBar
|
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.CustomSnackBar
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarControllerProvider
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarControllerProvider
|
||||||
@@ -51,11 +55,13 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.config.ConfigScreen
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.options.OptionsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.options.OptionsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.pinlock.PinLockScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.pinlock.PinLockScreen
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.scanner.ScannerScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.SettingsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.SettingsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.SupportScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.SupportScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.logs.LogsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.logs.LogsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.WireguardAutoTunnelTheme
|
import com.zaneschepke.wireguardautotunnel.ui.theme.WireguardAutoTunnelTheme
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestAutoTunnelTileServiceUpdate
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestTunnelTileServiceStateUpdate
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestTunnelTileServiceStateUpdate
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -68,11 +74,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var tunnelService: TunnelService
|
lateinit var tunnelService: TunnelService
|
||||||
|
|
||||||
|
private val viewModel by viewModels<AppViewModel>()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
val isPinLockEnabled = intent.extras?.getBoolean(SplashActivity.IS_PIN_LOCK_ENABLED_KEY)
|
|
||||||
|
|
||||||
enableEdgeToEdge(
|
enableEdgeToEdge(
|
||||||
navigationBarStyle = SystemBarStyle.auto(
|
navigationBarStyle = SystemBarStyle.auto(
|
||||||
lightScrim = Color.Transparent.toArgb(),
|
lightScrim = Color.Transparent.toArgb(),
|
||||||
@@ -80,10 +85,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
installSplashScreen().apply {
|
||||||
|
setKeepOnScreenCondition {
|
||||||
|
!viewModel.isAppReady.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
val appViewModel = hiltViewModel<AppViewModel>()
|
val appUiState by viewModel.uiState.collectAsStateWithLifecycle(lifecycle = this.lifecycle)
|
||||||
val appUiState by appViewModel.uiState.collectAsStateWithLifecycle(lifecycle = this.lifecycle)
|
val navController = rememberNavController()
|
||||||
val navController = appViewModel.navHostController
|
|
||||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||||
|
|
||||||
LaunchedEffect(appUiState.vpnState.status) {
|
LaunchedEffect(appUiState.vpnState.status) {
|
||||||
@@ -95,109 +105,114 @@ class MainActivity : AppCompatActivity() {
|
|||||||
context.requestTunnelTileServiceStateUpdate()
|
context.requestTunnelTileServiceStateUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
SnackbarControllerProvider { host ->
|
with(appUiState.settings) {
|
||||||
WireguardAutoTunnelTheme {
|
LaunchedEffect(isAutoTunnelPaused, isAutoTunnelEnabled) {
|
||||||
val focusRequester = remember { FocusRequester() }
|
this@MainActivity.requestAutoTunnelTileServiceUpdate()
|
||||||
Scaffold(
|
}
|
||||||
snackbarHost = {
|
}
|
||||||
SnackbarHost(host) { snackbarData: SnackbarData ->
|
|
||||||
CustomSnackBar(
|
CompositionLocalProvider(LocalNavController provides navController) {
|
||||||
snackbarData.visuals.message,
|
SnackbarControllerProvider { host ->
|
||||||
isRtl = false,
|
WireguardAutoTunnelTheme {
|
||||||
containerColor =
|
val focusRequester = remember { FocusRequester() }
|
||||||
MaterialTheme.colorScheme.surfaceColorAtElevation(
|
Scaffold(
|
||||||
2.dp,
|
snackbarHost = {
|
||||||
),
|
SnackbarHost(host) { snackbarData: SnackbarData ->
|
||||||
)
|
CustomSnackBar(
|
||||||
}
|
snackbarData.visuals.message,
|
||||||
},
|
isRtl = false,
|
||||||
containerColor = MaterialTheme.colorScheme.background,
|
containerColor =
|
||||||
modifier =
|
MaterialTheme.colorScheme.surfaceColorAtElevation(
|
||||||
Modifier
|
2.dp,
|
||||||
.focusable()
|
),
|
||||||
.focusProperties {
|
)
|
||||||
if (navBackStackEntry?.isCurrentRoute(Route.Lock) == true) {
|
|
||||||
Unit
|
|
||||||
} else {
|
|
||||||
up = focusRequester
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
bottomBar = {
|
modifier =
|
||||||
BottomNavBar(
|
Modifier
|
||||||
navController,
|
.focusable()
|
||||||
listOf(
|
.focusProperties {
|
||||||
BottomNavItem(
|
if (navBackStackEntry?.isCurrentRoute(Route.Lock) == true) {
|
||||||
name = stringResource(R.string.tunnels),
|
Unit
|
||||||
route = Route.Main,
|
} else {
|
||||||
icon = Icons.Rounded.Home,
|
up = focusRequester
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bottomBar = {
|
||||||
|
BottomNavBar(
|
||||||
|
navController,
|
||||||
|
listOf(
|
||||||
|
BottomNavItem(
|
||||||
|
name = stringResource(R.string.tunnels),
|
||||||
|
route = Route.Main,
|
||||||
|
icon = Icons.Rounded.Home,
|
||||||
|
),
|
||||||
|
BottomNavItem(
|
||||||
|
name = stringResource(R.string.settings),
|
||||||
|
route = Route.Settings,
|
||||||
|
icon = Icons.Rounded.Settings,
|
||||||
|
),
|
||||||
|
BottomNavItem(
|
||||||
|
name = stringResource(R.string.support),
|
||||||
|
route = Route.Support,
|
||||||
|
icon = Icons.Rounded.QuestionMark,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
BottomNavItem(
|
)
|
||||||
name = stringResource(R.string.settings),
|
},
|
||||||
route = Route.Settings,
|
) { padding ->
|
||||||
icon = Icons.Rounded.Settings,
|
Box(modifier = Modifier.fillMaxSize().padding(padding)) {
|
||||||
),
|
NavHost(
|
||||||
BottomNavItem(
|
navController,
|
||||||
name = stringResource(R.string.support),
|
enterTransition = { fadeIn(tween(Constants.TRANSITION_ANIMATION_TIME)) },
|
||||||
route = Route.Support,
|
exitTransition = { fadeOut(tween(Constants.TRANSITION_ANIMATION_TIME)) },
|
||||||
icon = Icons.Rounded.QuestionMark,
|
startDestination = (if (appUiState.generalState.isPinLockEnabled == true) Route.Lock else Route.Main),
|
||||||
),
|
) {
|
||||||
),
|
composable<Route.Main> {
|
||||||
)
|
MainScreen(
|
||||||
},
|
focusRequester = focusRequester,
|
||||||
) { padding ->
|
uiState = appUiState,
|
||||||
Surface(modifier = Modifier.fillMaxSize().padding(padding)) {
|
)
|
||||||
NavHost(
|
}
|
||||||
navController,
|
composable<Route.Settings> {
|
||||||
enterTransition = { fadeIn(tween(Constants.TRANSITION_ANIMATION_TIME)) },
|
SettingsScreen(
|
||||||
exitTransition = { fadeOut(tween(Constants.TRANSITION_ANIMATION_TIME)) },
|
appViewModel = viewModel,
|
||||||
startDestination = (if (isPinLockEnabled == true) Route.Lock else Route.Main),
|
uiState = appUiState,
|
||||||
) {
|
focusRequester = focusRequester,
|
||||||
composable<Route.Main> {
|
)
|
||||||
MainScreen(
|
}
|
||||||
focusRequester = focusRequester,
|
composable<Route.Support> {
|
||||||
uiState = appUiState,
|
SupportScreen(
|
||||||
navController = navController,
|
focusRequester = focusRequester,
|
||||||
)
|
appUiState = appUiState,
|
||||||
}
|
)
|
||||||
composable<Route.Settings> {
|
}
|
||||||
SettingsScreen(
|
composable<Route.Logs> {
|
||||||
appViewModel = appViewModel,
|
LogsScreen()
|
||||||
uiState = appUiState,
|
}
|
||||||
navController = navController,
|
composable<Route.Config> {
|
||||||
focusRequester = focusRequester,
|
val args = it.toRoute<Route.Config>()
|
||||||
)
|
ConfigScreen(
|
||||||
}
|
focusRequester = focusRequester,
|
||||||
composable<Route.Support> {
|
tunnelId = args.id,
|
||||||
SupportScreen(
|
)
|
||||||
focusRequester = focusRequester,
|
}
|
||||||
navController = navController,
|
composable<Route.Option> {
|
||||||
appUiState = appUiState,
|
val args = it.toRoute<Route.Option>()
|
||||||
)
|
OptionsScreen(
|
||||||
}
|
tunnelId = args.id,
|
||||||
composable<Route.Logs> {
|
focusRequester = focusRequester,
|
||||||
LogsScreen()
|
appUiState = appUiState,
|
||||||
}
|
)
|
||||||
composable<Route.Config> {
|
}
|
||||||
val args = it.toRoute<Route.Config>()
|
composable<Route.Lock> {
|
||||||
ConfigScreen(
|
PinLockScreen(
|
||||||
focusRequester = focusRequester,
|
appViewModel = viewModel,
|
||||||
tunnelId = args.id,
|
)
|
||||||
)
|
}
|
||||||
}
|
composable<Route.Scanner> {
|
||||||
composable<Route.Option> {
|
ScannerScreen()
|
||||||
val args = it.toRoute<Route.Option>()
|
}
|
||||||
OptionsScreen(
|
|
||||||
navController = navController,
|
|
||||||
tunnelId = args.id,
|
|
||||||
focusRequester = focusRequester,
|
|
||||||
appUiState = appUiState,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
composable<Route.Lock> {
|
|
||||||
PinLockScreen(
|
|
||||||
navController = navController,
|
|
||||||
appViewModel = appViewModel,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ sealed class Route {
|
|||||||
@Serializable
|
@Serializable
|
||||||
data object Lock : Route()
|
data object Lock : Route()
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data object Scanner : Route()
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Config(
|
data class Config(
|
||||||
val id: Int,
|
val id: Int,
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Intent
|
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
|
||||||
import androidx.activity.ComponentActivity
|
|
||||||
import androidx.activity.viewModels
|
|
||||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
|
||||||
import androidx.lifecycle.Lifecycle
|
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppStateRepository
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestAutoTunnelTileServiceUpdate
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
import kotlinx.coroutines.async
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import xyz.teamgravity.pin_lock_compose.PinManager
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Provider
|
|
||||||
|
|
||||||
@SuppressLint("CustomSplashScreen")
|
|
||||||
@AndroidEntryPoint
|
|
||||||
class SplashActivity : ComponentActivity() {
|
|
||||||
@Inject
|
|
||||||
lateinit var appStateRepository: AppStateRepository
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
lateinit var appDataRepository: AppDataRepository
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
lateinit var tunnelService: Provider<TunnelService>
|
|
||||||
|
|
||||||
private val appViewModel: AppViewModel by viewModels()
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
||||||
val splashScreen = installSplashScreen()
|
|
||||||
splashScreen.setKeepOnScreenCondition { true }
|
|
||||||
}
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
|
|
||||||
lifecycleScope.launch {
|
|
||||||
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
|
||||||
val pinLockEnabled = async {
|
|
||||||
appStateRepository.isPinLockEnabled().also {
|
|
||||||
if (it) PinManager.initialize(WireGuardAutoTunnel.instance)
|
|
||||||
}
|
|
||||||
}.await()
|
|
||||||
async {
|
|
||||||
val settings = appDataRepository.settings.getSettings()
|
|
||||||
if (settings.isAutoTunnelEnabled) ServiceManager.startWatcherService(application.applicationContext)
|
|
||||||
if (tunnelService.get().getState() == TunnelState.UP) tunnelService.get().startStatsJob()
|
|
||||||
val activeTunnels = appDataRepository.tunnels.getActive()
|
|
||||||
if (activeTunnels.isNotEmpty() &&
|
|
||||||
tunnelService.get().getState() == TunnelState.DOWN
|
|
||||||
) {
|
|
||||||
tunnelService.get().startTunnel(activeTunnels.first())
|
|
||||||
}
|
|
||||||
}.await()
|
|
||||||
|
|
||||||
async {
|
|
||||||
val tunnels = appDataRepository.tunnels.getAll()
|
|
||||||
appViewModel.setTunnels(tunnels)
|
|
||||||
}.await()
|
|
||||||
|
|
||||||
requestAutoTunnelTileServiceUpdate()
|
|
||||||
|
|
||||||
val intent =
|
|
||||||
Intent(this@SplashActivity, MainActivity::class.java).apply {
|
|
||||||
putExtra(IS_PIN_LOCK_ENABLED_KEY, pinLockEnabled)
|
|
||||||
}
|
|
||||||
startActivity(intent)
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val IS_PIN_LOCK_ENABLED_KEY = "is_pin_lock_enabled"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+69
@@ -0,0 +1,69 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.common
|
||||||
|
|
||||||
|
import androidx.compose.animation.animateContentSize
|
||||||
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.combinedClickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
|
@Composable
|
||||||
|
fun ExpandingRowListItem(
|
||||||
|
leading: @Composable () -> Unit,
|
||||||
|
text: String,
|
||||||
|
onHold: () -> Unit = {},
|
||||||
|
onClick: () -> Unit,
|
||||||
|
trailing: @Composable () -> Unit,
|
||||||
|
isExpanded: Boolean,
|
||||||
|
expanded: @Composable () -> Unit = {},
|
||||||
|
focusRequester: FocusRequester,
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.focusRequester(focusRequester)
|
||||||
|
.animateContentSize()
|
||||||
|
.clip(RoundedCornerShape(30.dp))
|
||||||
|
.combinedClickable(
|
||||||
|
onClick = { onClick() },
|
||||||
|
onLongClick = { onHold() },
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
Row(
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 15.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(15.dp),
|
||||||
|
modifier = Modifier.fillMaxWidth(13 / 20f),
|
||||||
|
) {
|
||||||
|
leading()
|
||||||
|
Text(text, maxLines = 1, overflow = TextOverflow.Ellipsis, style = MaterialTheme.typography.labelLarge)
|
||||||
|
}
|
||||||
|
trailing()
|
||||||
|
}
|
||||||
|
if (isExpanded) expanded()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.common
|
||||||
|
|
||||||
|
import androidx.compose.ui.geometry.Offset
|
||||||
|
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
||||||
|
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
|
||||||
|
|
||||||
|
class NestedScrollListener(val onUp: () -> Unit, val onDown: () -> Unit) : NestedScrollConnection {
|
||||||
|
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
||||||
|
if (available.y < -1) onDown()
|
||||||
|
if (available.y > 1) onUp()
|
||||||
|
return Offset.Zero
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common
|
|
||||||
|
|
||||||
import androidx.compose.animation.animateContentSize
|
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
|
||||||
import androidx.compose.foundation.combinedClickable
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
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.focus.FocusRequester
|
|
||||||
import androidx.compose.ui.focus.focusRequester
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.TunnelStatistics
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toThreeDecimalPlaceString
|
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
|
||||||
@Composable
|
|
||||||
fun RowListItem(
|
|
||||||
icon: @Composable () -> Unit,
|
|
||||||
text: String,
|
|
||||||
onHold: () -> Unit,
|
|
||||||
onClick: () -> Unit,
|
|
||||||
rowButton: @Composable () -> Unit,
|
|
||||||
expanded: Boolean,
|
|
||||||
statistics: TunnelStatistics?,
|
|
||||||
focusRequester: FocusRequester,
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.focusRequester(focusRequester)
|
|
||||||
.animateContentSize()
|
|
||||||
.clip(RoundedCornerShape(30.dp))
|
|
||||||
.combinedClickable(
|
|
||||||
onClick = { onClick() },
|
|
||||||
onLongClick = { onHold() },
|
|
||||||
),
|
|
||||||
) {
|
|
||||||
Column {
|
|
||||||
Row(
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 15.dp, vertical = 5.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
modifier = Modifier.fillMaxWidth(13 / 20f),
|
|
||||||
) {
|
|
||||||
icon()
|
|
||||||
Text(text, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
|
||||||
}
|
|
||||||
rowButton()
|
|
||||||
}
|
|
||||||
if (expanded) {
|
|
||||||
statistics?.getPeers()?.forEach {
|
|
||||||
Row(
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(end = 10.dp, bottom = 10.dp, start = 10.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly,
|
|
||||||
) {
|
|
||||||
// TODO change these to string resources
|
|
||||||
val handshakeEpoch = statistics.peerStats(it)!!.latestHandshakeEpochMillis
|
|
||||||
val peerTx = statistics.peerStats(it)!!.txBytes
|
|
||||||
val peerRx = statistics.peerStats(it)!!.rxBytes
|
|
||||||
val peerId = it.toBase64().subSequence(0, 3).toString() + "***"
|
|
||||||
val handshakeSec =
|
|
||||||
NumberUtils.getSecondsBetweenTimestampAndNow(handshakeEpoch)
|
|
||||||
val handshake =
|
|
||||||
if (handshakeSec == null) "never" else "$handshakeSec secs ago"
|
|
||||||
val peerTxMB = NumberUtils.bytesToMB(peerTx).toThreeDecimalPlaceString()
|
|
||||||
val peerRxMB = NumberUtils.bytesToMB(peerRx).toThreeDecimalPlaceString()
|
|
||||||
val fontSize = 9.sp
|
|
||||||
Text("peer: $peerId", fontSize = fontSize)
|
|
||||||
Text("handshake: $handshake", fontSize = fontSize)
|
|
||||||
Text("tx: $peerTxMB MB", fontSize = fontSize)
|
|
||||||
Text("rx: $peerRxMB MB", fontSize = fontSize)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
@@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
|
|||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Switch
|
import androidx.compose.material3.Switch
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -32,6 +33,7 @@ fun ConfigurationToggle(
|
|||||||
Text(
|
Text(
|
||||||
label,
|
label,
|
||||||
textAlign = TextAlign.Start,
|
textAlign = TextAlign.Start,
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
modifier =
|
modifier =
|
||||||
Modifier
|
Modifier
|
||||||
.weight(
|
.weight(
|
||||||
|
|||||||
+8
-1
@@ -10,13 +10,20 @@ import androidx.activity.compose.rememberLauncherForActivityResult
|
|||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun rememberFileImportLauncherForResult(onNoFileExplorer: () -> Unit, onData: (data: Uri) -> Unit): ManagedActivityResultLauncher<String, Uri?> {
|
fun rememberFileImportLauncherForResult(onNoFileExplorer: () -> Unit, onData: (data: Uri) -> Unit): ManagedActivityResultLauncher<String, Uri?> {
|
||||||
return rememberLauncherForActivityResult(
|
return rememberLauncherForActivityResult(
|
||||||
object : ActivityResultContracts.GetContent() {
|
object : ActivityResultContracts.GetContent() {
|
||||||
override fun createIntent(context: Context, input: String): Intent {
|
override fun createIntent(context: Context, input: String): Intent {
|
||||||
val intent = super.createIntent(context, input)
|
val intent = super.createIntent(context, input).apply {
|
||||||
|
type = if (context.isRunningOnTv()) {
|
||||||
|
Constants.ALLOWED_TV_FILE_TYPES
|
||||||
|
} else {
|
||||||
|
Constants.ALL_FILE_TYPES
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* AndroidTV now comes with stubs that do nothing but display a Toast less helpful than
|
/* AndroidTV now comes with stubs that do nothing but display a Toast less helpful than
|
||||||
* what we can do, so detect this and throw an exception that we can catch later. */
|
* what we can do, so detect this and throw an exception that we can catch later. */
|
||||||
|
|||||||
+4
-9
@@ -10,10 +10,7 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavDestination.Companion.hasRoute
|
|
||||||
import androidx.navigation.NavDestination.Companion.hierarchy
|
|
||||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
|
|
||||||
@@ -22,11 +19,9 @@ fun BottomNavBar(navController: NavController, bottomNavItems: List<BottomNavIte
|
|||||||
var showBottomBar by rememberSaveable { mutableStateOf(true) }
|
var showBottomBar by rememberSaveable { mutableStateOf(true) }
|
||||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||||
|
|
||||||
showBottomBar = bottomNavItems.firstOrNull {
|
showBottomBar = bottomNavItems.any {
|
||||||
navBackStackEntry?.destination?.hierarchy?.any { dest ->
|
navBackStackEntry?.isCurrentRoute(it.route) == true
|
||||||
bottomNavItems.map { dest.hasRoute(route = it.route::class) }.contains(true)
|
}
|
||||||
} == true
|
|
||||||
} != null
|
|
||||||
|
|
||||||
if (showBottomBar) {
|
if (showBottomBar) {
|
||||||
NavigationBar(
|
NavigationBar(
|
||||||
@@ -53,7 +48,7 @@ fun BottomNavBar(navController: NavController, bottomNavItems: List<BottomNavIte
|
|||||||
label = {
|
label = {
|
||||||
Text(
|
Text(
|
||||||
text = item.name,
|
text = item.name,
|
||||||
fontWeight = FontWeight.SemiBold,
|
style = MaterialTheme.typography.labelMedium,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
icon = {
|
icon = {
|
||||||
|
|||||||
+2
@@ -1,10 +1,12 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import androidx.navigation.NavBackStackEntry
|
import androidx.navigation.NavBackStackEntry
|
||||||
import androidx.navigation.NavDestination.Companion.hasRoute
|
import androidx.navigation.NavDestination.Companion.hasRoute
|
||||||
import androidx.navigation.NavDestination.Companion.hierarchy
|
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
|
|
||||||
|
@SuppressLint("RestrictedApi")
|
||||||
fun NavBackStackEntry?.isCurrentRoute(route: Route): Boolean {
|
fun NavBackStackEntry?.isCurrentRoute(route: Route): Boolean {
|
||||||
return this?.destination?.hierarchy?.any {
|
return this?.destination?.hierarchy?.any {
|
||||||
it.hasRoute(route = route::class)
|
it.hasRoute(route = route::class)
|
||||||
|
|||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||||
|
|
||||||
|
import androidx.compose.runtime.compositionLocalOf
|
||||||
|
import androidx.navigation.NavHostController
|
||||||
|
|
||||||
|
val LocalNavController = compositionLocalOf<NavHostController> {
|
||||||
|
error("NavController was not provided")
|
||||||
|
}
|
||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.navigation.NavHostController
|
|
||||||
import androidx.navigation.compose.ComposeNavigator
|
|
||||||
import androidx.navigation.compose.DialogNavigator
|
|
||||||
|
|
||||||
class NavigationService constructor(
|
|
||||||
context: Context,
|
|
||||||
) {
|
|
||||||
val navController = NavHostController(context).apply {
|
|
||||||
navigatorProvider.addNavigator(ComposeNavigator())
|
|
||||||
navigatorProvider.addNavigator(DialogNavigator())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.common.navigation
|
||||||
|
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.outlined.ArrowBack
|
||||||
|
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun TopNavBar(title: String, trailing: @Composable () -> Unit = {}) {
|
||||||
|
val navController = LocalNavController.current
|
||||||
|
CenterAlignedTopAppBar(
|
||||||
|
title = {
|
||||||
|
Text(title)
|
||||||
|
},
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { navController.popBackStack() }) {
|
||||||
|
val icon = Icons.AutoMirrored.Outlined.ArrowBack
|
||||||
|
Icon(
|
||||||
|
imageVector = icon,
|
||||||
|
contentDescription = icon.name,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions = {
|
||||||
|
trailing()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
+2
-4
@@ -1,22 +1,20 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common.text
|
package com.zaneschepke.wireguardautotunnel.ui.common.text
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
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.text.TextStyle
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
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.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SectionTitle(title: String, padding: Dp) {
|
fun SectionTitle(title: String, padding: Dp) {
|
||||||
Text(
|
Text(
|
||||||
title,
|
title,
|
||||||
textAlign = TextAlign.Start,
|
textAlign = TextAlign.Start,
|
||||||
style = TextStyle(fontSize = 18.sp, fontWeight = FontWeight.ExtraBold),
|
style = MaterialTheme.typography.titleMedium,
|
||||||
modifier = Modifier.padding(padding, bottom = 5.dp, top = 5.dp),
|
modifier = Modifier.padding(padding, bottom = 5.dp, top = 5.dp),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-9
@@ -34,6 +34,7 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.derivedStateOf
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@@ -56,8 +57,10 @@ 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
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationTextBox
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationTextBox
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationToggle
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationToggle
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt
|
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
||||||
@@ -78,12 +81,26 @@ fun ConfigScreen(tunnelId: Int, focusRequester: FocusRequester) {
|
|||||||
val snackbar = SnackbarController.current
|
val snackbar = SnackbarController.current
|
||||||
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
||||||
val keyboardController = LocalSoftwareKeyboardController.current
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
|
val navController = LocalNavController.current
|
||||||
|
|
||||||
var showApplicationsDialog by remember { mutableStateOf(false) }
|
var showApplicationsDialog by remember { mutableStateOf(false) }
|
||||||
var showAuthPrompt by remember { mutableStateOf(false) }
|
var showAuthPrompt by remember { mutableStateOf(false) }
|
||||||
var isAuthenticated by remember { mutableStateOf(false) }
|
var isAuthenticated by remember { mutableStateOf(false) }
|
||||||
var configType by remember { mutableStateOf(ConfigType.WIREGUARD) }
|
|
||||||
|
|
||||||
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
|
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||||
|
var configType by remember { mutableStateOf<ConfigType?>(null) }
|
||||||
|
val derivedConfigType = remember {
|
||||||
|
derivedStateOf<ConfigType> {
|
||||||
|
configType ?: if (!uiState.hasAmneziaProperties()) ConfigType.WIREGUARD else ConfigType.AMNEZIA
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val saved by viewModel.saved.collectAsStateWithLifecycle(null)
|
||||||
|
|
||||||
|
LaunchedEffect(saved) {
|
||||||
|
if (saved == true) {
|
||||||
|
navController.navigate(Route.Main)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
if (!uiState.loading && context.isRunningOnTv()) {
|
if (!uiState.loading && context.isRunningOnTv()) {
|
||||||
@@ -215,7 +232,7 @@ fun ConfigScreen(tunnelId: Int, focusRequester: FocusRequester) {
|
|||||||
)
|
)
|
||||||
ConfigurationToggle(
|
ConfigurationToggle(
|
||||||
stringResource(id = R.string.show_amnezia_properties),
|
stringResource(id = R.string.show_amnezia_properties),
|
||||||
checked = configType == ConfigType.AMNEZIA,
|
checked = derivedConfigType.value == ConfigType.AMNEZIA,
|
||||||
padding = screenPadding,
|
padding = screenPadding,
|
||||||
onCheckChanged = { configType = if (it) ConfigType.AMNEZIA else ConfigType.WIREGUARD },
|
onCheckChanged = { configType = if (it) ConfigType.AMNEZIA else ConfigType.WIREGUARD },
|
||||||
modifier = Modifier.focusRequester(focusRequester),
|
modifier = Modifier.focusRequester(focusRequester),
|
||||||
@@ -228,8 +245,7 @@ fun ConfigScreen(tunnelId: Int, focusRequester: FocusRequester) {
|
|||||||
hint = stringResource(R.string.tunnel_name).lowercase(),
|
hint = stringResource(R.string.tunnel_name).lowercase(),
|
||||||
modifier =
|
modifier =
|
||||||
Modifier
|
Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth(),
|
||||||
.focusRequester(focusRequester),
|
|
||||||
)
|
)
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
modifier =
|
modifier =
|
||||||
@@ -333,7 +349,7 @@ fun ConfigScreen(tunnelId: Int, focusRequester: FocusRequester) {
|
|||||||
modifier = Modifier.width(IntrinsicSize.Min),
|
modifier = Modifier.width(IntrinsicSize.Min),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (configType == ConfigType.AMNEZIA) {
|
if (derivedConfigType.value == ConfigType.AMNEZIA) {
|
||||||
ConfigurationTextBox(
|
ConfigurationTextBox(
|
||||||
value = uiState.interfaceProxy.junkPacketCount,
|
value = uiState.interfaceProxy.junkPacketCount,
|
||||||
onValueChange = viewModel::onJunkPacketCountChanged,
|
onValueChange = viewModel::onJunkPacketCountChanged,
|
||||||
@@ -523,15 +539,27 @@ fun ConfigScreen(tunnelId: Int, focusRequester: FocusRequester) {
|
|||||||
hint = stringResource(R.string.base64_key),
|
hint = stringResource(R.string.base64_key),
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
)
|
)
|
||||||
ConfigurationTextBox(
|
OutlinedTextField(
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable { showAuthPrompt = true },
|
||||||
value = peer.preSharedKey,
|
value = peer.preSharedKey,
|
||||||
|
visualTransformation =
|
||||||
|
if ((tunnelId == Constants.MANUAL_TUNNEL_CONFIG_ID.toInt()) || isAuthenticated) {
|
||||||
|
VisualTransformation.None
|
||||||
|
} else {
|
||||||
|
PasswordVisualTransformation()
|
||||||
|
},
|
||||||
|
enabled = (tunnelId == Constants.MANUAL_TUNNEL_CONFIG_ID.toInt()) || isAuthenticated || peer.preSharedKey.isEmpty(),
|
||||||
onValueChange = { value ->
|
onValueChange = { value ->
|
||||||
viewModel.onPreSharedKeyChange(index, value)
|
viewModel.onPreSharedKeyChange(index, value)
|
||||||
},
|
},
|
||||||
|
label = { Text(stringResource(R.string.preshared_key)) },
|
||||||
|
singleLine = true,
|
||||||
|
placeholder = { Text(stringResource(R.string.optional)) },
|
||||||
|
keyboardOptions = keyboardOptions,
|
||||||
keyboardActions = keyboardActions,
|
keyboardActions = keyboardActions,
|
||||||
label = stringResource(R.string.preshared_key),
|
|
||||||
hint = stringResource(R.string.optional),
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
)
|
)
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
|||||||
+3
@@ -18,6 +18,9 @@ data class ConfigUiState(
|
|||||||
var tunnelName: String = "",
|
var tunnelName: String = "",
|
||||||
val isAmneziaEnabled: Boolean = false,
|
val isAmneziaEnabled: Boolean = false,
|
||||||
) {
|
) {
|
||||||
|
fun hasAmneziaProperties(): Boolean {
|
||||||
|
return this.interfaceProxy.junkPacketCount != ""
|
||||||
|
}
|
||||||
companion object {
|
companion object {
|
||||||
fun from(config: Config): ConfigUiState {
|
fun from(config: Config): ConfigUiState {
|
||||||
val proxyPeers = config.peers.map { PeerProxy.from(it) }
|
val proxyPeers = config.peers.map { PeerProxy.from(it) }
|
||||||
|
|||||||
+6
-4
@@ -6,7 +6,6 @@ import android.content.pm.PackageManager
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import androidx.navigation.NavHostController
|
|
||||||
import com.wireguard.config.Config
|
import com.wireguard.config.Config
|
||||||
import com.wireguard.config.Interface
|
import com.wireguard.config.Interface
|
||||||
import com.wireguard.config.Peer
|
import com.wireguard.config.Peer
|
||||||
@@ -17,7 +16,6 @@ import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
|||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.config.model.PeerProxy
|
import com.zaneschepke.wireguardautotunnel.ui.screens.config.model.PeerProxy
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
@@ -30,8 +28,10 @@ import dagger.assisted.AssistedFactory
|
|||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.asSharedFlow
|
||||||
import kotlinx.coroutines.flow.onStart
|
import kotlinx.coroutines.flow.onStart
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
@@ -44,12 +44,14 @@ class ConfigViewModel
|
|||||||
@AssistedInject
|
@AssistedInject
|
||||||
constructor(
|
constructor(
|
||||||
private val appDataRepository: AppDataRepository,
|
private val appDataRepository: AppDataRepository,
|
||||||
private val navController: NavHostController,
|
|
||||||
@Assisted val id: Int,
|
@Assisted val id: Int,
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
private val packageManager = WireGuardAutoTunnel.instance.packageManager
|
private val packageManager = WireGuardAutoTunnel.instance.packageManager
|
||||||
|
|
||||||
|
private val _saved = MutableSharedFlow<Boolean>()
|
||||||
|
val saved = _saved.asSharedFlow()
|
||||||
|
|
||||||
private val _uiState = MutableStateFlow(ConfigUiState())
|
private val _uiState = MutableStateFlow(ConfigUiState())
|
||||||
val uiState = _uiState.onStart {
|
val uiState = _uiState.onStart {
|
||||||
appDataRepository.tunnels.getById(id)?.let {
|
appDataRepository.tunnels.getById(id)?.let {
|
||||||
@@ -335,7 +337,7 @@ constructor(
|
|||||||
SnackbarController.showMessage(
|
SnackbarController.showMessage(
|
||||||
StringValue.StringResource(R.string.config_changes_saved),
|
StringValue.StringResource(R.string.config_changes_saved),
|
||||||
)
|
)
|
||||||
navController.navigate(Route.Main)
|
_saved.emit(true)
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
Timber.e(it)
|
Timber.e(it)
|
||||||
val message = it.message?.substringAfter(":", missingDelimiterValue = "")
|
val message = it.message?.substringAfter(":", missingDelimiterValue = "")
|
||||||
|
|||||||
+1
-1
@@ -44,7 +44,7 @@ data class InterfaceProxy(
|
|||||||
publicKey = i.keyPair.publicKey.toBase64().trim(),
|
publicKey = i.keyPair.publicKey.toBase64().trim(),
|
||||||
privateKey = i.keyPair.privateKey.toBase64().trim(),
|
privateKey = i.keyPair.privateKey.toBase64().trim(),
|
||||||
addresses = i.addresses.joinToString(", ").trim(),
|
addresses = i.addresses.joinToString(", ").trim(),
|
||||||
dnsServers = i.dnsServers.joinToString(", ").replace("/", "").trim(),
|
dnsServers = (i.dnsServers + i.dnsSearchDomains).joinToString(", ").replace("/", "").trim(),
|
||||||
listenPort =
|
listenPort =
|
||||||
if (i.listenPort.isPresent) {
|
if (i.listenPort.isPresent) {
|
||||||
i.listenPort.get().toString().trim()
|
i.listenPort.get().toString().trim()
|
||||||
|
|||||||
+50
-353
@@ -1,40 +1,26 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.net.VpnService
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.AppCompatActivity.RESULT_OK
|
import androidx.appcompat.app.AppCompatActivity.RESULT_OK
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.focusable
|
|
||||||
import androidx.compose.foundation.gestures.ScrollableDefaults
|
import androidx.compose.foundation.gestures.ScrollableDefaults
|
||||||
import androidx.compose.foundation.gestures.detectTapGestures
|
import androidx.compose.foundation.gestures.detectTapGestures
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
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.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
import androidx.compose.material.icons.rounded.Bolt
|
|
||||||
import androidx.compose.material.icons.rounded.Circle
|
|
||||||
import androidx.compose.material.icons.rounded.CopyAll
|
|
||||||
import androidx.compose.material.icons.rounded.Delete
|
|
||||||
import androidx.compose.material.icons.rounded.Info
|
|
||||||
import androidx.compose.material.icons.rounded.Settings
|
|
||||||
import androidx.compose.material.icons.rounded.Smartphone
|
|
||||||
import androidx.compose.material.icons.rounded.Star
|
|
||||||
import androidx.compose.material3.FabPosition
|
import androidx.compose.material3.FabPosition
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Switch
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
|
||||||
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
|
||||||
@@ -45,97 +31,62 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.focus.focusRequester
|
|
||||||
import androidx.compose.ui.geometry.Offset
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
|
||||||
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
|
||||||
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
|
|
||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.buildAnnotatedString
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.navigation.NavController
|
|
||||||
import com.journeyapps.barcodescanner.ScanContract
|
|
||||||
import com.journeyapps.barcodescanner.ScanOptions
|
|
||||||
import com.wireguard.android.backend.GoBackend
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.HandshakeStatus
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.RowListItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.NestedScrollListener
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileImportLauncherForResult
|
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileImportLauncherForResult
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.AutoTunnelRowItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.GettingStartedLabel
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.GettingStartedLabel
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ScrollDismissFab
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ScrollDismissFab
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.TunnelImportSheet
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.TunnelImportSheet
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.TunnelRowItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.VpnDeniedDialog
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.VpnDeniedDialog
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.corn
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.mint
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.handshakeStatus
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.mapPeerStats
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.startTunnelBackground
|
import com.zaneschepke.wireguardautotunnel.util.extensions.startTunnelBackground
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import timber.log.Timber
|
|
||||||
|
|
||||||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState, focusRequester: FocusRequester, navController: NavController) {
|
fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState, focusRequester: FocusRequester) {
|
||||||
val haptic = LocalHapticFeedback.current
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
val navController = LocalNavController.current
|
||||||
val snackbar = SnackbarController.current
|
val snackbar = SnackbarController.current
|
||||||
|
|
||||||
var showBottomSheet by remember { mutableStateOf(false) }
|
var showBottomSheet by remember { mutableStateOf(false) }
|
||||||
var showVpnPermissionDialog by remember { mutableStateOf(false) }
|
var showVpnPermissionDialog by remember { mutableStateOf(false) }
|
||||||
val isVisible = rememberSaveable { mutableStateOf(true) }
|
var isFabVisible by rememberSaveable { mutableStateOf(true) }
|
||||||
var showDeleteTunnelAlertDialog by remember { mutableStateOf(false) }
|
var showDeleteTunnelAlertDialog by remember { mutableStateOf(false) }
|
||||||
var selectedTunnel by remember { mutableStateOf<TunnelConfig?>(null) }
|
var selectedTunnel by remember { mutableStateOf<TunnelConfig?>(null) }
|
||||||
|
|
||||||
val nestedScrollConnection =
|
val nestedScrollConnection = remember {
|
||||||
remember {
|
NestedScrollListener({ isFabVisible = false }, { isFabVisible = true })
|
||||||
object : NestedScrollConnection {
|
}
|
||||||
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
|
||||||
// Hide FAB
|
|
||||||
if (available.y < -1) {
|
|
||||||
isVisible.value = false
|
|
||||||
}
|
|
||||||
// Show FAB
|
|
||||||
if (available.y > 1) {
|
|
||||||
isVisible.value = true
|
|
||||||
}
|
|
||||||
return Offset.Zero
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val vpnActivityResultState =
|
val vpnActivityResultState =
|
||||||
rememberLauncherForActivityResult(
|
rememberLauncherForActivityResult(
|
||||||
ActivityResultContracts.StartActivityForResult(),
|
ActivityResultContracts.StartActivityForResult(),
|
||||||
onResult = {
|
onResult = {
|
||||||
val accepted = (it.resultCode == RESULT_OK)
|
if (it.resultCode != RESULT_OK) showVpnPermissionDialog = true
|
||||||
if (accepted) {
|
|
||||||
Timber.d("VPN permission granted")
|
|
||||||
} else {
|
|
||||||
showVpnPermissionDialog = true
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
if (context.isRunningOnTv()) {
|
if (context.isRunningOnTv()) {
|
||||||
delay(Constants.FOCUS_REQUEST_DELAY)
|
delay(Constants.FOCUS_REQUEST_DELAY)
|
||||||
kotlin.runCatching {
|
runCatching {
|
||||||
focusRequester.requestFocus()
|
focusRequester.requestFocus()
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
delay(Constants.FOCUS_REQUEST_DELAY)
|
delay(Constants.FOCUS_REQUEST_DELAY)
|
||||||
@@ -152,15 +103,12 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState,
|
|||||||
viewModel.onTunnelFileSelected(data, context)
|
viewModel.onTunnelFileSelected(data, context)
|
||||||
})
|
})
|
||||||
|
|
||||||
val scanLauncher =
|
val requestPermissionLauncher = rememberLauncherForActivityResult(
|
||||||
rememberLauncherForActivityResult(
|
ActivityResultContracts.RequestPermission(),
|
||||||
contract = ScanContract(),
|
) { isGranted ->
|
||||||
onResult = {
|
if (!isGranted) return@rememberLauncherForActivityResult snackbar.showMessage("Camera permission required")
|
||||||
if (it.contents != null) {
|
navController.navigate(Route.Scanner)
|
||||||
viewModel.onTunnelQrResult(it.contents)
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
VpnDeniedDialog(showVpnPermissionDialog, onDismiss = { showVpnPermissionDialog = false })
|
VpnDeniedDialog(showVpnPermissionDialog, onDismiss = { showVpnPermissionDialog = false })
|
||||||
|
|
||||||
@@ -179,51 +127,36 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onTunnelToggle(checked: Boolean, tunnel: TunnelConfig) {
|
fun onTunnelToggle(checked: Boolean, tunnel: TunnelConfig) {
|
||||||
if (checked) {
|
val intent = if (uiState.settings.isKernelEnabled) null else VpnService.prepare(context)
|
||||||
if (uiState.settings.isKernelEnabled) {
|
if (intent != null) return vpnActivityResultState.launch(intent)
|
||||||
context.startTunnelBackground(tunnel.id)
|
if (!checked) viewModel.onTunnelStop(tunnel).also { return }
|
||||||
} else {
|
if (uiState.settings.isKernelEnabled) {
|
||||||
viewModel.onTunnelStart(tunnel)
|
context.startTunnelBackground(tunnel.id)
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
viewModel.onTunnelStop(
|
viewModel.onTunnelStart(tunnel)
|
||||||
tunnel,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun launchQrScanner() {
|
|
||||||
val scanOptions = ScanOptions()
|
|
||||||
scanOptions.setDesiredBarcodeFormats(ScanOptions.QR_CODE)
|
|
||||||
scanOptions.setOrientationLocked(true)
|
|
||||||
scanOptions.setPrompt(
|
|
||||||
context.getString(R.string.scanning_qr),
|
|
||||||
)
|
|
||||||
scanOptions.setBeepEnabled(false)
|
|
||||||
scanLauncher.launch(scanOptions)
|
|
||||||
}
|
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.pointerInput(Unit) {
|
Modifier.pointerInput(Unit) {
|
||||||
if (uiState.tunnels.isNotEmpty()) {
|
if (uiState.tunnels.isEmpty()) return@pointerInput
|
||||||
detectTapGestures(
|
detectTapGestures(
|
||||||
onTap = {
|
onTap = {
|
||||||
selectedTunnel = null
|
selectedTunnel = null
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
|
||||||
},
|
},
|
||||||
floatingActionButtonPosition = FabPosition.End,
|
floatingActionButtonPosition = FabPosition.End,
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
ScrollDismissFab(icon = {
|
ScrollDismissFab({
|
||||||
val icon = Icons.Filled.Add
|
val icon = Icons.Filled.Add
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = icon,
|
imageVector = icon,
|
||||||
contentDescription = icon.name,
|
contentDescription = icon.name,
|
||||||
tint = MaterialTheme.colorScheme.onPrimary,
|
tint = MaterialTheme.colorScheme.onPrimary,
|
||||||
)
|
)
|
||||||
}, focusRequester, isVisible = isVisible.value, onClick = {
|
}, focusRequester, isVisible = isFabVisible, onClick = {
|
||||||
showBottomSheet = true
|
showBottomSheet = true
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -231,8 +164,8 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState,
|
|||||||
TunnelImportSheet(
|
TunnelImportSheet(
|
||||||
showBottomSheet,
|
showBottomSheet,
|
||||||
onDismiss = { showBottomSheet = false },
|
onDismiss = { showBottomSheet = false },
|
||||||
onFileClick = { tunnelFileImportResultLauncher.launch(Constants.ALLOWED_FILE_TYPES) },
|
onFileClick = { tunnelFileImportResultLauncher.launch(Constants.ALLOWED_TV_FILE_TYPES) },
|
||||||
onQrClick = { launchQrScanner() },
|
onQrClick = { requestPermissionLauncher.launch(android.Manifest.permission.CAMERA) },
|
||||||
onManualImportClick = {
|
onManualImportClick = {
|
||||||
navController.navigate(
|
navController.navigate(
|
||||||
Route.Config(Constants.MANUAL_TUNNEL_CONFIG_ID),
|
Route.Config(Constants.MANUAL_TUNNEL_CONFIG_ID),
|
||||||
@@ -257,69 +190,9 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState,
|
|||||||
GettingStartedLabel(onClick = { context.openWebUrl(it) })
|
GettingStartedLabel(onClick = { context.openWebUrl(it) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item {
|
if (uiState.settings.isAutoTunnelEnabled) {
|
||||||
if (uiState.settings.isAutoTunnelEnabled) {
|
item {
|
||||||
val itemFocusRequester = remember { FocusRequester() }
|
AutoTunnelRowItem(uiState.settings, { viewModel.onToggleAutoTunnelingPause() }, focusRequester)
|
||||||
val autoTunnelingLabel =
|
|
||||||
buildAnnotatedString {
|
|
||||||
append(stringResource(id = R.string.auto_tunneling))
|
|
||||||
append(": ")
|
|
||||||
if (uiState.settings.isAutoTunnelPaused) {
|
|
||||||
append(
|
|
||||||
stringResource(id = R.string.paused),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
append(
|
|
||||||
stringResource(id = R.string.active),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RowListItem(
|
|
||||||
icon = {
|
|
||||||
val icon = Icons.Rounded.Bolt
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
icon.name,
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.padding(end = 8.5.dp)
|
|
||||||
.size(25.dp),
|
|
||||||
tint =
|
|
||||||
if (uiState.settings.isAutoTunnelPaused) {
|
|
||||||
Color.Gray
|
|
||||||
} else {
|
|
||||||
mint
|
|
||||||
},
|
|
||||||
)
|
|
||||||
},
|
|
||||||
text = autoTunnelingLabel.text,
|
|
||||||
rowButton = {
|
|
||||||
if (uiState.settings.isAutoTunnelPaused) {
|
|
||||||
TextButton(
|
|
||||||
modifier = Modifier.focusRequester(itemFocusRequester),
|
|
||||||
onClick = { viewModel.resumeAutoTunneling() },
|
|
||||||
) {
|
|
||||||
Text(stringResource(id = R.string.resume))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
TextButton(
|
|
||||||
modifier = Modifier.focusRequester(itemFocusRequester),
|
|
||||||
onClick = { viewModel.pauseAutoTunneling() },
|
|
||||||
) {
|
|
||||||
Text(stringResource(id = R.string.pause))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onClick = {
|
|
||||||
if (context.isRunningOnTv()) {
|
|
||||||
itemFocusRequester.requestFocus()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onHold = {},
|
|
||||||
expanded = false,
|
|
||||||
statistics = null,
|
|
||||||
focusRequester = focusRequester,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
items(
|
items(
|
||||||
@@ -330,195 +203,19 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState,
|
|||||||
it.id == tunnel.id &&
|
it.id == tunnel.id &&
|
||||||
it.isActive
|
it.isActive
|
||||||
}
|
}
|
||||||
val leadingIconColor =
|
val expanded = uiState.generalState.isTunnelStatsExpanded
|
||||||
(
|
TunnelRowItem(
|
||||||
if (
|
isActive,
|
||||||
isActive && uiState.vpnState.statistics != null
|
expanded,
|
||||||
) {
|
selectedTunnel?.id == tunnel.id,
|
||||||
uiState.vpnState.statistics.mapPeerStats()
|
tunnel,
|
||||||
.map { it.value?.handshakeStatus() }
|
vpnState = uiState.vpnState,
|
||||||
.let { statuses ->
|
{ selectedTunnel = tunnel },
|
||||||
when {
|
{ viewModel.onExpandedChanged(!expanded) },
|
||||||
statuses.all { it == HandshakeStatus.HEALTHY } -> mint
|
onDelete = { showDeleteTunnelAlertDialog = true },
|
||||||
statuses.any { it == HandshakeStatus.STALE } -> corn
|
onCopy = { viewModel.onCopyTunnel(tunnel) },
|
||||||
statuses.all { it == HandshakeStatus.NOT_STARTED } ->
|
onSwitchClick = { onTunnelToggle(it, tunnel) },
|
||||||
Color.Gray
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
Color.Gray
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Color.Gray
|
|
||||||
}
|
|
||||||
)
|
|
||||||
val itemFocusRequester = remember { FocusRequester() }
|
|
||||||
val expanded = remember { mutableStateOf(false) }
|
|
||||||
RowListItem(
|
|
||||||
icon = {
|
|
||||||
val circleIcon = Icons.Rounded.Circle
|
|
||||||
val icon =
|
|
||||||
if (tunnel.isPrimaryTunnel) {
|
|
||||||
Icons.Rounded.Star
|
|
||||||
} else if (tunnel.isMobileDataTunnel) {
|
|
||||||
Icons.Rounded.Smartphone
|
|
||||||
} else {
|
|
||||||
circleIcon
|
|
||||||
}
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
icon.name,
|
|
||||||
tint = leadingIconColor,
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.padding(
|
|
||||||
end = if (icon == circleIcon) 12.5.dp else 10.dp,
|
|
||||||
start = if (icon == circleIcon) 2.5.dp else 0.dp,
|
|
||||||
)
|
|
||||||
.size(if (icon == circleIcon) 15.dp else 20.dp),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
text = tunnel.name,
|
|
||||||
onHold = {
|
|
||||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
|
||||||
selectedTunnel = tunnel
|
|
||||||
},
|
|
||||||
onClick = {
|
|
||||||
if (!context.isRunningOnTv()) {
|
|
||||||
if (
|
|
||||||
isActive
|
|
||||||
) {
|
|
||||||
expanded.value = !expanded.value
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
selectedTunnel = tunnel
|
|
||||||
itemFocusRequester.requestFocus()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
statistics = uiState.vpnState.statistics,
|
|
||||||
expanded = expanded.value,
|
|
||||||
focusRequester = focusRequester,
|
focusRequester = focusRequester,
|
||||||
rowButton = {
|
|
||||||
if (
|
|
||||||
tunnel.id == selectedTunnel?.id &&
|
|
||||||
!context.isRunningOnTv()
|
|
||||||
) {
|
|
||||||
Row {
|
|
||||||
IconButton(
|
|
||||||
onClick = {
|
|
||||||
selectedTunnel?.let {
|
|
||||||
navController.navigate(
|
|
||||||
Route.Option(it.id),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
val icon = Icons.Rounded.Settings
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
icon.name,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
IconButton(
|
|
||||||
modifier = Modifier.focusable(),
|
|
||||||
onClick = { viewModel.onCopyTunnel(selectedTunnel) },
|
|
||||||
) {
|
|
||||||
val icon = Icons.Rounded.CopyAll
|
|
||||||
Icon(icon, icon.name)
|
|
||||||
}
|
|
||||||
IconButton(
|
|
||||||
enabled = !isActive,
|
|
||||||
modifier = Modifier.focusable(),
|
|
||||||
onClick = { showDeleteTunnelAlertDialog = true },
|
|
||||||
) {
|
|
||||||
val icon = Icons.Rounded.Delete
|
|
||||||
Icon(icon, icon.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!isActive) expanded.value = false
|
|
||||||
@Composable
|
|
||||||
fun TunnelSwitch() = Switch(
|
|
||||||
modifier = Modifier.focusRequester(itemFocusRequester),
|
|
||||||
checked = isActive,
|
|
||||||
onCheckedChange = { checked ->
|
|
||||||
if (!checked) expanded.value = false
|
|
||||||
val intent = if (uiState.settings.isKernelEnabled) null else GoBackend.VpnService.prepare(context)
|
|
||||||
if (intent != null) return@Switch vpnActivityResultState.launch(intent)
|
|
||||||
onTunnelToggle(checked, tunnel)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if (context.isRunningOnTv()) {
|
|
||||||
Row {
|
|
||||||
IconButton(
|
|
||||||
onClick = {
|
|
||||||
selectedTunnel = tunnel
|
|
||||||
selectedTunnel?.let {
|
|
||||||
navController.navigate(
|
|
||||||
Route.Option(it.id),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
val icon = Icons.Rounded.Settings
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
icon.name,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
IconButton(
|
|
||||||
modifier = Modifier.focusRequester(focusRequester),
|
|
||||||
onClick = {
|
|
||||||
if (
|
|
||||||
uiState.vpnState.status == TunnelState.UP &&
|
|
||||||
(uiState.vpnState.tunnelConfig?.name == tunnel.name)
|
|
||||||
) {
|
|
||||||
expanded.value = !expanded.value
|
|
||||||
} else {
|
|
||||||
snackbar.showMessage(
|
|
||||||
context.getString(R.string.turn_on_tunnel),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
val icon = Icons.Rounded.Info
|
|
||||||
Icon(icon, icon.name)
|
|
||||||
}
|
|
||||||
IconButton(
|
|
||||||
onClick = { viewModel.onCopyTunnel(tunnel) },
|
|
||||||
) {
|
|
||||||
val icon = Icons.Rounded.CopyAll
|
|
||||||
Icon(icon, icon.name)
|
|
||||||
}
|
|
||||||
IconButton(
|
|
||||||
onClick = {
|
|
||||||
if (
|
|
||||||
uiState.vpnState.status == TunnelState.UP &&
|
|
||||||
tunnel.name == uiState.vpnState.tunnelConfig?.name
|
|
||||||
) {
|
|
||||||
snackbar.showMessage(
|
|
||||||
context.getString(R.string.turn_off_tunnel),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
selectedTunnel = tunnel
|
|
||||||
showDeleteTunnelAlertDialog = true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
val icon = Icons.Rounded.Delete
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
icon.name,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
TunnelSwitch()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
TunnelSwitch()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-34
@@ -19,6 +19,8 @@ import com.zaneschepke.wireguardautotunnel.util.FileReadException
|
|||||||
import com.zaneschepke.wireguardautotunnel.util.InvalidFileExtensionException
|
import com.zaneschepke.wireguardautotunnel.util.InvalidFileExtensionException
|
||||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.extractNameAndNumber
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.hasNumberInParentheses
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toWgQuickString
|
import com.zaneschepke.wireguardautotunnel.util.extensions.toWgQuickString
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
@@ -63,6 +65,10 @@ constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onExpandedChanged(expanded: Boolean) = viewModelScope.launch {
|
||||||
|
appDataRepository.appState.setTunnelStatsExpanded(expanded)
|
||||||
|
}
|
||||||
|
|
||||||
fun onTunnelStart(tunnelConfig: TunnelConfig) = viewModelScope.launch {
|
fun onTunnelStart(tunnelConfig: TunnelConfig) = viewModelScope.launch {
|
||||||
Timber.i("Starting tunnel ${tunnelConfig.name}")
|
Timber.i("Starting tunnel ${tunnelConfig.name}")
|
||||||
tunnelService.startTunnel(tunnelConfig)
|
tunnelService.startTunnel(tunnelConfig)
|
||||||
@@ -96,28 +102,18 @@ constructor(
|
|||||||
return defaultName
|
return defaultName
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onTunnelQrResult(result: String) = viewModelScope.launch(ioDispatcher) {
|
|
||||||
kotlin.runCatching {
|
|
||||||
val amConfig = TunnelConfig.configFromAmQuick(result)
|
|
||||||
val amQuick = amConfig.toAwgQuickString(true)
|
|
||||||
val wgQuick = amConfig.toWgQuickString()
|
|
||||||
|
|
||||||
val tunnelName = makeTunnelNameUnique(generateQrCodeTunnelName(result))
|
|
||||||
val tunnelConfig = TunnelConfig(name = tunnelName, wgQuick = wgQuick, amQuick = amQuick)
|
|
||||||
saveTunnel(tunnelConfig)
|
|
||||||
}.onFailure {
|
|
||||||
Timber.e(it)
|
|
||||||
SnackbarController.showMessage(StringValue.StringResource(R.string.error_invalid_code))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun makeTunnelNameUnique(name: String): String {
|
private suspend fun makeTunnelNameUnique(name: String): String {
|
||||||
return withContext(ioDispatcher) {
|
return withContext(ioDispatcher) {
|
||||||
val tunnels = appDataRepository.tunnels.getAll()
|
val tunnels = appDataRepository.tunnels.getAll()
|
||||||
var tunnelName = name
|
var tunnelName = name
|
||||||
var num = 1
|
var num = 1
|
||||||
while (tunnels.any { it.name == tunnelName }) {
|
while (tunnels.any { it.name == tunnelName }) {
|
||||||
tunnelName = "$name($num)"
|
tunnelName = if (!tunnelName.hasNumberInParentheses()) {
|
||||||
|
"$name($num)"
|
||||||
|
} else {
|
||||||
|
val pair = tunnelName.extractNameAndNumber()
|
||||||
|
"${pair?.first}($num)"
|
||||||
|
}
|
||||||
num++
|
num++
|
||||||
}
|
}
|
||||||
tunnelName
|
tunnelName
|
||||||
@@ -190,17 +186,10 @@ constructor(
|
|||||||
saveTunnelConfigFromStream(stream, name)
|
saveTunnelConfigFromStream(stream, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pauseAutoTunneling() = viewModelScope.launch {
|
fun onToggleAutoTunnelingPause() = viewModelScope.launch {
|
||||||
val settings = appDataRepository.settings.getSettings()
|
val settings = appDataRepository.settings.getSettings()
|
||||||
appDataRepository.settings.save(
|
appDataRepository.settings.save(
|
||||||
settings.copy(isAutoTunnelPaused = true),
|
settings.copy(isAutoTunnelPaused = !settings.isAutoTunnelPaused),
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun resumeAutoTunneling() = viewModelScope.launch {
|
|
||||||
val settings = appDataRepository.settings.getSettings()
|
|
||||||
appDataRepository.settings.save(
|
|
||||||
settings.copy(isAutoTunnelPaused = false),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,14 +240,15 @@ constructor(
|
|||||||
|
|
||||||
private fun saveSettings(settings: Settings) = viewModelScope.launch { appDataRepository.settings.save(settings) }
|
private fun saveSettings(settings: Settings) = viewModelScope.launch { appDataRepository.settings.save(settings) }
|
||||||
|
|
||||||
fun onCopyTunnel(tunnel: TunnelConfig?) = viewModelScope.launch {
|
fun onCopyTunnel(tunnel: TunnelConfig) = viewModelScope.launch {
|
||||||
tunnel?.let {
|
saveTunnel(
|
||||||
saveTunnel(
|
tunnel.copy(
|
||||||
TunnelConfig(
|
id = 0,
|
||||||
name = it.name.plus(NumberUtils.randomThree()),
|
isPrimaryTunnel = false,
|
||||||
wgQuick = it.wgQuick,
|
isMobileDataTunnel = false,
|
||||||
),
|
isActive = false,
|
||||||
)
|
name = makeTunnelNameUnique(tunnel.name),
|
||||||
}
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+78
@@ -0,0 +1,78 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.rounded.Bolt
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.scale
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.buildAnnotatedString
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.ExpandingRowListItem
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.theme.SilverTree
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun AutoTunnelRowItem(settings: Settings, onToggle: () -> Unit, focusRequester: FocusRequester) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val itemFocusRequester = remember { FocusRequester() }
|
||||||
|
val autoTunnelingLabel =
|
||||||
|
buildAnnotatedString {
|
||||||
|
append(stringResource(id = R.string.auto_tunneling))
|
||||||
|
append(": ")
|
||||||
|
if (settings.isAutoTunnelPaused) {
|
||||||
|
append(
|
||||||
|
stringResource(id = R.string.paused),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
append(
|
||||||
|
stringResource(id = R.string.active),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ExpandingRowListItem(
|
||||||
|
leading = {
|
||||||
|
val icon = Icons.Rounded.Bolt
|
||||||
|
Icon(
|
||||||
|
icon,
|
||||||
|
icon.name,
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.size(iconSize).scale(1.5f),
|
||||||
|
tint =
|
||||||
|
if (settings.isAutoTunnelPaused) {
|
||||||
|
Color.Gray
|
||||||
|
} else {
|
||||||
|
SilverTree
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
text = autoTunnelingLabel.text,
|
||||||
|
trailing = {
|
||||||
|
TextButton(
|
||||||
|
modifier = Modifier.focusRequester(itemFocusRequester),
|
||||||
|
onClick = { onToggle() },
|
||||||
|
) {
|
||||||
|
Text(stringResource(id = if (settings.isAutoTunnelPaused) R.string.resume else R.string.pause))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
|
if (context.isRunningOnTv()) {
|
||||||
|
itemFocusRequester.requestFocus()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isExpanded = false,
|
||||||
|
focusRequester = focusRequester,
|
||||||
|
)
|
||||||
|
}
|
||||||
+204
@@ -0,0 +1,204 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.focusable
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.rounded.Circle
|
||||||
|
import androidx.compose.material.icons.rounded.CopyAll
|
||||||
|
import androidx.compose.material.icons.rounded.Delete
|
||||||
|
import androidx.compose.material.icons.rounded.Info
|
||||||
|
import androidx.compose.material.icons.rounded.Settings
|
||||||
|
import androidx.compose.material.icons.rounded.Smartphone
|
||||||
|
import androidx.compose.material.icons.rounded.Star
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.Switch
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.ExpandingRowListItem
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asColor
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun TunnelRowItem(
|
||||||
|
isActive: Boolean,
|
||||||
|
expanded: Boolean,
|
||||||
|
isSelected: Boolean,
|
||||||
|
tunnel: TunnelConfig,
|
||||||
|
vpnState: VpnState,
|
||||||
|
onHold: () -> Unit,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
onCopy: () -> Unit,
|
||||||
|
onDelete: () -> Unit,
|
||||||
|
onSwitchClick: (checked: Boolean) -> Unit,
|
||||||
|
focusRequester: FocusRequester,
|
||||||
|
) {
|
||||||
|
val leadingIconColor = if (!isActive) Color.Gray else vpnState.statistics.asColor()
|
||||||
|
val context = LocalContext.current
|
||||||
|
val snackbar = SnackbarController.current
|
||||||
|
val navController = LocalNavController.current
|
||||||
|
val haptic = LocalHapticFeedback.current
|
||||||
|
val itemFocusRequester = remember { FocusRequester() }
|
||||||
|
ExpandingRowListItem(
|
||||||
|
leading = {
|
||||||
|
val circleIcon = Icons.Rounded.Circle
|
||||||
|
val icon =
|
||||||
|
if (tunnel.isPrimaryTunnel) {
|
||||||
|
Icons.Rounded.Star
|
||||||
|
} else if (tunnel.isMobileDataTunnel) {
|
||||||
|
Icons.Rounded.Smartphone
|
||||||
|
} else {
|
||||||
|
circleIcon
|
||||||
|
}
|
||||||
|
Icon(
|
||||||
|
icon,
|
||||||
|
icon.name,
|
||||||
|
tint = leadingIconColor,
|
||||||
|
modifier = Modifier.size(iconSize),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
text = tunnel.name,
|
||||||
|
onHold = {
|
||||||
|
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
|
onHold()
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
|
if (!context.isRunningOnTv()) {
|
||||||
|
if (isActive) {
|
||||||
|
onClick()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
onHold()
|
||||||
|
itemFocusRequester.requestFocus()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isExpanded = expanded && isActive,
|
||||||
|
expanded = { if (isActive && expanded) TunnelStatisticsRow(vpnState.statistics, tunnel) },
|
||||||
|
focusRequester = focusRequester,
|
||||||
|
trailing = {
|
||||||
|
if (
|
||||||
|
isSelected &&
|
||||||
|
!context.isRunningOnTv()
|
||||||
|
) {
|
||||||
|
Row {
|
||||||
|
IconButton(
|
||||||
|
onClick = {
|
||||||
|
navController.navigate(
|
||||||
|
Route.Option(tunnel.id),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
val icon = Icons.Rounded.Settings
|
||||||
|
Icon(
|
||||||
|
icon,
|
||||||
|
icon.name,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
IconButton(
|
||||||
|
modifier = Modifier.focusable(),
|
||||||
|
onClick = { onCopy() },
|
||||||
|
) {
|
||||||
|
val icon = Icons.Rounded.CopyAll
|
||||||
|
Icon(icon, icon.name)
|
||||||
|
}
|
||||||
|
IconButton(
|
||||||
|
enabled = !isActive,
|
||||||
|
modifier = Modifier.focusable(),
|
||||||
|
onClick = { onDelete() },
|
||||||
|
) {
|
||||||
|
val icon = Icons.Rounded.Delete
|
||||||
|
Icon(icon, icon.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (context.isRunningOnTv()) {
|
||||||
|
Row {
|
||||||
|
IconButton(
|
||||||
|
onClick = {
|
||||||
|
onHold()
|
||||||
|
navController.navigate(
|
||||||
|
Route.Option(tunnel.id),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
val icon = Icons.Rounded.Settings
|
||||||
|
Icon(
|
||||||
|
icon,
|
||||||
|
icon.name,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
IconButton(
|
||||||
|
modifier = Modifier.focusRequester(focusRequester),
|
||||||
|
onClick = {
|
||||||
|
if (isActive) {
|
||||||
|
onClick()
|
||||||
|
} else {
|
||||||
|
snackbar.showMessage(
|
||||||
|
context.getString(R.string.turn_on_tunnel),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
val icon = Icons.Rounded.Info
|
||||||
|
Icon(icon, icon.name)
|
||||||
|
}
|
||||||
|
IconButton(
|
||||||
|
onClick = { onCopy() },
|
||||||
|
) {
|
||||||
|
val icon = Icons.Rounded.CopyAll
|
||||||
|
Icon(icon, icon.name)
|
||||||
|
}
|
||||||
|
IconButton(
|
||||||
|
onClick = {
|
||||||
|
if (isActive) {
|
||||||
|
snackbar.showMessage(
|
||||||
|
context.getString(R.string.turn_off_tunnel),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
onHold()
|
||||||
|
onDelete()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
val icon = Icons.Rounded.Delete
|
||||||
|
Icon(
|
||||||
|
icon,
|
||||||
|
icon.name,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Switch(
|
||||||
|
modifier = Modifier.focusRequester(itemFocusRequester),
|
||||||
|
checked = isActive,
|
||||||
|
onCheckedChange = { checked ->
|
||||||
|
onSwitchClick(checked)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Switch(
|
||||||
|
modifier = Modifier.focusRequester(itemFocusRequester),
|
||||||
|
checked = isActive,
|
||||||
|
onCheckedChange = { checked ->
|
||||||
|
onSwitchClick(checked)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
+60
@@ -0,0 +1,60 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.TunnelStatistics
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.toThreeDecimalPlaceString
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun TunnelStatisticsRow(statistics: TunnelStatistics?, tunnelConfig: TunnelConfig) {
|
||||||
|
val config = TunnelConfig.configFromAmQuick(tunnelConfig.wgQuick)
|
||||||
|
|
||||||
|
Row(
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(end = 10.dp, bottom = 10.dp, start = 45.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(30.dp, Alignment.Start),
|
||||||
|
) {
|
||||||
|
config.peers.forEach {
|
||||||
|
val peerId = it.publicKey.toBase64().subSequence(0, 3).toString() + "***"
|
||||||
|
val peerRx = statistics?.peerStats(it.publicKey)?.rxBytes ?: 0
|
||||||
|
val peerTx = statistics?.peerStats(it.publicKey)?.txBytes ?: 0
|
||||||
|
val peerTxMB = NumberUtils.bytesToMB(peerTx).toThreeDecimalPlaceString()
|
||||||
|
val peerRxMB = NumberUtils.bytesToMB(peerRx).toThreeDecimalPlaceString()
|
||||||
|
val handshake = statistics?.peerStats(it.publicKey)?.latestHandshakeEpochMillis?.let {
|
||||||
|
if (it == 0L) {
|
||||||
|
stringResource(R.string.never)
|
||||||
|
} else {
|
||||||
|
"${NumberUtils.getSecondsBetweenTimestampAndNow(it)} ${stringResource(R.string.sec)}"
|
||||||
|
}
|
||||||
|
} ?: stringResource(R.string.never)
|
||||||
|
Column(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.peer).lowercase() + ": $peerId", style = MaterialTheme.typography.bodySmall)
|
||||||
|
Text("tx: $peerTxMB MB", style = MaterialTheme.typography.bodySmall)
|
||||||
|
}
|
||||||
|
Column(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.handshake) + ": $handshake", style = MaterialTheme.typography.bodySmall)
|
||||||
|
Text("rx: $peerRxMB MB", style = MaterialTheme.typography.bodySmall)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-8
@@ -21,6 +21,7 @@ import androidx.compose.material.icons.Icons
|
|||||||
import androidx.compose.material.icons.filled.Close
|
import androidx.compose.material.icons.filled.Close
|
||||||
import androidx.compose.material.icons.filled.Edit
|
import androidx.compose.material.icons.filled.Edit
|
||||||
import androidx.compose.material.icons.outlined.Add
|
import androidx.compose.material.icons.outlined.Add
|
||||||
|
import androidx.compose.material.icons.outlined.Edit
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@@ -47,13 +48,13 @@ import androidx.compose.ui.text.input.KeyboardCapitalization
|
|||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.navigation.NavController
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.ClickableIconButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.ClickableIconButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationToggle
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationToggle
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.SubmitConfigurationTextBox
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.SubmitConfigurationTextBox
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ScrollDismissFab
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ScrollDismissFab
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.WildcardSupportingLabel
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.WildcardSupportingLabel
|
||||||
@@ -66,15 +67,10 @@ import kotlinx.coroutines.delay
|
|||||||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
||||||
@OptIn(ExperimentalLayoutApi::class)
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun OptionsScreen(
|
fun OptionsScreen(optionsViewModel: OptionsViewModel = hiltViewModel(), focusRequester: FocusRequester, appUiState: AppUiState, tunnelId: Int) {
|
||||||
optionsViewModel: OptionsViewModel = hiltViewModel(),
|
|
||||||
navController: NavController,
|
|
||||||
focusRequester: FocusRequester,
|
|
||||||
appUiState: AppUiState,
|
|
||||||
tunnelId: Int,
|
|
||||||
) {
|
|
||||||
val scrollState = rememberScrollState()
|
val scrollState = rememberScrollState()
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
val navController = LocalNavController.current
|
||||||
val config = appUiState.tunnels.first { it.id == tunnelId }
|
val config = appUiState.tunnels.first { it.id == tunnelId }
|
||||||
|
|
||||||
val interactionSource = remember { MutableInteractionSource() }
|
val interactionSource = remember { MutableInteractionSource() }
|
||||||
|
|||||||
+6
-4
@@ -5,23 +5,24 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.navigation.NavController
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.ui.AppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||||
import xyz.teamgravity.pin_lock_compose.PinLock
|
import xyz.teamgravity.pin_lock_compose.PinLock
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PinLockScreen(navController: NavController, appViewModel: AppViewModel) {
|
fun PinLockScreen(appViewModel: AppViewModel) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
val navController = LocalNavController.current
|
||||||
val snackbar = SnackbarController.current
|
val snackbar = SnackbarController.current
|
||||||
PinLock(
|
PinLock(
|
||||||
title = { pinExists ->
|
title = { pinExists ->
|
||||||
Text(
|
Text(
|
||||||
color = MaterialTheme.colorScheme.onSecondary,
|
color = MaterialTheme.colorScheme.onSurface,
|
||||||
text =
|
text =
|
||||||
if (pinExists) {
|
if (pinExists) {
|
||||||
stringResource(id = R.string.enter_pin)
|
stringResource(id = R.string.enter_pin)
|
||||||
@@ -32,7 +33,8 @@ fun PinLockScreen(navController: NavController, appViewModel: AppViewModel) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
color = MaterialTheme.colorScheme.secondary,
|
backgroundColor = MaterialTheme.colorScheme.surface,
|
||||||
|
textColor = MaterialTheme.colorScheme.onSurface,
|
||||||
onPinCorrect = {
|
onPinCorrect = {
|
||||||
// pin is correct, navigate or hide pin lock
|
// pin is correct, navigate or hide pin lock
|
||||||
if (context.isRunningOnTv()) {
|
if (context.isRunningOnTv()) {
|
||||||
|
|||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.screens.scanner
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.viewinterop.AndroidView
|
||||||
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
|
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||||
|
import com.journeyapps.barcodescanner.CompoundBarcodeView
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||||
|
|
||||||
|
@OptIn(ExperimentalPermissionsApi::class)
|
||||||
|
@Composable
|
||||||
|
fun ScannerScreen(viewModel: ScannerViewModel = hiltViewModel()) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val navController = LocalNavController.current
|
||||||
|
|
||||||
|
val success = viewModel.success.collectAsStateWithLifecycle(null)
|
||||||
|
|
||||||
|
LaunchedEffect(success.value) {
|
||||||
|
if (success.value != null) navController.popBackStack()
|
||||||
|
}
|
||||||
|
|
||||||
|
val barcodeView = remember {
|
||||||
|
CompoundBarcodeView(context).apply {
|
||||||
|
this.initializeFromIntent((context as Activity).intent)
|
||||||
|
this.setStatusText("")
|
||||||
|
this.decodeSingle { result ->
|
||||||
|
result.text?.let { barCodeOrQr ->
|
||||||
|
viewModel.onTunnelQrResult(barCodeOrQr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AndroidView(factory = { barcodeView })
|
||||||
|
DisposableEffect(Unit) {
|
||||||
|
barcodeView.resume()
|
||||||
|
onDispose {
|
||||||
|
barcodeView.pause()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+69
@@ -0,0 +1,69 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.screens.scanner
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.toWgQuickString
|
||||||
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
import kotlinx.coroutines.flow.asSharedFlow
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import timber.log.Timber
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@HiltViewModel
|
||||||
|
class ScannerViewModel @Inject
|
||||||
|
constructor(
|
||||||
|
private val appDataRepository: AppDataRepository,
|
||||||
|
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||||
|
) : ViewModel() {
|
||||||
|
|
||||||
|
private val _success = MutableSharedFlow<Boolean>()
|
||||||
|
val success = _success.asSharedFlow()
|
||||||
|
|
||||||
|
private suspend fun makeTunnelNameUnique(name: String): String {
|
||||||
|
return withContext(ioDispatcher) {
|
||||||
|
val tunnels = appDataRepository.tunnels.getAll()
|
||||||
|
var tunnelName = name
|
||||||
|
var num = 1
|
||||||
|
while (tunnels.any { it.name == tunnelName }) {
|
||||||
|
tunnelName = "$name($num)"
|
||||||
|
num++
|
||||||
|
}
|
||||||
|
tunnelName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onTunnelQrResult(result: String) = viewModelScope.launch(ioDispatcher) {
|
||||||
|
kotlin.runCatching {
|
||||||
|
val amConfig = TunnelConfig.configFromAmQuick(result)
|
||||||
|
val amQuick = amConfig.toAwgQuickString(true)
|
||||||
|
val wgQuick = amConfig.toWgQuickString()
|
||||||
|
val tunnelName = makeTunnelNameUnique(generateQrCodeDefaultName(result))
|
||||||
|
val tunnelConfig = TunnelConfig(name = tunnelName, wgQuick = wgQuick, amQuick = amQuick)
|
||||||
|
appDataRepository.tunnels.save(tunnelConfig)
|
||||||
|
_success.emit(true)
|
||||||
|
}.onFailure {
|
||||||
|
_success.emit(false)
|
||||||
|
Timber.e(it)
|
||||||
|
SnackbarController.showMessage(StringValue.StringResource(R.string.error_invalid_code))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun generateQrCodeDefaultName(config: String): String {
|
||||||
|
return try {
|
||||||
|
TunnelConfig.configFromAmQuick(config).peers[0].endpoint.get().host
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Timber.e(e)
|
||||||
|
NumberUtils.generateRandomTunnelName()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
-30
@@ -1,7 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.settings
|
package com.zaneschepke.wireguardautotunnel.ui.screens.settings
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.app.Activity
|
|
||||||
import android.content.Context.POWER_SERVICE
|
import android.content.Context.POWER_SERVICE
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
@@ -60,7 +59,6 @@ import androidx.compose.ui.text.input.KeyboardCapitalization
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.navigation.NavController
|
|
||||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||||
import com.google.accompanist.permissions.isGranted
|
import com.google.accompanist.permissions.isGranted
|
||||||
import com.google.accompanist.permissions.rememberPermissionState
|
import com.google.accompanist.permissions.rememberPermissionState
|
||||||
@@ -72,6 +70,7 @@ import com.zaneschepke.wireguardautotunnel.ui.AppViewModel
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.ClickableIconButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.ClickableIconButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationToggle
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationToggle
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt
|
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
||||||
@@ -91,21 +90,17 @@ import xyz.teamgravity.pin_lock_compose.PinManager
|
|||||||
ExperimentalLayoutApi::class,
|
ExperimentalLayoutApi::class,
|
||||||
)
|
)
|
||||||
@Composable
|
@Composable
|
||||||
fun SettingsScreen(
|
fun SettingsScreen(viewModel: SettingsViewModel = hiltViewModel(), appViewModel: AppViewModel, uiState: AppUiState, focusRequester: FocusRequester) {
|
||||||
viewModel: SettingsViewModel = hiltViewModel(),
|
|
||||||
appViewModel: AppViewModel,
|
|
||||||
uiState: AppUiState,
|
|
||||||
navController: NavController,
|
|
||||||
focusRequester: FocusRequester,
|
|
||||||
) {
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
val navController = LocalNavController.current
|
||||||
val focusManager = LocalFocusManager.current
|
val focusManager = LocalFocusManager.current
|
||||||
val snackbar = SnackbarController.current
|
val snackbar = SnackbarController.current
|
||||||
|
|
||||||
val scrollState = rememberScrollState()
|
val scrollState = rememberScrollState()
|
||||||
val interactionSource = remember { MutableInteractionSource() }
|
val interactionSource = remember { MutableInteractionSource() }
|
||||||
val isRunningOnTv = context.isRunningOnTv()
|
val isRunningOnTv = context.isRunningOnTv()
|
||||||
|
|
||||||
val kernelSupport by viewModel.kernelSupport.collectAsStateWithLifecycle()
|
val settingsUiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
val fineLocationState = rememberPermissionState(Manifest.permission.ACCESS_FINE_LOCATION)
|
val fineLocationState = rememberPermissionState(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||||
var currentText by remember { mutableStateOf("") }
|
var currentText by remember { mutableStateOf("") }
|
||||||
@@ -119,10 +114,6 @@ fun SettingsScreen(
|
|||||||
val screenPadding = 5.dp
|
val screenPadding = 5.dp
|
||||||
val fillMaxWidth = .85f
|
val fillMaxWidth = .85f
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
viewModel.checkKernelSupport()
|
|
||||||
}
|
|
||||||
|
|
||||||
LaunchedEffect(uiState.settings.trustedNetworkSSIDs) {
|
LaunchedEffect(uiState.settings.trustedNetworkSSIDs) {
|
||||||
currentText = ""
|
currentText = ""
|
||||||
}
|
}
|
||||||
@@ -131,7 +122,7 @@ fun SettingsScreen(
|
|||||||
rememberLauncherForActivityResult(
|
rememberLauncherForActivityResult(
|
||||||
ActivityResultContracts.StartActivityForResult(),
|
ActivityResultContracts.StartActivityForResult(),
|
||||||
) { result: ActivityResult ->
|
) { result: ActivityResult ->
|
||||||
if (result.resultCode == Activity.RESULT_OK) {
|
if (result.resultCode == RESULT_OK) {
|
||||||
result.data
|
result.data
|
||||||
// Handle the Intent
|
// Handle the Intent
|
||||||
}
|
}
|
||||||
@@ -266,6 +257,18 @@ fun SettingsScreen(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onAutoTunnelWifiChecked() {
|
||||||
|
when (false) {
|
||||||
|
isBackgroundLocationGranted -> showLocationDialog = true
|
||||||
|
fineLocationState.status.isGranted -> showLocationDialog = true
|
||||||
|
viewModel.isLocationEnabled(context) ->
|
||||||
|
showLocationServicesAlertDialog = true
|
||||||
|
else -> {
|
||||||
|
viewModel.onToggleTunnelOnWifi()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.Top,
|
verticalArrangement = Arrangement.Top,
|
||||||
@@ -315,18 +318,8 @@ fun SettingsScreen(
|
|||||||
checked = uiState.settings.isTunnelOnWifiEnabled,
|
checked = uiState.settings.isTunnelOnWifiEnabled,
|
||||||
padding = screenPadding,
|
padding = screenPadding,
|
||||||
onCheckChanged = { checked ->
|
onCheckChanged = { checked ->
|
||||||
if (!checked) viewModel.onToggleTunnelOnWifi()
|
if (!checked || settingsUiState.isRooted) viewModel.onToggleTunnelOnWifi().also { return@ConfigurationToggle }
|
||||||
if (checked) {
|
onAutoTunnelWifiChecked()
|
||||||
when (false) {
|
|
||||||
isBackgroundLocationGranted -> showLocationDialog = true
|
|
||||||
fineLocationState.status.isGranted -> showLocationDialog = true
|
|
||||||
viewModel.isLocationEnabled(context) ->
|
|
||||||
showLocationServicesAlertDialog = true
|
|
||||||
else -> {
|
|
||||||
viewModel.onToggleTunnelOnWifi()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
modifier =
|
modifier =
|
||||||
if (uiState.settings.isAutoTunnelEnabled) {
|
if (uiState.settings.isAutoTunnelEnabled) {
|
||||||
@@ -495,7 +488,7 @@ fun SettingsScreen(
|
|||||||
uiState.settings.isAutoTunnelEnabled ||
|
uiState.settings.isAutoTunnelEnabled ||
|
||||||
uiState.settings.isAlwaysOnVpnEnabled ||
|
uiState.settings.isAlwaysOnVpnEnabled ||
|
||||||
(uiState.vpnState.status == TunnelState.UP) ||
|
(uiState.vpnState.status == TunnelState.UP) ||
|
||||||
!kernelSupport
|
!settingsUiState.isKernelAvailable
|
||||||
),
|
),
|
||||||
checked = uiState.settings.isKernelEnabled,
|
checked = uiState.settings.isKernelEnabled,
|
||||||
padding = screenPadding,
|
padding = screenPadding,
|
||||||
@@ -545,9 +538,12 @@ fun SettingsScreen(
|
|||||||
ConfigurationToggle(
|
ConfigurationToggle(
|
||||||
stringResource(R.string.always_on_vpn_support),
|
stringResource(R.string.always_on_vpn_support),
|
||||||
enabled = !(
|
enabled = !(
|
||||||
uiState.settings.isTunnelOnWifiEnabled ||
|
(
|
||||||
uiState.settings.isTunnelOnWifiEnabled ||
|
uiState.settings.isTunnelOnWifiEnabled ||
|
||||||
uiState.settings.isTunnelOnMobileDataEnabled
|
uiState.settings.isTunnelOnEthernetEnabled ||
|
||||||
|
uiState.settings.isTunnelOnMobileDataEnabled
|
||||||
|
) &&
|
||||||
|
uiState.settings.isAutoTunnelEnabled
|
||||||
),
|
),
|
||||||
checked = uiState.settings.isAlwaysOnVpnEnabled,
|
checked = uiState.settings.isAlwaysOnVpnEnabled,
|
||||||
padding = screenPadding,
|
padding = screenPadding,
|
||||||
|
|||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.screens.settings
|
||||||
|
|
||||||
|
data class SettingsUiState(
|
||||||
|
val isRooted: Boolean = false,
|
||||||
|
val isKernelAvailable: Boolean = false,
|
||||||
|
)
|
||||||
+26
-10
@@ -13,13 +13,14 @@ import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
|||||||
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.FileUtils
|
import com.zaneschepke.wireguardautotunnel.util.FileUtils
|
||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.onStart
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -38,8 +39,16 @@ constructor(
|
|||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
private val _kernelSupport = MutableStateFlow(false)
|
private val _uiState = MutableStateFlow(SettingsUiState())
|
||||||
val kernelSupport = _kernelSupport.asStateFlow()
|
val uiState = _uiState.onStart {
|
||||||
|
_uiState.update {
|
||||||
|
it.copy(isKernelAvailable = isKernelSupported(), isRooted = isRooted())
|
||||||
|
}
|
||||||
|
}.stateIn(
|
||||||
|
viewModelScope,
|
||||||
|
SharingStarted.WhileSubscribed(Constants.SUBSCRIPTION_TIMEOUT),
|
||||||
|
SettingsUiState(),
|
||||||
|
)
|
||||||
private val settings = appDataRepository.settings.getSettingsFlow()
|
private val settings = appDataRepository.settings.getSettingsFlow()
|
||||||
.stateIn(viewModelScope, SharingStarted.Eagerly, Settings())
|
.stateIn(viewModelScope, SharingStarted.Eagerly, Settings())
|
||||||
|
|
||||||
@@ -211,13 +220,9 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun checkKernelSupport() = viewModelScope.launch {
|
private suspend fun isKernelSupported(): Boolean {
|
||||||
val kernelSupport =
|
return withContext(ioDispatcher) {
|
||||||
withContext(ioDispatcher) {
|
WgQuickBackend.hasKernelSupport()
|
||||||
WgQuickBackend.hasKernelSupport()
|
|
||||||
}
|
|
||||||
_kernelSupport.update {
|
|
||||||
kernelSupport
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,6 +236,17 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun isRooted(): Boolean {
|
||||||
|
return try {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
rootShell.get().start()
|
||||||
|
}
|
||||||
|
true
|
||||||
|
} catch (_: Exception) {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun requestRoot(): Result<Unit> {
|
private suspend fun requestRoot(): Result<Unit> {
|
||||||
return withContext(ioDispatcher) {
|
return withContext(ioDispatcher) {
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
|
|||||||
+3
-2
@@ -42,18 +42,19 @@ import androidx.compose.ui.text.style.TextAlign
|
|||||||
import androidx.compose.ui.text.style.TextDecoration
|
import androidx.compose.ui.text.style.TextDecoration
|
||||||
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 androidx.navigation.NavController
|
|
||||||
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.launchSupportEmail
|
import com.zaneschepke.wireguardautotunnel.util.extensions.launchSupportEmail
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SupportScreen(navController: NavController, focusRequester: FocusRequester, appUiState: AppUiState) {
|
fun SupportScreen(focusRequester: FocusRequester, appUiState: AppUiState) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
val navController = LocalNavController.current
|
||||||
val fillMaxWidth = .85f
|
val fillMaxWidth = .85f
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
|
|||||||
+37
-19
@@ -1,7 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.support.logs
|
package com.zaneschepke.wireguardautotunnel.ui.screens.support.logs
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
@@ -13,7 +12,7 @@ import androidx.compose.foundation.lazy.itemsIndexed
|
|||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Save
|
import androidx.compose.material.icons.filled.Share
|
||||||
import androidx.compose.material3.FloatingActionButton
|
import androidx.compose.material3.FloatingActionButton
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@@ -21,8 +20,12 @@ import androidx.compose.material3.Scaffold
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
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.mutableIntStateOf
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.runtime.snapshotFlow
|
||||||
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
|
||||||
@@ -35,9 +38,7 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import com.zaneschepke.logcatter.model.LogMessage
|
import com.zaneschepke.logcatter.model.LogMessage
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.text.LogTypeLabel
|
import com.zaneschepke.wireguardautotunnel.ui.common.text.LogTypeLabel
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
||||||
@Composable
|
@Composable
|
||||||
@@ -45,35 +46,52 @@ fun LogsScreen(viewModel: LogsViewModel = hiltViewModel()) {
|
|||||||
val logs = viewModel.logs
|
val logs = viewModel.logs
|
||||||
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
||||||
|
|
||||||
val lazyColumnListState = rememberLazyListState()
|
val lazyColumnListState = rememberLazyListState()
|
||||||
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
var isAutoScrolling by remember { mutableStateOf(true) }
|
||||||
val scope = rememberCoroutineScope()
|
var lastScrollPosition by remember { mutableIntStateOf(0) }
|
||||||
|
|
||||||
LaunchedEffect(logs.size) {
|
LaunchedEffect(isAutoScrolling) {
|
||||||
scope.launch {
|
if (isAutoScrolling) {
|
||||||
lazyColumnListState.animateScrollToItem(logs.size)
|
lazyColumnListState.animateScrollToItem(logs.size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(logs.size) {
|
||||||
|
if (isAutoScrolling) {
|
||||||
|
lazyColumnListState.animateScrollToItem(logs.size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(lazyColumnListState) {
|
||||||
|
snapshotFlow { lazyColumnListState.firstVisibleItemIndex }
|
||||||
|
.collect { currentScrollPosition ->
|
||||||
|
if (currentScrollPosition < lastScrollPosition && isAutoScrolling) {
|
||||||
|
isAutoScrolling = false
|
||||||
|
}
|
||||||
|
val visible = lazyColumnListState.layoutInfo.visibleItemsInfo
|
||||||
|
if (visible.isNotEmpty()) {
|
||||||
|
if (visible.last().index
|
||||||
|
== lazyColumnListState.layoutInfo.totalItemsCount - 1 && !isAutoScrolling
|
||||||
|
) {
|
||||||
|
isAutoScrolling = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastScrollPosition = currentScrollPosition
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
scope.launch {
|
viewModel.shareLogs(context)
|
||||||
viewModel.saveLogsToFile().onSuccess {
|
|
||||||
Toast.makeText(
|
|
||||||
context,
|
|
||||||
context.getString(R.string.logs_saved),
|
|
||||||
Toast.LENGTH_SHORT,
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
shape = RoundedCornerShape(16.dp),
|
shape = RoundedCornerShape(16.dp),
|
||||||
containerColor = MaterialTheme.colorScheme.primary,
|
containerColor = MaterialTheme.colorScheme.primary,
|
||||||
) {
|
) {
|
||||||
val icon = Icons.Filled.Save
|
val icon = Icons.Filled.Share
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = icon,
|
imageVector = icon,
|
||||||
contentDescription = icon.name,
|
contentDescription = icon.name,
|
||||||
|
|||||||
+23
-12
@@ -1,19 +1,25 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.support.logs
|
package com.zaneschepke.wireguardautotunnel.ui.screens.support.logs
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import androidx.compose.runtime.mutableStateListOf
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
|
import androidx.core.content.FileProvider
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.zaneschepke.logcatter.LocalLogCollector
|
import com.zaneschepke.logcatter.LogReader
|
||||||
import com.zaneschepke.logcatter.model.LogMessage
|
import com.zaneschepke.logcatter.model.LogMessage
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.module.MainDispatcher
|
import com.zaneschepke.wireguardautotunnel.module.MainDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.FileUtils
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.chunked
|
import com.zaneschepke.wireguardautotunnel.util.extensions.chunked
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.launchShareFile
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import timber.log.Timber
|
||||||
|
import java.io.File
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -22,8 +28,7 @@ import javax.inject.Inject
|
|||||||
class LogsViewModel
|
class LogsViewModel
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val localLogCollector: LocalLogCollector,
|
private val localLogCollector: LogReader,
|
||||||
private val fileUtils: FileUtils,
|
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||||
@MainDispatcher private val mainDispatcher: CoroutineDispatcher,
|
@MainDispatcher private val mainDispatcher: CoroutineDispatcher,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
@@ -44,13 +49,19 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun saveLogsToFile(): Result<Unit> {
|
fun shareLogs(context: Context): Job = viewModelScope.launch(ioDispatcher) {
|
||||||
val file =
|
runCatching {
|
||||||
localLogCollector.getLogFile().getOrElse {
|
val sharePath = File(context.filesDir, "external_files")
|
||||||
return Result.failure(it)
|
if (sharePath.exists()) sharePath.delete()
|
||||||
}
|
sharePath.mkdir()
|
||||||
val fileContent = fileUtils.readBytesFromFile(file)
|
val file = File("${sharePath.path + "/" + Constants.BASE_LOG_FILE_NAME}-${Instant.now().epochSecond}.zip")
|
||||||
val fileName = "${Constants.BASE_LOG_FILE_NAME}-${Instant.now().epochSecond}.txt"
|
if (file.exists()) file.delete()
|
||||||
return fileUtils.saveByteArrayToDownloads(fileContent, fileName)
|
file.createNewFile()
|
||||||
|
localLogCollector.zipLogFiles(file.absolutePath)
|
||||||
|
val uri = FileProvider.getUriForFile(context, context.getString(R.string.provider), file)
|
||||||
|
context.launchShareFile(uri)
|
||||||
|
}.onFailure {
|
||||||
|
Timber.e(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,37 @@ package com.zaneschepke.wireguardautotunnel.ui.theme
|
|||||||
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
|
||||||
val Purple80 = Color(0xFFD0BCFF)
|
val OffWhite = Color(0xFFE5E1E5)
|
||||||
val PurpleGrey80 = Color(0xFFCCC2DC)
|
val LightGrey = Color(0xFF8D9D9F)
|
||||||
val Pink80 = Color(0xFF492532)
|
val Aqua = Color(0xFF76BEBD)
|
||||||
val virdigris = Color(0xFF5BC0BE)
|
val SilverTree = Color(0xFF6DB58B)
|
||||||
|
val Plantation = Color(0xFF264A49)
|
||||||
|
val Shark = Color(0xFF21272A)
|
||||||
|
val BalticSea = Color(0xFF1C1B1F)
|
||||||
|
val Brick = Color(0xFFCE4257)
|
||||||
|
val Corn = Color(0xFFFBEC5D)
|
||||||
|
|
||||||
val Purple40 = Color(0xFF6650a4)
|
sealed class ThemeColors(
|
||||||
val PurpleGrey40 = Color(0xFF625b71)
|
val background: Color,
|
||||||
val Pink40 = Color(0xFFFFFFFF)
|
val surface: Color,
|
||||||
|
val primary: Color,
|
||||||
|
val secondary: Color,
|
||||||
|
val onSurface: Color,
|
||||||
|
) {
|
||||||
|
// TODO fix light theme colors
|
||||||
|
data object Light : ThemeColors(
|
||||||
|
background = LightGrey,
|
||||||
|
surface = OffWhite,
|
||||||
|
primary = Plantation,
|
||||||
|
secondary = OffWhite,
|
||||||
|
onSurface = BalticSea,
|
||||||
|
)
|
||||||
|
|
||||||
// status colors
|
data object Dark : ThemeColors(
|
||||||
val brickRed = Color(0xFFCE4257)
|
background = BalticSea,
|
||||||
val corn = Color(0xFFFBEC5D)
|
surface = Shark,
|
||||||
val pinkRed = Color(0xFFEF476F)
|
primary = Aqua,
|
||||||
val mint = Color(0xFF52B788)
|
secondary = Plantation,
|
||||||
|
onSurface = OffWhite,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,30 +18,22 @@ import androidx.core.view.WindowCompat
|
|||||||
|
|
||||||
private val DarkColorScheme =
|
private val DarkColorScheme =
|
||||||
darkColorScheme(
|
darkColorScheme(
|
||||||
// primary = Purple80,
|
primary = ThemeColors.Dark.primary,
|
||||||
primary = virdigris,
|
surface = ThemeColors.Dark.surface,
|
||||||
secondary = PurpleGrey40,
|
background = ThemeColors.Dark.background,
|
||||||
// secondary = PurpleGrey80,
|
secondaryContainer = ThemeColors.Dark.secondary,
|
||||||
tertiary = Pink40,
|
onSurface = ThemeColors.Dark.onSurface,
|
||||||
surfaceTint = Pink80,
|
onSecondaryContainer = ThemeColors.Dark.primary,
|
||||||
// tertiary = Pink80
|
|
||||||
)
|
)
|
||||||
|
|
||||||
private val LightColorScheme =
|
private val LightColorScheme =
|
||||||
lightColorScheme(
|
lightColorScheme(
|
||||||
primary = Purple40,
|
primary = ThemeColors.Light.primary,
|
||||||
secondary = PurpleGrey40,
|
surface = ThemeColors.Light.surface,
|
||||||
tertiary = Pink40,
|
background = ThemeColors.Light.background,
|
||||||
surfaceTint = Pink80,
|
secondaryContainer = ThemeColors.Light.secondary,
|
||||||
/* Other default colors to override
|
onSurface = ThemeColors.Light.onSurface,
|
||||||
background = Color(0xFFFFFBFE),
|
onSecondaryContainer = ThemeColors.Light.primary,
|
||||||
surface = Color(0xFFFFFBFE),
|
|
||||||
onPrimary = Color.White,
|
|
||||||
onSecondary = Color.White,
|
|
||||||
onTertiary = Color.White,
|
|
||||||
onBackground = Color(0xFF1C1B1F),
|
|
||||||
onSurface = Color(0xFF1C1B1F),
|
|
||||||
*/
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -60,7 +52,8 @@ fun WireguardAutoTunnelTheme(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
useDarkTheme -> DarkColorScheme
|
useDarkTheme -> DarkColorScheme
|
||||||
else -> LightColorScheme
|
// TODO force dark theme for now until light theme designed
|
||||||
|
else -> DarkColorScheme
|
||||||
}
|
}
|
||||||
val view = LocalView.current
|
val view = LocalView.current
|
||||||
if (!view.isInEditMode) {
|
if (!view.isInEditMode) {
|
||||||
|
|||||||
@@ -2,35 +2,58 @@ package com.zaneschepke.wireguardautotunnel.ui.theme
|
|||||||
|
|
||||||
import androidx.compose.material3.Typography
|
import androidx.compose.material3.Typography
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
|
import androidx.compose.ui.text.font.Font
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
|
||||||
// Set of Material typography styles to start with
|
// Set of Material typography styles to start with
|
||||||
|
|
||||||
|
val inter = FontFamily(
|
||||||
|
Font(R.font.inter),
|
||||||
|
)
|
||||||
|
|
||||||
val Typography =
|
val Typography =
|
||||||
Typography(
|
Typography(
|
||||||
bodyLarge =
|
bodyLarge =
|
||||||
TextStyle(
|
TextStyle(
|
||||||
fontFamily = FontFamily.Default,
|
fontFamily = inter,
|
||||||
fontWeight = FontWeight.Normal,
|
fontWeight = FontWeight.Normal,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
lineHeight = 24.sp,
|
lineHeight = 24.sp,
|
||||||
letterSpacing = 0.5.sp,
|
letterSpacing = 0.5.sp,
|
||||||
),
|
),
|
||||||
/* Other default text styles to override
|
bodySmall = TextStyle(
|
||||||
titleLarge = TextStyle(
|
fontFamily = inter,
|
||||||
fontFamily = FontFamily.Default,
|
fontWeight = FontWeight.Normal,
|
||||||
fontWeight = FontWeight.Normal,
|
fontSize = 13.sp,
|
||||||
fontSize = 22.sp,
|
lineHeight = 20.sp,
|
||||||
lineHeight = 28.sp,
|
letterSpacing = 1.sp,
|
||||||
letterSpacing = 0.sp
|
color = LightGrey,
|
||||||
),
|
),
|
||||||
labelSmall = TextStyle(
|
labelLarge = TextStyle(
|
||||||
fontFamily = FontFamily.Default,
|
fontFamily = inter,
|
||||||
fontWeight = FontWeight.Medium,
|
fontWeight = FontWeight.Normal,
|
||||||
fontSize = 11.sp,
|
fontSize = 15.sp,
|
||||||
lineHeight = 16.sp,
|
lineHeight = 18.sp,
|
||||||
letterSpacing = 0.5.sp
|
letterSpacing = 0.sp,
|
||||||
)
|
),
|
||||||
*/
|
labelMedium = TextStyle(
|
||||||
|
fontFamily = inter,
|
||||||
|
fontWeight = FontWeight.SemiBold,
|
||||||
|
fontSize = 12.sp,
|
||||||
|
lineHeight = 16.sp,
|
||||||
|
letterSpacing = 0.5.sp,
|
||||||
|
),
|
||||||
|
titleMedium = TextStyle(
|
||||||
|
fontFamily = inter,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
fontSize = 17.sp,
|
||||||
|
lineHeight = 21.sp,
|
||||||
|
letterSpacing = 0.sp,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val iconSize = 15.dp
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ object Constants {
|
|||||||
const val CONF_FILE_EXTENSION = ".conf"
|
const val CONF_FILE_EXTENSION = ".conf"
|
||||||
const val ZIP_FILE_EXTENSION = ".zip"
|
const val ZIP_FILE_EXTENSION = ".zip"
|
||||||
const val URI_CONTENT_SCHEME = "content"
|
const val URI_CONTENT_SCHEME = "content"
|
||||||
const val ALLOWED_FILE_TYPES = "*/*"
|
|
||||||
const val TEXT_MIME_TYPE = "text/plain"
|
const val TEXT_MIME_TYPE = "text/plain"
|
||||||
const val ZIP_FILE_MIME_TYPE = "application/zip"
|
const val ZIP_FILE_MIME_TYPE = "application/zip"
|
||||||
|
const val ALLOWED_TV_FILE_TYPES = "${TEXT_MIME_TYPE}|${ZIP_FILE_MIME_TYPE}"
|
||||||
|
const val ALL_FILE_TYPES = "*/*"
|
||||||
const val GOOGLE_TV_EXPLORER_STUB = "com.google.android.tv.frameworkpackagestubs"
|
const val GOOGLE_TV_EXPLORER_STUB = "com.google.android.tv.frameworkpackagestubs"
|
||||||
const val ANDROID_TV_EXPLORER_STUB = "com.android.tv.frameworkpackagestubs"
|
const val ANDROID_TV_EXPLORER_STUB = "com.android.tv.frameworkpackagestubs"
|
||||||
const val VPN_SETTINGS_PACKAGE = "android.net.vpn.SETTINGS"
|
const val VPN_SETTINGS_PACKAGE = "android.net.vpn.SETTINGS"
|
||||||
const val EMAIL_MIME_TYPE = "plain/text"
|
|
||||||
const val SYSTEM_EXEMPT_SERVICE_TYPE_ID = 1024
|
const val SYSTEM_EXEMPT_SERVICE_TYPE_ID = 1024
|
||||||
|
|
||||||
const val SUBSCRIPTION_TIMEOUT = 5_000L
|
const val SUBSCRIPTION_TIMEOUT = 5_000L
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import kotlinx.coroutines.CoroutineDispatcher
|
|||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
@@ -23,23 +21,6 @@ class FileUtils(
|
|||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val ioDispatcher: CoroutineDispatcher,
|
private val ioDispatcher: CoroutineDispatcher,
|
||||||
) {
|
) {
|
||||||
suspend fun readBytesFromFile(file: File): ByteArray {
|
|
||||||
return withContext(ioDispatcher) {
|
|
||||||
FileInputStream(file).use {
|
|
||||||
it.readBytes()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun readTextFromFileName(fileName: String): String {
|
|
||||||
return withContext(ioDispatcher) {
|
|
||||||
context.assets.open(fileName).use { stream ->
|
|
||||||
stream.bufferedReader(Charsets.UTF_8).use {
|
|
||||||
it.readText()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createWgFiles(tunnels: TunnelConfigs): List<File> {
|
fun createWgFiles(tunnels: TunnelConfigs): List<File> {
|
||||||
return tunnels.map { config ->
|
return tunnels.map { config ->
|
||||||
@@ -61,43 +42,6 @@ class FileUtils(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun saveByteArrayToDownloads(content: ByteArray, fileName: String): Result<Unit> {
|
|
||||||
return withContext(ioDispatcher) {
|
|
||||||
try {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
val contentValues =
|
|
||||||
ContentValues().apply {
|
|
||||||
put(MediaColumns.DISPLAY_NAME, fileName)
|
|
||||||
put(MediaColumns.MIME_TYPE, Constants.TEXT_MIME_TYPE)
|
|
||||||
put(MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS)
|
|
||||||
}
|
|
||||||
val resolver = context.contentResolver
|
|
||||||
val uri =
|
|
||||||
resolver.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues)
|
|
||||||
if (uri != null) {
|
|
||||||
resolver.openOutputStream(uri).use { output ->
|
|
||||||
output?.write(content)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val target =
|
|
||||||
File(
|
|
||||||
Environment.getExternalStoragePublicDirectory(
|
|
||||||
Environment.DIRECTORY_DOWNLOADS,
|
|
||||||
),
|
|
||||||
fileName,
|
|
||||||
)
|
|
||||||
FileOutputStream(target).use { output ->
|
|
||||||
output.write(content)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Result.success(Unit)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Result.failure(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun saveFilesToZip(files: List<File>): Result<Unit> {
|
suspend fun saveFilesToZip(files: List<File>): Result<Unit> {
|
||||||
return withContext(ioDispatcher) {
|
return withContext(ioDispatcher) {
|
||||||
try {
|
try {
|
||||||
@@ -124,7 +68,7 @@ class FileUtils(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO issue with android 9
|
// TODO issue with android 9
|
||||||
private fun createDownloadsFileOutputStream(fileName: String, mimeType: String = Constants.ALLOWED_FILE_TYPES): OutputStream? {
|
private fun createDownloadsFileOutputStream(fileName: String, mimeType: String = Constants.ALL_FILE_TYPES): OutputStream? {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
val resolver = context.contentResolver
|
val resolver = context.contentResolver
|
||||||
val contentValues =
|
val contentValues =
|
||||||
|
|||||||
+20
-10
@@ -26,6 +26,16 @@ fun Context.openWebUrl(url: String): Result<Unit> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.launchShareFile(file: Uri) {
|
||||||
|
val shareIntent = Intent().apply {
|
||||||
|
setAction(Intent.ACTION_SEND)
|
||||||
|
setType("*/*")
|
||||||
|
putExtra(Intent.EXTRA_STREAM, file)
|
||||||
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
}
|
||||||
|
this.startActivity(Intent.createChooser(shareIntent, ""))
|
||||||
|
}
|
||||||
|
|
||||||
fun Context.showToast(resId: Int) {
|
fun Context.showToast(resId: Int) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
this,
|
this,
|
||||||
@@ -34,21 +44,21 @@ fun Context.showToast(resId: Int) {
|
|||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.launchSupportEmail(): Result<Unit> {
|
fun Context.launchSupportEmail() {
|
||||||
return runCatching {
|
val intent =
|
||||||
val intent =
|
Intent(Intent.ACTION_SENDTO).apply {
|
||||||
Intent(Intent.ACTION_SENDTO).apply {
|
data = Uri.parse("mailto:")
|
||||||
type = Constants.EMAIL_MIME_TYPE
|
putExtra(Intent.EXTRA_EMAIL, arrayOf(getString(R.string.my_email)))
|
||||||
putExtra(Intent.EXTRA_EMAIL, arrayOf(getString(R.string.my_email)))
|
putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_subject))
|
||||||
putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_subject))
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
}
|
||||||
}
|
if (intent.resolveActivity(packageManager) != null) {
|
||||||
startActivity(
|
startActivity(
|
||||||
Intent.createChooser(intent, getString(R.string.email_chooser)).apply {
|
Intent.createChooser(intent, getString(R.string.email_chooser)).apply {
|
||||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}.onFailure {
|
} else {
|
||||||
showToast(R.string.no_email_detected)
|
showToast(R.string.no_email_detected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
@@ -3,6 +3,8 @@ package com.zaneschepke.wireguardautotunnel.util.extensions
|
|||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
|
val hasNumberInParentheses = """^(.+?)\((\d+)\)$""".toRegex()
|
||||||
|
|
||||||
fun String.isValidIpv4orIpv6Address(): Boolean {
|
fun String.isValidIpv4orIpv6Address(): Boolean {
|
||||||
val ipv4Pattern = Pattern.compile(
|
val ipv4Pattern = Pattern.compile(
|
||||||
"^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\$",
|
"^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\$",
|
||||||
@@ -13,6 +15,18 @@ fun String.isValidIpv4orIpv6Address(): Boolean {
|
|||||||
return ipv4Pattern.matcher(this).matches() || ipv6Pattern.matcher(this).matches()
|
return ipv4Pattern.matcher(this).matches() || ipv6Pattern.matcher(this).matches()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun String.hasNumberInParentheses(): Boolean {
|
||||||
|
return hasNumberInParentheses.matches(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to extract name and number
|
||||||
|
fun String.extractNameAndNumber(): Pair<String, Int>? {
|
||||||
|
val matchResult = hasNumberInParentheses.matchEntire(this)
|
||||||
|
return matchResult?.let {
|
||||||
|
Pair(it.groupValues[1], it.groupValues[2].toInt())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun List<String>.isMatchingToWildcardList(value: String): Boolean {
|
fun List<String>.isMatchingToWildcardList(value: String): Boolean {
|
||||||
val excludeValues = this.filter { it.startsWith("!") }.map { it.removePrefix("!").toRegexWithWildcards() }
|
val excludeValues = this.filter { it.startsWith("!") }.map { it.removePrefix("!").toRegexWithWildcards() }
|
||||||
Timber.d("Excluded values: $excludeValues")
|
Timber.d("Excluded values: $excludeValues")
|
||||||
|
|||||||
+23
@@ -1,8 +1,12 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.util.extensions
|
package com.zaneschepke.wireguardautotunnel.util.extensions
|
||||||
|
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import com.wireguard.android.util.RootShell
|
||||||
import com.wireguard.config.Peer
|
import com.wireguard.config.Peer
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.HandshakeStatus
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.HandshakeStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.TunnelStatistics
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.theme.Corn
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.theme.SilverTree
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||||
import org.amnezia.awg.config.Config
|
import org.amnezia.awg.config.Config
|
||||||
@@ -48,6 +52,19 @@ fun Peer.isReachable(): Boolean {
|
|||||||
return reachable
|
return reachable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun TunnelStatistics?.asColor(): Color {
|
||||||
|
return this?.mapPeerStats()
|
||||||
|
?.map { it.value?.handshakeStatus() }
|
||||||
|
?.let { statuses ->
|
||||||
|
when {
|
||||||
|
statuses.all { it == HandshakeStatus.HEALTHY } -> SilverTree
|
||||||
|
statuses.any { it == HandshakeStatus.STALE } -> Corn
|
||||||
|
statuses.all { it == HandshakeStatus.NOT_STARTED } -> Color.Gray
|
||||||
|
else -> Color.Gray
|
||||||
|
}
|
||||||
|
} ?: Color.Gray
|
||||||
|
}
|
||||||
|
|
||||||
fun Config.toWgQuickString(): String {
|
fun Config.toWgQuickString(): String {
|
||||||
val amQuick = toAwgQuickString(true)
|
val amQuick = toAwgQuickString(true)
|
||||||
val lines = amQuick.lines().toMutableList()
|
val lines = amQuick.lines().toMutableList()
|
||||||
@@ -62,3 +79,9 @@ fun Config.toWgQuickString(): String {
|
|||||||
}
|
}
|
||||||
return lines.joinToString(System.lineSeparator())
|
return lines.joinToString(System.lineSeparator())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun RootShell.getCurrentWifiName(): String? {
|
||||||
|
val response = mutableListOf<String>()
|
||||||
|
this.run(response, "dumpsys wifi | grep -o \"SSID: [^,]*\" | cut -d ' ' -f2- | tr -d '\"'")
|
||||||
|
return response.lastOrNull()
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.util.extensions
|
||||||
|
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
|
|
||||||
|
fun NavController.navigateAndForget(route: Route) {
|
||||||
|
navigate(route) {
|
||||||
|
popUpTo(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources></resources>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources></resources>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources></resources>
|
||||||
@@ -196,4 +196,8 @@
|
|||||||
<string name="wildcard_supported">Learn about supported wildcards.</string>
|
<string name="wildcard_supported">Learn about supported wildcards.</string>
|
||||||
<string name="details">details</string>
|
<string name="details">details</string>
|
||||||
<string name="show_amnezia_properties">Show Amnezia properties</string>
|
<string name="show_amnezia_properties">Show Amnezia properties</string>
|
||||||
|
<string name="never">never</string>
|
||||||
|
<string name="sec">sec</string>
|
||||||
|
<string name="handshake">handshake</string>
|
||||||
|
<string name="logs">Logs</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -5,11 +5,9 @@
|
|||||||
<item name="android:windowBackground">@color/black_background</item>
|
<item name="android:windowBackground">@color/black_background</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="Theme.AppSplashScreen" parent="Theme.SplashScreen">
|
<style name="Theme.App.Start" parent="@style/Theme.SplashScreen">
|
||||||
<!--<item name="windowSplashScreenBackground">@color/white</item>-->
|
<item name="windowSplashScreenBackground">@color/black_background</item>
|
||||||
<!-- icon has to be a circle -->
|
|
||||||
<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item>
|
<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item>
|
||||||
<item name="windowSplashScreenAnimationDuration">500</item>
|
|
||||||
<item name="postSplashScreenTheme">@style/Theme.WireguardAutoTunnel</item>
|
<item name="postSplashScreenTheme">@style/Theme.WireguardAutoTunnel</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<paths>
|
||||||
|
<files-path
|
||||||
|
name="share"
|
||||||
|
path="external_files/"/>
|
||||||
|
</paths>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
object Constants {
|
object Constants {
|
||||||
const val VERSION_NAME = "3.5.2"
|
const val VERSION_NAME = "3.5.4"
|
||||||
const val JVM_TARGET = "17"
|
const val JVM_TARGET = "17"
|
||||||
const val VERSION_CODE = 35200
|
const val VERSION_CODE = 35400
|
||||||
const val TARGET_SDK = 34
|
const val TARGET_SDK = 34
|
||||||
const val MIN_SDK = 26
|
const val MIN_SDK = 26
|
||||||
const val APP_ID = "com.zaneschepke.wireguardautotunnel"
|
const val APP_ID = "com.zaneschepke.wireguardautotunnel"
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
Was ist Neu:
|
||||||
|
- Abstürze behoben
|
||||||
|
- Leistung der Kacheln verbessert
|
||||||
|
- Reaktivieren von PIN-Sperren
|
||||||
|
- "Beim Hochfahren starten" zur Einstellung gemacht
|
||||||
|
- verschiedene Leistungsanpassungen und Bugs behoben
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Was ist neu:
|
||||||
|
- Verbesserungen der Tunnelsteuerung in der AndroidTV Benutzeroberfläche
|
||||||
|
- Fehler beim Sperren im Portrait-Modus behoben
|
||||||
|
- Fehler welcher eine Umgehung der PIN-Sperre ermöglichte behoben
|
||||||
|
- Fehler in der Auot-Tunnel Kachel behoben
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
Was ist neu?
|
||||||
|
- Verbesserte Zuverlässigkeit des automatischen Tunnels
|
||||||
|
- Unterstützung für hell/dunkel/dynamisches Theming hinzugefügt
|
||||||
|
- Unterstützung für Pre-/Post-Up-/Down-Skripte hinzugefügt
|
||||||
|
- Entfernen der Benachrichtigung über das Fortbestehen des Tunnels
|
||||||
|
- Verschiedene andere Korrekturen und Verbesserungen
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Was ist neu?
|
||||||
|
- Behebung von Problemen beim Starten von Tunneln im Hintergrund
|
||||||
|
- Unterstützung für den Neustart von Diensten nach dem Update hinzugefügt
|
||||||
|
- Verbesserungen der UI-Animationsgeschwindigkeit
|
||||||
|
- Andere Optimierungen
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
What's new:
|
What's new:
|
||||||
- Added wildcard support for wifi names
|
- Added wildcard support for wifi names
|
||||||
|
- Live edit of tunnel/auto-tunnel settings while active
|
||||||
- Fix slowness on mobile data
|
- Fix slowness on mobile data
|
||||||
- Various bug fixes and improvements
|
- Various bug fixes and improvements
|
||||||
- UI optimizations
|
- UI optimizations
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
What's new:
|
||||||
|
- Rooted devices now get wifi name without location
|
||||||
|
- Logs screen scroll and sharing improvements
|
||||||
|
- Tunnel import bug fixes for AndroidTV 14
|
||||||
|
- Tunnel statistics UI enhancements
|
||||||
|
- Other bug fixes and improvements
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
What's new:
|
||||||
|
- Fix Android 12 crashing issue
|
||||||
|
- Fix copy tunnel bug
|
||||||
|
- Auto toggle Amnezia props
|
||||||
|
- Hide preshared key without auth
|
||||||
@@ -1,2 +1,5 @@
|
|||||||
Mejoras:
|
Mejoras:
|
||||||
- Añadida compatiblidad básica de Kernel WireGuard
|
- Añadida compatiblidad básica de Kernel WireGuard
|
||||||
|
- Flujo de divulgación de ubicación mejorada
|
||||||
|
- Corregido el fallo ede los persmisos del túnel automático
|
||||||
|
- Correcciones y mejoras varias
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Novedades:
|
||||||
|
- Corrección de la regresión del túnel de parada
|
||||||
|
- Añadir ofuscación de registros
|
||||||
|
- Añadir ocultar FAB en scroll
|
||||||
|
- Añadir localización turca
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Novedades:
|
||||||
|
- Agregue Amnezia junto con WireGuard
|
||||||
|
- Se corrigió el error de los accesos directos de la aplicación
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
Novedades:
|
||||||
|
- Soporte oficial para AmneziaWG
|
||||||
|
- Importación/exportación de configuraciones de Amnezia
|
||||||
|
- El túnel automático se activará solo una vez por cambio de red
|
||||||
|
- Soporte para idiomas adicionales
|
||||||
|
- Otras correcciones de errores y mejoras
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Novedades:
|
||||||
|
- Mejorar la denominación de las importaciones de túneles
|
||||||
|
- Se solucionó el error del estado inicial de tunelización automática
|
||||||
|
- Manejo de errores mejorado
|
||||||
|
- Se solucionó el error de importación del zip de Amnezia
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Novedades:
|
||||||
|
- Soporte de idiomas adicionales
|
||||||
|
- Corrección de errores en la tunelización automática de datos móviles
|
||||||
|
- Corrección del botón de acción flotante de AndroidTV
|
||||||
|
- Otras optimizaciones y mejoras
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
Novedades:
|
||||||
|
- Se corrigieron problemas con la operación del túnel automático.
|
||||||
|
- Se solucionó el problema con la copia de seguridad de Android.
|
||||||
|
- Mayor número de versiones
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
Novedades:
|
||||||
|
- Solucionar problemas de bloqueo
|
||||||
|
- Mejorar el rendimiento de los mosaicos
|
||||||
|
- Volver a habilitar el bloqueo del PIN
|
||||||
|
- Hacer que reiniciar al arrancar sea una configuración
|
||||||
|
- Varias correcciones de errores y rendimiento
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Novedades:
|
||||||
|
- Correcciones para el control del túnel de la interfaz de usuario de AndroidTV
|
||||||
|
- Corrige el error de bloqueo de retrato.
|
||||||
|
- Corrige el error de omisión del bloqueo del PIN
|
||||||
|
- Corrige el error de mosaico de túnel automático
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
Lo nuevo:
|
||||||
|
- Fiabilidad del túnel automático mejorada
|
||||||
|
- Compatible con tema claro/oscuro/dinámico
|
||||||
|
- Compatible con scripts pre/post up/down
|
||||||
|
- Notificación persistente del túnel quitada
|
||||||
|
- Correcciones y mejoras varias
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Lo nuevo:
|
||||||
|
- Inicio de túneles en segundo plano corregido
|
||||||
|
- Podibilidad de reiniciar los servicios tras una actualización
|
||||||
|
- Mojorada la velocidad de las animaciones del UI
|
||||||
|
- Otras mejoras
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
Características
|
Características
|
||||||
|
|
||||||
- Añade túneles a través de un archivo .conf, zip, entrada manual o código QR
|
- Añade túneles mediante archivo .conf, zip, entrada manual o código QR
|
||||||
- Conexión automática a VPN basada en Wi-Fi SSID, ethernet o datos móviles
|
- Conexión automática a VPN basada en Wi-Fi SSID, ethernet o datos móviles
|
||||||
- Túneles divididos por aplicación con búsqueda
|
- Túneles divididos por aplicación con búsqueda
|
||||||
- Soporte de WireGuard para los modos kernel y espacio de usuario
|
- Soporte de WireGuard para los modos kernel y espacio de usuario
|
||||||
@@ -11,4 +11,4 @@ Características
|
|||||||
- Soporte de accesos directos estáticos para el túnel principal para la integración de automatización.
|
- Soporte de accesos directos estáticos para el túnel principal para la integración de automatización.
|
||||||
- Soporte de automatización de intenciones para todos los túneles
|
- Soporte de automatización de intenciones para todos los túneles
|
||||||
- Reinicio automático del servicio tras reiniciar
|
- Reinicio automático del servicio tras reiniciar
|
||||||
- Medidas de conservación de la batería
|
- Medidas de ahorro de la batería
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
Features
|
||||||
|
|
||||||
|
- Add tunnels via .conf file, zip, manual entry, or QR code
|
||||||
|
- Auto connect to VPN based on Wi-Fi SSID, ethernet, or mobile data
|
||||||
|
- Split tunneling by application with search
|
||||||
|
- WireGuard support for kernel and userspace modes
|
||||||
|
- Amnezia support for userspace mode for DPI/censorship protection
|
||||||
|
- Always-On VPN support
|
||||||
|
- Export Amnezia and WireGuard tunnels to zip
|
||||||
|
- Quick tile support for VPN toggling
|
||||||
|
- Static shortcuts support for primary tunnel for automation integration
|
||||||
|
- Intent automation support for all tunnels
|
||||||
|
- Automatic service restart after reboot
|
||||||
|
- Battery preservation measures
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Een alternatieve VPN client app voor Wireguard met extra functies
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
WG Tunnel
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Usprawnienia:
|
||||||
|
- naprawiono błąd uprawnień na Android 9
|
||||||
|
- Inne optymalizacje
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
Что нового:
|
||||||
|
- Исправлены проблемы со сбоями
|
||||||
|
- Улучшена производительность плиток
|
||||||
|
- Возвращена блокировка PIN-кодом
|
||||||
|
- Добавлена функция перезапуска при загрузке
|
||||||
|
- Различные исправления производительности и ошибок
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Что нового:
|
||||||
|
- Исправления интерфейса управления туннелем на AndroidTV
|
||||||
|
- Исправление ошибки блокировки в портретной ориентации
|
||||||
|
- Исправлена ошибка обхода блокировки PIN-кодом
|
||||||
|
- Исправлена ошибка с плиткой авто-туннеля
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
Что нового:
|
||||||
|
- Повышена надежность авто-туннелирования
|
||||||
|
- Добавлена поддержка светлых/темных/динамических тем
|
||||||
|
- Добавлена поддержка сценариев до/после запуска/остановки интерфейса
|
||||||
|
- Удалено постоянное уведомление о туннеле
|
||||||
|
- Различные другие исправления и улучшения
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Что нового:
|
||||||
|
- Исправлены ошибки, из-за которых туннели не запускались в фоновом режиме
|
||||||
|
- Добавлена поддержка перезапуска служб после обновления
|
||||||
|
- Улучшена скорость анимации интерфейса
|
||||||
|
- Другие оптимизации
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
Возможности
|
Возможности
|
||||||
|
|
||||||
- Добавление туннелей через файлы .conf, .zip, вводом вручную, или через QR-код
|
- Добавление туннелей через файлы .conf, .zip, вводом вручную или через QR-код
|
||||||
- Автоматическое подключение к VPN основываясь на имени сети Wi-Fi, подключению по Ethernet или мобильных данных
|
- Автоматическое подключение к VPN основываясь на имени сети Wi-Fi, подключению по Ethernet или мобильных данных
|
||||||
- Разделение туннелирования по приложениям с поиском
|
- Разделение туннелирования по приложениям с поиском
|
||||||
- Поддержка WireGuard в режимах ядра и пользовательского пространства
|
- Поддержка WireGuard в режимах ядра и пользовательского пространства
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
增强:
|
||||||
|
- 修复 < Android 9 权限问题
|
||||||
|
- 其他优化
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user