Release Kaleido Desktop 0.1.0-beta.18
All checks were successful
Validate Kaleido Desktop / validate (push) Successful in 1m29s

Rebuild the Up Next screen on Kaleido's own components:
- Backdrop, colour wash, buttons and cards from the title pages; the
  credits play in a top-left frame with a matching hole in the page.
- Season and related rows use Shelf, so they scroll with side arrows
  instead of scrollbars; the season row starts at the playing episode.
- Returning to the video at the end no longer restarts the episode.
- Compact layout for short windows; Mac window buttons stay visible.
- Restore the flat Episodes and markers settings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-12 12:17:52 -07:00
parent 2db7d8b272
commit 70530e30e2
12 changed files with 427 additions and 346 deletions

View file

@ -911,7 +911,7 @@ export function PlayerOverlay() {
}, [st.open, st.mini, seekStep, poke]);
// The macOS traffic lights fade with the rest of the player's chrome.
const chromeHidden = st.open && !st.mini && !visible && st.firstFrame && !st.error;
const chromeHidden = st.open && !st.mini && !st.postPlay && !visible && st.firstFrame && !st.error;
useEffect(() => {
if (!chromeHidden) return;
win.setButtonsVisible(false);

View file

@ -1,181 +1,297 @@
import { useEffect, useRef, useState, type CSSProperties } from 'react';
import { useEffect, useLayoutEffect, useRef, type CSSProperties } from 'react';
import { useQuery } from '@tanstack/react-query';
import { usePlayer } from './store';
import { mpv } from './engine';
import { isNative } from '../platform/native';
import { useSession } from '../app/session';
import { navigate } from '../app/router';
import { clock, duration, episodeLabel } from '../app/format';
import { art, clock, duration, episodeLabel } from '../app/format';
import * as api from '../plex/api';
import type { Item } from '../plex/types';
import { Backdrop } from '../ui/Backdrop';
import { Facts, TitleArt } from '../ui/media';
import { Facts, Shelf, TitleArt } from '../ui/media';
import { Artwork } from '../ui/primitives';
import { Icon } from '../ui/Icon';
import { WindowControls } from '../app/TopBar';
import { Spinner } from '../ui/primitives';
/** One Up Next screen, with a transparent opening over the native video. */
/**
* Up Next, adapted from Kaleido for Android TV: the credits keep playing in the
* top-left corner (the native video is drawn into that rectangle, with a matching
* hole in the page) beside the next episode, with the season and related shows
* below. Play next episode carries the one countdown; moving the mouse, clicking,
* scrolling or pressing a key stops it. Clicking the video, or Esc, returns to it.
*/
export function PostPlay() {
const st = usePlayer();
const item = usePlayer((s) => s.item)!;
const nextUp = usePlayer((s) => s.nextUp);
const contextReady = usePlayer((s) => s.episodeContextReady);
const fullscreen = usePlayer((s) => s.fullscreen);
const server = useSession((s) => s.server);
const root = useRef<HTMLDivElement>(null);
const video = useRef<HTMLButtonElement>(null);
const play = useRef<HTMLButtonElement>(null);
const currentEpisode = useRef<HTMLButtonElement>(null);
const [season, setSeason] = useState<Item[]>([]);
const [related, setRelated] = useState<Item[]>([]);
const [details, setDetails] = useState<Item | null>(null);
const item = st.item!;
const upcoming = details?.id === st.nextUp?.id ? details : st.nextUp;
const counting = st.countdown !== null;
// The listed episode lacks the rating and full synopsis.
const details = useQuery({
queryKey: [server?.machineId, 'item', nextUp?.id],
queryFn: () => api.metadata(server!, nextUp!.id),
enabled: !!server && !!nextUp,
staleTime: 30_000,
});
const upcoming = nextUp && details.data?.id === nextUp.id ? details.data : nextUp;
useVideoRect(root, video);
useEffect(() => {
currentEpisode.current?.scrollIntoView({ block: 'nearest', inline: 'center' });
}, [season]);
useEffect(() => {
if (!server) return;
let alive = true;
if (item.parentId) api.children(server, item.parentId).then((items) => alive && setSeason(items), () => {});
if (item.grandparentId) api.related(server, item.grandparentId).then((hubs) => {
const seen = new Set<string>([item.grandparentId]);
const shows = hubs.flatMap((h) => h.items).filter((i) => i.type === 'show' && !seen.has(i.id) && !!seen.add(i.id));
if (alive) setRelated(shows);
}, () => {});
return () => { alive = false; };
}, [server, item.id]);
useEffect(() => {
if (!server || !st.nextUp) return;
let alive = true;
api.metadata(server, st.nextUp.id).then((next) => alive && setDetails(next), () => {});
return () => { alive = false; };
}, [server, st.nextUp?.id]);
useEffect(() => {
const previous = document.activeElement as HTMLElement | null;
(play.current ?? video.current)?.focus({ preventScroll: true });
const cancel = () => {
const player = usePlayer.getState();
if (!player.postPlayDismissed) player.cancelCountdown();
};
const move = (event: MouseEvent) => {
if (event.movementX !== 0 || event.movementY !== 0) cancel();
const stop = () => {
if (usePlayer.getState().countdown !== null) usePlayer.getState().cancelCountdown();
};
// Layout changes can send a mousemove without the mouse moving.
const move = (e: MouseEvent) => (e.movementX || e.movementY) && stop();
const key = (e: KeyboardEvent) => {
cancel();
stop();
if (e.key === 'Escape' || e.key === 'Backspace') {
e.preventDefault();
e.stopImmediatePropagation();
usePlayer.getState().dismissPostPlay();
} else if (e.key === 'F11' || (e.key.toLowerCase() === 'f' && !e.ctrlKey && !e.metaKey && !e.altKey)) {
} else if (e.key === 'F11' || ((e.key === 'f' || e.key === 'F') && !e.ctrlKey && !e.metaKey && !e.altKey)) {
e.preventDefault();
usePlayer.getState().toggleFullscreen();
} else if (e.key === 'Tab') {
// Keep keyboard focus in the player, including after Shift+Tab.
const buttons = [...root.current!.querySelectorAll<HTMLButtonElement>('button:not(:disabled)')];
const first = buttons[0], last = buttons[buttons.length - 1];
if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last?.focus(); }
else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first?.focus(); }
}
};
const opts = { capture: true, passive: true };
window.addEventListener('keydown', key, true);
window.addEventListener('pointerdown', cancel, true);
window.addEventListener('mousemove', move, { capture: true, passive: true });
window.addEventListener('wheel', cancel, { capture: true, passive: true });
window.addEventListener('pointerdown', stop, opts);
window.addEventListener('mousemove', move, opts);
window.addEventListener('wheel', stop, opts);
return () => {
window.removeEventListener('keydown', key, true);
window.removeEventListener('pointerdown', cancel, true);
window.removeEventListener('mousemove', move, true);
window.removeEventListener('wheel', cancel, true);
if (previous?.isConnected) previous.focus({ preventScroll: true });
window.removeEventListener('pointerdown', stop, opts);
window.removeEventListener('mousemove', move, opts);
window.removeEventListener('wheel', stop, opts);
};
}, []);
useEffect(() => {
const el = video.current;
if (!el) return;
let frame = 0;
const backToVideo = () => usePlayer.getState().dismissPostPlay();
return (
<div className="player up-next" ref={root} role="dialog" aria-modal="true" aria-labelledby="up-next-label">
<div className="up-next-scene">{server && <Backdrop item={upcoming ?? item} className="up-next-backdrop" />}</div>
<div className="up-next-top" data-tauri-drag-region={isNative ? true : undefined}>
{!fullscreen && <WindowControls />}
</div>
<div className="up-next-head">
<div className="up-next-now">
<button ref={video} className="up-next-video" onClick={backToVideo} aria-label={`Return to ${item.title}`} />
<NowPlaying item={item} />
</div>
<div className="up-next-info">
<span className="micro" id="up-next-label">
{upcoming || !contextReady ? 'Up next' : 'More to watch'}
</span>
<TitleArt item={item} maxWidth={300} maxHeight={64} as="h2" className="up-next-logo" />
{upcoming ? (
<>
<h1>{upcoming.title}</h1>
<Facts item={{ ...upcoming, viewOffset: 0, originallyAvailableAt: '' }} withFormats={false} />
{upcoming.summary && <p className="up-next-summary">{upcoming.summary}</p>}
<PlayNext ref={play} />
</>
) : (
contextReady && <p className="up-next-summary">You’ve reached the end of this series.</p>
)}
</div>
</div>
{server && <UpNextRows item={item} nextUp={nextUp} />}
</div>
);
}
/**
* Draws the native video into the frame's rectangle and cuts the same hole in
* the page, following window resizes and display scale changes.
*/
function useVideoRect(root: React.RefObject<HTMLDivElement | null>, frame: React.RefObject<HTMLElement | null>) {
useLayoutEffect(() => {
const el = frame.current;
const page = root.current;
if (!el || !page) return;
let raf = 0;
const place = () => {
cancelAnimationFrame(frame);
frame = requestAnimationFrame(() => {
cancelAnimationFrame(raf);
raf = requestAnimationFrame(() => {
const r = el.getBoundingClientRect();
const style = root.current!.style;
for (const [key, value] of Object.entries({ x: r.x, y: r.y, w: r.width, h: r.height })) style.setProperty(`--up-video-${key}`, `${value}px`);
page.style.setProperty('--up-x', `${r.x}px`);
page.style.setProperty('--up-y', `${r.y}px`);
page.style.setProperty('--up-w', `${r.width}px`);
page.style.setProperty('--up-h', `${r.height}px`);
page.classList.add('placed');
const dpr = window.devicePixelRatio || 1;
// A pixel of overdraw on each side keeps the hole covered at any scale.
if (isNative) mpv.rect({ x: r.x * dpr - 1, y: r.y * dpr - 1, width: r.width * dpr + 2, height: r.height * dpr + 2 }).catch(() => {});
root.current!.classList.add('placed');
});
};
const observer = new ResizeObserver(place);
observer.observe(el);
const ro = new ResizeObserver(place);
ro.observe(el);
window.addEventListener('resize', place);
place();
return () => {
cancelAnimationFrame(frame);
observer.disconnect();
cancelAnimationFrame(raf);
ro.disconnect();
window.removeEventListener('resize', place);
if (isNative) mpv.rect(null).catch(() => {});
};
}, []);
}
const watch = () => {
if (st.ended) st.togglePause();
st.dismissPostPlay();
};
const choose = (episode: Item) => {
if (episode.id === item.id) watch();
else st.play(episode, { resume: true, quality: st.quality });
};
const browse = async (show: Item) => {
await st.close();
navigate({ name: 'item', id: show.id, title: show.title });
};
const rail = (label: string, items: Item[], episodes: boolean) => items.length > 0 && (
<section className="up-next-rail" aria-label={label}>
<h2>{label}</h2>
<div className="up-next-cards">
{items.map((entry) => (
<button key={entry.id} ref={entry.id === item.id ? currentEpisode : undefined} className="up-next-card" onClick={() => episodes ? choose(entry) : void browse(entry)} aria-current={entry.id === item.id ? 'true' : undefined}>
<div className="up-next-card-art">
{server && (entry.thumb || entry.art) && <img src={server.image(episodes ? entry.thumb : entry.art || entry.thumb, 360, 202)} alt="" loading="lazy" draggable={false} />}
</div>
<b>{episodes ? `${entry.index}. ${entry.title}` : entry.title}</b>
<small>{entry.id === item.id ? 'Now playing' : entry.id === st.nextUp?.id ? 'Up next' : episodes ? duration(entry.duration) : entry.year || ''}</small>
</button>
))}
</div>
</section>
);
/** Where the playing episode is, under the video. Its own subscription: position ticks re-render only this. */
function NowPlaying({ item }: { item: Item }) {
const position = usePlayer((s) => s.position);
const total = usePlayer((s) => s.duration);
return (
<div className="player up-next" ref={root} role="dialog" aria-modal="true" aria-labelledby="up-next-heading">
<div className="up-next-scene">{server && <Backdrop item={upcoming ?? item} />}</div>
{!st.fullscreen && <div className="up-next-window-controls"><WindowControls /></div>}
<div className="up-next-header" data-tauri-drag-region={isNative ? true : undefined}>
<div className="up-next-now">
<button ref={video} className="up-next-video" onClick={watch} aria-label={`Return to ${item.title}`} />
<div className="up-next-caption"><span>{episodeLabel(item)} · {item.title}</span><small>−{clock(Math.max(0, st.duration - st.position))}</small></div>
<div className="up-next-progress"><i style={{ width: `${st.duration ? Math.min(100, st.position / st.duration * 100) : 0}%` }} /></div>
</div>
<div className="up-next-details">
<span className="micro" id="up-next-heading">{upcoming || !st.episodeContextReady ? 'Up next' : 'More to watch'}</span>
<TitleArt item={item} maxWidth={280} maxHeight={52} as="h2" />
{upcoming ? <>
<h1>{upcoming.title}</h1>
<Facts item={{ ...upcoming, viewOffset: 0, originallyAvailableAt: '' }} withFormats={false} />
{upcoming.summary && <p className="up-next-summary">{upcoming.summary}</p>}
<div className="actions">
<button ref={play} className={`up-next-play${counting ? ' counting' : ''}`} style={{ '--p': `${counting && st.countdownTotal ? (1 - st.countdown! / st.countdownTotal) * 100 : 0}%` } as CSSProperties} onClick={() => st.playNext()}>
<span><Icon name="play" size={18} /> Play next episode</span>
</button>
</div>
</> : st.episodeContextReady ? <p className="up-next-summary">You’ve reached the end of this series.</p> : <Spinner size={24} />}
</div>
<div className="up-next-progress">
<div className="up-next-progress-text">
<span>
{episodeLabel(item)} · {item.title}
</span>
<small>−{clock(Math.max(0, total - position))}</small>
</div>
<div className="up-next-rows">
{rail(item.parentIndex ? `Season ${item.parentIndex}` : 'Episodes', season, true)}
{rail('Related shows', related, false)}
<div className="up-next-progress-bar">
<i style={{ width: `${total ? Math.min(100, (position / total) * 100) : 0}%` }} />
</div>
</div>
);
}
/** Play next episode. While autoplay counts down, a lighter fill sweeps across it. */
function PlayNext({ ref }: { ref: React.Ref<HTMLButtonElement> }) {
const countdown = usePlayer((s) => s.countdown);
const total = usePlayer((s) => s.countdownTotal);
const counting = countdown !== null && total > 0;
const fill = counting ? (1 - countdown / total) * 100 : 0;
return (
<button
ref={ref}
className={`btn primary lg up-next-play${counting ? ' counting' : ''}`}
style={{ '--fill': `${fill}%` } as CSSProperties}
onClick={() => usePlayer.getState().playNext()}
>
<Icon name="play" size={17} />
<span>Play next episode</span>
</button>
);
}
function UpNextRows({ item, nextUp }: { item: Item; nextUp: Item | null }) {
const server = useSession((s) => s.server)!;
const season = useQuery({
queryKey: [server.machineId, 'children', item.parentId],
queryFn: () => api.children(server, item.parentId),
enabled: !!item.parentId,
staleTime: 30_000,
});
const related = useQuery({
queryKey: [server.machineId, 'related', item.grandparentId],
queryFn: () => api.related(server, item.grandparentId),
enabled: !!item.grandparentId,
staleTime: 10 * 60_000,
});
const episodes = (season.data ?? []).filter((e) => e.type === 'episode');
const seen = new Set([item.grandparentId]);
const shows = (related.data ?? []).flatMap((h) => h.items).filter((i) => i.type === 'show' && !seen.has(i.id) && !!seen.add(i.id));
// The season row starts just before the playing episode.
const seasonRow = useRef<HTMLDivElement>(null);
useLayoutEffect(() => {
const row = seasonRow.current?.querySelector<HTMLElement>('.shelf');
const current = row?.querySelector<HTMLElement>('[aria-current]');
if (!row || !current) return;
const start = (current.previousElementSibling as HTMLElement | null) ?? current;
const target = row.scrollLeft + start.getBoundingClientRect().left - row.getBoundingClientRect().left - parseFloat(getComputedStyle(row).paddingLeft);
row.scrollTo({ left: target, behavior: 'instant' });
}, [episodes.length]);
const choose = (episode: Item) => {
const st = usePlayer.getState();
if (episode.id === item.id) st.dismissPostPlay();
else st.play(episode, { resume: true, quality: st.quality });
};
const browse = async (show: Item) => {
await usePlayer.getState().close();
navigate({ name: 'item', id: show.id, title: show.title });
};
if (!episodes.length && !shows.length) return null;
return (
<div className="up-next-rows">
{episodes.length > 0 && (
<div ref={seasonRow}>
<Shelf title={item.parentIndex ? `Season ${item.parentIndex}` : 'Episodes'} kind="landscape" className="up-next-shelf">
{episodes.map((ep) => (
<UpNextCard
key={ep.id}
item={ep}
current={ep.id === item.id}
caption={ep.id === item.id ? 'Now playing' : ep.id === nextUp?.id ? 'Up next' : duration(ep.duration)}
onChoose={() => choose(ep)}
/>
))}
</Shelf>
</div>
)}
{shows.length > 0 && (
<Shelf title="Related shows" kind="landscape" className="up-next-shelf">
{shows.map((show) => (
<UpNextCard key={show.id} item={show} caption={show.year ? String(show.year) : ''} onChoose={() => void browse(show)} />
))}
</Shelf>
)}
</div>
);
}
function UpNextCard({ item, caption, current, onChoose }: { item: Item; caption: string; current?: boolean; onChoose: () => void }) {
const server = useSession((s) => s.server)!;
const episode = item.type === 'episode';
const title = episode ? `${item.index}. ${item.title}` : item.title;
const progress = episode && !current && item.viewOffset && item.duration ? item.viewOffset / item.duration : 0;
return (
<article
className="card landscape"
role="button"
tabIndex={0}
aria-label={title}
aria-current={current || undefined}
onClick={onChoose}
onKeyDown={(e) => {
if (e.key !== 'Enter' && e.key !== ' ') return;
e.preventDefault();
onChoose();
}}
>
<div className="card-cover">
<Artwork src={server.image(art.landscape(item), 400, 225)} alt="" fallback={<span className="cover-fallback">{title}</span>} />
<div className="card-hover" />
{episode && !current && (
<div className="card-actions">
<span className="card-play" aria-hidden="true">
<Icon name="play" size={18} />
</span>
</div>
)}
{progress > 0 && (
<span className="progress-line">
<i style={{ width: `${Math.max(3, progress * 100)}%` }} />
</span>
)}
</div>
<div className="card-caption">
<div className="card-title" title={title}>
{title}
</div>
{caption && <div className="card-meta">{caption}</div>}
</div>
</article>
);
}