From 6b65a230ea1653bb57adda18babe49d3b5481b9a Mon Sep 17 00:00:00 2001 From: Pauljd Date: Fri, 6 Nov 2026 12:46:56 +0000 Subject: [PATCH] Setting channels up no longer restarts the background round for each one (0.108.54) Seen on the upstairs box: each channel set up changed extraChannels, which restarted the hourly top-up round from the first channel, so 305 and 601 were re-planned dozens of times while setting up. The round now waits until setting up is over, then a moment. Co-Authored-By: Claude Opus 5.5 (1M context) --- android/app/build.gradle.kts | 4 ++-- android/app/src/main/java/tv/orbit/classic/EmbyClient.kt | 4 ++-- .../src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt | 6 ++++++ .../src/main/java/tv/orbit/classic/SecureMediaDataSource.kt | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 003ee7a0..4de3aee8 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -9,8 +9,8 @@ android { applicationId = "tv.orbit.classic" minSdk = 26 targetSdk = 36 - versionCode = 213 - versionName = "0.108.53-autoscan" + versionCode = 214 + versionName = "0.108.54-setup-once" } buildFeatures { compose = true } // Android logging and the like do nothing in unit tests, so whole flows (a channel read from a fake server) can run. diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt index 5a2d0ab2..7a16ce4f 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt @@ -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 = when (kind) { - ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.53\"") + + ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.54\"") + (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.53\"" + + ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.54\"" + (token?.let { ", Token=\"$it\"" } ?: "")) } /** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */ diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt index d22caa99..a05dc01b 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt @@ -48,6 +48,7 @@ import kotlinx.coroutines.CancellationException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.flow.first import kotlinx.coroutines.Job import kotlinx.coroutines.ensureActive import kotlinx.coroutines.delay @@ -373,6 +374,11 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea reminders = liveReminders(scheduleStore.loadReminders(active.accountId), System.currentTimeMillis()) } } catch (cancelled: CancellationException) { throw cancelled } catch (_: Exception) { /* The round below tries again. */ } + // Setting channels up adds each to extraChannels, which restarts this round from the first channel every time: with + // 30 channels that was hundreds of needless top-ups (seen on the upstairs box, 6 November 2026). Wait until setting up + // is over, and a moment more so a run of changes counts once. + androidx.compose.runtime.snapshotFlow { ChannelSetup.wanted.isEmpty() || ChannelSetup.finished }.first { it } + delay(3_000) while (true) { for (programming in SmartChannels) { val loop = smartLoop(programming) ?: continue diff --git a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt index 0ccb62f6..cd26a574 100644 --- a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt +++ b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt @@ -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.53") + next.setRequestProperty("User-Agent", "OrbitTV/0.108.54") 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()) {