android: add ExitNodeAllowLANAccess toggle in exit node picker (#241)

Updates ENG-3011

Just like on iOS, we should show a switch to toggle the ExitNodeAllowLANAccess preference.

Signed-off-by: Andrea Gottardo <andrea@gottardo.me>
pull/244/head
Andrea Gottardo 2 months ago committed by GitHub
parent 28d0ab4dd6
commit bf74edd551
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -42,7 +42,7 @@ class Ipn {
var LocalTCPPort: Int? = null,
var IncomingFiles: List<PartialFile>? = null,
var ClientVersion: Tailcfg.ClientVersion? = null,
var TailFSShares: Map<String, String>? = null,
var TailFSShares: List<String>? = null,
)
@Serializable

@ -109,6 +109,8 @@ fun ExitNodePicker(
})
}
}
item("allowLANAccessToggle") { SettingRow(model.allowLANAccessSetting) }
}
}
}

@ -210,7 +210,7 @@ fun SettingsButton(user: IpnLocal.LoginProfile?, action: () -> Unit) {
fun StartingView() {
// (jonathan) TODO: On iOS this is the game-of-life Tailscale animation.
Column(
modifier = Modifier.fillMaxSize().background(MaterialTheme.colorScheme.background),
modifier = Modifier.fillMaxSize().background(MaterialTheme.colorScheme.secondaryContainer),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally) {
Text(

@ -43,10 +43,7 @@ class DNSSettingsViewModel() : IpnViewModel() {
isOn = MutableStateFlow(Notifier.prefs.value?.CorpDNS),
onToggle = {
LoadingIndicator.start()
toggleCorpDNS {
LoadingIndicator.stop()
// (jonathan) TODO: Error handling
}
toggleCorpDNS { LoadingIndicator.stop() }
})
init {

@ -6,6 +6,7 @@ package com.tailscale.ipn.ui.viewModel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.tailscale.ipn.R
import com.tailscale.ipn.ui.localapi.Client
import com.tailscale.ipn.ui.model.Ipn
import com.tailscale.ipn.ui.model.StableNodeID
@ -51,7 +52,18 @@ class ExitNodePickerViewModel(private val nav: ExitNodePickerNav) : IpnViewModel
MutableStateFlow(TreeMap())
val mullvadBestAvailableByCountry: StateFlow<Map<String, ExitNode>> = MutableStateFlow(TreeMap())
val anyActive: StateFlow<Boolean> = MutableStateFlow(false)
val isRunningExitNode: StateFlow<Boolean> = MutableStateFlow(false)
val isRunningExitNode: StateFlow<Boolean> = MutableStateFlow(false)
val allowLANAccessSetting =
Setting(
R.string.allow_lan_access,
SettingType.SWITCH,
isOn = MutableStateFlow(Notifier.prefs.value?.ExitNodeAllowLANAccess),
enabled = MutableStateFlow(true),
onToggle = {
LoadingIndicator.start()
toggleAllowLANAccess { LoadingIndicator.stop() }
})
init {
viewModelScope.launch {
@ -59,7 +71,7 @@ class ExitNodePickerViewModel(private val nav: ExitNodePickerNav) : IpnViewModel
.combine(Notifier.prefs) { netmap, prefs -> Pair(netmap, prefs) }
.stateIn(viewModelScope)
.collect { (netmap, prefs) ->
isRunningExitNode.set(prefs?.let { AdvertisedRoutesHelper.exitNodeOnFromPrefs(it) })
isRunningExitNode.set(prefs?.let { AdvertisedRoutesHelper.exitNodeOnFromPrefs(it) })
val exitNodeId = prefs?.ExitNodeID
netmap?.Peers?.let { peers ->
val allNodes =
@ -137,4 +149,17 @@ class ExitNodePickerViewModel(private val nav: ExitNodePickerNav) : IpnViewModel
LoadingIndicator.stop()
}
}
fun toggleAllowLANAccess(callback: (Result<Ipn.Prefs>) -> Unit) {
val prefs =
Notifier.prefs.value
?: run {
callback(Result.failure(Exception("no prefs")))
return@toggleAllowLANAccess
}
val prefsOut = Ipn.MaskedPrefs()
prefsOut.ExitNodeAllowLANAccess = !prefs.ExitNodeAllowLANAccess
Client(viewModelScope).editPrefs(prefsOut, callback)
}
}

@ -124,5 +124,6 @@
<string name="tailscale_is_not_running_this_device_is_using_the_system_dns_resolver">Tailscale is not running. This device is using the system\'s DNS resolver.</string>
<string name="this_device_is_using_the_system_dns_resolver">This device is using the system DNS resolver.</string>
<string name="not_using_tailscale_dns">Not Using Tailscale DNS</string>
<string name="allow_lan_access">Allow LAN Access</string>
</resources>

Loading…
Cancel
Save