android: include hex in LoginQRView (#502)

Updates tailscale/tailscale#13277

Signed-off-by: kari-ts <kari@tailscale.com>
pull/518/head
kari-ts 2 months ago committed by GitHub
parent 2ec7304092
commit 9654bb5d9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -40,6 +40,7 @@ fun LoginQRView(onDismiss: () -> Unit = {}, model: LoginQRViewModel = viewModel(
Surface(color = MaterialTheme.colorScheme.scrim, modifier = Modifier.fillMaxSize()) {
Dialog(onDismissRequest = onDismiss) {
val image by model.qrCode.collectAsState()
val numCode by model.numCode.collectAsState()
Column(
modifier =
@ -65,6 +66,12 @@ fun LoginQRView(onDismiss: () -> Unit = {}, model: LoginQRViewModel = viewModel(
modifier = Modifier.fillMaxSize())
}
}
numCode?.let { it ->
Text(
text = stringResource(R.string.enter_code_to_connect_to_tailnet, it),
style = MaterialTheme.typography.titleMedium,
color = MaterialTheme.colorScheme.onSurface)
}
Button(onClick = onDismiss) { Text(text = stringResource(R.string.dismiss)) }
}
}
@ -76,5 +83,6 @@ fun LoginQRView(onDismiss: () -> Unit = {}, model: LoginQRViewModel = viewModel(
fun LoginQRViewPreview() {
val vm = LoginQRViewModel()
vm.qrCode.set(vm.generateQRCode("https://tailscale.com", 200, 0))
vm.numCode.set("123456789")
AppTheme { LoginQRView({}, vm) }
}

@ -20,12 +20,28 @@ import kotlinx.coroutines.launch
class LoginQRViewModel : IpnViewModel() {
val numCode: StateFlow<String?> = MutableStateFlow(null)
val qrCode: StateFlow<ImageBitmap?> = MutableStateFlow(null)
init {
viewModelScope.launch {
Notifier.browseToURL.collect { url ->
url?.let { qrCode.set(generateQRCode(url, 200, 0)) } ?: run { qrCode.set(null) }
url?.let {
qrCode.set(generateQRCode(url, 200, 0))
// Extract the string after "https://login.tailscale.com/a/"
val prefix = "https://login.tailscale.com/a/"
val code =
if (it.startsWith(prefix)) {
it.removePrefix(prefix)
} else {
null
}
numCode.set(code)
}
?: run {
qrCode.set(null)
numCode.set(null)
}
}
}
}

@ -244,6 +244,7 @@
<string name="welcome1">Tailscale is a mesh VPN for securely connecting your devices.</string>
<string name="welcome2">All connections are device-to-device, so we never see your data. We collect and use your email address and name, as well as your device name, OS version, and IP address in order to help you to connect your devices and manage your settings. We log when you are connected to your network.</string>
<string name="scan_to_connect_to_your_tailnet">Scan this QR code to log in to your tailnet</string>
<string name="enter_code_to_connect_to_tailnet">or enter this code in the admin console: %1$s</string>
<!-- Strings for intent handling -->
<string name="vpn_is_not_ready_to_start">VPN is not ready to start</string>

Loading…
Cancel
Save