ui/UserView: show custom control server URL in account switcher (#529)

pull/530/head
Andrea Gottardo 1 year ago committed by GitHub
parent be89cb10fe
commit 2daeee584d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -4,6 +4,7 @@
package com.tailscale.ipn.ui.model package com.tailscale.ipn.ui.model
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import java.net.URL
class IpnState { class IpnState {
@Serializable @Serializable
@ -123,9 +124,29 @@ class IpnLocal {
val UserProfile: Tailcfg.UserProfile, val UserProfile: Tailcfg.UserProfile,
val NetworkProfile: Tailcfg.NetworkProfile? = null, val NetworkProfile: Tailcfg.NetworkProfile? = null,
val LocalUserID: String, val LocalUserID: String,
var ControlURL: String? = null,
) { ) {
fun isEmpty(): Boolean { fun isEmpty(): Boolean {
return ID.isEmpty() return ID.isEmpty()
} }
// Returns true if the profile uses a custom control server (not Tailscale SaaS).
fun isUsingCustomControlServer(): Boolean {
return ControlURL != null && ControlURL != "controlplane.tailscale.com"
}
// Returns the hostname of the custom control server, if any was set.
//
// Returns null if the ControlURL provided by the backend is an invalid URL, and
// a hostname cannot be extracted.
fun customControlServerHostname(): String? {
if (!isUsingCustomControlServer()) return null
return try {
URL(ControlURL).host
} catch (e: Exception) {
null
}
}
} }
} }

@ -5,6 +5,7 @@ package com.tailscale.ipn.ui.view
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.offset
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
@ -54,17 +55,27 @@ fun UserView(
leadingContent = { Avatar(profile = profile, size = 36) }, leadingContent = { Avatar(profile = profile, size = 36) },
headlineContent = { headlineContent = {
AutoResizingText( AutoResizingText(
text = profile.UserProfile.DisplayName, text = profile.UserProfile.LoginName,
style = MaterialTheme.typography.titleMedium.short, style = MaterialTheme.typography.titleMedium.short,
minFontSize = MaterialTheme.typography.minTextSize, minFontSize = MaterialTheme.typography.minTextSize,
overflow = TextOverflow.Ellipsis) overflow = TextOverflow.Ellipsis)
}, },
supportingContent = { supportingContent = {
AutoResizingText( Column {
text = profile.NetworkProfile?.DomainName ?: "", AutoResizingText(
style = MaterialTheme.typography.bodyMedium.short, text = profile.NetworkProfile?.DomainName ?: "",
minFontSize = MaterialTheme.typography.minTextSize, style = MaterialTheme.typography.bodyMedium.short,
overflow = TextOverflow.Ellipsis) minFontSize = MaterialTheme.typography.minTextSize,
overflow = TextOverflow.Ellipsis)
profile.customControlServerHostname()?.let {
AutoResizingText(
text = it,
style = MaterialTheme.typography.bodyMedium.short,
minFontSize = MaterialTheme.typography.minTextSize,
overflow = TextOverflow.Ellipsis)
}
}
}, },
trailingContent = { trailingContent = {
when (actionState) { when (actionState) {

Loading…
Cancel
Save