Skip to content

Commit 9654bb5

Browse files
authored
android: include hex in LoginQRView (#502)
Updates tailscale/tailscale#13277 Signed-off-by: kari-ts <[email protected]>
1 parent 2ec7304 commit 9654bb5

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

android/src/main/java/com/tailscale/ipn/ui/view/LoginQRView.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fun LoginQRView(onDismiss: () -> Unit = {}, model: LoginQRViewModel = viewModel(
4040
Surface(color = MaterialTheme.colorScheme.scrim, modifier = Modifier.fillMaxSize()) {
4141
Dialog(onDismissRequest = onDismiss) {
4242
val image by model.qrCode.collectAsState()
43+
val numCode by model.numCode.collectAsState()
4344

4445
Column(
4546
modifier =
@@ -65,6 +66,12 @@ fun LoginQRView(onDismiss: () -> Unit = {}, model: LoginQRViewModel = viewModel(
6566
modifier = Modifier.fillMaxSize())
6667
}
6768
}
69+
numCode?.let { it ->
70+
Text(
71+
text = stringResource(R.string.enter_code_to_connect_to_tailnet, it),
72+
style = MaterialTheme.typography.titleMedium,
73+
color = MaterialTheme.colorScheme.onSurface)
74+
}
6875
Button(onClick = onDismiss) { Text(text = stringResource(R.string.dismiss)) }
6976
}
7077
}
@@ -76,5 +83,6 @@ fun LoginQRView(onDismiss: () -> Unit = {}, model: LoginQRViewModel = viewModel(
7683
fun LoginQRViewPreview() {
7784
val vm = LoginQRViewModel()
7885
vm.qrCode.set(vm.generateQRCode("https://tailscale.com", 200, 0))
86+
vm.numCode.set("123456789")
7987
AppTheme { LoginQRView({}, vm) }
8088
}

android/src/main/java/com/tailscale/ipn/ui/viewModel/LoginQRViewModel.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,28 @@ import kotlinx.coroutines.launch
2020

2121
class LoginQRViewModel : IpnViewModel() {
2222

23+
val numCode: StateFlow<String?> = MutableStateFlow(null)
2324
val qrCode: StateFlow<ImageBitmap?> = MutableStateFlow(null)
2425

2526
init {
2627
viewModelScope.launch {
2728
Notifier.browseToURL.collect { url ->
28-
url?.let { qrCode.set(generateQRCode(url, 200, 0)) } ?: run { qrCode.set(null) }
29+
url?.let {
30+
qrCode.set(generateQRCode(url, 200, 0))
31+
// Extract the string after "https://login.tailscale.com/a/"
32+
val prefix = "https://login.tailscale.com/a/"
33+
val code =
34+
if (it.startsWith(prefix)) {
35+
it.removePrefix(prefix)
36+
} else {
37+
null
38+
}
39+
numCode.set(code)
40+
}
41+
?: run {
42+
qrCode.set(null)
43+
numCode.set(null)
44+
}
2945
}
3046
}
3147
}

android/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
<string name="welcome1">Tailscale is a mesh VPN for securely connecting your devices.</string>
245245
<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>
246246
<string name="scan_to_connect_to_your_tailnet">Scan this QR code to log in to your tailnet</string>
247+
<string name="enter_code_to_connect_to_tailnet">or enter this code in the admin console: %1$s</string>
247248

248249
<!-- Strings for intent handling -->
249250
<string name="vpn_is_not_ready_to_start">VPN is not ready to start</string>

0 commit comments

Comments
 (0)