Android: connect bookmarks on startup

The bookmark page has a "Connect on startup" switch, the same flag the
desktop client and the TeamSpeak import use. A fresh launch connects
every such bookmark once per process, skipping the server a link or
home-screen shortcut opened the app to. The bookmarks list marks them
with a green "AC".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 13:15:28 +00:00
co-authored by Claude Opus 5.5
parent 55e8b7bccb
commit 8d04cc5ba4
4 changed files with 54 additions and 12 deletions
@@ -16,7 +16,7 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge() enableEdgeToEdge()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
if (savedInstanceState == null) handle(intent) if (savedInstanceState == null) sessions.connectStartupBookmarks(handle(intent))
setContent { setContent {
Ts3Theme { App(sessions) } Ts3Theme { App(sessions) }
} }
@@ -37,13 +37,14 @@ class MainActivity : ComponentActivity() {
super.onStop() super.onStop()
} }
/** A notification opens its conversation; a `ts3server://` link or a bookmark shortcut connects. */ /** A notification opens its conversation; a `ts3server://` link or a bookmark shortcut connects, returning where. */
private fun handle(intent: Intent) { private fun handle(intent: Intent): ServerLink? = when (intent.action) {
when (intent.action) { Intent.ACTION_VIEW -> ServerLink.parse(intent.dataString)?.also { sessions.open(it) }
Intent.ACTION_VIEW -> ServerLink.parse(intent.dataString)?.let { sessions.open(it) } BookmarkShortcuts.ACTION_CONNECT -> intent.getStringExtra(BookmarkShortcuts.EXTRA_BOOKMARK)
BookmarkShortcuts.ACTION_CONNECT -> intent.getStringExtra(BookmarkShortcuts.EXTRA_BOOKMARK) ?.let(sessions::openBookmark)
?.let(sessions::openBookmark) else -> {
else -> openRequestedChat(intent) openRequestedChat(intent)
null
} }
} }
@@ -238,9 +238,24 @@ class SessionController(private val context: Context) {
} }
/** What a home-screen shortcut does: connects to the bookmark, or goes to its channel when already on its server. */ /** What a home-screen shortcut does: connects to the bookmark, or goes to its channel when already on its server. */
fun openBookmark(id: String) { fun openBookmark(id: String): ServerLink? {
val bookmark = bookmarkStore.find(id) ?: return error("That bookmark no longer exists") val bookmark = bookmarkStore.find(id)
open(ServerLink.of(bookmark), bookmark.identityId) if (bookmark == null) {
error("That bookmark no longer exists")
return null
}
return ServerLink.of(bookmark).also { open(it, bookmark.identityId) }
}
private var startedUp = false
/** Connects the bookmarks flagged for startup, once per process; [opened] is a server the launch already went to. */
fun connectStartupBookmarks(opened: ServerLink?) {
if (startedUp) return
startedUp = true
for (b in bookmarkStore.startupBookmarks()) {
if (opened?.pointsAt(b.address, b.port) != true) start { it.open(ServerLink.of(b), b.identityId) }
}
} }
fun select(server: ServerController) { fun select(server: ServerController) {
@@ -1,7 +1,9 @@
package com.ts3client.android.ui package com.ts3client.android.ui
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.imePadding import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
@@ -14,6 +16,7 @@ import androidx.compose.material3.ExposedDropdownMenuAnchorType
import androidx.compose.material3.ExposedDropdownMenuBox import androidx.compose.material3.ExposedDropdownMenuBox
import androidx.compose.material3.ExposedDropdownMenuDefaults import androidx.compose.material3.ExposedDropdownMenuDefaults
import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Switch
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextButton import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@@ -23,6 +26,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.listSaver import androidx.compose.runtime.saveable.listSaver
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.input.PasswordVisualTransformation
@@ -68,6 +72,7 @@ fun BookmarkScreen(vm: SessionController, edit: BookmarkEdit, onDone: () -> Unit
var identityId by rememberSaveable { mutableStateOf(b.identityId.orEmpty()) } var identityId by rememberSaveable { mutableStateOf(b.identityId.orEmpty()) }
var channel by rememberSaveable { mutableStateOf(b.channel.orEmpty()) } var channel by rememberSaveable { mutableStateOf(b.channel.orEmpty()) }
var channelPassword by rememberSaveable { mutableStateOf(b.channelPassword.orEmpty()) } var channelPassword by rememberSaveable { mutableStateOf(b.channelPassword.orEmpty()) }
var connectOnStartup by rememberSaveable { mutableStateOf(b.connectOnStartup) }
val save = { val save = {
val (host, port) = SessionController.parseAddress(address) val (host, port) = SessionController.parseAddress(address)
@@ -80,6 +85,7 @@ fun BookmarkScreen(vm: SessionController, edit: BookmarkEdit, onDone: () -> Unit
it.identityId = identityId it.identityId = identityId
it.channel = channel.trim() it.channel = channel.trim()
it.channelPassword = channelPassword it.channelPassword = channelPassword
it.connectOnStartup = connectOnStartup
}) })
onDone() onDone()
} }
@@ -109,6 +115,11 @@ fun BookmarkScreen(vm: SessionController, edit: BookmarkEdit, onDone: () -> Unit
label = { Text("Channel password") }, singleLine = true, label = { Text("Channel password") }, singleLine = true,
visualTransformation = PasswordVisualTransformation(), visualTransformation = PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password)) keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password))
Row(Modifier.fillMaxWidth().clickable { connectOnStartup = !connectOnStartup },
verticalAlignment = Alignment.CenterVertically) {
Text("Connect on startup", Modifier.weight(1f))
Switch(connectOnStartup, { connectOnStartup = it })
}
} }
} }
} }
@@ -44,7 +44,12 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@@ -182,6 +187,8 @@ private fun BookmarkIcon(iconId: Long) {
else PackIcon("BOOKMARK_MANAGER", null) else PackIcon("BOOKMARK_MANAGER", null)
} }
private val AUTOCONNECT = Color(0xFF3A9D4A)
@Composable @Composable
private fun BookmarkRow( private fun BookmarkRow(
bookmark: Bookmark, bookmark: Bookmark,
@@ -195,7 +202,15 @@ private fun BookmarkRow(
val identity = identities.firstOrNull { it.id == bookmark.identityId } val identity = identities.firstOrNull { it.id == bookmark.identityId }
var menu by remember { mutableStateOf(false) } var menu by remember { mutableStateOf(false) }
ListItem( ListItem(
headlineContent = { Text(bookmark.displayName()) }, headlineContent = {
Text(buildAnnotatedString {
if (bookmark.connectOnStartup) {
withStyle(SpanStyle(color = AUTOCONNECT, fontWeight = FontWeight.Bold)) { append("AC") }
append(' ')
}
append(bookmark.displayName())
})
},
supportingContent = { supportingContent = {
Text(listOfNotNull("${bookmark.address}:${bookmark.port}", bookmark.channel.ifBlank { null }, identity?.name) Text(listOfNotNull("${bookmark.address}:${bookmark.port}", bookmark.channel.ifBlank { null }, identity?.name)
.joinToString(" · ")) .joinToString(" · "))