Open ts3server:// links on both apps
A link connects with its nickname, passwords, channel (path or cid) and privilege key, the key used once on; addbookmark saves it as a bookmark. A link to a server we are on already goes to its channel instead. Android takes the links from browsers and other apps through an intent filter, and from chat. The desktop opens them from chat and descriptions, and its launcher entry claims the scheme when run from the jar; a second launch hands its link to the running instance over a Unix socket in the user's runtime directory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,13 @@
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<!-- TeamSpeak server links from browsers and other apps connect. -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="ts3server" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import com.ts3client.android.ui.App
|
||||
import com.ts3client.android.ui.Ts3Theme
|
||||
import com.ts3client.session.ServerLink
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
||||
@@ -15,7 +16,7 @@ class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
enableEdgeToEdge()
|
||||
super.onCreate(savedInstanceState)
|
||||
if (savedInstanceState == null) openRequestedChat(intent)
|
||||
if (savedInstanceState == null) handle(intent)
|
||||
setContent {
|
||||
Ts3Theme { App(sessions) }
|
||||
}
|
||||
@@ -23,7 +24,7 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
openRequestedChat(intent)
|
||||
handle(intent)
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
@@ -36,7 +37,14 @@ class MainActivity : ComponentActivity() {
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
/** A private message notification opens its conversation. */
|
||||
/** A notification opens its conversation; a `ts3server://` link connects. */
|
||||
private fun handle(intent: Intent) {
|
||||
when (intent.action) {
|
||||
Intent.ACTION_VIEW -> ServerLink.parse(intent.dataString)?.let { sessions.open(it) }
|
||||
else -> openRequestedChat(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun openRequestedChat(intent: Intent) {
|
||||
val serverId = intent.getIntExtra(MessageNotifier.EXTRA_SERVER, -1)
|
||||
val clientId = intent.getIntExtra(MessageNotifier.EXTRA_CHAT, -1)
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.ts3client.net.GroupChoice
|
||||
import com.ts3client.net.ban.BanEntry
|
||||
import com.ts3client.net.ban.BanRule
|
||||
import com.ts3client.net.ConnectionListener.ChatScope
|
||||
import com.ts3client.session.ServerLink
|
||||
import com.ts3client.session.ServerSession
|
||||
import com.ts3client.text.ChatHtml
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -113,6 +114,13 @@ class ServerController internal constructor(
|
||||
refresh()
|
||||
}
|
||||
|
||||
internal fun open(link: ServerLink, identityId: String) {
|
||||
network.connecting()
|
||||
started = true
|
||||
session.open(link, identityId)
|
||||
refresh()
|
||||
}
|
||||
|
||||
/** A bookmark leading back to this server, joining [channelId]; not yet saved. */
|
||||
fun bookmark(channelId: Int): Bookmark? = session.toBookmark(conn.model.channelPath(channelId))
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.ts3client.myts.MyTeamSpeak
|
||||
import com.ts3client.myts.MyTeamSpeakLogin
|
||||
import com.ts3client.net.HostButton
|
||||
import com.ts3client.session.SelfState
|
||||
import com.ts3client.session.ServerLink
|
||||
import com.ts3client.session.ServerSession
|
||||
import com.ts3client.session.Sessions
|
||||
import com.ts3client.sound.SoundNotifier
|
||||
@@ -71,6 +72,8 @@ internal class SharedFile(val name: String, val size: Long, val data: InputStrea
|
||||
sealed interface SessionEvent {
|
||||
data class Poke(val from: String, val message: String) : SessionEvent
|
||||
data class Error(val message: String) : SessionEvent
|
||||
/** A link or shortcut brought a server on screen, in front of whatever page was open. */
|
||||
data object ServerOpened : SessionEvent
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,19 +190,42 @@ class SessionController(private val context: Context) {
|
||||
}
|
||||
|
||||
fun connect(bookmark: Bookmark) {
|
||||
start(bookmark.address, bookmark.port, bookmark.nickname.orEmpty(), bookmark.password, bookmark.identityId,
|
||||
bookmark.channel, bookmark.channelPassword)
|
||||
start { it.start(bookmark.address, bookmark.port, bookmark.nickname.orEmpty(), bookmark.password,
|
||||
bookmark.identityId, bookmark.channel, bookmark.channelPassword) }
|
||||
}
|
||||
|
||||
private fun start(host: String, port: Int, nickname: String, password: String, identityId: String,
|
||||
channel: String, channelPassword: String) {
|
||||
start { it.start(host, port, nickname, password, identityId, channel, channelPassword) }
|
||||
}
|
||||
|
||||
private fun start(connect: (ServerController) -> Unit) {
|
||||
val server = ServerController(nextId.incrementAndGet(), this)
|
||||
sessions.add(server.session)
|
||||
_servers.update { it + server }
|
||||
_current.value = server
|
||||
_lastEnd.value = null
|
||||
context.startForegroundService(Intent(context, ConnectionService::class.java))
|
||||
server.start(host, port, nickname, password, identityId, channel, channelPassword)
|
||||
connect(server)
|
||||
}
|
||||
|
||||
/**
|
||||
* Goes where a `ts3server://` link leads: on a server we are on already, to the channel it
|
||||
* names; else connects there as another server.
|
||||
*/
|
||||
fun open(link: ServerLink, identityId: String = "") {
|
||||
if (link.bookmarkLabel.isNotEmpty()) {
|
||||
bookmarkStore.add(link.toBookmark())
|
||||
saveBookmarks()
|
||||
}
|
||||
val on = _servers.value.firstOrNull { it.session.isOn(link) }
|
||||
if (on != null) {
|
||||
_current.value = on
|
||||
on.session.follow(link)
|
||||
} else {
|
||||
start { it.open(link, identityId) }
|
||||
}
|
||||
_events.tryEmit(SessionEvent.ServerOpened)
|
||||
}
|
||||
|
||||
fun select(server: ServerController) {
|
||||
|
||||
@@ -42,6 +42,12 @@ fun App(vm: SessionController) {
|
||||
when (event) {
|
||||
is SessionEvent.Poke -> poke = event
|
||||
is SessionEvent.Error -> snackbar.showSnackbar(event.message)
|
||||
SessionEvent.ServerOpened -> {
|
||||
connectOpen = false
|
||||
settingsOpen = false
|
||||
contactsOpen = false
|
||||
editingBookmark = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ import com.ts3client.android.TreeFind
|
||||
import com.ts3client.android.findIn
|
||||
import com.ts3client.config.Settings
|
||||
import com.ts3client.myts.ChatAttachment
|
||||
import com.ts3client.session.ServerLink
|
||||
import com.ts3client.text.TsLink
|
||||
|
||||
private val ChatKeySaver = Saver<ChatKey, String>(
|
||||
@@ -159,6 +160,7 @@ fun ServerScreen(
|
||||
val ref = TsLink.parse(href)
|
||||
when {
|
||||
ChatAttachment.isHref(href) -> attachments.open(href)
|
||||
ServerLink.isLink(href) -> ServerLink.parse(href)?.let { vm.open(it) }
|
||||
ref == null -> runCatching { uriHandler.openUri(href) }
|
||||
ref.client -> { clientSheet = ref.id; clientSheetFromTree = false }
|
||||
else -> channelSheet = ref.id
|
||||
|
||||
@@ -129,7 +129,7 @@ fun ClientSheet(
|
||||
}
|
||||
}
|
||||
|
||||
/** What can be done with a channel: join it, and whether to hear who is in it. */
|
||||
/** What can be done with a channel: join it, whether to hear who is in it, its files, and editing it. */
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ChannelSheet(
|
||||
|
||||
Reference in New Issue
Block a user