android: hide Accounts if VPN not prepared (#402)

Updates tailscale/tailscale#12148

Signed-off-by: kari-ts <kari@tailscale.com>
angott/l10n-it
kari-ts 2 years ago committed by GitHub
parent 9aa3a840de
commit 32e29c4efd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -44,6 +44,7 @@ fun SettingsView(settingsNav: SettingsNav, viewModel: SettingsViewModel = viewMo
val managedByOrganization = viewModel.managedByOrganization.collectAsState().value val managedByOrganization = viewModel.managedByOrganization.collectAsState().value
val tailnetLockEnabled = viewModel.tailNetLockEnabled.collectAsState().value val tailnetLockEnabled = viewModel.tailNetLockEnabled.collectAsState().value
val corpDNSEnabled = viewModel.corpDNSEnabled.collectAsState().value val corpDNSEnabled = viewModel.corpDNSEnabled.collectAsState().value
val isVPNPrepared = viewModel.vpnPrepared.collectAsState().value
val showTailnetLock = MDMSettings.manageTailnetLock.flow.collectAsState().value val showTailnetLock = MDMSettings.manageTailnetLock.flow.collectAsState().value
@ -52,10 +53,12 @@ fun SettingsView(settingsNav: SettingsNav, viewModel: SettingsViewModel = viewMo
Header(titleRes = R.string.settings_title, onBack = settingsNav.onNavigateBackHome) Header(titleRes = R.string.settings_title, onBack = settingsNav.onNavigateBackHome)
}) { innerPadding -> }) { innerPadding ->
Column(modifier = Modifier.padding(innerPadding).verticalScroll(rememberScrollState())) { Column(modifier = Modifier.padding(innerPadding).verticalScroll(rememberScrollState())) {
UserView( if (isVPNPrepared){
profile = user, UserView(
actionState = UserActionState.NAV, profile = user,
onClick = settingsNav.onNavigateToUserSwitcher) actionState = UserActionState.NAV,
onClick = settingsNav.onNavigateToUserSwitcher)
}
if (isAdmin) { if (isAdmin) {
Lists.ItemDivider() Lists.ItemDivider()

@ -29,6 +29,8 @@ open class IpnViewModel : ViewModel() {
val loggedInUser: StateFlow<IpnLocal.LoginProfile?> = MutableStateFlow(null) val loggedInUser: StateFlow<IpnLocal.LoginProfile?> = MutableStateFlow(null)
val loginProfiles: StateFlow<List<IpnLocal.LoginProfile>?> = MutableStateFlow(null) val loginProfiles: StateFlow<List<IpnLocal.LoginProfile>?> = MutableStateFlow(null)
private val _vpnPrepared = MutableStateFlow(false)
val vpnPrepared: StateFlow<Boolean> = _vpnPrepared
// The userId associated with the current node. ie: The logged in user. // The userId associated with the current node. ie: The logged in user.
private var selfNodeUserId: UserID? = null private var selfNodeUserId: UserID? = null
@ -59,11 +61,15 @@ open class IpnViewModel : ViewModel() {
} }
// VPN Control // VPN Control
fun setVpnPrepared(prepared: Boolean) {
_vpnPrepared.value = prepared
}
fun startVPN() { fun startVPN() {
UninitializedApp.get().startVPN() UninitializedApp.get().startVPN()
} }
fun stopVPN() { fun stopVPN() {
UninitializedApp.get().stopVPN() UninitializedApp.get().stopVPN()
} }

@ -33,9 +33,7 @@ class MainViewModel : IpnViewModel() {
private val _vpnToggleState = MutableStateFlow(false) private val _vpnToggleState = MutableStateFlow(false)
val vpnToggleState: StateFlow<Boolean> = _vpnToggleState val vpnToggleState: StateFlow<Boolean> = _vpnToggleState
// Whether or not the VPN has been prepared // Permission to prepare VPN
private val _vpnPrepared = MutableStateFlow(false)
val vpnPrepared: StateFlow<Boolean> = _vpnPrepared
private var vpnPermissionLauncher: ActivityResultLauncher<Intent>? = null private var vpnPermissionLauncher: ActivityResultLauncher<Intent>? = null
// The list of peers // The list of peers
@ -131,10 +129,6 @@ class MainViewModel : IpnViewModel() {
fun setVpnPermissionLauncher(launcher: ActivityResultLauncher<Intent>) { fun setVpnPermissionLauncher(launcher: ActivityResultLauncher<Intent>) {
vpnPermissionLauncher = launcher vpnPermissionLauncher = launcher
} }
fun setVpnPrepared(prepared: Boolean) {
_vpnPrepared.value = prepared
}
} }
private fun userStringRes(currentState: State?, previousState: State?, vpnPrepared: Boolean): Int { private fun userStringRes(currentState: State?, previousState: State?, vpnPrepared: Boolean): Int {

Loading…
Cancel
Save