Safety limits after the ban, and four new themes
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 4m18s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 2m50s
release-gate / verify (push) Successful in 15m8s

- Every request this TV makes counts towards 400 in any 60 minutes; at that point background work stops (watching never
  does) and Settings says when. Background budget 200 an hour; channel setup one request a second.
- The guide's picture rests after 10 minutes with no button press; any button brings it back.
- Velvet, Evergreen, Sunset and Frost join the six looks; the picker shows ten, five to a row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 07:22:28 +00:00
co-authored by Claude Opus 5.5
parent e3f8eb5a80
commit 22f018bd82
8 changed files with 119 additions and 16 deletions
@@ -64,6 +64,19 @@ internal fun channelMediaItem(plan: EmbyPlaybackPlan): MediaItem = MediaItem.Bui
.setLanguage(subtitle.language).setLabel(subtitle.label).build()
}).build()
/** The last button press anywhere in Orbit, so a guide left open with nobody there can rest its picture. */
internal object RemoteKeys {
var lastMs by mutableLongStateOf(System.currentTimeMillis())
private set
fun pressed() { lastMs = System.currentTimeMillis() }
}
/**
* After this long with no button press, the guide's picture stops and its artwork shows (12 November 2026): a guide left
* open cost the server as much as watching, about 156 requests an hour. Any button brings the picture back, on time.
*/
internal const val GUIDE_PICTURE_REST_MS = 10 * 60_000L
/** How long until [endMs], plus a moment so the programme at that time is the next one; never negative. */
internal fun programmeEndDelayMs(endMs: Long, nowMs: Long) = (endMs - nowMs).coerceAtLeast(0L) + 50L
@@ -92,11 +105,17 @@ internal fun GuidePicture(session: EmbySampleSession, channel: SampleChannel, li
delay(programmeEndDelayMs(current.endMs, System.currentTimeMillis()))
ended = System.currentTimeMillis()
}
var ready by remember(channel.number, current.startMs, live, foreground) { mutableStateOf(false) }
var resting by remember { mutableStateOf(false) }
LaunchedEffect(RemoteKeys.lastMs) {
resting = false
delay(programmeEndDelayMs(RemoteKeys.lastMs + GUIDE_PICTURE_REST_MS, System.currentTimeMillis()))
resting = true
}
var ready by remember(channel.number, current.startMs, live, foreground, resting) { mutableStateOf(false) }
// A file that can't play here leaves the artwork up until the next programme.
var cantPlay by remember(channel.number, current.startMs) { mutableStateOf(false) }
Box(Modifier.fillMaxSize().background(Panel)) {
if (live && foreground && !cantPlay) key(channel.number, current.startMs) {
if (live && foreground && !cantPlay && !resting) key(channel.number, current.startMs) {
GuideLiveProgramme(session, channel.number, current, handoff, onReady = { ready = true }, onCantPlay = { id -> cantPlay = true; ready = false; id?.let(onUnplayable) })
}
val branding = ChannelBrands.forNumber(channel.number)
@@ -24,14 +24,14 @@ import androidx.compose.ui.unit.sp
import androidx.tv.material3.Text
/**
* The six looks as small screens, each in its own colours (design/first-run/first-run-5-look.png). OK uses one at once: every
* The ten looks as small screens, five to a row,, each in its own colours (design/first-run/first-run-5-look.png). OK uses one at once: every
* screen, this one included, changes there and then. Used by onboarding's Look step and Settings › Look.
*/
@Composable
internal fun LookPicker(first: FocusRequester, cardWidth: Dp = 220.dp, onChosen: (OrbitLook) -> Unit = {}) {
val context = LocalContext.current
Column(verticalArrangement = Arrangement.spacedBy(14.dp)) {
OrbitLook.entries.chunked(3).forEachIndexed { row, looks ->
OrbitLook.entries.chunked(5).forEachIndexed { row, looks ->
Row(horizontalArrangement = Arrangement.spacedBy(18.dp)) {
looks.forEachIndexed { i, look ->
var focused by remember { mutableStateOf(false) }
@@ -192,7 +192,7 @@ private fun OrbitApp() {
LaunchedEffect(Unit) { while (true) { delay(1000); if (SleepTimer.tick(System.currentTimeMillis())) { SleepTimer.clear(); activity?.finish() } } }
Box(Modifier.fillMaxSize().background(Navy).onPreviewKeyEvent { event ->
// Timings (0.129 stage 0): when the press came, for the next frame drawn after it. Off unless switched on.
if (event.nativeKeyEvent.action == android.view.KeyEvent.ACTION_DOWN && event.nativeKeyEvent.repeatCount == 0) OrbitTiming.key(event.nativeKeyEvent.keyCode)
if (event.nativeKeyEvent.action == android.view.KeyEvent.ACTION_DOWN && event.nativeKeyEvent.repeatCount == 0) { OrbitTiming.key(event.nativeKeyEvent.keyCode); RemoteKeys.pressed() }
// The first press after two hours without one asks who's watching, and does nothing else (WatchCheck).
if (event.nativeKeyEvent.action == android.view.KeyEvent.ACTION_DOWN && WatchCheck.key()) { WatchCheck.swallowUp = true; return@onPreviewKeyEvent true }
if (event.nativeKeyEvent.action == android.view.KeyEvent.ACTION_UP && WatchCheck.swallowUp) { WatchCheck.swallowUp = false; return@onPreviewKeyEvent true }
@@ -176,7 +176,7 @@ private fun LookStep(onNext: () -> Unit) {
Column(Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(10.dp, Alignment.CenterVertically)) {
Text("Choose your look", color = Ink, fontFamily = Anton, fontSize = 32.sp)
Text(if (Onboarding.tour) "Try one: it goes back to yours when the tour ends." else "It changes straight away. You can change it any time in Settings › On screen.", color = Muted, fontSize = 15.sp)
LookPicker(first, cardWidth = 200.dp)
LookPicker(first, cardWidth = 160.dp)
OrbitButton("Next", Modifier.padding(top = 6.dp).width(200.dp), centred = true, onClick = onNext)
}
}
@@ -53,8 +53,15 @@ internal object ServerRequests {
fun attach(dir: File) { file = File(dir, "server-requests.json"); load() }
/** When each request of the last 60 minutes was made, background or not: what [BackgroundPacing.TOTAL_CEILING] is checked against. */
private val lastHour = ArrayDeque<Long>()
/** Every request to the server in the last 60 minutes, playback included. */
@Synchronized fun inLastHour(): Int { trim(clock()); return lastHour.size }
private fun trim(now: Long) { while (lastHour.isNotEmpty() && lastHour.first() <= now - HOUR_MS) lastHour.removeFirst() }
@Synchronized fun count(kind: RequestKind, ok: Boolean, background: Boolean = BackgroundPacing.active) {
val now = clock()
trim(now); lastHour.addLast(now)
val start = now - now % HOUR_MS
val hour = hours.lastOrNull()?.takeIf { it.startMs == start } ?: Hour(start).also { hours.addLast(it); while (hours.size > KEEP_HOURS) hours.removeFirst() }
hour.byKind[kind.ordinal]++
@@ -68,7 +75,7 @@ internal object ServerRequests {
@Synchronized fun lastHourTotal(): Int { val now = clock(); return hours.filter { it.startMs > now - HOUR_MS * 2 && it.startMs <= now }.lastOrNull()?.total ?: 0 }
@Synchronized fun lastDayTotal(): Int { val now = clock(); return hours.filter { it.startMs > now - 24 * HOUR_MS }.sumOf { it.total } }
@Synchronized fun summary(): JSONObject = JSONObject().put("hours", org.json.JSONArray(hours.map { it.toJson() }))
@Synchronized internal fun clearForTest() { hours.clear(); file = null; lastSaveMs = 0 }
@Synchronized internal fun clearForTest() { hours.clear(); lastHour.clear(); file = null; lastSaveMs = 0 }
@Synchronized fun save() {
val target = file ?: return
@@ -96,13 +103,21 @@ internal class PacedOut : EmbyCheckException("Orbit is pacing its background rea
internal object BackgroundPacing {
/** At most one background request this often: 1.5 s is at most 2,400 an hour, and the budget keeps it well under. */
const val GAP_MS = 1_500L
/** Background requests per TV per hour (Paul: never thousands an hour again). */
const val HOURLY_BUDGET = 600
/** Background requests per TV in any 60 minutes (Paul: never thousands an hour again; 200 since Orbit was banned from a share, 12 November 2026). */
const val HOURLY_BUDGET = 200
/**
* Every request this TV makes, playback included, in any 60 minutes (12 November 2026). Watching is never stopped, but
* once the TV reaches this, background work stops until the hour has room again, and Settings says so.
*/
const val TOTAL_CEILING = 400
/** When background work last stopped at [TOTAL_CEILING], for Settings; null if it hasn't since Orbit opened. */
@Volatile var ceilingHitMs: Long? = null
/**
* First-run and switch-on channel setup (0.129 audit): not on the hourly budget, since someone is waiting for it, but
* at most one request every [SETUP_GAP_MS], so a library check can't arrive as a burst (230 in 10 seconds before this).
* at most one request every [SETUP_GAP_MS], so a library check can't arrive as a burst (230 in 10 seconds before 0.129's
* audit; one a second since 12 November 2026, after the ban: eight channels on a new box take a few minutes).
*/
const val SETUP_GAP_MS = 150L
const val SETUP_GAP_MS = 1_000L
private val inBackground = ThreadLocal<Boolean>()
private val inSetup = ThreadLocal<Boolean>()
/** This thread is doing the background round's work. */
@@ -148,10 +163,11 @@ internal object BackgroundPacing {
if (wait > 0) { sleep(wait); now = clock() }
while (sent.isNotEmpty() && sent.first() <= now - 60 * 60_000L) sent.removeFirst()
if (sent.size >= HOURLY_BUDGET) throw PacedOut()
if (ServerRequests.inLastHour() >= TOTAL_CEILING) { ceilingHitMs = now; throw PacedOut() }
lastMs = now; sent.addLast(now)
}
}
internal fun resetForTest() { lastMs = 0; lastSetupMs = 0; sent.clear(); clock = System::currentTimeMillis; sleep = { Thread.sleep(it) } }
internal fun resetForTest() { lastMs = 0; lastSetupMs = 0; sent.clear(); ceilingHitMs = null; clock = System::currentTimeMillis; sleep = { Thread.sleep(it) } }
@Synchronized internal fun usedThisHour(): Int { val now = clock(); return sent.count { it > now - 60 * 60_000L } }
}
@@ -538,7 +538,9 @@ private fun AccountDetail(server: String, titles: Long?, onSignOut: () -> Unit,
} else SettingLine("Remove this server", "For leaving a box or starting again: deletes this server's data from this box only.") { OrbitButton("Remove", onClick = { removing = true }) }
// Requests to the server (0.129): counted on this TV only, so you can see Orbit is a light user of it.
val requestsHour = remember { ServerRequests.lastHourTotal() }; val requestsDay = remember { ServerRequests.lastDayTotal() }
SettingLine("Requests to your server", "This hour: $requestsHour. Last 24 hours: $requestsDay. Counted on this TV only; nothing is sent anywhere. Background reading keeps to $BACKGROUND_BUDGET_LINE.") {}
val ceilingHit = remember { BackgroundPacing.ceilingHitMs?.let { java.text.SimpleDateFormat("HH:mm", java.util.Locale.UK).format(java.util.Date(it)) } }
SettingLine("Requests to your server", "This hour: $requestsHour. Last 24 hours: $requestsDay. Counted on this TV only; nothing is sent anywhere. Background reading keeps to $BACKGROUND_BUDGET_LINE, " +
"and stops whenever this TV has made ${BackgroundPacing.TOTAL_CEILING} requests in an hour." + (ceilingHit?.let { " It last stopped at $it; watching carried on." } ?: "")) {}
SettingLine("Welcome tour", "See the first-launch steps a new box goes through, from Ollie's welcome to You're on air. Nothing is changed by it.") {
OrbitButton("Show it", onClick = { Onboarding.start(tour = true) })
}
@@ -612,7 +614,7 @@ internal fun SettingsScreen(section: SettingsSection, onSection: (SettingsSectio
SettingsSection.OnScreen -> ViewingDetail(firstSwitch, detail) {
Heading("Look")
Text("Every screen takes the look you pick, straight away. The cast, the channels' idents and the games keep their own colours.", color = Muted, fontSize = 12.sp)
LookPicker(firstSwitch, cardWidth = 150.dp)
LookPicker(firstSwitch, cardWidth = 128.dp)
}
SettingsSection.Family -> FamilyDetail(isOn(TOTS_NUMBER), windingDown, onWindDown, firstSwitch, detail)
SettingsSection.Rooms -> RoomsDetail(firstSwitch, detail, park = { runCatching { firstFocus.requestFocus() } })
@@ -12,7 +12,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
/**
* Orbit's looks (Paul, 5 November 2026, design/first-run/themes.png): six palettes, chosen at the start of onboarding or in
* Orbit's looks (Paul, 5 November 2026, design/first-run/themes.png; four more on 11 November): ten palettes, chosen at the start of onboarding or in
* Settings, applied at once everywhere. Every screen takes its colours from these tokens; nothing keeps a fixed navy or gold.
* Things with their own colours stay as they are in every look: the cast, the channels' idents and marks, the games' boards,
* and anything drawn over a picture. Orbit Night is the original, colour for colour.
@@ -81,7 +81,25 @@ internal enum class OrbitLook(val title: String, val line: String, val palette:
background = Color.Black, surface = Color(0xFF1A1A1A), raised = Color(0xFF333333), accent = Color(0xFFFFFF00),
ink = Color.White, muted = Color(0xFFDCDCDC), deep = Color(0xFF0D0D0D), sky = Color(0xFF66CCFF), mint = Color(0xFF66FF99),
onAccent = Color.Black, stars = Color(0xFF3C3C3C), gold = Color(0xFFFFFF00), later = Color(0xFF111111),
chairPanel = Color(0xFF1A1A1A), dim = Color(0xFF0D0D0D)));
chairPanel = Color(0xFF1A1A1A), dim = Color(0xFF0D0D0D))),
// Four more (Paul, 11 November 2026, design/layouts/build-themes.py): any layout can wear any of the ten.
Velvet("Velvet", "Burgundy and brass, like a cinema curtain", Palette(
background = Color(0xFF1E0710), surface = Color(0xFF4A1428), raised = Color(0xFF6B2340), accent = Color(0xFFD9A441),
ink = Color(0xFFFFF6EE), muted = Color(0xFFE3C3B0), deep = Color(0xFF2A0B17), sky = Color(0xFF9FC9FF), mint = Color(0xFF9EE0B5),
onAccent = Color(0xFF1E0710), stars = Color(0xFF5A2A3C), gold = Color(0xFFE7C27A))),
Evergreen("Evergreen", "Forest green and warm cream", Palette(
background = Color(0xFF0B1F17), surface = Color(0xFF1C4232), raised = Color(0xFF2C5E47), accent = Color(0xFFE8C468),
ink = Color(0xFFF6EFE0), muted = Color(0xFFBFD3C2), deep = Color(0xFF10291F), sky = Color(0xFF9ED4F0), mint = Color(0xFF9EE0B5),
onAccent = Color(0xFF0B1F17), stars = Color(0xFF2F5444), gold = Color(0xFFF0D58C))),
Sunset("Sunset", "Dusky plum and amber, gentle late at night", Palette(
background = Color(0xFF1F0F2E), surface = Color(0xFF4A2358), raised = Color(0xFF6A3466), accent = Color(0xFFFFB066),
ink = Color(0xFFFFF4EC), muted = Color(0xFFE5C2D4), deep = Color(0xFF2A1440), sky = Color(0xFFA9C8FF), mint = Color(0xFF9EE8C4),
onAccent = Color(0xFF1F0F2E), stars = Color(0xFF5A3470), gold = Color(0xFFFFC98A))),
Frost("Frost", "Ice-blue and silver, light and calm", Palette(
background = Color(0xFFEAF2F8), surface = Color(0xFFFFFFFF), raised = Color(0xFFC3D6E6), accent = Color(0xFF1F5F8F),
ink = Color(0xFF12324A), muted = Color(0xFF46617A), deep = Color(0xFFDCE8F2), sky = Color(0xFF1F6FA8), mint = Color(0xFF1E7D55),
onAccent = Color.White, stars = Color(0xFFBCCFDF), gold = Color(0xFF9A6A12), later = Color(0xFFF4F8FB),
chairPage = Color(0xFFEAF2F8), chairPanel = Color(0xFFF7FAFC), dim = Color(0xFFDDE7EF), light = true));
}
/** The look in use. Read during drawing, so changing it redraws every screen at once. */
@@ -0,0 +1,48 @@
package tv.orbit.classic
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
/** The limits added after the ban (12 November 2026): a 400-an-hour ceiling on everything, 200 in the background. */
class SafetyLimitsTest {
private var now = 1_800_000_000_000L
@Before fun up() { ServerRequests.clearForTest(); ServerRequests.clock = { now }; BackgroundPacing.resetForTest(); BackgroundPacing.clock = { now }; BackgroundPacing.sleep = { now += it } }
@After fun down() { ServerRequests.clearForTest(); ServerRequests.clock = System::currentTimeMillis; BackgroundPacing.resetForTest() }
private fun background(): Boolean = try { BackgroundPacing.run { BackgroundPacing.beforeRequest(); ServerRequests.count(RequestKind.Catalogue, true) }; true } catch (_: PacedOut) { false }
@Test fun backgroundStopsAtTwoHundredAnHour() {
var made = 0
while (background()) made++
assertEquals(200, made)
}
@Test fun watchingNeverStopsButBackgroundYieldsAtTheCeiling() {
// An evening of heavy use: 380 playback requests in the hour, none of them slowed or refused.
repeat(380) { BackgroundPacing.beforeRequest(); ServerRequests.count(RequestKind.Report, true); now += 1_000 }
var made = 0
while (made < 100 && background()) made++
assertEquals("background stops once the TV reaches 400 in all", 20, made)
assertNotNull(BackgroundPacing.ceilingHitMs)
// Playback still goes through at the ceiling.
BackgroundPacing.beforeRequest(); ServerRequests.count(RequestKind.Report, true)
assertEquals(401, ServerRequests.inLastHour())
// An hour on, there's room again.
now += 60 * 60_000L
assertTrue(background())
}
@Test fun setupIsOneRequestASecond() {
val times = mutableListOf<Long>()
BackgroundPacing.setup { repeat(30) { BackgroundPacing.beforeRequest(); times += now } }
assertTrue(times.zipWithNext().all { (a, b) -> b - a >= 1_000 })
}
@Test fun theGuidePictureRestsAfterTenMinutes() {
assertEquals(10 * 60_000L, GUIDE_PICTURE_REST_MS)
// The rest begins exactly ten minutes after the last press (plus the same small margin as a programme's end).
assertEquals(GUIDE_PICTURE_REST_MS + 50, programmeEndDelayMs(1_000L + GUIDE_PICTURE_REST_MS, 1_000L))
}
}