@ -87,8 +87,6 @@ class App : Application(), libtailscale.AppContext {
}
val dns = DnsConfig ( )
var autoConnect = false
var vpnReady = false
private lateinit var connectivityManager : ConnectivityManager
private lateinit var app : libtailscale . Application
@ -124,7 +122,7 @@ class App : Application(), libtailscale.AppContext {
FILE _CHANNEL _ID , " File transfers " , NotificationManagerCompat . IMPORTANCE _DEFAULT )
appInstance = this
applicationScope . launch {
Notifier . tile Ready. collect { isTileReady -> setTileReady ( isTileReady ) }
Notifier . tile Active. collect { isTileReadyToBeActive -> setTileActive ( isTileReadyToBeActive ) }
}
}
@ -137,7 +135,7 @@ class App : Application(), libtailscale.AppContext {
fun setWantRunning ( wantRunning : Boolean ) {
val callback : ( Result < Ipn . Prefs > ) -> Unit = { result ->
result . fold (
onSuccess = { _ -> setTileStatus ( wantRunning ) } ,
onSuccess = { } ,
onFailure = { error ->
Log . d ( " TAG " , " Set want running: failed to update preferences: ${error.message} " )
} )
@ -187,11 +185,6 @@ class App : Application(), libtailscale.AppContext {
startService ( intent )
}
fun stopVPN ( ) {
val intent = Intent ( this , IPNService :: class . java )
intent . setAction ( IPNService . ACTION _STOP _VPN )
startService ( intent )
}
// encryptToPref a byte array of data using the Jetpack Security
// library and writes it to a global encrypted preference store.
@ -219,19 +212,17 @@ class App : Application(), libtailscale.AppContext {
EncryptedSharedPreferences . PrefValueEncryptionScheme . AES256 _GCM )
}
fun setTileReady ( ready : Boolean ) {
fun setTileActive ( ready : Boolean ) {
if ( Build . VERSION . SDK _INT < Build . VERSION_CODES . N ) {
return
}
QuickToggleService . setReady ( this , ready )
Log . d ( " App " , " Set Tile Ready: ready= $ready , autoConnect= $autoConnect " )
vpnReady = ready
if ( ready && autoConnect ) {
Log . d ( " App " , " Set Tile Ready: $ready " )
if ( ready ) {
startVPN ( )
}
}
fun setTileStatus ( status : Boolean ) {
QuickToggleService . setStatus ( this , status )
}
fun getHostname ( ) : String {
val userConfiguredDeviceName = getUserConfiguredDeviceName ( )
if ( ! userConfiguredDeviceName . isNullOrEmpty ( ) ) return userConfiguredDeviceName