Morning fixes: Catch Up-only Continue watching, Companion stays up, guide clock, VHS and Horror samples (0.108.104)
Continue watching only notes programmes watched in Catch Up; the lists made from live viewing are set aside once. The phone server keeps running while Orbit is in the background, and the Companion says when Orbit isn't on screen and retries. The guide, Catch Up and channel clocks put the time right as soon as full screen ends. Paul's royalty-free cassette and scream samples are mastered into the VHS and Horror idents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -151,7 +151,8 @@ internal fun catchUpMatches(entry: CatchUpEntry, channel: Int?, query: String):
|
||||
internal fun CatchUpScreen(channels: List<SampleChannel>, session: EmbySampleSession?, modifier: Modifier = Modifier, onOpen: (CatchUpEntry) -> Unit,
|
||||
onResume: (ContinueEntry) -> Unit = {}) {
|
||||
var now by remember { mutableLongStateOf(System.currentTimeMillis()) }
|
||||
LaunchedEffect(Unit) { while (true) { delay(30_000); if (!FullScreen.active) now = System.currentTimeMillis() } }
|
||||
val fullScreen = FullScreen.active
|
||||
LaunchedEffect(fullScreen) { if (!fullScreen) now = System.currentTimeMillis(); while (true) { delay(30_000); if (!FullScreen.active) now = System.currentTimeMillis() } }
|
||||
var channelFilter by remember { mutableStateOf<Int?>(null) }
|
||||
var query by remember { mutableStateOf("") }
|
||||
var searching by remember { mutableStateOf(false) }
|
||||
|
||||
@@ -8,7 +8,8 @@ import org.json.JSONObject
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Continue watching (Paul, 7 November 2026): where you left a programme part-way, from Catch Up or live, so Catch Up can
|
||||
* Continue watching (Paul, 7 November 2026): where you left a programme part-way in Catch Up (live viewing isn't counted, since
|
||||
* 8 November 2026), so Catch Up can
|
||||
* carry it on from there while it's still in Catch Up. One list per profile, on this box only. It only reads the plans.
|
||||
*/
|
||||
internal class ContinueMark(val number: Int, val startMs: Long, val itemId: String, val positionMs: Long, val durationMs: Long, val atMs: Long) {
|
||||
@@ -63,6 +64,12 @@ internal object ContinueWatching {
|
||||
private var file: File? = null
|
||||
|
||||
fun load(scheduleDir: File, profile: String?) {
|
||||
// Once: the lists made while live viewing counted too are set aside, now that only Catch Up adds to them.
|
||||
val flag = File(scheduleDir, "continue-catchup-only")
|
||||
if (!flag.exists()) runCatching {
|
||||
scheduleDir.listFiles { f -> Regex("continue-[A-Za-z0-9]{1,40}\\.json").matches(f.name) }?.forEach { it.renameTo(File(scheduleDir, it.name + ".before-catchup-only")) }
|
||||
flag.writeText("")
|
||||
}
|
||||
file = File(scheduleDir, "continue-${(profile ?: "all").filter { it.isLetterOrDigit() }.take(40)}.json")
|
||||
marks = runCatching { JSONArray(file!!.readText()).let { a -> (0 until minOf(a.length(), CONTINUE_MAX)).mapNotNull { runCatching { ContinueMark.fromJson(a.getJSONObject(it)) }.getOrNull() } } }.getOrDefault(emptyList())
|
||||
}
|
||||
|
||||
@@ -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.103\"") +
|
||||
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.104\"") +
|
||||
(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.103\"" +
|
||||
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.104\"" +
|
||||
(token?.let { ", Token=\"$it\"" } ?: ""))
|
||||
}
|
||||
/** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */
|
||||
|
||||
@@ -327,7 +327,8 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
catch (_: Exception) { message = "Connected, but this setup could not be saved securely. It will need sign-in after restart." }
|
||||
}
|
||||
}
|
||||
LaunchedEffect(Unit) { while (true) { delay(1000); if (!FullScreen.active) now = System.currentTimeMillis() } }
|
||||
val fullScreen = FullScreen.active
|
||||
LaunchedEffect(fullScreen) { if (!fullScreen) now = System.currentTimeMillis(); while (true) { delay(1000); if (!FullScreen.active) now = System.currentTimeMillis() } }
|
||||
LaunchedEffect(scheduledChannels) { windingDown = scheduledChannels[TOTS_NUMBER]?.stepIn?.let { it.endMs > System.currentTimeMillis() } == true }
|
||||
fun smartLoop(programming: ChannelProgramming) = (extraChannels + listOfNotNull(channel, afterDarkChannel, toonamiChannel)).firstOrNull { it.number == programming.number }
|
||||
LaunchedEffect(session != null) { if (session != null) onSignedIn() }
|
||||
@@ -380,7 +381,8 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
val now = System.currentTimeMillis(); val at = now + channelClockOffset
|
||||
val show = runCatching { channel.at(at) }.getOrNull() ?: continue
|
||||
if (show.endMs - show.startMs < 10 * 60_000L) continue
|
||||
runCatching { withContext(Dispatchers.IO) { ContinueWatching.note(channel.number, show, at - show.startMs, now) } }
|
||||
// Continue watching is for Catch Up only (Paul, 8 November 2026): what you watch live isn't added to it.
|
||||
if (channelClockOffset < 0) runCatching { withContext(Dispatchers.IO) { ContinueWatching.note(channel.number, show, at - show.startMs, now) } }
|
||||
runCatching { withContext(Dispatchers.IO) { Taste.watching(channel.number, show, channel.seriesIdAt(show.startMs), at - show.startMs, now) } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ internal fun clock(time: Long) = SimpleDateFormat("HH:mm", Locale.UK).format(Dat
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onStart() {
|
||||
super.onStart(); if (PhoneLink.phones.isNotEmpty()) PhoneLink.start()
|
||||
super.onStart(); OrbitCompanion.onTv = true; if (PhoneLink.phones.isNotEmpty()) PhoneLink.start()
|
||||
// Multiroom auto-scan: a set-up Orbit can be found by a new TV while it's open.
|
||||
if (Onboarding.done(this)) {
|
||||
RoomBeacon.on(this)
|
||||
@@ -54,7 +54,9 @@ class MainActivity : ComponentActivity() {
|
||||
lifecycleScope.launch { runCatching { RoomUpdates.look(this@MainActivity) } }
|
||||
}
|
||||
}
|
||||
override fun onStop() { RoomBeacon.off(this); PhoneLink.offerRoom(null); PhoneLink.stop(); super.onStop() }
|
||||
// Phones stay connected while Orbit is in the background (Paul, 8 November 2026: the web app couldn't connect while the TV
|
||||
// was in another app), and paired rooms keep syncing; the phone says Orbit isn't on screen instead of failing to load.
|
||||
override fun onStop() { OrbitCompanion.onTv = false; PhoneLink.offerRoom(null); if (PhoneLink.phones.isEmpty() && RoomLinks.links.none { it.on }) { RoomBeacon.off(this); PhoneLink.stop() }; super.onStop() }
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
OrbitCompanion.activity = java.lang.ref.WeakReference(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
@@ -122,6 +122,8 @@ internal object OrbitCompanion {
|
||||
private fun channelJson(c: SampleChannel) = JSONObject().put("number", c.number).put("name", ChannelBrands.forNumber(c.number)?.displayName ?: c.name)
|
||||
|
||||
/** What the TV is on: the chosen channel, what it's showing at the TV's clock, and what's next. */
|
||||
/** Orbit is on the TV's screen; false while the TV shows another app (phones and paired rooms still connect). */
|
||||
@Volatile var onTv = true
|
||||
fun now(screen: CompanionScreen, nowMs: Long): JSONObject {
|
||||
val reply = JSONObject().put("room", Rooms.name).put("look", look()).put("serverMs", nowMs)
|
||||
val channel = screen.channels().firstOrNull { it.number == screen.selected() } ?: return reply.put("channel", JSONObject.NULL)
|
||||
|
||||
@@ -491,7 +491,7 @@ internal object PhoneLink {
|
||||
fun body() = runCatching { JSONObject(r.body) }.getOrNull() ?: JSONObject()
|
||||
fun onScreen(block: () -> Unit) = runBlocking { withContext(mainDispatcher) { block() } }
|
||||
when ("${r.method} ${r.path}") {
|
||||
"GET /api/now" -> json(out, 200, OrbitCompanion.now(s, now).put("queue", OrbitCompanion.queueJson()))
|
||||
"GET /api/now" -> json(out, 200, OrbitCompanion.now(s, now).put("queue", OrbitCompanion.queueJson()).put("onTv", OrbitCompanion.onTv))
|
||||
"GET /api/guide" -> json(out, 200, OrbitCompanion.guide(s, now))
|
||||
"GET /api/catchup" -> json(out, 200, JSONObject().put("shelves", OrbitCompanion.catchUp(s, now)))
|
||||
"GET /api/rooms" -> json(out, 200, OrbitCompanion.rooms(appContext))
|
||||
|
||||
@@ -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.103")
|
||||
next.setRequestProperty("User-Agent", "OrbitTV/0.108.104")
|
||||
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()) {
|
||||
|
||||
@@ -15,7 +15,10 @@ import kotlinx.coroutines.delay
|
||||
@Composable
|
||||
internal fun rememberMinuteClock(): State<Long> {
|
||||
val now = remember { mutableLongStateOf(System.currentTimeMillis()) }
|
||||
LaunchedEffect(Unit) {
|
||||
// Back from full screen: the time is put right at once, not when the next minute turns (Paul, 8 November 2026).
|
||||
val full = FullScreen.active
|
||||
LaunchedEffect(full) {
|
||||
if (!full) now.longValue = System.currentTimeMillis()
|
||||
while (true) {
|
||||
val at = System.currentTimeMillis()
|
||||
delay(MINUTE_MS - at % MINUTE_MS + 50)
|
||||
|
||||
Reference in New Issue
Block a user