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
+2 -2
View File
@@ -9,8 +9,8 @@ android {
applicationId = "tv.orbit.classic"
minSdk = 26
targetSdk = 36
versionCode = 236
versionName = "0.108.76-companion"
versionCode = 237
versionName = "0.108.77-companion"
}
buildFeatures { compose = true }
// The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so
@@ -1,6 +1,8 @@
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"><title>Orbit</title>
<meta name="theme-color" content="#071632">
<link rel="manifest" href="/manifest.webmanifest"><link rel="apple-touch-icon" href="/icon-180.png"><link rel="icon" href="/icon-192.png">
<meta name="apple-mobile-web-app-capable" content="yes"><meta name="mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-title" content="Orbit">
<style>
/* Orbit Companion (design/companion v2): the TV's look, filled in from /api/now. Orbit Night until then. */
:root{--bg:#071632;--surface:#12356B;--raised:#194C91;--deep:#0C2148;--accent:#FFDE59;--on-accent:#071632;--ink:#FFFFFF;--muted:#B7CBE8;--mint:#7EE0A8;--sky:#7FD1FF}
@@ -197,6 +199,7 @@ function rooms() {
function more() {
return head('More') + `<div class="label">Your channels</div>
<a class="line" href="/create" style="text-decoration:none;color:inherit">Create a channel <span>Name, shows, style, hours</span></a>
${standalone() ? '' : '<button class="line" data-home="1">Add to home screen <span>One tap to the remote</span></button>'}
<div class="label">Look</div>
<div class="chips" style="flex-wrap:wrap"><button class="${keptLook() ? '' : 'on'}" data-look="">Follow this TV${state.now?.look ? ' (' + esc(state.now.look.name) + ')' : ''}</button>
${(state.looks || []).map(l => `<button class="${keptLook() === l.name ? 'on' : ''}" data-look="${esc(l.name)}">${esc(l.name)}</button>`).join('')}</div>
@@ -204,6 +207,24 @@ function more() {
<div class="label">About</div><div class="card small">Orbit Companion runs on the TV itself, over your home Wi-Fi. Nothing to install, no account. It works while Orbit is open on the TV.
To stop this phone, remove it in Settings › Rooms and phones.</div>`;
}
// Add to home screen (Paul, 6 November 2026): offered once after joining, and any time from More. The TV's page is plain
// http on the home Wi-Fi, so most phones add it from their own menu; Chrome's own button is used where it's offered.
const standalone = () => matchMedia('(display-mode: standalone)').matches || navigator.standalone === true;
let installAsk = null; addEventListener('beforeinstallprompt', e => { e.preventDefault(); installAsk = e; });
function homeSteps() {
const ios = /iPhone|iPad|iPod/.test(navigator.userAgent);
return `<div class="title" style="white-space:normal">Add Orbit to your home screen</div>
<div class="small" style="margin:6px 0 14px">One tap opens the remote whenever Orbit is on, on this Wi-Fi. No app to install.</div>
${installAsk ? '<button class="btn gold" data-install="1">Add to home screen</button>' : `
<div class="line" style="font-weight:500"><span style="color:var(--accent);font-weight:800;margin-right:10px">1</span><span style="color:var(--ink);flex:1">${ios ? 'Tap Share at the bottom of Safari' : "Tap the browser's menu (⋮)"}</span></div>
<div class="line" style="font-weight:500"><span style="color:var(--accent);font-weight:800;margin-right:10px">2</span><span style="color:var(--ink);flex:1">${ios ? 'Choose Add to Home Screen' : 'Choose Add to home screen'}</span></div>
<button class="btn gold" data-homedone="1">Done</button>`}
<button class="btn" data-homedone="1" style="margin-top:8px;background:none;color:var(--muted)">Not now</button>`;
}
function offerHome() {
let asked = false; try { asked = localStorage.getItem('orbit.home') === '1'; } catch {}
if (!asked && !standalone()) setTimeout(() => openSheet(homeSteps()), 900);
}
function render() {
tabs();
$('#app').className = tab === 'remote' ? 'fit' : '';
@@ -237,12 +258,15 @@ document.addEventListener('click', e => {
if (d.sheet) openSheet(moreControls());
if (d.go) send('/api/section', {section: d.go}, () => { closeSheet(); toast('On the TV now'); });
if (d.look !== undefined) { try { d.look ? localStorage.setItem('orbit.look', d.look) : localStorage.removeItem('orbit.look'); } catch {} look(state.now?.look); render(); return; }
if (d.homedone) { try { localStorage.setItem('orbit.home', '1'); } catch {} closeSheet(); return; }
if (d.install) { installAsk?.prompt(); installAsk = null; try { localStorage.setItem('orbit.home', '1'); } catch {} closeSheet(); return; }
if (d.home) { openSheet(homeSteps()); return; }
if (d.filter) { state.filter = d.filter; render(); }
if (d.pick) openSheet(pickSheet(+d.pick));
if (d.tune) send('/api/tune', {number: +d.tune}, () => { closeSheet(); toast('Watching on the TV'); setTimeout(() => load('guide'), 700); });
if (d.cu) { const [number, startMs] = d.cu.split(':').map(Number); send('/api/catchup/watch', {number, startMs}, () => toast('Playing from the start on the TV')); }
});
render(); (keptLook() || tab === 'more' ? load('more') : Promise.resolve()).then(() => load('now')); if (tab !== 'remote' && tab !== 'more') load(tab);
offerHome(); render(); (keptLook() || tab === 'more' ? load('more') : Promise.resolve()).then(() => load('now')); if (tab !== 'remote' && tab !== 'more') load(tab);
// Kept fresh while the phone is looking: what's on every 15 seconds, and the open list every minute.
setInterval(() => { if (!document.hidden) load('now'); }, 15000);
setInterval(() => { if (!document.hidden && ['guide','catchup','rooms'].includes(tab)) load(tab); }, 60000);
Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

@@ -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()) {
@@ -148,6 +148,8 @@ class PhoneLinkTest {
PhoneLink.screen = CompanionScreen({ companionChannels }, { selected }, { true }, { 0 }, { n, o -> tuned += n to o; selected = n })
try {
assertTrue(call("/api/now").body.contains("Enter the code")) // not joined: nothing
// The home-screen manifest needs no phone, and carries Orbit's name only.
assertEquals("Orbit", JSONObject(call("/manifest.webmanifest").body).getString("short_name"))
val cookie = joinedCookie()
assertTrue(call("/", cookie = cookie).status == 200)
val n = JSONObject(call("/api/now", cookie = cookie).body)