feat: ui update with full config edit
feat: Change config screen UI to accommodate editing of all fields. Change config screen to allow the addition of new peers. Closes #31 Change main screen to denote primary tunnel with star. Change main screen tunnel options to allow changing tunnel to primary. feat: Change settings screen UI to improve usability. Closes #32 fix: Change application shortcuts to static shortcuts for the primary tunnel. Remove dynamic shortcuts. Closes #38 fix: Database changes from the previous version causing crashes. #40 #37 fix: bug on detail screen where tunnel name was not showing feat: Change button color when hovering on AndroidTV to improve visibility #36 fix: Change file importing method to fix bug on FireTV Closes #39 docs: update README with new screenshots
|
@ -38,7 +38,7 @@ This is an alternative Android Application for [WireGuard](https://www.wireguard
|
||||||
|
|
||||||
<p float="center">
|
<p float="center">
|
||||||
<img label="Main" style="padding-right:25px" src="asset/main_screen.png" width="200" />
|
<img label="Main" style="padding-right:25px" src="asset/main_screen.png" width="200" />
|
||||||
<img label="Config" style="padding-left:25px" src="./asset/config_screen.png" width="200" />
|
<img label="Config" style="padding-left:25px" src="asset/config_screen.png" width="200" />
|
||||||
<img label="Settings" style="padding-left:25px" src="asset/settings_screen.png" width="200" />
|
<img label="Settings" style="padding-left:25px" src="asset/settings_screen.png" width="200" />
|
||||||
<img label="Support" style="padding-left:25px" src="asset/support_screen.png" width="200" />
|
<img label="Support" style="padding-left:25px" src="asset/support_screen.png" width="200" />
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -14,8 +14,8 @@ android {
|
||||||
applicationId = "com.zaneschepke.wireguardautotunnel"
|
applicationId = "com.zaneschepke.wireguardautotunnel"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 30003
|
versionCode = 31000
|
||||||
versionName = "3.0.3"
|
versionName = "3.1.0"
|
||||||
|
|
||||||
multiDexEnabled = true
|
multiDexEnabled = true
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,8 @@
|
||||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||||
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES"/>
|
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<meta-data android:name="android.app.shortcuts"
|
||||||
|
android:resource="@xml/shortcuts" />
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.CaptureActivityPortrait"
|
android:name=".ui.CaptureActivityPortrait"
|
||||||
|
@ -67,6 +69,8 @@
|
||||||
android:windowSoftInputMode="stateAlwaysHidden" />
|
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||||
<activity
|
<activity
|
||||||
android:finishOnTaskLaunch="true"
|
android:finishOnTaskLaunch="true"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true"
|
||||||
android:theme="@android:style/Theme.NoDisplay"
|
android:theme="@android:style/Theme.NoDisplay"
|
||||||
android:name=".service.shortcut.ShortcutsActivity"/>
|
android:name=".service.shortcut.ShortcutsActivity"/>
|
||||||
<service
|
<service
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.zaneschepke.wireguardautotunnel
|
package com.zaneschepke.wireguardautotunnel
|
||||||
|
|
||||||
object Constants {
|
object Constants {
|
||||||
|
const val MANUAL_TUNNEL_CONFIG_ID = "0"
|
||||||
const val VPN_CONNECTIVITY_CHECK_INTERVAL = 3000L
|
const val VPN_CONNECTIVITY_CHECK_INTERVAL = 3000L
|
||||||
const val VPN_STATISTIC_CHECK_INTERVAL = 10000L
|
const val VPN_STATISTIC_CHECK_INTERVAL = 10000L
|
||||||
const val SNACKBAR_DELAY = 3000L
|
|
||||||
const val TOGGLE_TUNNEL_DELAY = 500L
|
const val TOGGLE_TUNNEL_DELAY = 500L
|
||||||
const val FADE_IN_ANIMATION_DURATION = 1000
|
const val FADE_IN_ANIMATION_DURATION = 1000
|
||||||
const val SLIDE_IN_ANIMATION_DURATION = 500
|
const val SLIDE_IN_ANIMATION_DURATION = 500
|
||||||
|
@ -12,6 +12,5 @@ object Constants {
|
||||||
const val URI_CONTENT_SCHEME = "content"
|
const val URI_CONTENT_SCHEME = "content"
|
||||||
const val URI_PACKAGE_SCHEME = "package"
|
const val URI_PACKAGE_SCHEME = "package"
|
||||||
const val ALLOWED_FILE_TYPES = "*/*"
|
const val ALLOWED_FILE_TYPES = "*/*"
|
||||||
const val FILES_SHOW_ADVANCED = "android.content.extra.SHOW_ADVANCED"
|
|
||||||
const val ANDROID_TV_STUBS = "com.google.android.tv.frameworkpackagestubs"
|
const val ANDROID_TV_STUBS = "com.google.android.tv.frameworkpackagestubs"
|
||||||
}
|
}
|
|
@ -3,17 +3,35 @@ package com.zaneschepke.wireguardautotunnel
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
|
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
||||||
|
import com.zaneschepke.wireguardautotunnel.repository.model.Settings
|
||||||
import dagger.hilt.android.HiltAndroidApp
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltAndroidApp
|
@HiltAndroidApp
|
||||||
class WireGuardAutoTunnel : Application() {
|
class WireGuardAutoTunnel : Application() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var settingsRepo : SettingsDoa
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
if(BuildConfig.DEBUG) {
|
if(BuildConfig.DEBUG) {
|
||||||
Timber.plant(Timber.DebugTree())
|
Timber.plant(Timber.DebugTree())
|
||||||
}
|
}
|
||||||
|
initSettings()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initSettings() {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
if(settingsRepo.getAll().isEmpty()) {
|
||||||
|
settingsRepo.save(Settings())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -19,7 +19,8 @@ class DatabaseModule {
|
||||||
fun provideDatabase(@ApplicationContext context : Context) : AppDatabase {
|
fun provideDatabase(@ApplicationContext context : Context) : AppDatabase {
|
||||||
return Room.databaseBuilder(
|
return Room.databaseBuilder(
|
||||||
context,
|
context,
|
||||||
AppDatabase::class.java, context.getString(R.string.db_name)
|
AppDatabase::class.java, context.getString(R.string.db_name))
|
||||||
).build()
|
.fallbackToDestructiveMigration()
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -27,5 +27,4 @@ class TunnelModule {
|
||||||
fun provideVpnService(backend: Backend) : VpnService {
|
fun provideVpnService(backend: Backend) : VpnService {
|
||||||
return WireGuardTunnel(backend)
|
return WireGuardTunnel(backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -13,4 +13,13 @@ data class Settings(
|
||||||
@ColumnInfo(name = "default_tunnel") var defaultTunnel : String? = null,
|
@ColumnInfo(name = "default_tunnel") var defaultTunnel : String? = null,
|
||||||
@ColumnInfo(name = "is_always_on_vpn_enabled") var isAlwaysOnVpnEnabled : Boolean = false,
|
@ColumnInfo(name = "is_always_on_vpn_enabled") var isAlwaysOnVpnEnabled : Boolean = false,
|
||||||
@ColumnInfo(name = "is_tunnel_on_ethernet_enabled") var isTunnelOnEthernetEnabled : Boolean = false,
|
@ColumnInfo(name = "is_tunnel_on_ethernet_enabled") var isTunnelOnEthernetEnabled : Boolean = false,
|
||||||
)
|
) {
|
||||||
|
fun isTunnelConfigDefault(tunnelConfig: TunnelConfig) : Boolean {
|
||||||
|
return if (defaultTunnel != null) {
|
||||||
|
val defaultConfig = TunnelConfig.from(defaultTunnel!!)
|
||||||
|
(tunnelConfig.id == defaultConfig.id)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,57 +22,7 @@ data class TunnelConfig(
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val INCLUDED_APPLICATIONS = "IncludedApplications = "
|
|
||||||
private const val EXCLUDED_APPLICATIONS = "ExcludedApplications = "
|
|
||||||
private const val INTERFACE = "[Interface]"
|
|
||||||
private const val NEWLINE_CHAR = "\n"
|
|
||||||
private const val APP_CONFIG_SEPARATOR = ", "
|
|
||||||
|
|
||||||
private fun addApplicationsToConfig(appConfig : String, wgQuick : String) : String {
|
|
||||||
val configList = wgQuick.split(NEWLINE_CHAR).toMutableList()
|
|
||||||
val interfaceIndex = configList.indexOf(INTERFACE)
|
|
||||||
configList.add(interfaceIndex + 1, appConfig)
|
|
||||||
return configList.joinToString(NEWLINE_CHAR)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun clearAllApplicationsFromConfig(wgQuick : String) : String {
|
|
||||||
val configList = wgQuick.split(NEWLINE_CHAR).toMutableList()
|
|
||||||
val itr = configList.iterator()
|
|
||||||
while (itr.hasNext()) {
|
|
||||||
val next = itr.next()
|
|
||||||
if(next.contains(INCLUDED_APPLICATIONS) || next.contains(EXCLUDED_APPLICATIONS)) {
|
|
||||||
itr.remove()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return configList.joinToString(NEWLINE_CHAR)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun setExcludedApplicationsOnQuick(packages : List<String>, wgQuick: String) : String {
|
|
||||||
if(packages.isEmpty()) {
|
|
||||||
return wgQuick
|
|
||||||
}
|
|
||||||
val clearedWgQuick = clearAllApplicationsFromConfig(wgQuick)
|
|
||||||
val excludeConfig = buildExcludedApplicationsString(packages)
|
|
||||||
return addApplicationsToConfig(excludeConfig, clearedWgQuick)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setIncludedApplicationsOnQuick(packages : List<String>, wgQuick: String) : String {
|
|
||||||
if(packages.isEmpty()) {
|
|
||||||
return wgQuick
|
|
||||||
}
|
|
||||||
val clearedWgQuick = clearAllApplicationsFromConfig(wgQuick)
|
|
||||||
val includeConfig = buildIncludedApplicationsString(packages)
|
|
||||||
return addApplicationsToConfig(includeConfig, clearedWgQuick)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun buildExcludedApplicationsString(packages : List<String>) : String {
|
|
||||||
return EXCLUDED_APPLICATIONS + packages.joinToString(APP_CONFIG_SEPARATOR)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun buildIncludedApplicationsString(packages : List<String>) : String {
|
|
||||||
return INCLUDED_APPLICATIONS + packages.joinToString(APP_CONFIG_SEPARATOR)
|
|
||||||
}
|
|
||||||
fun from(string : String) : TunnelConfig {
|
fun from(string : String) : TunnelConfig {
|
||||||
return Json.decodeFromString<TunnelConfig>(string)
|
return Json.decodeFromString<TunnelConfig>(string)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,52 +1,76 @@
|
||||||
package com.zaneschepke.wireguardautotunnel.service.shortcut
|
package com.zaneschepke.wireguardautotunnel.service.shortcut
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.activity.ComponentActivity
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
||||||
|
import com.zaneschepke.wireguardautotunnel.repository.TunnelConfigDao
|
||||||
|
import com.zaneschepke.wireguardautotunnel.repository.model.Settings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.Action
|
import com.zaneschepke.wireguardautotunnel.service.foreground.Action
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardTunnelService
|
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardTunnelService
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.WgTunnelException
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ShortcutsActivity : AppCompatActivity() {
|
class ShortcutsActivity : ComponentActivity() {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var settingsRepo : SettingsDoa
|
lateinit var settingsRepo : SettingsDoa
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var tunnelConfigRepo : TunnelConfigDao
|
||||||
|
|
||||||
private val scope = CoroutineScope(Dispatchers.Main);
|
private val scope = CoroutineScope(Dispatchers.Main);
|
||||||
|
|
||||||
private fun attemptWatcherServiceToggle(tunnelConfig : String) {
|
private fun attemptWatcherServiceToggle(tunnelConfig : String) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val settings = settingsRepo.getAll()
|
val settings = getSettings()
|
||||||
if (settings.isNotEmpty()) {
|
if(settings.isAutoTunnelEnabled) {
|
||||||
val setting = settings.first()
|
|
||||||
if(setting.isAutoTunnelEnabled) {
|
|
||||||
ServiceManager.toggleWatcherServiceForeground(this@ShortcutsActivity, tunnelConfig)
|
ServiceManager.toggleWatcherServiceForeground(this@ShortcutsActivity, tunnelConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
if(intent.getStringExtra(ShortcutsManager.CLASS_NAME_EXTRA_KEY)
|
if(intent.getStringExtra(CLASS_NAME_EXTRA_KEY)
|
||||||
.equals(WireGuardTunnelService::class.java.name)) {
|
.equals(WireGuardTunnelService::class.java.simpleName)) {
|
||||||
|
scope.launch {
|
||||||
intent.getStringExtra(getString(R.string.tunnel_extras_key))?.let {
|
try {
|
||||||
attemptWatcherServiceToggle(it)
|
val settings = getSettings()
|
||||||
|
val tunnelConfig = if(settings.defaultTunnel == null) {
|
||||||
|
tunnelConfigRepo.getAll().first()
|
||||||
|
} else {
|
||||||
|
TunnelConfig.from(settings.defaultTunnel!!)
|
||||||
}
|
}
|
||||||
|
attemptWatcherServiceToggle(tunnelConfig.toString())
|
||||||
when(intent.action){
|
when(intent.action){
|
||||||
Action.STOP.name -> ServiceManager.stopVpnService(this)
|
Action.STOP.name -> ServiceManager.stopVpnService(this@ShortcutsActivity)
|
||||||
Action.START.name -> intent.getStringExtra(getString(R.string.tunnel_extras_key))
|
Action.START.name -> ServiceManager.startVpnService(this@ShortcutsActivity, tunnelConfig.toString())
|
||||||
?.let { ServiceManager.startVpnService(this, it) }
|
}
|
||||||
|
} catch (e : Exception) {
|
||||||
|
Timber.e(e.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun getSettings() : Settings {
|
||||||
|
val settings = settingsRepo.getAll()
|
||||||
|
return if (settings.isNotEmpty()) {
|
||||||
|
settings.first()
|
||||||
|
} else {
|
||||||
|
throw WgTunnelException("Settings empty")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
companion object {
|
||||||
|
const val CLASS_NAME_EXTRA_KEY = "className"
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,75 +0,0 @@
|
||||||
package com.zaneschepke.wireguardautotunnel.service.shortcut
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import androidx.core.content.pm.ShortcutInfoCompat
|
|
||||||
import androidx.core.content.pm.ShortcutManagerCompat
|
|
||||||
import androidx.core.graphics.drawable.IconCompat
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.Action
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardTunnelService
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
|
||||||
|
|
||||||
object ShortcutsManager {
|
|
||||||
|
|
||||||
private const val SHORT_LABEL_MAX_SIZE = 10;
|
|
||||||
private const val LONG_LABEL_MAX_SIZE = 25;
|
|
||||||
private const val APPEND_ON = " On";
|
|
||||||
private const val APPEND_OFF = " Off"
|
|
||||||
const val CLASS_NAME_EXTRA_KEY = "className"
|
|
||||||
|
|
||||||
private fun createAndPushShortcut(context : Context, intent : Intent, id : String, shortLabel : String,
|
|
||||||
longLabel : String, drawable : Int ) {
|
|
||||||
val shortcut = ShortcutInfoCompat.Builder(context, id)
|
|
||||||
.setShortLabel(shortLabel)
|
|
||||||
.setLongLabel(longLabel)
|
|
||||||
.setIcon(IconCompat.createWithResource(context, drawable))
|
|
||||||
.setIntent(intent)
|
|
||||||
.build()
|
|
||||||
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createTunnelShortcuts(context : Context, tunnelConfig : TunnelConfig) {
|
|
||||||
createAndPushShortcut(context,
|
|
||||||
createTunnelOnIntent(context, mapOf(context.getString(R.string.tunnel_extras_key) to tunnelConfig.toString())),
|
|
||||||
tunnelConfig.id.toString() + APPEND_ON,
|
|
||||||
tunnelConfig.name.take((SHORT_LABEL_MAX_SIZE - APPEND_ON.length)) + APPEND_ON,
|
|
||||||
tunnelConfig.name.take((LONG_LABEL_MAX_SIZE - APPEND_ON.length)) + APPEND_ON,
|
|
||||||
R.drawable.vpn_on
|
|
||||||
)
|
|
||||||
createAndPushShortcut(context,
|
|
||||||
createTunnelOffIntent(context, mapOf(context.getString(R.string.tunnel_extras_key) to tunnelConfig.toString())),
|
|
||||||
tunnelConfig.id.toString() + APPEND_OFF,
|
|
||||||
tunnelConfig.name.take((SHORT_LABEL_MAX_SIZE - APPEND_OFF.length)) + APPEND_OFF,
|
|
||||||
tunnelConfig.name.take((LONG_LABEL_MAX_SIZE - APPEND_OFF.length)) + APPEND_OFF,
|
|
||||||
R.drawable.vpn_off
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeTunnelShortcuts(context : Context, tunnelConfig : TunnelConfig?) {
|
|
||||||
if(tunnelConfig != null) {
|
|
||||||
ShortcutManagerCompat.removeDynamicShortcuts(context, listOf(tunnelConfig.id.toString() + APPEND_ON,
|
|
||||||
tunnelConfig.id.toString() + APPEND_OFF ))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createTunnelOnIntent(context: Context, extras : Map<String,String>) : Intent {
|
|
||||||
return Intent(context, ShortcutsActivity::class.java).also {
|
|
||||||
it.action = Action.START.name
|
|
||||||
it.putExtra(CLASS_NAME_EXTRA_KEY, WireGuardTunnelService::class.java.name)
|
|
||||||
extras.forEach {(k, v) ->
|
|
||||||
it.putExtra(k, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createTunnelOffIntent(context : Context, extras : Map<String,String>) : Intent {
|
|
||||||
return Intent(context, ShortcutsActivity::class.java).also {
|
|
||||||
it.action = Action.STOP.name
|
|
||||||
it.putExtra(CLASS_NAME_EXTRA_KEY, WireGuardTunnelService::class.java.name)
|
|
||||||
extras.forEach {(k, v) ->
|
|
||||||
it.putExtra(k, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -15,9 +15,14 @@ import androidx.compose.animation.ExperimentalAnimationApi
|
||||||
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.slideInHorizontally
|
import androidx.compose.animation.slideInHorizontally
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
|
import androidx.compose.material3.SnackbarData
|
||||||
|
import androidx.compose.material3.SnackbarDuration
|
||||||
import androidx.compose.material3.SnackbarHost
|
import androidx.compose.material3.SnackbarHost
|
||||||
import androidx.compose.material3.SnackbarHostState
|
import androidx.compose.material3.SnackbarHostState
|
||||||
|
import androidx.compose.material3.SnackbarResult
|
||||||
|
import androidx.compose.material3.surfaceColorAtElevation
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
@ -26,6 +31,7 @@ import androidx.compose.runtime.setValue
|
||||||
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.input.key.onKeyEvent
|
import androidx.compose.ui.input.key.onKeyEvent
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import com.google.accompanist.navigation.animation.AnimatedNavHost
|
import com.google.accompanist.navigation.animation.AnimatedNavHost
|
||||||
import com.google.accompanist.navigation.animation.composable
|
import com.google.accompanist.navigation.animation.composable
|
||||||
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
|
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
|
||||||
|
@ -35,6 +41,7 @@ import com.google.accompanist.permissions.rememberPermissionState
|
||||||
import com.wireguard.android.backend.GoBackend
|
import com.wireguard.android.backend.GoBackend
|
||||||
import com.zaneschepke.wireguardautotunnel.Constants
|
import com.zaneschepke.wireguardautotunnel.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.CustomSnackBar
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.PermissionRequestFailedScreen
|
import com.zaneschepke.wireguardautotunnel.ui.common.PermissionRequestFailedScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavBar
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavBar
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.config.ConfigScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.config.ConfigScreen
|
||||||
|
@ -44,10 +51,11 @@ 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.theme.TransparentSystemBars
|
import com.zaneschepke.wireguardautotunnel.ui.theme.TransparentSystemBars
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.WireguardAutoTunnelTheme
|
import com.zaneschepke.wireguardautotunnel.ui.theme.WireguardAutoTunnelTheme
|
||||||
import com.zaneschepke.wireguardautotunnel.util.WgTunnelException
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.lang.IllegalStateException
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
@ -90,7 +98,29 @@ class MainActivity : AppCompatActivity() {
|
||||||
} else requestNotificationPermission()
|
} else requestNotificationPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
Scaffold(snackbarHost = { SnackbarHost(snackbarHostState)},
|
fun showSnackBarMessage(message : String) {
|
||||||
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
|
val result = snackbarHostState.showSnackbar(
|
||||||
|
message = message,
|
||||||
|
actionLabel = "Okay",
|
||||||
|
duration = SnackbarDuration.Short,
|
||||||
|
)
|
||||||
|
when (result) {
|
||||||
|
SnackbarResult.ActionPerformed -> { snackbarHostState.currentSnackbarData?.dismiss() }
|
||||||
|
SnackbarResult.Dismissed -> { snackbarHostState.currentSnackbarData?.dismiss() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Scaffold(snackbarHost = {
|
||||||
|
SnackbarHost(snackbarHostState) { snackbarData: SnackbarData ->
|
||||||
|
CustomSnackBar(
|
||||||
|
snackbarData.visuals.message,
|
||||||
|
isRtl = false,
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
modifier = Modifier.onKeyEvent {
|
modifier = Modifier.onKeyEvent {
|
||||||
if (it.nativeKeyEvent.action == KeyEvent.ACTION_UP) {
|
if (it.nativeKeyEvent.action == KeyEvent.ACTION_UP) {
|
||||||
when (it.nativeKeyEvent.keyCode) {
|
when (it.nativeKeyEvent.keyCode) {
|
||||||
|
@ -140,6 +170,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
)
|
)
|
||||||
return@Scaffold
|
return@Scaffold
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimatedNavHost(navController, startDestination = Routes.Main.name) {
|
AnimatedNavHost(navController, startDestination = Routes.Main.name) {
|
||||||
composable(Routes.Main.name, enterTransition = {
|
composable(Routes.Main.name, enterTransition = {
|
||||||
when (initialState.destination.route) {
|
when (initialState.destination.route) {
|
||||||
|
@ -154,7 +185,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
MainScreen(padding = padding, snackbarHostState = snackbarHostState, navController = navController)
|
MainScreen(padding = padding, showSnackbarMessage = { message -> showSnackBarMessage(message) }, navController = navController)
|
||||||
}
|
}
|
||||||
composable(Routes.Settings.name, enterTransition = {
|
composable(Routes.Settings.name, enterTransition = {
|
||||||
when (initialState.destination.route) {
|
when (initialState.destination.route) {
|
||||||
|
@ -175,7 +206,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
fadeIn(animationSpec = tween(Constants.FADE_IN_ANIMATION_DURATION))
|
fadeIn(animationSpec = tween(Constants.FADE_IN_ANIMATION_DURATION))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}) { SettingsScreen(padding = padding, snackbarHostState = snackbarHostState, navController = navController, focusRequester = focusRequester) }
|
}) { SettingsScreen(padding = padding, showSnackbarMessage = { message -> showSnackBarMessage(message) }, focusRequester = focusRequester) }
|
||||||
composable(Routes.Support.name, enterTransition = {
|
composable(Routes.Support.name, enterTransition = {
|
||||||
when (initialState.destination.route) {
|
when (initialState.destination.route) {
|
||||||
Routes.Settings.name, Routes.Main.name ->
|
Routes.Settings.name, Routes.Main.name ->
|
||||||
|
@ -191,17 +222,17 @@ class MainActivity : AppCompatActivity() {
|
||||||
}) { SupportScreen(padding = padding, focusRequester) }
|
}) { SupportScreen(padding = padding, focusRequester) }
|
||||||
composable("${Routes.Config.name}/{id}", enterTransition = {
|
composable("${Routes.Config.name}/{id}", enterTransition = {
|
||||||
fadeIn(animationSpec = tween(Constants.FADE_IN_ANIMATION_DURATION))
|
fadeIn(animationSpec = tween(Constants.FADE_IN_ANIMATION_DURATION))
|
||||||
}) {
|
}) { it ->
|
||||||
val id = it.arguments?.getString("id")
|
val id = it.arguments?.getString("id")
|
||||||
if(!id.isNullOrBlank()) {
|
if(!id.isNullOrBlank()) {
|
||||||
ConfigScreen(padding = padding, navController = navController, id = id, focusRequester = focusRequester)}
|
ConfigScreen(navController = navController, id = id, showSnackbarMessage = { message -> showSnackBarMessage(message) }, focusRequester = focusRequester)}
|
||||||
}
|
}
|
||||||
composable("${Routes.Detail.name}/{id}", enterTransition = {
|
composable("${Routes.Detail.name}/{id}", enterTransition = {
|
||||||
fadeIn(animationSpec = tween(Constants.FADE_IN_ANIMATION_DURATION))
|
fadeIn(animationSpec = tween(Constants.FADE_IN_ANIMATION_DURATION))
|
||||||
}) {
|
}) {
|
||||||
val id = it.arguments?.getString("id")
|
val id = it.arguments?.getString("id")
|
||||||
if(!id.isNullOrBlank()) {
|
if(!id.isNullOrBlank()) {
|
||||||
DetailScreen(padding = padding, id = id)
|
DetailScreen(padding = padding, focusRequester = focusRequester, id = id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,24 +3,26 @@ package com.zaneschepke.wireguardautotunnel.ui.common
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.material3.Button
|
|
||||||
import androidx.compose.material3.ButtonDefaults
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
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.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ClickableIconButton(onIconClick : () -> Unit, text : String, icon : ImageVector, enabled : Boolean) {
|
fun ClickableIconButton(onIconClick : () -> Unit, text : String, icon : ImageVector, enabled : Boolean) {
|
||||||
Button(onClick = {},
|
TextButton(onClick = {},
|
||||||
enabled = enabled
|
enabled = enabled
|
||||||
) {
|
) {
|
||||||
Text(text)
|
Text(text)
|
||||||
Spacer(modifier = Modifier.size(ButtonDefaults.IconSpacing))
|
Spacer(modifier = Modifier.size(ButtonDefaults.IconSpacing))
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = icon,
|
imageVector = icon,
|
||||||
contentDescription = "Delete",
|
contentDescription = stringResource(R.string.delete),
|
||||||
modifier = Modifier.size(ButtonDefaults.IconSize).clickable {
|
modifier = Modifier.size(ButtonDefaults.IconSize).clickable {
|
||||||
if(enabled) {
|
if(enabled) {
|
||||||
onIconClick()
|
onIconClick()
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.zaneschepke.wireguardautotunnel.ui.common
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.rounded.Info
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Snackbar
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun CustomSnackBar(
|
||||||
|
message: String,
|
||||||
|
isRtl: Boolean = true,
|
||||||
|
containerColor: Color = MaterialTheme.colorScheme.surface
|
||||||
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
Snackbar(containerColor = containerColor,
|
||||||
|
modifier = Modifier.fillMaxWidth(
|
||||||
|
if(WireGuardAutoTunnel.isRunningOnAndroidTv(context)) 1/3f else 2/3f).padding(bottom = 100.dp),
|
||||||
|
shape = RoundedCornerShape(16.dp)
|
||||||
|
) {
|
||||||
|
CompositionLocalProvider(
|
||||||
|
LocalLayoutDirection provides
|
||||||
|
if (isRtl) LayoutDirection.Rtl else LayoutDirection.Ltr
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceEvenly
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Rounded.Info,
|
||||||
|
contentDescription = stringResource(R.string.info),
|
||||||
|
tint = Color.White
|
||||||
|
)
|
||||||
|
Text(message, color = Color.White, modifier = Modifier.padding(end = 5.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun RowListItem(leadingIcon : ImageVector? = null, leadingIconColor : Color = Color.Gray, text : String, onHold : () -> Unit, onClick: () -> Unit, rowButton : @Composable() () -> Unit ) {
|
fun RowListItem(icon : @Composable() () -> Unit, text : String, onHold : () -> Unit, onClick: () -> Unit, rowButton : @Composable() () -> Unit ) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.combinedClickable(
|
.combinedClickable(
|
||||||
|
@ -39,13 +39,7 @@ fun RowListItem(leadingIcon : ImageVector? = null, leadingIconColor : Color = Co
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
) {
|
) {
|
||||||
Row(verticalAlignment = Alignment.CenterVertically,) {
|
Row(verticalAlignment = Alignment.CenterVertically,) {
|
||||||
if(leadingIcon != null) {
|
icon()
|
||||||
Icon(
|
|
||||||
leadingIcon, "status",
|
|
||||||
tint = leadingIconColor,
|
|
||||||
modifier = Modifier.padding(end = 10.dp).size(15.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Text(text)
|
Text(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.zaneschepke.wireguardautotunnel.ui.common.config
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
|
import androidx.compose.ui.text.input.KeyboardCapitalization
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun
|
||||||
|
ConfigurationTextBox(value : String, hint : String, onValueChange : (String) -> Unit, label : String, onDone : () -> Unit, modifier: Modifier) {
|
||||||
|
OutlinedTextField(
|
||||||
|
modifier = modifier,
|
||||||
|
value = value,
|
||||||
|
singleLine = true,
|
||||||
|
onValueChange = {
|
||||||
|
onValueChange(it)
|
||||||
|
},
|
||||||
|
label = { Text(label) },
|
||||||
|
maxLines = 1,
|
||||||
|
placeholder = {
|
||||||
|
Text(hint)
|
||||||
|
},
|
||||||
|
keyboardOptions = KeyboardOptions(
|
||||||
|
capitalization = KeyboardCapitalization.None,
|
||||||
|
imeAction = ImeAction.Done
|
||||||
|
),
|
||||||
|
keyboardActions = KeyboardActions(
|
||||||
|
onDone = {
|
||||||
|
onDone()
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.zaneschepke.wireguardautotunnel.ui.common.config
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.Switch
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ConfigurationToggle(label : String, enabled : Boolean, checked : Boolean, padding : Dp,
|
||||||
|
onCheckChanged : () -> Unit) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(padding),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
|
) {
|
||||||
|
Text(label)
|
||||||
|
Switch(
|
||||||
|
enabled = enabled,
|
||||||
|
checked = checked,
|
||||||
|
onCheckedChange = {
|
||||||
|
onCheckChanged()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.zaneschepke.wireguardautotunnel.ui.common.text
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
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.unit.Dp
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SectionTitle(title : String, padding : Dp) {
|
||||||
|
Text(
|
||||||
|
title,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
style = TextStyle(fontSize = 18.sp, fontWeight = FontWeight.ExtraBold),
|
||||||
|
modifier = Modifier.padding(padding, bottom = 5.dp, top = 5.dp)
|
||||||
|
)
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.zaneschepke.wireguardautotunnel.ui.models
|
||||||
|
|
||||||
|
import com.wireguard.config.Interface
|
||||||
|
import com.wireguard.config.Peer
|
||||||
|
|
||||||
|
data class InterfaceProxy(
|
||||||
|
var privateKey : String = "",
|
||||||
|
var publicKey : String = "",
|
||||||
|
var addresses : String = "",
|
||||||
|
var dnsServers : String = "",
|
||||||
|
var listenPort : String = "",
|
||||||
|
var mtu : String = "",
|
||||||
|
){
|
||||||
|
companion object {
|
||||||
|
fun from(i : Interface) : InterfaceProxy {
|
||||||
|
return InterfaceProxy(
|
||||||
|
publicKey = i.keyPair.publicKey.toBase64(),
|
||||||
|
privateKey = i.keyPair.privateKey.toBase64(),
|
||||||
|
addresses = i.addresses.joinToString(","),
|
||||||
|
dnsServers = i.dnsServers.joinToString(",").replace("/", ""),
|
||||||
|
listenPort = if(i.listenPort.isPresent) i.listenPort.get().toString() else "",
|
||||||
|
mtu = if(i.mtu.isPresent) i.mtu.get().toString() else ""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.zaneschepke.wireguardautotunnel.ui.models
|
||||||
|
|
||||||
|
import com.wireguard.config.Peer
|
||||||
|
|
||||||
|
data class PeerProxy(
|
||||||
|
var publicKey : String = "",
|
||||||
|
var preSharedKey : String = "",
|
||||||
|
var persistentKeepalive : String = "",
|
||||||
|
var endpoint : String = "",
|
||||||
|
var allowedIps: String = IPV4_WILDCARD.joinToString(",")
|
||||||
|
){
|
||||||
|
companion object {
|
||||||
|
fun from(peer : Peer) : PeerProxy {
|
||||||
|
return PeerProxy(
|
||||||
|
publicKey = peer.publicKey.toBase64(),
|
||||||
|
preSharedKey = if(peer.preSharedKey.isPresent) peer.preSharedKey.get().toString() else "",
|
||||||
|
persistentKeepalive = if(peer.persistentKeepalive.isPresent) peer.persistentKeepalive.get().toString() else "",
|
||||||
|
endpoint = if(peer.endpoint.isPresent) peer.endpoint.get().toString() else "",
|
||||||
|
allowedIps = peer.allowedIps.joinToString(",")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val IPV4_PUBLIC_NETWORKS = setOf(
|
||||||
|
"0.0.0.0/5", "8.0.0.0/7", "11.0.0.0/8", "12.0.0.0/6", "16.0.0.0/4", "32.0.0.0/3",
|
||||||
|
"64.0.0.0/2", "128.0.0.0/3", "160.0.0.0/5", "168.0.0.0/6", "172.0.0.0/12",
|
||||||
|
"172.32.0.0/11", "172.64.0.0/10", "172.128.0.0/9", "173.0.0.0/8", "174.0.0.0/7",
|
||||||
|
"176.0.0.0/4", "192.0.0.0/9", "192.128.0.0/11", "192.160.0.0/13", "192.169.0.0/16",
|
||||||
|
"192.170.0.0/15", "192.172.0.0/14", "192.176.0.0/12", "192.192.0.0/10",
|
||||||
|
"193.0.0.0/8", "194.0.0.0/7", "196.0.0.0/6", "200.0.0.0/5", "208.0.0.0/4"
|
||||||
|
)
|
||||||
|
val IPV4_WILDCARD = setOf("0.0.0.0/0")
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,120 +1,167 @@
|
||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.config
|
package com.zaneschepke.wireguardautotunnel.ui.screens.config
|
||||||
|
|
||||||
import android.widget.Toast
|
import android.annotation.SuppressLint
|
||||||
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
|
import androidx.compose.foundation.focusGroup
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.IntrinsicSize
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
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.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.rounded.Android
|
import androidx.compose.material.icons.rounded.Android
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material.icons.rounded.ContentCopy
|
||||||
|
import androidx.compose.material.icons.rounded.Delete
|
||||||
|
import androidx.compose.material.icons.rounded.Refresh
|
||||||
|
import androidx.compose.material.icons.rounded.Save
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.Checkbox
|
import androidx.compose.material3.Checkbox
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.FabPosition
|
||||||
|
import androidx.compose.material3.FloatingActionButton
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.Scaffold
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Switch
|
import androidx.compose.material3.Switch
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.material3.surfaceColorAtElevation
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.focus.focusRequester
|
import androidx.compose.ui.focus.focusRequester
|
||||||
|
import androidx.compose.ui.focus.onFocusChanged
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.ClipboardManager
|
||||||
|
import androidx.compose.ui.platform.LocalClipboardManager
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalFocusManager
|
import androidx.compose.ui.platform.LocalFocusManager
|
||||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.input.KeyboardCapitalization
|
import androidx.compose.ui.text.input.KeyboardCapitalization
|
||||||
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||||
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 androidx.navigation.NavController
|
||||||
import com.google.accompanist.drawablepainter.DrawablePainter
|
import com.google.accompanist.drawablepainter.DrawablePainter
|
||||||
|
import com.zaneschepke.wireguardautotunnel.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Routes
|
import com.zaneschepke.wireguardautotunnel.ui.Routes
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.SearchBar
|
import com.zaneschepke.wireguardautotunnel.ui.common.SearchBar
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationTextBox
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
@OptIn(ExperimentalComposeUiApi::class)
|
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
||||||
|
@OptIn(ExperimentalComposeUiApi::class, ExperimentalMaterial3Api::class,
|
||||||
|
ExperimentalFoundationApi::class
|
||||||
|
)
|
||||||
@Composable
|
@Composable
|
||||||
fun ConfigScreen(
|
fun ConfigScreen(
|
||||||
viewModel: ConfigViewModel = hiltViewModel(),
|
viewModel: ConfigViewModel = hiltViewModel(),
|
||||||
padding: PaddingValues,
|
|
||||||
focusRequester: FocusRequester,
|
focusRequester: FocusRequester,
|
||||||
navController: NavController,
|
navController: NavController,
|
||||||
|
showSnackbarMessage: (String) -> Unit,
|
||||||
id: String
|
id: String
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val focusManager = LocalFocusManager.current
|
val focusManager = LocalFocusManager.current
|
||||||
|
|
||||||
val keyboardController = LocalSoftwareKeyboardController.current
|
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
||||||
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
|
|
||||||
|
|
||||||
val tunnel by viewModel.tunnel.collectAsStateWithLifecycle(null)
|
val tunnel by viewModel.tunnel.collectAsStateWithLifecycle(null)
|
||||||
val tunnelName = viewModel.tunnelName.collectAsStateWithLifecycle()
|
val tunnelName = viewModel.tunnelName.collectAsStateWithLifecycle()
|
||||||
val packages by viewModel.packages.collectAsStateWithLifecycle()
|
val packages by viewModel.packages.collectAsStateWithLifecycle()
|
||||||
val checkedPackages by viewModel.checkedPackages.collectAsStateWithLifecycle()
|
val checkedPackages by viewModel.checkedPackages.collectAsStateWithLifecycle()
|
||||||
val include by viewModel.include.collectAsStateWithLifecycle()
|
val include by viewModel.include.collectAsStateWithLifecycle()
|
||||||
val allApplications by viewModel.allApplications.collectAsStateWithLifecycle()
|
val isAllApplicationsEnabled by viewModel.isAllApplicationsEnabled.collectAsStateWithLifecycle()
|
||||||
val sortedPackages = remember(packages) {
|
val proxyPeers by viewModel.proxyPeers.collectAsStateWithLifecycle()
|
||||||
packages.sortedBy { viewModel.getPackageLabel(it) }
|
val proxyInterface by viewModel.interfaceProxy.collectAsStateWithLifecycle()
|
||||||
}
|
var showApplicationsDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
val keyboardActions = KeyboardActions(
|
||||||
viewModel.emitScreenData(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
if(tunnel != null) {
|
|
||||||
LazyColumn(
|
|
||||||
horizontalAlignment = Alignment.Start,
|
|
||||||
verticalArrangement = Arrangement.Top,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(padding)
|
|
||||||
) {
|
|
||||||
item {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 20.dp, vertical = 7.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
|
||||||
) {
|
|
||||||
OutlinedTextField(
|
|
||||||
modifier = Modifier.focusRequester(focusRequester),
|
|
||||||
value = tunnelName.value,
|
|
||||||
onValueChange = {
|
|
||||||
viewModel.onTunnelNameChange(it)
|
|
||||||
},
|
|
||||||
label = { Text(stringResource(id = R.string.tunnel_name)) },
|
|
||||||
maxLines = 1,
|
|
||||||
keyboardOptions = KeyboardOptions(
|
|
||||||
capitalization = KeyboardCapitalization.None,
|
|
||||||
imeAction = ImeAction.Done
|
|
||||||
),
|
|
||||||
keyboardActions = KeyboardActions(
|
|
||||||
onDone = {
|
onDone = {
|
||||||
focusManager.clearFocus()
|
focusManager.clearFocus()
|
||||||
keyboardController?.hide()
|
keyboardController?.hide()
|
||||||
viewModel.onTunnelNameChange(tunnelName.value)
|
|
||||||
}
|
}
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val keyboardOptions = KeyboardOptions(
|
||||||
|
capitalization = KeyboardCapitalization.None,
|
||||||
|
imeAction = ImeAction.Done
|
||||||
|
)
|
||||||
|
|
||||||
|
val fillMaxHeight = .85f
|
||||||
|
val fillMaxWidth = .85f
|
||||||
|
val screenPadding = 5.dp
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
try {
|
||||||
|
viewModel.onScreenLoad(id)
|
||||||
|
} catch (e : Exception) {
|
||||||
|
showSnackbarMessage(e.message!!)
|
||||||
|
navController.navigate(Routes.Main.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item {
|
|
||||||
|
val applicationButtonText = {
|
||||||
|
"Tunneling apps: " +
|
||||||
|
if (isAllApplicationsEnabled) "all"
|
||||||
|
else "${checkedPackages.size} " + (if (include) "included" else "excluded")
|
||||||
|
|
||||||
|
}
|
||||||
|
if (showApplicationsDialog) {
|
||||||
|
val sortedPackages = remember(packages) {
|
||||||
|
packages.sortedBy { viewModel.getPackageLabel(it) }
|
||||||
|
}
|
||||||
|
AlertDialog(onDismissRequest = {
|
||||||
|
showApplicationsDialog = false
|
||||||
|
}) {
|
||||||
|
Surface(
|
||||||
|
tonalElevation = 2.dp,
|
||||||
|
shadowElevation = 2.dp,
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
color = MaterialTheme.colorScheme.surface,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.fillMaxHeight(if (isAllApplicationsEnabled) 1 / 5f else 4 / 5f)
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
@ -124,19 +171,20 @@ fun ConfigScreen(
|
||||||
) {
|
) {
|
||||||
Text(stringResource(id = R.string.tunnel_all))
|
Text(stringResource(id = R.string.tunnel_all))
|
||||||
Switch(
|
Switch(
|
||||||
checked = allApplications,
|
checked = isAllApplicationsEnabled,
|
||||||
onCheckedChange = {
|
onCheckedChange = {
|
||||||
viewModel.onAllApplicationsChange(!allApplications)
|
viewModel.onAllApplicationsChange(it)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
if (!isAllApplicationsEnabled) {
|
||||||
if (!allApplications) {
|
|
||||||
item {
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(horizontal = 20.dp, vertical = 7.dp),
|
.padding(
|
||||||
|
horizontal = 20.dp,
|
||||||
|
vertical = 7.dp
|
||||||
|
),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
) {
|
) {
|
||||||
|
@ -165,50 +213,77 @@ fun ConfigScreen(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
item {
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(horizontal = 20.dp, vertical = 7.dp),
|
.padding(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
horizontal = 20.dp,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween) {
|
vertical = 7.dp
|
||||||
SearchBar(viewModel::emitQueriedPackages);
|
),
|
||||||
}
|
|
||||||
}
|
|
||||||
items(sortedPackages, key = { it.packageName }) { pack ->
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
) {
|
) {
|
||||||
|
SearchBar(viewModel::emitQueriedPackages);
|
||||||
|
}
|
||||||
|
Spacer(Modifier.padding(5.dp))
|
||||||
|
LazyColumn(
|
||||||
|
horizontalAlignment = Alignment.Start,
|
||||||
|
verticalArrangement = Arrangement.Top,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxHeight(4 / 5f)
|
||||||
|
) {
|
||||||
|
items(
|
||||||
|
sortedPackages,
|
||||||
|
key = { it.packageName }) { pack ->
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.Center,
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier.padding(5.dp)
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(5.dp)
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(
|
||||||
|
fillMaxWidth
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
val drawable =
|
val drawable =
|
||||||
pack.applicationInfo?.loadIcon(context.packageManager)
|
pack.applicationInfo?.loadIcon(
|
||||||
|
context.packageManager
|
||||||
|
)
|
||||||
if (drawable != null) {
|
if (drawable != null) {
|
||||||
Image(
|
Image(
|
||||||
painter = DrawablePainter(drawable),
|
painter = DrawablePainter(
|
||||||
|
drawable
|
||||||
|
),
|
||||||
stringResource(id = R.string.icon),
|
stringResource(id = R.string.icon),
|
||||||
modifier = Modifier.size(50.dp, 50.dp)
|
modifier = Modifier.size(
|
||||||
|
50.dp,
|
||||||
|
50.dp
|
||||||
|
)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Rounded.Android,
|
Icons.Rounded.Android,
|
||||||
stringResource(id = R.string.edit),
|
stringResource(id = R.string.edit),
|
||||||
modifier = Modifier.size(50.dp, 50.dp)
|
modifier = Modifier.size(
|
||||||
|
50.dp,
|
||||||
|
50.dp
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
viewModel.getPackageLabel(pack), modifier = Modifier.padding(5.dp)
|
viewModel.getPackageLabel(pack),
|
||||||
|
modifier = Modifier.padding(5.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Checkbox(
|
Checkbox(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
checked = (checkedPackages.contains(pack.packageName)),
|
checked = (checkedPackages.contains(pack.packageName)),
|
||||||
onCheckedChange = {
|
onCheckedChange = {
|
||||||
if (it) viewModel.onAddCheckedPackage(pack.packageName) else viewModel.onRemoveCheckedPackage(
|
if (it) viewModel.onAddCheckedPackage(
|
||||||
|
pack.packageName
|
||||||
|
) else viewModel.onRemoveCheckedPackage(
|
||||||
pack.packageName
|
pack.packageName
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -216,25 +291,367 @@ fun ConfigScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item {
|
}
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.Center,
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(top = 5.dp),
|
||||||
|
horizontalArrangement = Arrangement.Center
|
||||||
) {
|
) {
|
||||||
Button(onClick = {
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
showApplicationsDialog = false
|
||||||
|
}) {
|
||||||
|
Text(stringResource(R.string.done))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (tunnel != null) {
|
||||||
|
Scaffold(
|
||||||
|
floatingActionButtonPosition = FabPosition.End,
|
||||||
|
floatingActionButton = {
|
||||||
|
val secondaryColor = MaterialTheme.colorScheme.secondary
|
||||||
|
val hoverColor = MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp)
|
||||||
|
var fobColor by remember { mutableStateOf(secondaryColor) }
|
||||||
|
FloatingActionButton(
|
||||||
|
modifier = Modifier.padding(bottom = 90.dp).onFocusChanged {
|
||||||
|
if(WireGuardAutoTunnel.isRunningOnAndroidTv(context)) {
|
||||||
|
fobColor = if (it.isFocused) hoverColor else secondaryColor }
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
|
try {
|
||||||
viewModel.onSaveAllChanges()
|
viewModel.onSaveAllChanges()
|
||||||
Toast.makeText(
|
|
||||||
context,
|
|
||||||
context.resources.getString(R.string.config_changes_saved),
|
|
||||||
Toast.LENGTH_LONG
|
|
||||||
).show()
|
|
||||||
navController.navigate(Routes.Main.name)
|
navController.navigate(Routes.Main.name)
|
||||||
|
showSnackbarMessage(context.resources.getString(R.string.config_changes_saved))
|
||||||
|
} catch (e : Exception) {
|
||||||
|
Timber.e(e.message)
|
||||||
|
showSnackbarMessage(e.message!!)
|
||||||
}
|
}
|
||||||
}, Modifier.padding(25.dp)) {
|
}
|
||||||
Text(stringResource(id = R.string.save_changes))
|
},
|
||||||
}
|
containerColor = fobColor,
|
||||||
|
shape = RoundedCornerShape(16.dp),
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Rounded.Save,
|
||||||
|
contentDescription = stringResource(id = R.string.save_changes),
|
||||||
|
tint = Color.DarkGray,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
Column {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Top,
|
||||||
|
modifier = Modifier
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.weight(1f, true)
|
||||||
|
.fillMaxSize()
|
||||||
|
) {
|
||||||
|
Surface(
|
||||||
|
tonalElevation = 2.dp,
|
||||||
|
shadowElevation = 2.dp,
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
color = MaterialTheme.colorScheme.surface,
|
||||||
|
modifier = (if (WireGuardAutoTunnel.isRunningOnAndroidTv(context))
|
||||||
|
Modifier
|
||||||
|
.fillMaxHeight(fillMaxHeight)
|
||||||
|
.fillMaxWidth(fillMaxWidth)
|
||||||
|
else Modifier.fillMaxWidth(fillMaxWidth)).padding(
|
||||||
|
top = 50.dp,
|
||||||
|
bottom = 10.dp
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.Start,
|
||||||
|
verticalArrangement = Arrangement.Top,
|
||||||
|
modifier = Modifier.padding(15.dp).focusGroup()
|
||||||
|
) {
|
||||||
|
SectionTitle(stringResource(R.string.interface_), padding = screenPadding)
|
||||||
|
ConfigurationTextBox(
|
||||||
|
value = tunnelName.value,
|
||||||
|
onValueChange = { value ->
|
||||||
|
viewModel.onTunnelNameChange(value)
|
||||||
|
},
|
||||||
|
onDone = {
|
||||||
|
focusManager.clearFocus()
|
||||||
|
keyboardController?.hide()
|
||||||
|
},
|
||||||
|
label = stringResource(R.string.name),
|
||||||
|
hint = stringResource(R.string.tunnel_name).lowercase(),
|
||||||
|
modifier = Modifier.fillMaxWidth().focusRequester(focusRequester)
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
value = proxyInterface.privateKey,
|
||||||
|
visualTransformation = PasswordVisualTransformation(),
|
||||||
|
enabled = id == Constants.MANUAL_TUNNEL_CONFIG_ID,
|
||||||
|
onValueChange = { value ->
|
||||||
|
viewModel.onPrivateKeyChange(value)
|
||||||
|
},
|
||||||
|
trailingIcon = {
|
||||||
|
IconButton(
|
||||||
|
modifier = Modifier.focusRequester(FocusRequester.Default),
|
||||||
|
onClick = {
|
||||||
|
viewModel.generateKeyPair()
|
||||||
|
}) {
|
||||||
|
Icon(
|
||||||
|
Icons.Rounded.Refresh,
|
||||||
|
stringResource(R.string.rotate_keys),
|
||||||
|
tint = Color.White
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
label = { Text(stringResource(R.string.private_key)) },
|
||||||
|
singleLine = true,
|
||||||
|
placeholder = { Text(stringResource(R.string.base64_key)) },
|
||||||
|
keyboardOptions = keyboardOptions,
|
||||||
|
keyboardActions = keyboardActions
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
modifier = Modifier.fillMaxWidth().focusRequester(FocusRequester.Default),
|
||||||
|
value = proxyInterface.publicKey,
|
||||||
|
enabled = false,
|
||||||
|
onValueChange = {},
|
||||||
|
trailingIcon = {
|
||||||
|
IconButton(
|
||||||
|
modifier = Modifier.focusRequester(FocusRequester.Default),
|
||||||
|
onClick = {
|
||||||
|
clipboardManager.setText(AnnotatedString(proxyInterface.publicKey))
|
||||||
|
}) {
|
||||||
|
Icon(
|
||||||
|
Icons.Rounded.ContentCopy,
|
||||||
|
stringResource(R.string.copy_public_key),
|
||||||
|
tint = Color.White
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
label = { Text(stringResource(R.string.public_key)) },
|
||||||
|
singleLine = true,
|
||||||
|
placeholder = { Text(stringResource(R.string.base64_key)) },
|
||||||
|
keyboardOptions = keyboardOptions,
|
||||||
|
keyboardActions = keyboardActions
|
||||||
|
)
|
||||||
|
Row(modifier = Modifier.fillMaxWidth()) {
|
||||||
|
ConfigurationTextBox(
|
||||||
|
value = proxyInterface.addresses,
|
||||||
|
onValueChange = { value ->
|
||||||
|
viewModel.onAddressesChanged(value)
|
||||||
|
},
|
||||||
|
onDone = {
|
||||||
|
focusManager.clearFocus()
|
||||||
|
keyboardController?.hide()
|
||||||
|
},
|
||||||
|
label = stringResource(R.string.addresses),
|
||||||
|
hint = stringResource(R.string.comma_separated_list),
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth(3 / 5f)
|
||||||
|
.padding(end = 5.dp)
|
||||||
|
)
|
||||||
|
ConfigurationTextBox(
|
||||||
|
value = proxyInterface.listenPort,
|
||||||
|
onValueChange = { value -> viewModel.onListenPortChanged(value) },
|
||||||
|
onDone = {
|
||||||
|
focusManager.clearFocus()
|
||||||
|
keyboardController?.hide()
|
||||||
|
},
|
||||||
|
label = stringResource(R.string.listen_port),
|
||||||
|
hint = stringResource(R.string.random),
|
||||||
|
modifier = Modifier.width(IntrinsicSize.Min)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Row(modifier = Modifier.fillMaxWidth()) {
|
||||||
|
ConfigurationTextBox(
|
||||||
|
value = proxyInterface.dnsServers,
|
||||||
|
onValueChange = { value -> viewModel.onDnsServersChanged(value) },
|
||||||
|
onDone = {
|
||||||
|
focusManager.clearFocus()
|
||||||
|
keyboardController?.hide()
|
||||||
|
},
|
||||||
|
label = stringResource(R.string.dns_servers),
|
||||||
|
hint = stringResource(R.string.comma_separated_list),
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth(3 / 5f)
|
||||||
|
.padding(end = 5.dp)
|
||||||
|
)
|
||||||
|
ConfigurationTextBox(
|
||||||
|
value = proxyInterface.mtu,
|
||||||
|
onValueChange = { value -> viewModel.onMtuChanged(value) },
|
||||||
|
onDone = {
|
||||||
|
focusManager.clearFocus()
|
||||||
|
keyboardController?.hide()
|
||||||
|
},
|
||||||
|
label = stringResource(R.string.mtu),
|
||||||
|
hint = stringResource(R.string.auto),
|
||||||
|
modifier = Modifier.width(IntrinsicSize.Min)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(top = 5.dp),
|
||||||
|
horizontalArrangement = Arrangement.Center
|
||||||
|
) {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
showApplicationsDialog = true
|
||||||
|
}) {
|
||||||
|
Text(applicationButtonText())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
proxyPeers.forEachIndexed { index, peer ->
|
||||||
|
Surface(
|
||||||
|
tonalElevation = 2.dp,
|
||||||
|
shadowElevation = 2.dp,
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
color = MaterialTheme.colorScheme.surface,
|
||||||
|
modifier = (if (WireGuardAutoTunnel.isRunningOnAndroidTv(context))
|
||||||
|
Modifier
|
||||||
|
.fillMaxHeight(fillMaxHeight)
|
||||||
|
.fillMaxWidth(fillMaxWidth)
|
||||||
|
else Modifier.fillMaxWidth(fillMaxWidth)).padding(
|
||||||
|
top = 10.dp,
|
||||||
|
bottom = 10.dp
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.Start,
|
||||||
|
verticalArrangement = Arrangement.Top,
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(horizontal = 15.dp)
|
||||||
|
.padding(bottom = 10.dp)
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 5.dp)
|
||||||
|
) {
|
||||||
|
SectionTitle(stringResource(R.string.peer), padding = screenPadding)
|
||||||
|
IconButton(
|
||||||
|
onClick = {
|
||||||
|
viewModel.onDeletePeer(index)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Icon(Icons.Rounded.Delete, stringResource(R.string.delete))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigurationTextBox(
|
||||||
|
value = peer.publicKey,
|
||||||
|
onValueChange = { value ->
|
||||||
|
viewModel.onPeerPublicKeyChange(
|
||||||
|
index,
|
||||||
|
value
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onDone = {
|
||||||
|
focusManager.clearFocus()
|
||||||
|
keyboardController?.hide()
|
||||||
|
},
|
||||||
|
label = stringResource(R.string.public_key),
|
||||||
|
hint = stringResource(R.string.base64_key),
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
)
|
||||||
|
ConfigurationTextBox(
|
||||||
|
value = peer.preSharedKey,
|
||||||
|
onValueChange = { value ->
|
||||||
|
viewModel.onPreSharedKeyChange(
|
||||||
|
index,
|
||||||
|
value
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onDone = {
|
||||||
|
focusManager.clearFocus()
|
||||||
|
keyboardController?.hide()
|
||||||
|
},
|
||||||
|
label = stringResource(R.string.preshared_key),
|
||||||
|
hint = stringResource(R.string.optional),
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
value = peer.persistentKeepalive,
|
||||||
|
enabled = true,
|
||||||
|
onValueChange = { value ->
|
||||||
|
viewModel.onPersistentKeepaliveChanged(index, value)
|
||||||
|
},
|
||||||
|
trailingIcon = { Text(stringResource(R.string.seconds), modifier = Modifier.padding(end = 10.dp)) },
|
||||||
|
label = { Text(stringResource(R.string.persistent_keepalive)) },
|
||||||
|
singleLine = true,
|
||||||
|
placeholder = { Text(stringResource(R.string.optional_no_recommend)) },
|
||||||
|
keyboardOptions = keyboardOptions,
|
||||||
|
keyboardActions = keyboardActions
|
||||||
|
)
|
||||||
|
ConfigurationTextBox(
|
||||||
|
value = peer.endpoint,
|
||||||
|
onValueChange = { value ->
|
||||||
|
viewModel.onEndpointChange(
|
||||||
|
index,
|
||||||
|
value
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onDone = {
|
||||||
|
focusManager.clearFocus()
|
||||||
|
keyboardController?.hide()
|
||||||
|
},
|
||||||
|
label = stringResource(R.string.endpoint),
|
||||||
|
hint = stringResource(R.string.endpoint).lowercase(),
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
value = peer.allowedIps,
|
||||||
|
enabled = true,
|
||||||
|
onValueChange = { value ->
|
||||||
|
viewModel.onAllowedIpsChange(
|
||||||
|
index,
|
||||||
|
value
|
||||||
|
)
|
||||||
|
},
|
||||||
|
label = { Text(stringResource(R.string.allowed_ips)) },
|
||||||
|
singleLine = true,
|
||||||
|
placeholder = { Text(stringResource(R.string.comma_separated_list)) },
|
||||||
|
keyboardOptions = keyboardOptions,
|
||||||
|
keyboardActions = keyboardActions
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.SpaceEvenly,
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(bottom = 140.dp)
|
||||||
|
) {
|
||||||
|
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.Center
|
||||||
|
) {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
viewModel.addEmptyPeer()
|
||||||
|
}) {
|
||||||
|
Text(stringResource(R.string.add_peer))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(WireGuardAutoTunnel.isRunningOnAndroidTv(context)) {
|
||||||
|
Spacer(modifier = Modifier.weight(.17f))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,28 +10,43 @@ import androidx.compose.runtime.toMutableStateList
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.wireguard.config.Config
|
import com.wireguard.config.Config
|
||||||
|
import com.wireguard.config.Interface
|
||||||
|
import com.wireguard.config.Peer
|
||||||
|
import com.wireguard.crypto.Key
|
||||||
|
import com.wireguard.crypto.KeyPair
|
||||||
|
import com.zaneschepke.wireguardautotunnel.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.TunnelConfigDao
|
import com.zaneschepke.wireguardautotunnel.repository.TunnelConfigDao
|
||||||
import com.zaneschepke.wireguardautotunnel.service.shortcut.ShortcutsManager
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.models.InterfaceProxy
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.models.PeerProxy
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||||
import com.zaneschepke.wireguardautotunnel.util.WgTunnelException
|
import com.zaneschepke.wireguardautotunnel.util.WgTunnelException
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import kotlinx.coroutines.withContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class ConfigViewModel @Inject constructor(private val application : Application,
|
class ConfigViewModel @Inject constructor(private val application : Application,
|
||||||
private val tunnelRepo : TunnelConfigDao,
|
private val tunnelRepo : TunnelConfigDao,
|
||||||
private val settingsRepo : SettingsDoa) : ViewModel() {
|
private val settingsRepo : SettingsDoa
|
||||||
|
) : ViewModel() {
|
||||||
|
|
||||||
private val _tunnel = MutableStateFlow<TunnelConfig?>(null)
|
private val _tunnel = MutableStateFlow<TunnelConfig?>(null)
|
||||||
private val _tunnelName = MutableStateFlow("")
|
private val _tunnelName = MutableStateFlow("")
|
||||||
val tunnelName get() = _tunnelName.asStateFlow()
|
val tunnelName get() = _tunnelName.asStateFlow()
|
||||||
val tunnel get() = _tunnel.asStateFlow()
|
val tunnel get() = _tunnel.asStateFlow()
|
||||||
|
|
||||||
|
private var _proxyPeers = MutableStateFlow(mutableStateListOf<PeerProxy>())
|
||||||
|
val proxyPeers get() = _proxyPeers.asStateFlow()
|
||||||
|
|
||||||
|
private var _interface = MutableStateFlow(InterfaceProxy())
|
||||||
|
val interfaceProxy = _interface.asStateFlow()
|
||||||
|
|
||||||
private val _packages = MutableStateFlow(emptyList<PackageInfo>())
|
private val _packages = MutableStateFlow(emptyList<PackageInfo>())
|
||||||
val packages get() = _packages.asStateFlow()
|
val packages get() = _packages.asStateFlow()
|
||||||
private val packageManager = application.packageManager
|
private val packageManager = application.packageManager
|
||||||
|
@ -41,38 +56,91 @@ class ConfigViewModel @Inject constructor(private val application : Application,
|
||||||
private val _include = MutableStateFlow(true)
|
private val _include = MutableStateFlow(true)
|
||||||
val include get() = _include.asStateFlow()
|
val include get() = _include.asStateFlow()
|
||||||
|
|
||||||
private val _allApplications = MutableStateFlow(true)
|
private val _isAllApplicationsEnabled = MutableStateFlow(false)
|
||||||
val allApplications get() = _allApplications.asStateFlow()
|
val isAllApplicationsEnabled get() = _isAllApplicationsEnabled.asStateFlow()
|
||||||
|
private val _isDefaultTunnel = MutableStateFlow(false)
|
||||||
|
val isDefaultTunnel = _isDefaultTunnel.asStateFlow()
|
||||||
|
|
||||||
fun emitScreenData(id : String) {
|
private lateinit var tunnelConfig: TunnelConfig
|
||||||
|
|
||||||
|
fun onScreenLoad(id : String) {
|
||||||
|
if(id != Constants.MANUAL_TUNNEL_CONFIG_ID) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val tunnelConfig = getTunnelConfigById(id);
|
tunnelConfig = withContext(this.coroutineContext) {
|
||||||
emitTunnelConfig(tunnelConfig);
|
getTunnelConfigById(id) ?: throw WgTunnelException("Config not found")
|
||||||
emitTunnelConfigName(tunnelConfig?.name)
|
|
||||||
emitQueriedPackages("")
|
|
||||||
emitCurrentPackageConfigurations(id)
|
|
||||||
}
|
}
|
||||||
|
emitScreenData()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
emitEmptyScreenData()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun emitEmptyScreenData() {
|
||||||
|
tunnelConfig = TunnelConfig(name = NumberUtils.generateRandomTunnelName(), wgQuick = "")
|
||||||
|
viewModelScope.launch {
|
||||||
|
emitTunnelConfig()
|
||||||
|
emitPeerProxy(PeerProxy())
|
||||||
|
emitInterfaceProxy(InterfaceProxy())
|
||||||
|
emitTunnelConfigName()
|
||||||
|
emitDefaultTunnelStatus()
|
||||||
|
emitQueriedPackages("")
|
||||||
|
emitTunnelAllApplicationsEnabled()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private suspend fun emitScreenData() {
|
||||||
|
emitTunnelConfig()
|
||||||
|
emitPeersFromConfig()
|
||||||
|
emitInterfaceFromConfig()
|
||||||
|
emitTunnelConfigName()
|
||||||
|
emitDefaultTunnelStatus()
|
||||||
|
emitQueriedPackages("")
|
||||||
|
emitCurrentPackageConfigurations()
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun emitDefaultTunnelStatus() {
|
||||||
|
val settings = settingsRepo.getAll()
|
||||||
|
if(settings.isNotEmpty()) {
|
||||||
|
_isDefaultTunnel.value = settings.first().isTunnelConfigDefault(tunnelConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun emitInterfaceFromConfig() {
|
||||||
|
val config = TunnelConfig.configFromQuick(tunnelConfig.wgQuick)
|
||||||
|
_interface.value = InterfaceProxy.from(config.`interface`)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun emitPeersFromConfig() {
|
||||||
|
val config = TunnelConfig.configFromQuick(tunnelConfig.wgQuick)
|
||||||
|
config.peers.forEach{
|
||||||
|
_proxyPeers.value.add(PeerProxy.from(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun emitPeerProxy(peerProxy: PeerProxy) {
|
||||||
|
_proxyPeers.value.add(peerProxy)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun emitInterfaceProxy(interfaceProxy: InterfaceProxy) {
|
||||||
|
_interface.value = interfaceProxy
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getTunnelConfigById(id : String) : TunnelConfig? {
|
private suspend fun getTunnelConfigById(id : String) : TunnelConfig? {
|
||||||
return try {
|
return try {
|
||||||
tunnelRepo.getById(id.toLong())
|
tunnelRepo.getById(id.toLong())
|
||||||
} catch (e : Exception) {
|
} catch (_ : Exception) {
|
||||||
Timber.e(e.message)
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun emitTunnelConfig(tunnelConfig: TunnelConfig?) {
|
private suspend fun emitTunnelConfig() {
|
||||||
if(tunnelConfig != null) {
|
|
||||||
_tunnel.emit(tunnelConfig)
|
_tunnel.emit(tunnelConfig)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun emitTunnelConfigName(name : String?) {
|
private suspend fun emitTunnelConfigName() {
|
||||||
if(name != null) {
|
_tunnelName.emit(tunnelConfig.name)
|
||||||
_tunnelName.emit(name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onTunnelNameChange(name : String) {
|
fun onTunnelNameChange(name : String) {
|
||||||
|
@ -86,8 +154,8 @@ class ConfigViewModel @Inject constructor(private val application : Application,
|
||||||
_checkedPackages.value.add(packageName)
|
_checkedPackages.value.add(packageName)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onAllApplicationsChange(allApplications : Boolean) {
|
fun onAllApplicationsChange(isAllApplicationsEnabled : Boolean) {
|
||||||
_allApplications.value = allApplications
|
_isAllApplicationsEnabled.value = isAllApplicationsEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onRemoveCheckedPackage(packageName : String) {
|
fun onRemoveCheckedPackage(packageName : String) {
|
||||||
|
@ -128,22 +196,19 @@ class ConfigViewModel @Inject constructor(private val application : Application,
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun emitTunnelAllApplicationsEnabled() {
|
private suspend fun emitTunnelAllApplicationsEnabled() {
|
||||||
_allApplications.emit(true)
|
_isAllApplicationsEnabled.emit(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun emitTunnelAllApplicationsDisabled() {
|
private suspend fun emitTunnelAllApplicationsDisabled() {
|
||||||
_allApplications.emit(false)
|
_isAllApplicationsEnabled.emit(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun emitCurrentPackageConfigurations(id : String) {
|
private fun emitCurrentPackageConfigurations() {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val tunnelConfig = getTunnelConfigById(id)
|
|
||||||
if (tunnelConfig != null) {
|
|
||||||
val config = TunnelConfig.configFromQuick(tunnelConfig.wgQuick)
|
val config = TunnelConfig.configFromQuick(tunnelConfig.wgQuick)
|
||||||
emitSplitTunnelConfiguration(config)
|
emitSplitTunnelConfiguration(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun emitQueriedPackages(query : String) {
|
fun emitQueriedPackages(query : String) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
@ -171,44 +236,20 @@ class ConfigViewModel @Inject constructor(private val application : Application,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeTunnelShortcuts(tunnelConfig: TunnelConfig?) {
|
|
||||||
if(tunnelConfig != null) {
|
|
||||||
ShortcutsManager.removeTunnelShortcuts(application, tunnelConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isAllApplicationsEnabled() : Boolean {
|
private fun isAllApplicationsEnabled() : Boolean {
|
||||||
return _allApplications.value
|
return _isAllApplicationsEnabled.value
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isIncludeApplicationsEnabled() : Boolean {
|
private fun isIncludeApplicationsEnabled() : Boolean {
|
||||||
return _include.value
|
return _include.value
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateQuickStringWithSelectedPackages() : String {
|
|
||||||
var wgQuick = _tunnel.value?.wgQuick
|
|
||||||
if(wgQuick != null) {
|
|
||||||
wgQuick = if(isAllApplicationsEnabled()) {
|
|
||||||
TunnelConfig.clearAllApplicationsFromConfig(wgQuick)
|
|
||||||
} else if(isIncludeApplicationsEnabled()) {
|
|
||||||
TunnelConfig.setIncludedApplicationsOnQuick(_checkedPackages.value, wgQuick)
|
|
||||||
} else {
|
|
||||||
TunnelConfig.setExcludedApplicationsOnQuick(_checkedPackages.value, wgQuick)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw WgTunnelException("Wg quick string is null")
|
|
||||||
}
|
|
||||||
return wgQuick;
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun saveConfig(tunnelConfig: TunnelConfig) {
|
private suspend fun saveConfig(tunnelConfig: TunnelConfig) {
|
||||||
tunnelRepo.save(tunnelConfig)
|
tunnelRepo.save(tunnelConfig)
|
||||||
}
|
}
|
||||||
private suspend fun updateTunnelConfig(tunnelConfig: TunnelConfig?) {
|
private suspend fun updateTunnelConfig(tunnelConfig: TunnelConfig?) {
|
||||||
if(tunnelConfig != null) {
|
if(tunnelConfig != null) {
|
||||||
saveConfig(tunnelConfig)
|
saveConfig(tunnelConfig)
|
||||||
addTunnelShortcuts(tunnelConfig)
|
|
||||||
updateSettingsDefaultTunnel(tunnelConfig)
|
updateSettingsDefaultTunnel(tunnelConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,21 +268,133 @@ class ConfigViewModel @Inject constructor(private val application : Application,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addTunnelShortcuts(tunnelConfig: TunnelConfig) {
|
fun buildPeerListFromProxyPeers() : List<Peer> {
|
||||||
ShortcutsManager.createTunnelShortcuts(application, tunnelConfig)
|
return _proxyPeers.value.map {
|
||||||
|
val builder = Peer.Builder()
|
||||||
|
if (it.allowedIps.isNotEmpty()) builder.parseAllowedIPs(it.allowedIps)
|
||||||
|
if (it.publicKey.isNotEmpty()) builder.parsePublicKey(it.publicKey)
|
||||||
|
if (it.preSharedKey.isNotEmpty()) builder.parsePreSharedKey(it.preSharedKey)
|
||||||
|
if (it.endpoint.isNotEmpty()) builder.parseEndpoint(it.endpoint)
|
||||||
|
if (it.persistentKeepalive.isNotEmpty()) builder.parsePersistentKeepalive(it.persistentKeepalive)
|
||||||
|
builder.build()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun buildInterfaceListFromProxyInterface() : Interface {
|
||||||
|
val builder = Interface.Builder()
|
||||||
|
builder.parsePrivateKey(_interface.value.privateKey)
|
||||||
|
builder.parseAddresses(_interface.value.addresses)
|
||||||
|
builder.parseDnsServers(_interface.value.dnsServers)
|
||||||
|
if(_interface.value.mtu.isNotEmpty()) builder.parseMtu(_interface.value.mtu)
|
||||||
|
if(_interface.value.listenPort.isNotEmpty()) builder.parseListenPort(_interface.value.listenPort)
|
||||||
|
if(isAllApplicationsEnabled()) _checkedPackages.value.clear()
|
||||||
|
if(_include.value) builder.includeApplications(_checkedPackages.value)
|
||||||
|
if(!_include.value) builder.excludeApplications(_checkedPackages.value)
|
||||||
|
return builder.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
suspend fun onSaveAllChanges() {
|
suspend fun onSaveAllChanges() {
|
||||||
try {
|
try {
|
||||||
removeTunnelShortcuts(_tunnel.value)
|
val peerList = buildPeerListFromProxyPeers()
|
||||||
val wgQuick = updateQuickStringWithSelectedPackages()
|
val wgInterface = buildInterfaceListFromProxyInterface()
|
||||||
|
val config = Config.Builder().addPeers(peerList).setInterface(wgInterface).build()
|
||||||
val tunnelConfig = _tunnel.value?.copy(
|
val tunnelConfig = _tunnel.value?.copy(
|
||||||
name = _tunnelName.value,
|
name = _tunnelName.value,
|
||||||
wgQuick = wgQuick
|
wgQuick = config.toWgQuickString()
|
||||||
)
|
)
|
||||||
updateTunnelConfig(tunnelConfig)
|
updateTunnelConfig(tunnelConfig)
|
||||||
} catch (e : Exception) {
|
} catch (e : Exception) {
|
||||||
Timber.e(e.message)
|
throw WgTunnelException("Error: ${e.cause?.message?.lowercase() ?: "unknown error occurred"}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onPeerPublicKeyChange(index: Int, publicKey: String) {
|
||||||
|
_proxyPeers.value[index] = _proxyPeers.value[index].copy(
|
||||||
|
publicKey = publicKey
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onPreSharedKeyChange(index: Int, value: String) {
|
||||||
|
_proxyPeers.value[index] = _proxyPeers.value[index].copy(
|
||||||
|
preSharedKey = value
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onEndpointChange(index: Int, value: String) {
|
||||||
|
_proxyPeers.value[index] = _proxyPeers.value[index].copy(
|
||||||
|
endpoint = value
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onAllowedIpsChange(index: Int, value: String) {
|
||||||
|
_proxyPeers.value[index] = _proxyPeers.value[index].copy(
|
||||||
|
allowedIps = value
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onPersistentKeepaliveChanged(index : Int, value : String) {
|
||||||
|
_proxyPeers.value[index] = _proxyPeers.value[index].copy(
|
||||||
|
persistentKeepalive = value
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onDeletePeer(index: Int) {
|
||||||
|
proxyPeers.value.removeAt(index)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addEmptyPeer() {
|
||||||
|
_proxyPeers.value.add(PeerProxy())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun generateKeyPair() {
|
||||||
|
val keyPair = KeyPair()
|
||||||
|
_interface.value = _interface.value.copy(
|
||||||
|
privateKey = keyPair.privateKey.toBase64(),
|
||||||
|
publicKey = keyPair.publicKey.toBase64()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onAddressesChanged(value: String) {
|
||||||
|
_interface.value = _interface.value.copy(
|
||||||
|
addresses = value
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onListenPortChanged(value: String) {
|
||||||
|
_interface.value = _interface.value.copy(
|
||||||
|
listenPort = value
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onDnsServersChanged(value: String) {
|
||||||
|
_interface.value = _interface.value.copy(
|
||||||
|
dnsServers = value
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onMtuChanged(value: String) {
|
||||||
|
_interface.value = _interface.value.copy(
|
||||||
|
mtu = value
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onInterfacePublicKeyChange(value : String) {
|
||||||
|
_interface.value = _interface.value.copy(
|
||||||
|
publicKey = value
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onPrivateKeyChange(value: String) {
|
||||||
|
_interface.value = _interface.value.copy(
|
||||||
|
privateKey = value
|
||||||
|
)
|
||||||
|
if(NumberUtils.isValidKey(value)) {
|
||||||
|
val pair = KeyPair(Key.fromBase64(value))
|
||||||
|
onInterfacePublicKeyChange(pair.publicKey.toBase64())
|
||||||
|
} else {
|
||||||
|
onInterfacePublicKeyChange("")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,11 +1,15 @@
|
||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.detail
|
package com.zaneschepke.wireguardautotunnel.ui.screens.detail
|
||||||
|
|
||||||
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.focusGroup
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
@ -17,8 +21,11 @@ import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
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.platform.ClipboardManager
|
import androidx.compose.ui.platform.ClipboardManager
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
import androidx.compose.ui.platform.LocalClipboardManager
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
import androidx.compose.ui.text.font.FontStyle
|
import androidx.compose.ui.text.font.FontStyle
|
||||||
|
@ -28,17 +35,21 @@ import androidx.compose.ui.unit.sp
|
||||||
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.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun DetailScreen(
|
fun DetailScreen(
|
||||||
viewModel: DetailViewModel = hiltViewModel(),
|
viewModel: DetailViewModel = hiltViewModel(),
|
||||||
|
focusRequester: FocusRequester,
|
||||||
padding: PaddingValues,
|
padding: PaddingValues,
|
||||||
id : String
|
id : String
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
val context = LocalContext.current
|
||||||
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
||||||
val tunnelStats by viewModel.tunnelStats.collectAsStateWithLifecycle(null)
|
val tunnelStats by viewModel.tunnelStats.collectAsStateWithLifecycle(null)
|
||||||
val tunnel by viewModel.tunnel.collectAsStateWithLifecycle(null)
|
val tunnel by viewModel.tunnel.collectAsStateWithLifecycle(null)
|
||||||
|
@ -62,18 +73,20 @@ fun DetailScreen(
|
||||||
horizontalAlignment = Alignment.Start,
|
horizontalAlignment = Alignment.Start,
|
||||||
verticalArrangement = Arrangement.Top,
|
verticalArrangement = Arrangement.Top,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxWidth()
|
||||||
|
.fillMaxHeight(if(WireGuardAutoTunnel.isRunningOnAndroidTv(context)) 4/5f else 1f)
|
||||||
.verticalScroll(rememberScrollState())
|
.verticalScroll(rememberScrollState())
|
||||||
|
.focusRequester(focusRequester)
|
||||||
.padding(padding)
|
.padding(padding)
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(horizontal = 20.dp, vertical = 7.dp),
|
.padding(horizontal = 20.dp, vertical = 7.dp).focusGroup(),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
) {
|
) {
|
||||||
Column {
|
Column(modifier = Modifier.weight(1f, true)) {
|
||||||
Text(stringResource(R.string.config_interface), fontWeight = FontWeight.Bold, fontSize = 20.sp)
|
Text(stringResource(R.string.config_interface), fontWeight = FontWeight.Bold, fontSize = 20.sp)
|
||||||
Text(stringResource(R.string.name), fontStyle = FontStyle.Italic)
|
Text(stringResource(R.string.name), fontStyle = FontStyle.Italic)
|
||||||
Text(text = tunnelName, modifier = Modifier.clickable {
|
Text(text = tunnelName, modifier = Modifier.clickable {
|
||||||
|
@ -122,15 +135,22 @@ fun DetailScreen(
|
||||||
val rxKB = NumberUtils.bytesToKB(tunnelStats!!.totalRx())
|
val rxKB = NumberUtils.bytesToKB(tunnelStats!!.totalRx())
|
||||||
val txKB = NumberUtils.bytesToKB(tunnelStats!!.totalTx())
|
val txKB = NumberUtils.bytesToKB(tunnelStats!!.totalTx())
|
||||||
Text(stringResource(R.string.transfer), fontStyle = FontStyle.Italic)
|
Text(stringResource(R.string.transfer), fontStyle = FontStyle.Italic)
|
||||||
Text("rx: ${NumberUtils.formatDecimalTwoPlaces(rxKB)} KB tx: ${NumberUtils.formatDecimalTwoPlaces(txKB)} KB")
|
val transfer = "rx: ${NumberUtils.formatDecimalTwoPlaces(rxKB)} KB tx: ${NumberUtils.formatDecimalTwoPlaces(txKB)} KB"
|
||||||
|
Text(transfer, modifier = Modifier.clickable {
|
||||||
|
clipboardManager.setText(AnnotatedString(transfer))})
|
||||||
Text(stringResource(R.string.last_handshake), fontStyle = FontStyle.Italic)
|
Text(stringResource(R.string.last_handshake), fontStyle = FontStyle.Italic)
|
||||||
val handshakeEpoch = lastHandshake[it.publicKey]
|
val handshakeEpoch = lastHandshake[it.publicKey]
|
||||||
if(handshakeEpoch != null) {
|
if(handshakeEpoch != null) {
|
||||||
if(handshakeEpoch == 0L) {
|
if(handshakeEpoch == 0L) {
|
||||||
Text(stringResource(id = R.string.never))
|
Text(stringResource(id = R.string.never), modifier = Modifier.clickable {
|
||||||
|
clipboardManager.setText(AnnotatedString(context.getString(R.string.never)))
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
val time = Instant.ofEpochMilli(handshakeEpoch)
|
val time = Instant.ofEpochMilli(handshakeEpoch)
|
||||||
Text("${Duration.between(time, Instant.now()).seconds} seconds ago")
|
val duration = "${Duration.between(time, Instant.now()).seconds} seconds ago"
|
||||||
|
Text(duration, modifier = Modifier.clickable {
|
||||||
|
clipboardManager.setText(AnnotatedString(duration))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ class DetailViewModel @Inject constructor(private val tunnelRepo : TunnelConfigD
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val tunnelConfig = getTunnelConfigById(id)
|
val tunnelConfig = getTunnelConfigById(id)
|
||||||
if(tunnelConfig != null) {
|
if(tunnelConfig != null) {
|
||||||
|
_tunnelName.emit(tunnelConfig.name)
|
||||||
_tunnel.emit(TunnelConfig.configFromQuick(tunnelConfig.wgQuick))
|
_tunnel.emit(TunnelConfig.configFromQuick(tunnelConfig.wgQuick))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
@ -17,10 +16,12 @@ import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
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.Create
|
||||||
import androidx.compose.material.icons.filled.FileOpen
|
import androidx.compose.material.icons.filled.FileOpen
|
||||||
import androidx.compose.material.icons.filled.QrCode
|
import androidx.compose.material.icons.filled.QrCode
|
||||||
import androidx.compose.material.icons.rounded.Add
|
import androidx.compose.material.icons.rounded.Add
|
||||||
|
@ -28,6 +29,8 @@ import androidx.compose.material.icons.rounded.Circle
|
||||||
import androidx.compose.material.icons.rounded.Delete
|
import androidx.compose.material.icons.rounded.Delete
|
||||||
import androidx.compose.material.icons.rounded.Edit
|
import androidx.compose.material.icons.rounded.Edit
|
||||||
import androidx.compose.material.icons.rounded.Info
|
import androidx.compose.material.icons.rounded.Info
|
||||||
|
import androidx.compose.material.icons.rounded.Star
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.Divider
|
import androidx.compose.material3.Divider
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.FabPosition
|
import androidx.compose.material3.FabPosition
|
||||||
|
@ -37,14 +40,12 @@ import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.ModalBottomSheet
|
import androidx.compose.material3.ModalBottomSheet
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.SnackbarDuration
|
|
||||||
import androidx.compose.material3.SnackbarHostState
|
|
||||||
import androidx.compose.material3.SnackbarResult
|
|
||||||
import androidx.compose.material3.Switch
|
import androidx.compose.material3.Switch
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.material3.rememberModalBottomSheetState
|
import androidx.compose.material3.rememberModalBottomSheetState
|
||||||
|
import androidx.compose.material3.surfaceColorAtElevation
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
@ -55,6 +56,7 @@ import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.focus.focusRequester
|
import androidx.compose.ui.focus.focusRequester
|
||||||
|
import androidx.compose.ui.focus.onFocusChanged
|
||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||||
|
@ -89,8 +91,10 @@ import kotlinx.coroutines.launch
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun MainScreen(
|
fun MainScreen(
|
||||||
viewModel: MainViewModel = hiltViewModel(), padding: PaddingValues,
|
viewModel: MainViewModel = hiltViewModel(),
|
||||||
snackbarHostState: SnackbarHostState, navController: NavController
|
padding: PaddingValues,
|
||||||
|
showSnackbarMessage: (String) -> Unit,
|
||||||
|
navController: NavController
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val haptic = LocalHapticFeedback.current
|
val haptic = LocalHapticFeedback.current
|
||||||
|
@ -100,13 +104,13 @@ fun MainScreen(
|
||||||
|
|
||||||
val sheetState = rememberModalBottomSheetState()
|
val sheetState = rememberModalBottomSheetState()
|
||||||
var showBottomSheet by remember { mutableStateOf(false) }
|
var showBottomSheet by remember { mutableStateOf(false) }
|
||||||
|
var showPrimaryChangeAlertDialog by remember { mutableStateOf(false) }
|
||||||
val tunnels by viewModel.tunnels.collectAsStateWithLifecycle(mutableListOf())
|
val tunnels by viewModel.tunnels.collectAsStateWithLifecycle(mutableListOf())
|
||||||
val handshakeStatus by viewModel.handshakeStatus.collectAsStateWithLifecycle(HandshakeStatus.NOT_STARTED)
|
val handshakeStatus by viewModel.handshakeStatus.collectAsStateWithLifecycle(HandshakeStatus.NOT_STARTED)
|
||||||
val viewState = viewModel.viewState.collectAsStateWithLifecycle()
|
|
||||||
var selectedTunnel by remember { mutableStateOf<TunnelConfig?>(null) }
|
var selectedTunnel by remember { mutableStateOf<TunnelConfig?>(null) }
|
||||||
val state by viewModel.state.collectAsStateWithLifecycle(Tunnel.State.DOWN)
|
val state by viewModel.state.collectAsStateWithLifecycle(Tunnel.State.DOWN)
|
||||||
val tunnelName by viewModel.tunnelName.collectAsStateWithLifecycle("")
|
val tunnelName by viewModel.tunnelName.collectAsStateWithLifecycle("")
|
||||||
|
val settings by viewModel.settings.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
// Nested scroll for control FAB
|
// Nested scroll for control FAB
|
||||||
val nestedScrollConnection = remember {
|
val nestedScrollConnection = remember {
|
||||||
|
@ -125,24 +129,14 @@ fun MainScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(viewState.value) {
|
|
||||||
if (viewState.value.showSnackbarMessage) {
|
|
||||||
val result = snackbarHostState.showSnackbar(
|
|
||||||
message = viewState.value.snackbarMessage,
|
|
||||||
actionLabel = viewState.value.snackbarActionText,
|
|
||||||
duration = SnackbarDuration.Long,
|
|
||||||
)
|
|
||||||
when (result) {
|
|
||||||
SnackbarResult.ActionPerformed -> viewState.value.onSnackbarActionClick
|
|
||||||
SnackbarResult.Dismissed -> viewState.value.onSnackbarActionClick
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val pickFileLauncher = rememberLauncherForActivityResult(
|
val pickFileLauncher = rememberLauncherForActivityResult(
|
||||||
ActivityResultContracts.StartActivityForResult()
|
ActivityResultContracts.GetContent()
|
||||||
) { result ->
|
) { result -> if (result != null)
|
||||||
result.data?.data?.let { viewModel.onTunnelFileSelected(it) }
|
try {
|
||||||
|
viewModel.onTunnelFileSelected(result)
|
||||||
|
} catch (e : Exception) {
|
||||||
|
showSnackbarMessage(e.message ?: "Unknown error occurred")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val scanLauncher = rememberLauncherForActivityResult(
|
val scanLauncher = rememberLauncherForActivityResult(
|
||||||
|
@ -151,11 +145,45 @@ fun MainScreen(
|
||||||
try {
|
try {
|
||||||
viewModel.onTunnelQrResult(it.contents)
|
viewModel.onTunnelQrResult(it.contents)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
viewModel.showSnackBarMessage(context.getString(R.string.qr_result_failed))
|
showSnackbarMessage(context.getString(R.string.qr_result_failed))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(showPrimaryChangeAlertDialog) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = {
|
||||||
|
showPrimaryChangeAlertDialog = false
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = {
|
||||||
|
scope.launch {
|
||||||
|
viewModel.onDefaultTunnelChange(selectedTunnel)
|
||||||
|
showPrimaryChangeAlertDialog = false
|
||||||
|
selectedTunnel = null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
{ Text(text = "Okay") }
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = {
|
||||||
|
showPrimaryChangeAlertDialog = false
|
||||||
|
})
|
||||||
|
{ Text(text = "Cancel") }
|
||||||
|
},
|
||||||
|
title = { Text(text = "Primary tunnel change") },
|
||||||
|
text = { Text(text = "Would you like to make this your primary tunnel?") }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onTunnelToggle(checked : Boolean , tunnel : TunnelConfig) {
|
||||||
|
try {
|
||||||
|
if (checked) viewModel.onTunnelStart(tunnel) else viewModel.onTunnelStop()
|
||||||
|
} catch (e : Exception) {
|
||||||
|
showSnackbarMessage(e.message!!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier = Modifier.pointerInput(Unit) {
|
modifier = Modifier.pointerInput(Unit) {
|
||||||
detectTapGestures(onTap = {
|
detectTapGestures(onTap = {
|
||||||
|
@ -169,12 +197,19 @@ fun MainScreen(
|
||||||
enter = slideInVertically(initialOffsetY = { it * 2 }),
|
enter = slideInVertically(initialOffsetY = { it * 2 }),
|
||||||
exit = slideOutVertically(targetOffsetY = { it * 2 }),
|
exit = slideOutVertically(targetOffsetY = { it * 2 }),
|
||||||
) {
|
) {
|
||||||
|
val secondaryColor = MaterialTheme.colorScheme.secondary
|
||||||
|
val hoverColor = MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp)
|
||||||
|
var fobColor by remember { mutableStateOf(secondaryColor) }
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
modifier = Modifier.padding(bottom = 90.dp),
|
modifier = Modifier.padding(bottom = 90.dp).onFocusChanged {
|
||||||
|
if(WireGuardAutoTunnel.isRunningOnAndroidTv(context)) {
|
||||||
|
fobColor = if (it.isFocused) hoverColor else secondaryColor }
|
||||||
|
}
|
||||||
|
,
|
||||||
onClick = {
|
onClick = {
|
||||||
showBottomSheet = true
|
showBottomSheet = true
|
||||||
},
|
},
|
||||||
containerColor = MaterialTheme.colorScheme.secondary,
|
containerColor = fobColor,
|
||||||
shape = RoundedCornerShape(16.dp),
|
shape = RoundedCornerShape(16.dp),
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
|
@ -210,20 +245,11 @@ fun MainScreen(
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable {
|
.clickable {
|
||||||
showBottomSheet = false
|
showBottomSheet = false
|
||||||
val fileSelectionIntent = Intent(Intent.ACTION_GET_CONTENT).apply {
|
try {
|
||||||
addCategory(Intent.CATEGORY_OPENABLE)
|
pickFileLauncher.launch(Constants.ALLOWED_FILE_TYPES)
|
||||||
putExtra(Constants.FILES_SHOW_ADVANCED, true)
|
} catch (_: Exception) {
|
||||||
type = Constants.ALLOWED_FILE_TYPES
|
showSnackbarMessage("No file explorer")
|
||||||
}
|
}
|
||||||
if(!viewModel.isIntentAvailable(fileSelectionIntent)) {
|
|
||||||
fileSelectionIntent.action = Intent.ACTION_OPEN_DOCUMENT
|
|
||||||
fileSelectionIntent.setPackage(null)
|
|
||||||
if (!viewModel.isIntentAvailable(fileSelectionIntent)) {
|
|
||||||
viewModel.showSnackBarMessage(context.getString(R.string.no_file_app))
|
|
||||||
return@clickable
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pickFileLauncher.launch(fileSelectionIntent)
|
|
||||||
}
|
}
|
||||||
.padding(10.dp)
|
.padding(10.dp)
|
||||||
) {
|
) {
|
||||||
|
@ -264,6 +290,26 @@ fun MainScreen(
|
||||||
modifier = Modifier.padding(10.dp)
|
modifier = Modifier.padding(10.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Divider()
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable {
|
||||||
|
showBottomSheet = false
|
||||||
|
navController.navigate("${Routes.Config.name}/${Constants.MANUAL_TUNNEL_CONFIG_ID}")
|
||||||
|
}
|
||||||
|
.padding(10.dp)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Create,
|
||||||
|
contentDescription = stringResource(id = R.string.create_import),
|
||||||
|
modifier = Modifier.padding(10.dp)
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
stringResource(id = R.string.create_import),
|
||||||
|
modifier = Modifier.padding(10.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Column(
|
Column(
|
||||||
|
@ -273,27 +319,36 @@ fun MainScreen(
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(padding)
|
.padding(padding)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.nestedScroll(nestedScrollConnection),
|
.nestedScroll(nestedScrollConnection),
|
||||||
) {
|
) {
|
||||||
items(tunnels, key = { tunnel -> tunnel.id }) { tunnel ->
|
items(tunnels, key = { tunnel -> tunnel.id }) { tunnel ->
|
||||||
val focusRequester = remember { FocusRequester() }
|
val leadingIconColor = (if (tunnelName == tunnel.name) when (handshakeStatus) {
|
||||||
RowListItem(leadingIcon = Icons.Rounded.Circle,
|
|
||||||
leadingIconColor = if (tunnelName == tunnel.name) when (handshakeStatus) {
|
|
||||||
HandshakeStatus.HEALTHY -> mint
|
HandshakeStatus.HEALTHY -> mint
|
||||||
HandshakeStatus.UNHEALTHY -> brickRed
|
HandshakeStatus.UNHEALTHY -> brickRed
|
||||||
HandshakeStatus.NOT_STARTED -> Color.Gray
|
HandshakeStatus.NOT_STARTED -> Color.Gray
|
||||||
HandshakeStatus.NEVER_CONNECTED -> brickRed
|
HandshakeStatus.NEVER_CONNECTED -> brickRed
|
||||||
} else Color.Gray,
|
} else {Color.Gray})
|
||||||
|
val focusRequester = remember { FocusRequester() }
|
||||||
|
RowListItem(icon = {
|
||||||
|
if (settings.isTunnelConfigDefault(tunnel))
|
||||||
|
Icon(
|
||||||
|
Icons.Rounded.Star, "status",
|
||||||
|
tint = leadingIconColor,
|
||||||
|
modifier = Modifier.padding(end = 10.dp).size(20.dp)
|
||||||
|
)
|
||||||
|
else Icon(
|
||||||
|
Icons.Rounded.Circle, "status",
|
||||||
|
tint = leadingIconColor,
|
||||||
|
modifier = Modifier.padding(end = 15.dp).size(15.dp)
|
||||||
|
)
|
||||||
|
},
|
||||||
text = tunnel.name,
|
text = tunnel.name,
|
||||||
onHold = {
|
onHold = {
|
||||||
if (state == Tunnel.State.UP && tunnel.name == tunnelName) {
|
if (state == Tunnel.State.UP && tunnel.name == tunnelName) {
|
||||||
scope.launch {
|
showSnackbarMessage(context.resources.getString(R.string.turn_off_tunnel))
|
||||||
viewModel.showSnackBarMessage(context.resources.getString(R.string.turn_off_tunnel))
|
|
||||||
}
|
|
||||||
return@RowListItem
|
return@RowListItem
|
||||||
}
|
}
|
||||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
|
@ -303,12 +358,22 @@ fun MainScreen(
|
||||||
if (!WireGuardAutoTunnel.isRunningOnAndroidTv(context)) {
|
if (!WireGuardAutoTunnel.isRunningOnAndroidTv(context)) {
|
||||||
navController.navigate("${Routes.Detail.name}/${tunnel.id}")
|
navController.navigate("${Routes.Detail.name}/${tunnel.id}")
|
||||||
} else {
|
} else {
|
||||||
|
selectedTunnel = tunnel
|
||||||
focusRequester.requestFocus()
|
focusRequester.requestFocus()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
rowButton = {
|
rowButton = {
|
||||||
if (tunnel.id == selectedTunnel?.id) {
|
if (tunnel.id == selectedTunnel?.id && !WireGuardAutoTunnel.isRunningOnAndroidTv(context)) {
|
||||||
Row {
|
Row {
|
||||||
|
if(!settings.isTunnelConfigDefault(tunnel)) {
|
||||||
|
IconButton(onClick = {
|
||||||
|
if(settings.isAutoTunnelEnabled) {
|
||||||
|
showSnackbarMessage(context.resources.getString(R.string.turn_off_auto))
|
||||||
|
} else showPrimaryChangeAlertDialog = true
|
||||||
|
}) {
|
||||||
|
Icon(Icons.Rounded.Star, stringResource(id = R.string.set_primary))
|
||||||
|
}
|
||||||
|
}
|
||||||
IconButton(onClick = {
|
IconButton(onClick = {
|
||||||
navController.navigate("${Routes.Config.name}/${selectedTunnel?.id}")
|
navController.navigate("${Routes.Config.name}/${selectedTunnel?.id}")
|
||||||
}) {
|
}) {
|
||||||
|
@ -326,6 +391,15 @@ fun MainScreen(
|
||||||
} else {
|
} else {
|
||||||
if (WireGuardAutoTunnel.isRunningOnAndroidTv(context)) {
|
if (WireGuardAutoTunnel.isRunningOnAndroidTv(context)) {
|
||||||
Row {
|
Row {
|
||||||
|
if(!settings.isTunnelConfigDefault(tunnel)) {
|
||||||
|
IconButton(onClick = {
|
||||||
|
if(settings.isAutoTunnelEnabled) {
|
||||||
|
showSnackbarMessage(context.resources.getString(R.string.turn_off_auto))
|
||||||
|
} else showPrimaryChangeAlertDialog = true
|
||||||
|
}) {
|
||||||
|
Icon(Icons.Rounded.Star, stringResource(id = R.string.set_primary))
|
||||||
|
}
|
||||||
|
}
|
||||||
IconButton(
|
IconButton(
|
||||||
modifier = Modifier.focusRequester(focusRequester),
|
modifier = Modifier.focusRequester(focusRequester),
|
||||||
onClick = {
|
onClick = {
|
||||||
|
@ -335,13 +409,12 @@ fun MainScreen(
|
||||||
}
|
}
|
||||||
IconButton(onClick = {
|
IconButton(onClick = {
|
||||||
if (state == Tunnel.State.UP && tunnel.name == tunnelName)
|
if (state == Tunnel.State.UP && tunnel.name == tunnelName)
|
||||||
scope.launch {
|
showSnackbarMessage(
|
||||||
viewModel.showSnackBarMessage(
|
|
||||||
context.resources.getString(
|
context.resources.getString(
|
||||||
R.string.turn_off_tunnel
|
R.string.turn_off_tunnel
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
} else {
|
else {
|
||||||
navController.navigate("${Routes.Config.name}/${tunnel.id}")
|
navController.navigate("${Routes.Config.name}/${tunnel.id}")
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
@ -352,13 +425,12 @@ fun MainScreen(
|
||||||
}
|
}
|
||||||
IconButton(onClick = {
|
IconButton(onClick = {
|
||||||
if (state == Tunnel.State.UP && tunnel.name == tunnelName)
|
if (state == Tunnel.State.UP && tunnel.name == tunnelName)
|
||||||
scope.launch {
|
showSnackbarMessage(
|
||||||
viewModel.showSnackBarMessage(
|
|
||||||
context.resources.getString(
|
context.resources.getString(
|
||||||
R.string.turn_off_tunnel
|
R.string.turn_off_tunnel
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
} else {
|
else {
|
||||||
viewModel.onDelete(tunnel)
|
viewModel.onDelete(tunnel)
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
@ -370,7 +442,7 @@ fun MainScreen(
|
||||||
Switch(
|
Switch(
|
||||||
checked = (state == Tunnel.State.UP && tunnel.name == tunnelName),
|
checked = (state == Tunnel.State.UP && tunnel.name == tunnelName),
|
||||||
onCheckedChange = { checked ->
|
onCheckedChange = { checked ->
|
||||||
if (checked) viewModel.onTunnelStart(tunnel) else viewModel.onTunnelStop()
|
onTunnelToggle(checked, tunnel)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -378,7 +450,7 @@ fun MainScreen(
|
||||||
Switch(
|
Switch(
|
||||||
checked = (state == Tunnel.State.UP && tunnel.name == tunnelName),
|
checked = (state == Tunnel.State.UP && tunnel.name == tunnelName),
|
||||||
onCheckedChange = { checked ->
|
onCheckedChange = { checked ->
|
||||||
if (checked) viewModel.onTunnelStart(tunnel) else viewModel.onTunnelStop()
|
onTunnelToggle(checked, tunnel)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,12 @@ package com.zaneschepke.wireguardautotunnel.ui.screens.main
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.OpenableColumns
|
import android.provider.OpenableColumns
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.wireguard.config.BadConfigException
|
import com.wireguard.config.BadConfigException
|
||||||
import com.wireguard.config.Config
|
import com.wireguard.config.Config
|
||||||
import com.zaneschepke.wireguardautotunnel.Constants
|
import com.zaneschepke.wireguardautotunnel.Constants
|
||||||
|
@ -21,13 +20,10 @@ import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceState
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceState
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardConnectivityWatcherService
|
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardConnectivityWatcherService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardTunnelService
|
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardTunnelService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.shortcut.ShortcutsManager
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.ViewState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||||
import com.zaneschepke.wireguardautotunnel.util.WgTunnelException
|
import com.zaneschepke.wireguardautotunnel.util.WgTunnelException
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
@ -45,8 +41,6 @@ class MainViewModel @Inject constructor(private val application : Application,
|
||||||
private val vpnService: VpnService
|
private val vpnService: VpnService
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
private val _viewState = MutableStateFlow(ViewState())
|
|
||||||
val viewState get() = _viewState.asStateFlow()
|
|
||||||
val tunnels get() = tunnelRepo.getAllFlow()
|
val tunnels get() = tunnelRepo.getAllFlow()
|
||||||
val state get() = vpnService.state
|
val state get() = vpnService.state
|
||||||
|
|
||||||
|
@ -87,7 +81,6 @@ class MainViewModel @Inject constructor(private val application : Application,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tunnelRepo.delete(tunnel)
|
tunnelRepo.delete(tunnel)
|
||||||
ShortcutsManager.removeTunnelShortcuts(application.applicationContext, tunnel)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +120,7 @@ class MainViewModel @Inject constructor(private val application : Application,
|
||||||
val tunnelConfig = TunnelConfig(name = NumberUtils.generateRandomTunnelName(), wgQuick = result)
|
val tunnelConfig = TunnelConfig(name = NumberUtils.generateRandomTunnelName(), wgQuick = result)
|
||||||
addTunnel(tunnelConfig)
|
addTunnel(tunnelConfig)
|
||||||
} catch (e : WgTunnelException) {
|
} catch (e : WgTunnelException) {
|
||||||
showSnackBarMessage(e.message ?: application.getString(R.string.unknown_error_message))
|
throw WgTunnelException(e.message ?: application.getString(R.string.unknown_error_message))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,40 +149,25 @@ class MainViewModel @Inject constructor(private val application : Application,
|
||||||
|
|
||||||
fun onTunnelFileSelected(uri : Uri) {
|
fun onTunnelFileSelected(uri : Uri) {
|
||||||
try {
|
try {
|
||||||
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val fileName = getFileName(application.applicationContext, uri)
|
val fileName = getFileName(application.applicationContext, uri)
|
||||||
validateFileExtension(fileName)
|
validateFileExtension(fileName)
|
||||||
val stream = getInputStreamFromUri(uri)
|
val stream = getInputStreamFromUri(uri)
|
||||||
saveTunnelConfigFromStream(stream, fileName)
|
saveTunnelConfigFromStream(stream, fileName)
|
||||||
|
}
|
||||||
} catch (e : Exception) {
|
} catch (e : Exception) {
|
||||||
showExceptionMessage(e)
|
throw WgTunnelException(e.message ?: "Error importing file")
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showExceptionMessage(e : Exception) {
|
|
||||||
when(e) {
|
|
||||||
is BadConfigException -> {
|
|
||||||
showSnackBarMessage(application.getString(R.string.bad_config))
|
|
||||||
}
|
|
||||||
is WgTunnelException -> {
|
|
||||||
showSnackBarMessage(e.message ?: application.getString(R.string.unknown_error_message))
|
|
||||||
}
|
|
||||||
else -> showSnackBarMessage(application.getString(R.string.unknown_error_message))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun addTunnel(tunnelConfig: TunnelConfig) {
|
private suspend fun addTunnel(tunnelConfig: TunnelConfig) {
|
||||||
saveTunnel(tunnelConfig)
|
saveTunnel(tunnelConfig)
|
||||||
createTunnelAppShortcuts(tunnelConfig)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun saveTunnel(tunnelConfig : TunnelConfig) {
|
private suspend fun saveTunnel(tunnelConfig : TunnelConfig) {
|
||||||
tunnelRepo.save(tunnelConfig)
|
tunnelRepo.save(tunnelConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createTunnelAppShortcuts(tunnelConfig: TunnelConfig) {
|
|
||||||
ShortcutsManager.createTunnelShortcuts(application.applicationContext, tunnelConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getFileNameByCursor(context: Context, uri: Uri) : String {
|
private fun getFileNameByCursor(context: Context, uri: Uri) : String {
|
||||||
val cursor = context.contentResolver.query(uri, null, null, null, null)
|
val cursor = context.contentResolver.query(uri, null, null, null, null)
|
||||||
if(cursor != null) {
|
if(cursor != null) {
|
||||||
|
@ -209,23 +187,6 @@ class MainViewModel @Inject constructor(private val application : Application,
|
||||||
return columnIndex
|
return columnIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isIntentAvailable(i: Intent?): Boolean {
|
|
||||||
val packageManager = application.packageManager
|
|
||||||
val list = packageManager.queryIntentActivities(
|
|
||||||
i!!,
|
|
||||||
PackageManager.MATCH_DEFAULT_ONLY
|
|
||||||
)
|
|
||||||
// Ignore the Android TV framework app in the list
|
|
||||||
var size = list.size
|
|
||||||
for (ri in list) {
|
|
||||||
// Ignore stub apps
|
|
||||||
if (Constants.ANDROID_TV_STUBS == ri.activityInfo.packageName) {
|
|
||||||
size--
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return size > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getDisplayNameByCursor(cursor: Cursor) : String {
|
private fun getDisplayNameByCursor(cursor: Cursor) : String {
|
||||||
if(cursor.moveToFirst()) {
|
if(cursor.moveToFirst()) {
|
||||||
val index = getDisplayNameColumnIndex(cursor)
|
val index = getDisplayNameColumnIndex(cursor)
|
||||||
|
@ -251,29 +212,6 @@ class MainViewModel @Inject constructor(private val application : Application,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showSnackBarMessage(message : String) {
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
|
||||||
_viewState.emit(_viewState.value.copy(
|
|
||||||
showSnackbarMessage = true,
|
|
||||||
snackbarMessage = message,
|
|
||||||
snackbarActionText = application.getString(R.string.okay),
|
|
||||||
onSnackbarActionClick = {
|
|
||||||
viewModelScope.launch {
|
|
||||||
dismissSnackBar()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
))
|
|
||||||
delay(Constants.SNACKBAR_DELAY)
|
|
||||||
dismissSnackBar()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun dismissSnackBar() {
|
|
||||||
_viewState.emit(_viewState.value.copy(
|
|
||||||
showSnackbarMessage = false
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getNameFromFileName(fileName : String) : String {
|
private fun getNameFromFileName(fileName : String) : String {
|
||||||
return fileName.substring(0 , fileName.lastIndexOf('.') )
|
return fileName.substring(0 , fileName.lastIndexOf('.') )
|
||||||
}
|
}
|
||||||
|
@ -285,4 +223,13 @@ class MainViewModel @Inject constructor(private val application : Application,
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun onDefaultTunnelChange(selectedTunnel: TunnelConfig?) {
|
||||||
|
if(selectedTunnel != null) {
|
||||||
|
_settings.emit(_settings.value.copy(
|
||||||
|
defaultTunnel = selectedTunnel.toString()
|
||||||
|
))
|
||||||
|
settingsRepo.save(_settings.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -11,14 +11,18 @@ import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||||
import androidx.compose.foundation.layout.FlowRow
|
import androidx.compose.foundation.layout.FlowRow
|
||||||
|
import androidx.compose.foundation.layout.IntrinsicSize
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxHeight
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
@ -26,22 +30,14 @@ 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.outlined.Add
|
import androidx.compose.material.icons.outlined.Add
|
||||||
import androidx.compose.material.icons.rounded.LocationOff
|
import androidx.compose.material.icons.rounded.LocationOff
|
||||||
import androidx.compose.material3.Button
|
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
||||||
import androidx.compose.material3.ExposedDropdownMenuBox
|
|
||||||
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
|
||||||
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.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.SnackbarDuration
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.SnackbarHostState
|
|
||||||
import androidx.compose.material3.SnackbarResult
|
|
||||||
import androidx.compose.material3.Switch
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextField
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
@ -63,27 +59,26 @@ 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 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
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Routes
|
|
||||||
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.text.SectionTitle
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalPermissionsApi::class,
|
@OptIn(
|
||||||
|
ExperimentalPermissionsApi::class,
|
||||||
ExperimentalLayoutApi::class
|
ExperimentalLayoutApi::class
|
||||||
)
|
)
|
||||||
@Composable
|
@Composable
|
||||||
fun SettingsScreen(
|
fun SettingsScreen(
|
||||||
viewModel: SettingsViewModel = hiltViewModel(),
|
viewModel: SettingsViewModel = hiltViewModel(),
|
||||||
padding: PaddingValues,
|
padding: PaddingValues,
|
||||||
navController: NavController,
|
showSnackbarMessage: (String) -> Unit,
|
||||||
focusRequester: FocusRequester,
|
focusRequester: FocusRequester,
|
||||||
snackbarHostState: SnackbarHostState = remember { SnackbarHostState() }
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
@ -91,38 +86,36 @@ fun SettingsScreen(
|
||||||
val focusManager = LocalFocusManager.current
|
val focusManager = LocalFocusManager.current
|
||||||
val interactionSource = remember { MutableInteractionSource() }
|
val interactionSource = remember { MutableInteractionSource() }
|
||||||
|
|
||||||
var expanded by remember { mutableStateOf(false) }
|
|
||||||
val viewState by viewModel.viewState.collectAsStateWithLifecycle()
|
|
||||||
val settings by viewModel.settings.collectAsStateWithLifecycle()
|
val settings by viewModel.settings.collectAsStateWithLifecycle()
|
||||||
val trustedSSIDs by viewModel.trustedSSIDs.collectAsStateWithLifecycle()
|
val trustedSSIDs by viewModel.trustedSSIDs.collectAsStateWithLifecycle()
|
||||||
val tunnels by viewModel.tunnels.collectAsStateWithLifecycle(mutableListOf())
|
val tunnels by viewModel.tunnels.collectAsStateWithLifecycle(mutableListOf())
|
||||||
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("") }
|
||||||
val scrollState = rememberScrollState()
|
val scrollState = rememberScrollState()
|
||||||
var isLocationServicesEnabled by remember { mutableStateOf(viewModel.checkLocationServicesEnabled())}
|
var didShowLocationDisclaimer by remember { mutableStateOf(false) }
|
||||||
|
var isBackgroundLocationGranted by remember { mutableStateOf(true) }
|
||||||
|
|
||||||
|
val screenPadding = 5.dp
|
||||||
|
val fillMaxHeight = .85f
|
||||||
|
val fillMaxWidth = .85f
|
||||||
|
|
||||||
LaunchedEffect(viewState) {
|
|
||||||
if (viewState.showSnackbarMessage) {
|
|
||||||
val result = snackbarHostState.showSnackbar(
|
|
||||||
message = viewState.snackbarMessage,
|
|
||||||
actionLabel = viewState.snackbarActionText,
|
|
||||||
duration = SnackbarDuration.Long,
|
|
||||||
)
|
|
||||||
when (result) {
|
|
||||||
SnackbarResult.ActionPerformed -> viewState.onSnackbarActionClick
|
|
||||||
SnackbarResult.Dismissed -> viewState.onSnackbarActionClick
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun saveTrustedSSID() {
|
fun saveTrustedSSID() {
|
||||||
if (currentText.isNotEmpty()) {
|
if (currentText.isNotEmpty()) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
|
try {
|
||||||
viewModel.onSaveTrustedSSID(currentText)
|
viewModel.onSaveTrustedSSID(currentText)
|
||||||
currentText = ""
|
currentText = ""
|
||||||
|
} catch (e : Exception) {
|
||||||
|
showSnackbarMessage(e.message ?: "Unknown error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isAllAutoTunnelPermissionsEnabled() : Boolean {
|
||||||
|
return(isBackgroundLocationGranted && fineLocationState.status.isGranted && !viewModel.isLocationServicesNeeded())
|
||||||
|
}
|
||||||
|
|
||||||
fun openSettings() {
|
fun openSettings() {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
|
@ -133,21 +126,40 @@ fun SettingsScreen(
|
||||||
context.startActivity(intentSettings)
|
context.startActivity(intentSettings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
val backgroundLocationState =
|
val backgroundLocationState =
|
||||||
rememberPermissionState(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
rememberPermissionState(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
||||||
if(!backgroundLocationState.status.isGranted) {
|
if(!backgroundLocationState.status.isGranted) {
|
||||||
Column(horizontalAlignment = Alignment.CenterHorizontally,
|
isBackgroundLocationGranted = false
|
||||||
|
if(!didShowLocationDisclaimer) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.Top,
|
verticalArrangement = Arrangement.Top,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.verticalScroll(scrollState)
|
.verticalScroll(scrollState)
|
||||||
.padding(padding)) {
|
.padding(padding)
|
||||||
Icon(Icons.Rounded.LocationOff, contentDescription = stringResource(id = R.string.map), modifier = Modifier
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Rounded.LocationOff,
|
||||||
|
contentDescription = stringResource(id = R.string.map),
|
||||||
|
modifier = Modifier
|
||||||
.padding(30.dp)
|
.padding(30.dp)
|
||||||
.size(128.dp))
|
.size(128.dp)
|
||||||
Text(stringResource(R.string.prominent_background_location_title), textAlign = TextAlign.Center, modifier = Modifier.padding(30.dp), fontSize = 20.sp)
|
)
|
||||||
Text(stringResource(R.string.prominent_background_location_message), textAlign = TextAlign.Center, modifier = Modifier.padding(30.dp), fontSize = 15.sp)
|
Text(
|
||||||
|
stringResource(R.string.prominent_background_location_title),
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
modifier = Modifier.padding(30.dp),
|
||||||
|
fontSize = 20.sp
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.prominent_background_location_message),
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
modifier = Modifier.padding(30.dp),
|
||||||
|
fontSize = 15.sp
|
||||||
|
)
|
||||||
Row(
|
Row(
|
||||||
modifier = if (WireGuardAutoTunnel.isRunningOnAndroidTv(context)) Modifier
|
modifier = if (WireGuardAutoTunnel.isRunningOnAndroidTv(context)) Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
@ -157,12 +169,12 @@ fun SettingsScreen(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly
|
horizontalArrangement = Arrangement.SpaceEvenly
|
||||||
) {
|
) {
|
||||||
Button(onClick = {
|
TextButton(onClick = {
|
||||||
navController.navigate(Routes.Main.name)
|
didShowLocationDisclaimer = true
|
||||||
}) {
|
}) {
|
||||||
Text(stringResource(id = R.string.no_thanks))
|
Text(stringResource(id = R.string.no_thanks))
|
||||||
}
|
}
|
||||||
Button(modifier = Modifier.focusRequester(focusRequester), onClick = {
|
TextButton(modifier = Modifier.focusRequester(focusRequester), onClick = {
|
||||||
openSettings()
|
openSettings()
|
||||||
}) {
|
}) {
|
||||||
Text(stringResource(id = R.string.turn_on))
|
Text(stringResource(id = R.string.turn_on))
|
||||||
|
@ -171,30 +183,9 @@ fun SettingsScreen(
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
isBackgroundLocationGranted = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!fineLocationState.status.isGranted) {
|
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.Center,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(padding)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
stringResource(id = R.string.precise_location_message),
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(15.dp),
|
|
||||||
fontStyle = FontStyle.Italic
|
|
||||||
)
|
|
||||||
Button(modifier = Modifier.focusRequester(focusRequester),onClick = {
|
|
||||||
fineLocationState.launchPermissionRequest()
|
|
||||||
}) {
|
|
||||||
Text(stringResource(id = R.string.request))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tunnels.isEmpty()) {
|
if (tunnels.isEmpty()) {
|
||||||
|
@ -214,120 +205,34 @@ fun SettingsScreen(
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if(!isLocationServicesEnabled && Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
|
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.Center,
|
verticalArrangement = Arrangement.Top,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(padding)
|
.verticalScroll(scrollState)
|
||||||
|
.clickable(indication = null, interactionSource = interactionSource) {
|
||||||
|
focusManager.clearFocus()
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Surface(
|
||||||
|
tonalElevation = 2.dp,
|
||||||
|
shadowElevation = 2.dp,
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
color = MaterialTheme.colorScheme.surface,
|
||||||
|
modifier = (if (WireGuardAutoTunnel.isRunningOnAndroidTv(context))
|
||||||
|
Modifier
|
||||||
|
.height(IntrinsicSize.Min)
|
||||||
|
.fillMaxWidth(fillMaxWidth)
|
||||||
|
else Modifier.fillMaxWidth(fillMaxWidth)).padding(top = 60.dp, bottom = 25.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
|
||||||
stringResource(id = R.string.location_services_not_detected),
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(15.dp),
|
|
||||||
fontStyle = FontStyle.Italic
|
|
||||||
)
|
|
||||||
Button(modifier = Modifier.focusRequester(focusRequester), onClick = {
|
|
||||||
val locationServicesEnabled = viewModel.checkLocationServicesEnabled()
|
|
||||||
isLocationServicesEnabled = locationServicesEnabled
|
|
||||||
if(!locationServicesEnabled) {
|
|
||||||
scope.launch {
|
|
||||||
viewModel.showSnackBarMessage(context.getString(R.string.detecting_location_services_disabled))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
Text(stringResource(id = R.string.check_again))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val screenPadding = if(WireGuardAutoTunnel.isRunningOnAndroidTv(context)) 5.dp else 15.dp
|
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.Start,
|
horizontalAlignment = Alignment.Start,
|
||||||
verticalArrangement = Arrangement.Top,
|
verticalArrangement = Arrangement.Top,
|
||||||
modifier = if(WireGuardAutoTunnel.isRunningOnAndroidTv(context)) Modifier
|
modifier = Modifier.padding(15.dp)
|
||||||
.fillMaxHeight(.85f)
|
|
||||||
.fillMaxWidth()
|
|
||||||
.verticalScroll(scrollState)
|
|
||||||
.clickable(indication = null, interactionSource = interactionSource) {
|
|
||||||
focusManager.clearFocus()
|
|
||||||
}
|
|
||||||
.padding(padding) else Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.verticalScroll(scrollState)
|
|
||||||
.clickable(indication = null, interactionSource = interactionSource) {
|
|
||||||
focusManager.clearFocus()
|
|
||||||
}
|
|
||||||
.padding(padding)
|
|
||||||
) {
|
) {
|
||||||
Row(
|
SectionTitle(title = stringResource(id = R.string.auto_tunneling), padding = screenPadding)
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(screenPadding),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
|
||||||
) {
|
|
||||||
Text(stringResource(R.string.enable_auto_tunnel))
|
|
||||||
Switch(
|
|
||||||
modifier = Modifier.focusRequester(focusRequester),
|
|
||||||
enabled = !settings.isAlwaysOnVpnEnabled,
|
|
||||||
checked = settings.isAutoTunnelEnabled,
|
|
||||||
onCheckedChange = {
|
|
||||||
scope.launch {
|
|
||||||
viewModel.toggleAutoTunnel()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Text(
|
|
||||||
stringResource(id = R.string.select_tunnel),
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(screenPadding, bottom = 5.dp, top = 5.dp)
|
|
||||||
)
|
|
||||||
ExposedDropdownMenuBox(
|
|
||||||
expanded = expanded,
|
|
||||||
onExpandedChange = {
|
|
||||||
if(!(settings.isAutoTunnelEnabled || settings.isAlwaysOnVpnEnabled)) {
|
|
||||||
expanded = !expanded }},
|
|
||||||
modifier = Modifier.padding(start = 15.dp, top = 5.dp, bottom = 10.dp).clickable {
|
|
||||||
expanded = !expanded
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
TextField(
|
|
||||||
enabled = !(settings.isAutoTunnelEnabled || settings.isAlwaysOnVpnEnabled),
|
|
||||||
value = settings.defaultTunnel?.let {
|
|
||||||
TunnelConfig.from(it).name }
|
|
||||||
?: "",
|
|
||||||
readOnly = true,
|
|
||||||
modifier = Modifier.menuAnchor(),
|
|
||||||
label = { Text(stringResource(R.string.tunnels)) },
|
|
||||||
onValueChange = { },
|
|
||||||
trailingIcon = {
|
|
||||||
ExposedDropdownMenuDefaults.TrailingIcon(
|
|
||||||
expanded = expanded
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
ExposedDropdownMenu(
|
|
||||||
expanded = expanded,
|
|
||||||
onDismissRequest = {
|
|
||||||
expanded = false
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
tunnels.forEach() { tunnel ->
|
|
||||||
DropdownMenuItem(
|
|
||||||
onClick = {
|
|
||||||
scope.launch {
|
|
||||||
viewModel.onDefaultTunnelSelected(tunnel)
|
|
||||||
}
|
|
||||||
expanded = false
|
|
||||||
},
|
|
||||||
text = { Text(text = tunnel.name) }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.trusted_ssid),
|
stringResource(R.string.trusted_ssid),
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
|
@ -339,11 +244,19 @@ fun SettingsScreen(
|
||||||
verticalArrangement = Arrangement.SpaceEvenly
|
verticalArrangement = Arrangement.SpaceEvenly
|
||||||
) {
|
) {
|
||||||
trustedSSIDs.forEach { ssid ->
|
trustedSSIDs.forEach { ssid ->
|
||||||
ClickableIconButton(onIconClick = {
|
ClickableIconButton(
|
||||||
|
onIconClick = {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
viewModel.onDeleteTrustedSSID(ssid)
|
viewModel.onDeleteTrustedSSID(ssid)
|
||||||
}
|
}
|
||||||
}, text = ssid, icon = Icons.Filled.Close, enabled = !(settings.isAutoTunnelEnabled || settings.isAlwaysOnVpnEnabled))
|
},
|
||||||
|
text = ssid,
|
||||||
|
icon = Icons.Filled.Close,
|
||||||
|
enabled = !(settings.isAutoTunnelEnabled || settings.isAlwaysOnVpnEnabled)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if(trustedSSIDs.isEmpty()) {
|
||||||
|
Text(stringResource(R.string.none), fontStyle = FontStyle.Italic, color = Color.Gray)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
|
@ -351,7 +264,7 @@ fun SettingsScreen(
|
||||||
value = currentText,
|
value = currentText,
|
||||||
onValueChange = { currentText = it },
|
onValueChange = { currentText = it },
|
||||||
label = { Text(stringResource(R.string.add_trusted_ssid)) },
|
label = { Text(stringResource(R.string.add_trusted_ssid)) },
|
||||||
modifier = Modifier.padding(start = screenPadding, top = 5.dp),
|
modifier = Modifier.padding(start = screenPadding, top = 5.dp).focusRequester(focusRequester),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
keyboardOptions = KeyboardOptions(
|
keyboardOptions = KeyboardOptions(
|
||||||
capitalization = KeyboardCapitalization.None,
|
capitalization = KeyboardCapitalization.None,
|
||||||
|
@ -369,59 +282,74 @@ fun SettingsScreen(
|
||||||
contentDescription = if (currentText == "") stringResource(id = R.string.trusted_ssid_empty_description) else stringResource(
|
contentDescription = if (currentText == "") stringResource(id = R.string.trusted_ssid_empty_description) else stringResource(
|
||||||
id = R.string.trusted_ssid_value_description
|
id = R.string.trusted_ssid_value_description
|
||||||
),
|
),
|
||||||
tint = if(currentText == "") Color.Transparent else Color.Green
|
tint = if (currentText == "") Color.Transparent else MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
Row(
|
ConfigurationToggle(stringResource(R.string.tunnel_mobile_data),
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(screenPadding),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
|
||||||
) {
|
|
||||||
Text(stringResource(R.string.tunnel_mobile_data))
|
|
||||||
Switch(
|
|
||||||
enabled = !(settings.isAutoTunnelEnabled || settings.isAlwaysOnVpnEnabled),
|
enabled = !(settings.isAutoTunnelEnabled || settings.isAlwaysOnVpnEnabled),
|
||||||
checked = settings.isTunnelOnMobileDataEnabled,
|
checked = settings.isTunnelOnMobileDataEnabled,
|
||||||
onCheckedChange = {
|
padding = screenPadding,
|
||||||
|
onCheckChanged = {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
viewModel.onToggleTunnelOnMobileData()
|
viewModel.onToggleTunnelOnMobileData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
ConfigurationToggle(stringResource(id = R.string.tunnel_on_ethernet),
|
||||||
Row(
|
enabled = !(settings.isAutoTunnelEnabled || settings.isAlwaysOnVpnEnabled),
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(screenPadding),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
|
||||||
) {
|
|
||||||
Text("Tunnel on Ethernet")
|
|
||||||
Switch(
|
|
||||||
enabled = !settings.isAutoTunnelEnabled,
|
|
||||||
checked = settings.isTunnelOnEthernetEnabled,
|
checked = settings.isTunnelOnEthernetEnabled,
|
||||||
onCheckedChange = {
|
padding = screenPadding,
|
||||||
|
onCheckChanged = {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
viewModel.onToggleTunnelOnEthernet()
|
viewModel.onToggleTunnelOnEthernet()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
ConfigurationToggle(stringResource(R.string.enable_auto_tunnel),
|
||||||
|
enabled = !settings.isAlwaysOnVpnEnabled,
|
||||||
|
checked = settings.isAutoTunnelEnabled,
|
||||||
|
padding = screenPadding,
|
||||||
|
onCheckChanged = {
|
||||||
|
if(!isAllAutoTunnelPermissionsEnabled()) {
|
||||||
|
val message = if(viewModel.isLocationServicesNeeded()){
|
||||||
|
"Location services required"
|
||||||
|
} else if(!isBackgroundLocationGranted){
|
||||||
|
"Background location required"
|
||||||
|
} else {
|
||||||
|
"Precise location required"
|
||||||
}
|
}
|
||||||
Row(
|
showSnackbarMessage(message)
|
||||||
modifier = Modifier
|
} else scope.launch {
|
||||||
.fillMaxWidth()
|
viewModel.toggleAutoTunnel()
|
||||||
.padding(screenPadding),
|
}
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
}
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(!WireGuardAutoTunnel.isRunningOnAndroidTv(context)) {
|
||||||
|
Surface(
|
||||||
|
tonalElevation = 2.dp,
|
||||||
|
shadowElevation = 2.dp,
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
color = MaterialTheme.colorScheme.surface,
|
||||||
|
modifier = Modifier.fillMaxWidth(fillMaxWidth)
|
||||||
|
.height(IntrinsicSize.Min)
|
||||||
|
.padding(bottom = 180.dp)
|
||||||
) {
|
) {
|
||||||
Text(stringResource(R.string.always_on_vpn_support))
|
Column(
|
||||||
Switch(
|
horizontalAlignment = Alignment.Start,
|
||||||
|
verticalArrangement = Arrangement.Top,
|
||||||
|
modifier = Modifier.padding(15.dp)
|
||||||
|
) {
|
||||||
|
SectionTitle(title = stringResource(id = R.string.other), padding = screenPadding)
|
||||||
|
ConfigurationToggle(stringResource(R.string.always_on_vpn_support),
|
||||||
enabled = !settings.isAutoTunnelEnabled,
|
enabled = !settings.isAutoTunnelEnabled,
|
||||||
checked = settings.isAlwaysOnVpnEnabled,
|
checked = settings.isAlwaysOnVpnEnabled,
|
||||||
onCheckedChange = {
|
padding = screenPadding,
|
||||||
|
onCheckChanged = {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
viewModel.onToggleAlwaysOnVPN()
|
viewModel.onToggleAlwaysOnVPN()
|
||||||
}
|
}
|
||||||
|
@ -430,5 +358,10 @@ fun SettingsScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(WireGuardAutoTunnel.isRunningOnAndroidTv(context)) {
|
||||||
|
Spacer(modifier = Modifier.weight(.17f))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,22 +3,20 @@ package com.zaneschepke.wireguardautotunnel.ui.screens.settings
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.location.LocationManager
|
import android.location.LocationManager
|
||||||
|
import android.os.Build
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.TunnelConfigDao
|
import com.zaneschepke.wireguardautotunnel.repository.TunnelConfigDao
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.Settings
|
import com.zaneschepke.wireguardautotunnel.repository.model.Settings
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.ViewState
|
import com.zaneschepke.wireguardautotunnel.util.WgTunnelException
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asSharedFlow
|
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
|
||||||
import kotlinx.coroutines.flow.filter
|
import kotlinx.coroutines.flow.filter
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -34,11 +32,8 @@ class SettingsViewModel @Inject constructor(private val application : Applicatio
|
||||||
private val _settings = MutableStateFlow(Settings())
|
private val _settings = MutableStateFlow(Settings())
|
||||||
val settings get() = _settings.asStateFlow()
|
val settings get() = _settings.asStateFlow()
|
||||||
val tunnels get() = tunnelRepo.getAllFlow()
|
val tunnels get() = tunnelRepo.getAllFlow()
|
||||||
private val _viewState = MutableStateFlow(ViewState())
|
|
||||||
val viewState get() = _viewState.asStateFlow()
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
checkLocationServicesEnabled()
|
isLocationServicesEnabled()
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
settingsRepo.getAllFlow().filter { it.isNotEmpty() }.collect {
|
settingsRepo.getAllFlow().filter { it.isNotEmpty() }.collect {
|
||||||
val settings = it.first()
|
val settings = it.first()
|
||||||
|
@ -54,16 +49,10 @@ class SettingsViewModel @Inject constructor(private val application : Applicatio
|
||||||
_settings.value.trustedNetworkSSIDs.add(trimmed)
|
_settings.value.trustedNetworkSSIDs.add(trimmed)
|
||||||
settingsRepo.save(_settings.value)
|
settingsRepo.save(_settings.value)
|
||||||
} else {
|
} else {
|
||||||
showSnackBarMessage("SSID already exists.")
|
throw WgTunnelException("SSID already exists.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun onDefaultTunnelSelected(tunnelConfig: TunnelConfig) {
|
|
||||||
settingsRepo.save(_settings.value.copy(
|
|
||||||
defaultTunnel = tunnelConfig.toString()
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun onToggleTunnelOnMobileData() {
|
suspend fun onToggleTunnelOnMobileData() {
|
||||||
settingsRepo.save(_settings.value.copy(
|
settingsRepo.save(_settings.value.copy(
|
||||||
isTunnelOnMobileDataEnabled = !_settings.value.isTunnelOnMobileDataEnabled
|
isTunnelOnMobileDataEnabled = !_settings.value.isTunnelOnMobileDataEnabled
|
||||||
|
@ -75,68 +64,65 @@ class SettingsViewModel @Inject constructor(private val application : Applicatio
|
||||||
settingsRepo.save(_settings.value)
|
settingsRepo.save(_settings.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun toggleAutoTunnel() {
|
private fun emitFirstTunnelAsDefault() = viewModelScope.async {
|
||||||
if(_settings.value.defaultTunnel.isNullOrEmpty() && !_settings.value.isAutoTunnelEnabled) {
|
_settings.emit(_settings.value.copy(defaultTunnel = getFirstTunnelConfig().toString()))
|
||||||
showSnackBarMessage(application.getString(R.string.select_tunnel_message))
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun toggleAutoTunnel() {
|
||||||
if(_settings.value.isAutoTunnelEnabled) {
|
if(_settings.value.isAutoTunnelEnabled) {
|
||||||
ServiceManager.stopWatcherService(application)
|
ServiceManager.stopWatcherService(application)
|
||||||
} else {
|
} else {
|
||||||
if(_settings.value.defaultTunnel != null) {
|
if(_settings.value.defaultTunnel == null) {
|
||||||
|
emitFirstTunnelAsDefault().await()
|
||||||
|
}
|
||||||
val defaultTunnel = _settings.value.defaultTunnel
|
val defaultTunnel = _settings.value.defaultTunnel
|
||||||
ServiceManager.startWatcherService(application, defaultTunnel!!)
|
ServiceManager.startWatcherService(application, defaultTunnel!!)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
settingsRepo.save(_settings.value.copy(
|
settingsRepo.save(_settings.value.copy(
|
||||||
isAutoTunnelEnabled = !_settings.value.isAutoTunnelEnabled
|
isAutoTunnelEnabled = !_settings.value.isAutoTunnelEnabled
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun showSnackBarMessage(message : String) {
|
private suspend fun getFirstTunnelConfig() : TunnelConfig {
|
||||||
_viewState.emit(_viewState.value.copy(
|
return tunnelRepo.getAll().first();
|
||||||
showSnackbarMessage = true,
|
|
||||||
snackbarMessage = message,
|
|
||||||
snackbarActionText = "Okay",
|
|
||||||
onSnackbarActionClick = {
|
|
||||||
viewModelScope.launch {
|
|
||||||
dismissSnackBar()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun dismissSnackBar() {
|
|
||||||
_viewState.emit(_viewState.value.copy(
|
|
||||||
showSnackbarMessage = false
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun onToggleAlwaysOnVPN() {
|
suspend fun onToggleAlwaysOnVPN() {
|
||||||
if(_settings.value.defaultTunnel != null) {
|
if(_settings.value.defaultTunnel == null) {
|
||||||
_settings.emit(
|
emitFirstTunnelAsDefault().await()
|
||||||
_settings.value.copy(isAlwaysOnVpnEnabled = !_settings.value.isAlwaysOnVpnEnabled)
|
|
||||||
)
|
|
||||||
settingsRepo.save(_settings.value)
|
|
||||||
} else {
|
|
||||||
showSnackBarMessage(application.getString(R.string.select_tunnel_message))
|
|
||||||
}
|
}
|
||||||
|
val updatedSettings = _settings.value.copy(isAlwaysOnVpnEnabled = !_settings.value.isAlwaysOnVpnEnabled)
|
||||||
|
emitSettings(updatedSettings)
|
||||||
|
saveSettings(updatedSettings)
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun emitSettings(settings: Settings) {
|
||||||
|
_settings.emit(
|
||||||
|
settings
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun saveSettings(settings: Settings) {
|
||||||
|
settingsRepo.save(settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun onToggleTunnelOnEthernet() {
|
suspend fun onToggleTunnelOnEthernet() {
|
||||||
if(_settings.value.defaultTunnel != null) {
|
if(_settings.value.defaultTunnel == null) {
|
||||||
|
emitFirstTunnelAsDefault().await()
|
||||||
|
}
|
||||||
_settings.emit(
|
_settings.emit(
|
||||||
_settings.value.copy(isTunnelOnEthernetEnabled = !_settings.value.isTunnelOnEthernetEnabled)
|
_settings.value.copy(isTunnelOnEthernetEnabled = !_settings.value.isTunnelOnEthernetEnabled)
|
||||||
)
|
)
|
||||||
settingsRepo.save(_settings.value)
|
settingsRepo.save(_settings.value)
|
||||||
} else {
|
|
||||||
showSnackBarMessage(application.getString(R.string.select_tunnel_message))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun checkLocationServicesEnabled() : Boolean {
|
private fun isLocationServicesEnabled() : Boolean {
|
||||||
val locationManager =
|
val locationManager =
|
||||||
application.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
application.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||||
return locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
|
return locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isLocationServicesNeeded() : Boolean {
|
||||||
|
return(!isLocationServicesEnabled() && Build.VERSION.SDK_INT > Build.VERSION_CODES.P)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.support
|
package com.zaneschepke.wireguardautotunnel.ui.screens.support
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.focusable
|
import androidx.compose.foundation.focusable
|
||||||
|
@ -19,8 +18,6 @@ import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
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.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
|
|
@ -8,11 +8,16 @@ import java.time.Instant
|
||||||
object NumberUtils {
|
object NumberUtils {
|
||||||
|
|
||||||
private const val BYTES_IN_KB = 1024L
|
private const val BYTES_IN_KB = 1024L
|
||||||
|
private val keyValidationRegex = """^[A-Za-z0-9+/]{42}[AEIMQUYcgkosw480]=${'$'}""".toRegex()
|
||||||
|
|
||||||
fun bytesToKB(bytes : Long) : BigDecimal {
|
fun bytesToKB(bytes : Long) : BigDecimal {
|
||||||
return bytes.toBigDecimal().divide(BYTES_IN_KB.toBigDecimal())
|
return bytes.toBigDecimal().divide(BYTES_IN_KB.toBigDecimal())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isValidKey(key : String) : Boolean {
|
||||||
|
return key.matches(keyValidationRegex)
|
||||||
|
}
|
||||||
|
|
||||||
fun generateRandomTunnelName() : String {
|
fun generateRandomTunnelName() : String {
|
||||||
return "tunnel${(Math.random() * 100000).toInt()}"
|
return "tunnel${(Math.random() * 100000).toInt()}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,9 @@
|
||||||
<string name="notification_permission_required">Notifications permission is required for the app to work properly.</string>
|
<string name="notification_permission_required">Notifications permission is required for the app to work properly.</string>
|
||||||
<string name="open_settings">Open Settings</string>
|
<string name="open_settings">Open Settings</string>
|
||||||
<string name="add_trusted_ssid">Add Trusted SSID</string>
|
<string name="add_trusted_ssid">Add Trusted SSID</string>
|
||||||
<string name="trusted_ssid">Trusted SSID</string>
|
<string name="trusted_ssid">Trusted SSIDs</string>
|
||||||
<string name="tunnels">Tunnels</string>
|
<string name="tunnels">Tunnels</string>
|
||||||
<string name="select_tunnel">Select Tunnel</string>
|
<string name="enable_auto_tunnel">Enable auto-tunneling</string>
|
||||||
<string name="enable_auto_tunnel">Enable auto tunneling</string>
|
|
||||||
<string name="tunnel_mobile_data">Tunnel on mobile data</string>
|
<string name="tunnel_mobile_data">Tunnel on mobile data</string>
|
||||||
<string name="background_location_reason">\"Allow all the time\" location permission is required for retrieving Wi-Fi SSID in the background. Permission is needed for this feature.</string>
|
<string name="background_location_reason">\"Allow all the time\" location permission is required for retrieving Wi-Fi SSID in the background. Permission is needed for this feature.</string>
|
||||||
<string name="location_permission_reason">Location permission is required for this feature to work properly.</string>
|
<string name="location_permission_reason">Location permission is required for this feature to work properly.</string>
|
||||||
|
@ -32,6 +31,7 @@
|
||||||
<string name="retry">"Retry"</string>
|
<string name="retry">"Retry"</string>
|
||||||
<string name="privacy_policy">View Privacy Policy</string>
|
<string name="privacy_policy">View Privacy Policy</string>
|
||||||
<string name="okay">Okay</string>
|
<string name="okay">Okay</string>
|
||||||
|
<string name="tunnel_on_ethernet">Tunnel on ethernet</string>
|
||||||
<string name="prominent_background_location_message">This feature requires background location permission to enable Wi-Fi SSID monitoring even while the application is closed. For more details, please see the Privacy Policy linked on the Support screen.</string>
|
<string name="prominent_background_location_message">This feature requires background location permission to enable Wi-Fi SSID monitoring even while the application is closed. For more details, please see the Privacy Policy linked on the Support screen.</string>
|
||||||
<string name="prominent_background_location_title">Background Location Disclosure</string>
|
<string name="prominent_background_location_title">Background Location Disclosure</string>
|
||||||
<string name="support_text">Thank you for using WG Tunnel! If you are experiencing issues with the app, please reach out on Discord or create an issue on Github. I will try to address the issue as quickly as possible. Thank you!</string>
|
<string name="support_text">Thank you for using WG Tunnel! If you are experiencing issues with the app, please reach out on Discord or create an issue on Github. I will try to address the issue as quickly as possible. Thank you!</string>
|
||||||
|
@ -51,7 +51,7 @@
|
||||||
<string name="include">Include</string>
|
<string name="include">Include</string>
|
||||||
<string name="tunnel_all">Tunnel all applications</string>
|
<string name="tunnel_all">Tunnel all applications</string>
|
||||||
<string name="config_changes_saved">Configuration changes saved.</string>
|
<string name="config_changes_saved">Configuration changes saved.</string>
|
||||||
<string name="save_changes">Save changes</string>
|
<string name="save_changes">Save</string>
|
||||||
<string name="icon">Icon</string>
|
<string name="icon">Icon</string>
|
||||||
<string name="no_thanks">No thanks</string>
|
<string name="no_thanks">No thanks</string>
|
||||||
<string name="turn_on">Turn on</string>
|
<string name="turn_on">Turn on</string>
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
<string name="failed_connection_to">Failed connection to -</string>
|
<string name="failed_connection_to">Failed connection to -</string>
|
||||||
<string name="initial_connection_failure_message">Attempting to connect to server after 30 seconds of no response.</string>
|
<string name="initial_connection_failure_message">Attempting to connect to server after 30 seconds of no response.</string>
|
||||||
<string name="lost_connection_failure_message">Attempting to reconnect to server after more than one minute of no response.</string>
|
<string name="lost_connection_failure_message">Attempting to reconnect to server after more than one minute of no response.</string>
|
||||||
<string name="always_on_vpn_support">Enable Always-On VPN support</string>
|
<string name="always_on_vpn_support">Allow Always-On VPN </string>
|
||||||
<string name="select_tunnel_message">Please select a tunnel first</string>
|
<string name="select_tunnel_message">Please select a tunnel first</string>
|
||||||
<string name="location_services_not_detected">Unable to detect Location Services which are required for this feature. Please enable Location Services.</string>
|
<string name="location_services_not_detected">Unable to detect Location Services which are required for this feature. Please enable Location Services.</string>
|
||||||
<string name="check_again">Check again</string>
|
<string name="check_again">Check again</string>
|
||||||
|
@ -97,4 +97,31 @@
|
||||||
<string name="stream_failed">Failed to open file stream.</string>
|
<string name="stream_failed">Failed to open file stream.</string>
|
||||||
<string name="unknown_error_message">An unknown error occurred.</string>
|
<string name="unknown_error_message">An unknown error occurred.</string>
|
||||||
<string name="no_file_app">No file app installed.</string>
|
<string name="no_file_app">No file app installed.</string>
|
||||||
|
<string name="other">Other</string>
|
||||||
|
<string name="auto_tunneling">Auto-tunneling</string>
|
||||||
|
<string name="select_tunnel">Select tunnel to use</string>
|
||||||
|
<string name="vpn_on">VPN on</string>
|
||||||
|
<string name="vpn_off">VPN off</string>
|
||||||
|
<string name="default_vpn_on">Primary VPN on</string>
|
||||||
|
<string name="default_vpn_off">Primary VPN off</string>
|
||||||
|
<string name="create_import">Create from scratch</string>
|
||||||
|
<string name="set_primary">Set primary</string>
|
||||||
|
<string name="turn_off_auto">Action requires auto-tunnel disabled</string>
|
||||||
|
<string name="add_peer">Add peer</string>
|
||||||
|
<string name="info">Info</string>
|
||||||
|
<string name="done">Done</string>
|
||||||
|
<string name="interface_">Interface</string>
|
||||||
|
<string name="rotate_keys">Rotate keys</string>
|
||||||
|
<string name="private_key">Private key</string>
|
||||||
|
<string name="copy_public_key">Copy public key</string>
|
||||||
|
<string name="base64_key">base64 key</string>
|
||||||
|
<string name="comma_separated_list">comma separated list</string>
|
||||||
|
<string name="listen_port">Listen port</string>
|
||||||
|
<string name="random">(random)</string>
|
||||||
|
<string name="auto">(auto)</string>
|
||||||
|
<string name="optional">(optional)</string>
|
||||||
|
<string name="optional_no_recommend">(optional, not recommended)</string>
|
||||||
|
<string name="preshared_key">Pre-shared key</string>
|
||||||
|
<string name="seconds">seconds</string>
|
||||||
|
<string name="persistent_keepalive">Persistent keepalive</string>
|
||||||
</resources>
|
</resources>
|
|
@ -0,0 +1,32 @@
|
||||||
|
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<shortcut
|
||||||
|
android:shortcutId="defaultOn1"
|
||||||
|
android:enabled="true"
|
||||||
|
android:icon="@drawable/vpn_on"
|
||||||
|
android:shortcutShortLabel="@string/vpn_on"
|
||||||
|
android:shortcutLongLabel="@string/default_vpn_on"
|
||||||
|
android:shortcutDisabledMessage="@string/vpn_on">
|
||||||
|
<intent
|
||||||
|
android:action="START"
|
||||||
|
android:targetPackage="com.zaneschepke.wireguardautotunnel"
|
||||||
|
android:targetClass="com.zaneschepke.wireguardautotunnel.service.shortcut.ShortcutsActivity">
|
||||||
|
<extra android:name="className" android:value="WireGuardTunnelService" />
|
||||||
|
</intent>
|
||||||
|
<capability-binding android:key="actions.intent.START" />
|
||||||
|
</shortcut>
|
||||||
|
<shortcut
|
||||||
|
android:shortcutId="defaultOff1"
|
||||||
|
android:enabled="true"
|
||||||
|
android:icon="@drawable/vpn_off"
|
||||||
|
android:shortcutShortLabel="@string/vpn_off"
|
||||||
|
android:shortcutLongLabel="@string/default_vpn_off"
|
||||||
|
android:shortcutDisabledMessage="@string/vpn_off">
|
||||||
|
<intent
|
||||||
|
android:action="STOP"
|
||||||
|
android:targetPackage="com.zaneschepke.wireguardautotunnel"
|
||||||
|
android:targetClass="com.zaneschepke.wireguardautotunnel.service.shortcut.ShortcutsActivity">
|
||||||
|
<extra android:name="className" android:value="WireGuardTunnelService" />
|
||||||
|
</intent>
|
||||||
|
<capability-binding android:key="actions.intent.STOP" />
|
||||||
|
</shortcut>
|
||||||
|
</shortcuts>
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 0 B |
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 0 B |
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 101 KiB |
After Width: | Height: | Size: 154 KiB |
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 52 KiB |
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 0 B |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 0 B |
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 99 KiB |
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 89 KiB |
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 0 B |
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 88 KiB |
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 88 KiB |
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 0 B |
Before Width: | Height: | Size: 238 KiB After Width: | Height: | Size: 0 B |
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 101 KiB |
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 52 KiB |
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 99 KiB |
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 88 KiB |
|
@ -6,25 +6,25 @@ appcompat = "1.6.1"
|
||||||
coreKtx = "1.12.0"
|
coreKtx = "1.12.0"
|
||||||
espressoCore = "3.5.1"
|
espressoCore = "3.5.1"
|
||||||
firebase-crashlytics-gradle = "2.9.9"
|
firebase-crashlytics-gradle = "2.9.9"
|
||||||
google-services = "4.3.15"
|
google-services = "4.4.0"
|
||||||
hiltAndroid = "2.48"
|
hiltAndroid = "2.48"
|
||||||
hiltNavigationCompose = "1.0.0"
|
hiltNavigationCompose = "1.0.0"
|
||||||
junit = "4.13.2"
|
junit = "4.13.2"
|
||||||
kotlinx-serialization-json = "1.5.1"
|
kotlinx-serialization-json = "1.5.1"
|
||||||
lifecycle-runtime-compose = "2.6.2"
|
lifecycle-runtime-compose = "2.6.2"
|
||||||
material-icons-extended = "1.5.1"
|
material-icons-extended = "1.5.2"
|
||||||
material3 = "1.1.1"
|
material3 = "1.1.2"
|
||||||
navigationCompose = "2.7.2"
|
navigationCompose = "2.7.3"
|
||||||
roomVersion = "2.6.0-beta01"
|
roomVersion = "2.6.0-rc01"
|
||||||
timber = "5.0.1"
|
timber = "5.0.1"
|
||||||
tunnel = "1.0.20230706"
|
tunnel = "1.0.20230706"
|
||||||
androidGradlePlugin = "8.2.0-beta03"
|
androidGradlePlugin = "8.3.0-alpha06"
|
||||||
kotlin="1.9.10"
|
kotlin="1.9.10"
|
||||||
ksp="1.9.10-1.0.13"
|
ksp="1.9.10-1.0.13"
|
||||||
composeBom="2023.09.00"
|
composeBom="2023.09.02"
|
||||||
firebaseBom="32.2.3"
|
firebaseBom="32.3.1"
|
||||||
compose="1.5.1"
|
compose="1.5.2"
|
||||||
crashlytics="18.4.1"
|
crashlytics="18.4.3"
|
||||||
analytics="21.3.0"
|
analytics="21.3.0"
|
||||||
composeCompiler="1.5.3"
|
composeCompiler="1.5.3"
|
||||||
zxingAndroidEmbedded = "4.3.0"
|
zxingAndroidEmbedded = "4.3.0"
|
||||||
|
@ -38,6 +38,7 @@ accompanist-flowlayout = { module = "com.google.accompanist:accompanist-flowlayo
|
||||||
accompanist-navigation-animation = { module = "com.google.accompanist:accompanist-navigation-animation", version.ref = "accompanist" }
|
accompanist-navigation-animation = { module = "com.google.accompanist:accompanist-navigation-animation", version.ref = "accompanist" }
|
||||||
accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanist" }
|
accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanist" }
|
||||||
accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" }
|
accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" }
|
||||||
|
|
||||||
#room
|
#room
|
||||||
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "roomVersion" }
|
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "roomVersion" }
|
||||||
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "roomVersion" }
|
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "roomVersion" }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#Mon Apr 24 22:46:45 EDT 2023
|
#Mon Apr 24 22:46:45 EDT 2023
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-rc-2-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|