@ -13,6 +13,7 @@ import android.os.Bundle
import android.util.Log
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.compose.setContent
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContract
import androidx.activity.result.contract.ActivityResultContract
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavType
import androidx.navigation.NavType
@ -45,6 +46,7 @@ import kotlinx.coroutines.launch
class MainActivity : ComponentActivity ( ) {
class MainActivity : ComponentActivity ( ) {
private var notifierScope : CoroutineScope ? = null
private var notifierScope : CoroutineScope ? = null
private lateinit var requestVpnPermission : ActivityResultLauncher < Unit >
override fun onCreate ( savedInstanceState : Bundle ? ) {
override fun onCreate ( savedInstanceState : Bundle ? ) {
super . onCreate ( savedInstanceState )
super . onCreate ( savedInstanceState )
@ -150,14 +152,15 @@ class MainActivity : ComponentActivity() {
val vpnIntent = VpnService . prepare ( this )
val vpnIntent = VpnService . prepare ( this )
if ( vpnIntent != null ) {
if ( vpnIntent != null ) {
val contract = VpnPermissionContract ( )
val contract = VpnPermissionContract ( )
registerForActivityResult ( contract ) { granted ->
requestVpnPermission =
Notifier . vpnPermissionGranted . set ( granted )
registerForActivityResult ( contract ) { granted ->
if ( granted ) {
Notifier . vpnPermissionGranted . set ( granted )
Log . i ( " VPN " , " VPN permission granted " )
Log . i ( " VPN " , " VPN permission ${if (granted) "granted" else "denied"} " )
} else {
}
Log . i ( " VPN " , " VPN permission not granted " )
requestVpnPermission . launch ( Unit )
}
} else {
}
Notifier . vpnPermissionGranted . set ( true )
Log . i ( " VPN " , " VPN permission granted " )
}
}
}
}
}
}