Orbit Companion: offer Add to home screen after joining

A one-time sheet on the phone (and an entry in More) shows how to put Orbit on
the home screen, using Chrome's own button where it's offered. The TV serves a
manifest and Orbit's icon so the shortcut opens the remote full screen. Tests
no longer leave a pairing code behind for the next one.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-06 22:14:47 +00:00
co-authored by Claude Opus 5.5
parent 973fbcdb11
commit 513a617205
10 changed files with 42 additions and 7 deletions
@@ -62,9 +62,9 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI
}
/** The sign-in headers for this kind of server. */
internal fun authHeaders(token: String?): Map<String, String> = when (kind) {
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.76\"") +
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.77\"") +
(token?.let { mapOf("X-Emby-Token" to it) } ?: emptyMap())
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.76\"" +
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.77\"" +
(token?.let { ", Token=\"$it\"" } ?: ""))
}
/** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */
@@ -118,7 +118,7 @@ internal object PhoneLink {
fun init(context: Context) { appContext = context.applicationContext; store = PrefsPhoneStore(context.applicationContext); loadPhones(); if (phones.isNotEmpty()) start() }
/** For tests: a store of its own, no Android. */
internal fun initForTest(testStore: PhoneStore) { store = testStore; strikes.clear(); loadPhones() }
internal fun initForTest(testStore: PhoneStore) { store = testStore; strikes.clear(); pairing = null; loadPhones() }
/** A new one-time code, and the server running to receive it. */
fun beginPairing(): Pairing {
@@ -224,6 +224,9 @@ internal object PhoneLink {
val (status, reply) = runCatching { offer.handle(r.method, r.path, r.body) }.getOrElse { 400 to JSONObject() }
return json(out, status, reply)
}
// The home-screen icon and its manifest (Paul, 6 November 2026): no catalogue in them, so they're answered before joining.
if (r.method == "GET" && r.path in PhonePages.icons) return PhonePages.icon(r.path)?.let { respond(out, 200, "image/png", it) } ?: json(out, 404, JSONObject())
if (r.method == "GET" && r.path == "/manifest.webmanifest") return respond(out, 200, "application/manifest+json", PhonePages.manifest().toByteArray())
val phone = phoneOf(r)
when {
r.path == "/join" -> join(r, out, socket.inetAddress.hostAddress.orEmpty())
@@ -21,4 +21,10 @@ background:#ffde59;color:#071632;font-size:18px;font-weight:700}.note{color:#ffd
fun app(): String = asset("app.html")
/** The Companion, at /: Remote, Guide, Catch Up, Rooms and More (which leads to Create your own). */
fun companion(): String = asset("companion.html")
/** For "Add to home screen": Orbit's icon and name, opening on the remote. */
val icons = setOf("/icon-180.png", "/icon-192.png", "/icon-512.png")
fun icon(path: String): ByteArray? = runCatching { PhoneLink.context()?.assets?.open("phone" + path)?.use { it.readBytes() } }.getOrNull()
fun manifest(): String = org.json.JSONObject().put("name", "Orbit ${Rooms.name}").put("short_name", "Orbit").put("start_url", "/").put("scope", "/")
.put("display", "standalone").put("background_color", "#071632").put("theme_color", "#071632")
.put("icons", org.json.JSONArray(listOf(192, 512).map { org.json.JSONObject().put("src", "/icon-$it.png").put("sizes", "${it}x$it").put("type", "image/png") })).toString()
}
@@ -39,7 +39,7 @@ internal class SecureMediaDataSource(private val session: EmbySampleSession) : B
next.instanceFollowRedirects = false
next.connectTimeout = 10_000
next.readTimeout = 20_000
next.setRequestProperty("User-Agent", "OrbitTV/0.108.76")
next.setRequestProperty("User-Agent", "OrbitTV/0.108.77")
next.setRequestProperty("Accept-Encoding", "identity")
session.mediaHeaders(address).forEach { (key, value) -> next.setRequestProperty(key, value) }
if (dataSpec.position != 0L || dataSpec.length != C.LENGTH_UNSET.toLong()) {