Skip to content

Commit 2daeee5

Browse files
authored
ui/UserView: show custom control server URL in account switcher (#529)
1 parent be89cb1 commit 2daeee5

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

android/src/main/java/com/tailscale/ipn/ui/model/IpnState.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package com.tailscale.ipn.ui.model
55

66
import kotlinx.serialization.Serializable
7+
import java.net.URL
78

89
class IpnState {
910
@Serializable
@@ -123,9 +124,29 @@ class IpnLocal {
123124
val UserProfile: Tailcfg.UserProfile,
124125
val NetworkProfile: Tailcfg.NetworkProfile? = null,
125126
val LocalUserID: String,
127+
var ControlURL: String? = null,
126128
) {
127129
fun isEmpty(): Boolean {
128130
return ID.isEmpty()
129131
}
132+
133+
// Returns true if the profile uses a custom control server (not Tailscale SaaS).
134+
fun isUsingCustomControlServer(): Boolean {
135+
return ControlURL != null && ControlURL != "controlplane.tailscale.com"
136+
}
137+
138+
// Returns the hostname of the custom control server, if any was set.
139+
//
140+
// Returns null if the ControlURL provided by the backend is an invalid URL, and
141+
// a hostname cannot be extracted.
142+
fun customControlServerHostname(): String? {
143+
if (!isUsingCustomControlServer()) return null
144+
145+
return try {
146+
URL(ControlURL).host
147+
} catch (e: Exception) {
148+
null
149+
}
150+
}
130151
}
131152
}

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package com.tailscale.ipn.ui.view
55

66
import androidx.compose.foundation.clickable
77
import androidx.compose.foundation.layout.Box
8+
import androidx.compose.foundation.layout.Column
89
import androidx.compose.foundation.layout.offset
910
import androidx.compose.material.icons.Icons
1011
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
@@ -54,17 +55,27 @@ fun UserView(
5455
leadingContent = { Avatar(profile = profile, size = 36) },
5556
headlineContent = {
5657
AutoResizingText(
57-
text = profile.UserProfile.DisplayName,
58+
text = profile.UserProfile.LoginName,
5859
style = MaterialTheme.typography.titleMedium.short,
5960
minFontSize = MaterialTheme.typography.minTextSize,
6061
overflow = TextOverflow.Ellipsis)
6162
},
6263
supportingContent = {
63-
AutoResizingText(
64-
text = profile.NetworkProfile?.DomainName ?: "",
65-
style = MaterialTheme.typography.bodyMedium.short,
66-
minFontSize = MaterialTheme.typography.minTextSize,
67-
overflow = TextOverflow.Ellipsis)
64+
Column {
65+
AutoResizingText(
66+
text = profile.NetworkProfile?.DomainName ?: "",
67+
style = MaterialTheme.typography.bodyMedium.short,
68+
minFontSize = MaterialTheme.typography.minTextSize,
69+
overflow = TextOverflow.Ellipsis)
70+
71+
profile.customControlServerHostname()?.let {
72+
AutoResizingText(
73+
text = it,
74+
style = MaterialTheme.typography.bodyMedium.short,
75+
minFontSize = MaterialTheme.typography.minTextSize,
76+
overflow = TextOverflow.Ellipsis)
77+
}
78+
}
6879
},
6980
trailingContent = {
7081
when (actionState) {

0 commit comments

Comments
 (0)