Create a channel: watch it now, or after this programme

Once a channel is made, the phone offers Watch after this programme (it joins
the queue) and Watch now, waiting while its first programmes are planned.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-07 08:30:02 +00:00
co-authored by Claude Opus 5.5
parent 10cd9b278a
commit 2f41a76cc5
4 changed files with 31 additions and 6 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ android {
applicationId = "tv.orbit.classic"
minSdk = 26
targetSdk = 36
versionCode = 243
versionName = "0.108.83-smart-setup"
versionCode = 244
versionName = "0.108.84-smart-setup"
}
buildFeatures { compose = true }
// The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so
@@ -258,6 +258,13 @@ const SLOTS = [['Daytime','06:00 to 17:00'],['Evening','17:00 to 22:00'],['Late'
const sameHours = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
function create() {
const c = state.create, d = c.draft;
if (c.done) return `<div style="text-align:center;padding:40px 8px 0"><div style="font-size:44px;color:var(--mint)">✓</div>
<div class="title" style="white-space:normal">${esc(c.done.name)} is ready on ${c.done.number}</div>
<div class="small" style="margin:8px 0 22px">${esc(c.done.message || '')}</div>
${c.watching ? `<div class="card small" style="margin-bottom:12px">${esc(c.watching)}</div>` : ''}
<button class="btn gold" data-cwatch="next" style="margin-bottom:8px">Watch after this programme</button>
<button class="btn" data-cwatch="now" style="margin-bottom:8px">Watch now</button>
<button class="btn" data-cdone="1" style="background:none;color:var(--muted)">Done</button></div>`;
const bar = `<div style="display:flex;gap:6px;margin:4px 0 4px">${STEPS.map((n, i) => `<div style="flex:1"><div style="height:4px;border-radius:2px;background:${i <= c.step ? 'var(--accent)' : 'var(--surface)'}"></div>
<div class="small" style="font-size:10px;margin-top:4px;${i === c.step ? 'color:var(--ink);font-weight:700' : ''}">${n}</div></div>`).join('')}</div>`;
const top = `<header><button data-cback="1" aria-label="Back" style="padding:4px 6px 4px 0">${I.chev('left')}</button><span class="title" style="font-size:20px;margin:0">${d.number ? 'Edit ' + esc(d.name) : 'Create a channel'}</span></header>` + bar;
@@ -374,11 +381,27 @@ async function suggestShows() {
catch (e) { c.note = e.message; }
c.busy = false; render();
}
// A new channel takes a moment to plan its first programmes, so the phone keeps asking until the TV can tune it.
async function watchNew(when) {
const c = state.create; if (!c?.done || c.trying) return;
c.trying = true; c.watching = 'Planning its first programmes…'; render();
for (let i = 0; i < 30; i++) {
try {
if (when === 'now') await api('/api/tune', {number: c.done.number});
else await api('/api/queue', {number: c.done.number});
state.create = null; tab = 'remote'; render(); load('now');
toast(when === 'now' ? 'On the TV now' : 'Switches when this programme ends'); return;
} catch (e) { if (!/isn't on this TV/.test(e.message)) { c.watching = e.message; break; } }
await new Promise(r => setTimeout(r, 3000));
}
c.trying = false; if (c.watching === 'Planning its first programmes…') c.watching = "It's still planning. Try again in a minute, or find it in the Guide."; render();
}
async function makeChannel() {
const c = state.create, d = c.draft; if (c.busy) return; c.busy = true; render();
try { const r = await api('/api/channels', {number: d.number, name: d.name, description: d.description, style: d.style, hours: d.hours, shows: d.shows,
slots: d.style === 'Shaped' ? d.slots : undefined, core: d.style === 'Shaped' ? d.core : undefined});
state.create = null; toast(r.message || 'Saved'); load('more'); }
// Made: offer to watch it now, or straight after the programme on the TV (Paul, 7 November 2026).
c.done = {number: r.number, name: d.name, message: r.message, edit: !!d.number}; c.busy = false; render(); load('more'); }
catch (e) { c.note = e.message; c.busy = false; render(); }
}
@@ -496,6 +519,8 @@ document.addEventListener('click', e => {
if (d.cout) { const dr = state.create.draft; dr.shows = dr.shows.filter(x => x.id !== d.cout); dr.core = dr.core.filter(x => x !== d.cout); delete dr.slots[d.cout];
if (!dr.shows.length) { state.create.step = 1; } render(); return; }
if (d.cmake) { makeChannel(); return; }
if (d.cdone) { state.create = null; render(); return; }
if (d.cwatch) { watchNew(d.cwatch); 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; }
@@ -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.83\"") +
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.84\"") +
(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.83\"" +
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.84\"" +
(token?.let { ", Token=\"$it\"" } ?: ""))
}
/** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */
@@ -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.83")
next.setRequestProperty("User-Agent", "OrbitTV/0.108.84")
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()) {