Address the first beta's bugs and requested changes

Startup now uses the Android iris animation, and playback can continue
in a corner miniplayer while browsing (the video is drawn into a corner
rectangle beneath a matching hole in the page). The player keeps the
window controls, hides its chrome when the pointer leaves, and gains
audio/subtitle tracks, audio sync, source bitrate and playback details
in its options. Subtitles can be styled in Settings with a live preview.
Categories replace Collections, the A–Z rail magnifies, descriptions
expand in place, downloads can be removed in bulk, and search keeps its
results while typing.

Fixes scroll jank from per-card and scrolling backdrop blurs, the hidden
colour wash, the cubic volume curve, loud theme music, the search focus
ring, a stray nav indicator, Continue Watching previews and the TV Shows
header overlap. Removes the star rating, the duplicate Settings menu
entry and the server settings' Show advanced switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-10-30 18:06:54 -07:00
parent be865fa992
commit 43c168da95
35 changed files with 1771 additions and 327 deletions

View file

@ -117,6 +117,15 @@ export default function Downloads({ offline }: { offline?: boolean }) {
const used = store.items.reduce((a, d) => a + (d.status === 'completed' ? d.total || d.received : d.received), 0);
const movies = done.filter((d) => d.meta.raw?.type !== 'episode');
const episodes = done.filter((d) => d.meta.raw?.type === 'episode');
const removeMany = async (list: Download[], what: string) => {
const ok = await confirmDialog({
title: `Remove ${what}?`,
message: `${list.length} download${list.length === 1 ? '' : 's'} will be deleted from this computer. ${list.length === 1 ? 'It stays' : 'They stay'} available on your Plex server.`,
confirm: 'Remove',
danger: true,
});
if (ok) await Promise.all(list.map((d) => store.remove(d.id)));
};
const shows = new Map<string, Download[]>();
for (const e of episodes) {
const k = e.meta.raw?.grandparentTitle ?? 'Episodes';
@ -127,9 +136,14 @@ export default function Downloads({ offline }: { offline?: boolean }) {
<div className={`downloads-page page-pad${offline ? '' : ' top'}`}>
<div className="download-intro">
<div>
<div className="micro">Offline · This computer</div>
<h1 className="page-title">Downloads</h1>
<p className="page-subtitle">Movies and episodes saved to this computer play without a connection. Progress syncs to Plex when you’re back online.</p>
{store.items.length > 0 && (
<div className="actions download-intro-actions">
<Button variant="ghost" size="sm" icon="trash" onClick={() => removeMany(store.items, 'all downloads')}>
Remove all
</Button>
</div>
)}
</div>
{isNative && (
<div className="storage-card">
@ -158,14 +172,16 @@ export default function Downloads({ offline }: { offline?: boolean }) {
</div>
{!isNative && (
<EmptyState icon="download" title="Downloads need the desktop app">
Install Kaleido for Windows to save movies and episodes for offline viewing.
</EmptyState>
<div className="downloads-empty">
<EmptyState icon="download" title="Downloads need the desktop app">
Install Kaleido for Windows to save movies and episodes for offline viewing.
</EmptyState>
</div>
)}
{isNative && !store.items.length && (
<EmptyState icon="download" title="Nothing downloaded yet" action={!offline && <Button variant="ghost" icon="film" onClick={() => navigate({ name: 'section', kind: 'movie', tab: 'library' })}>Browse movies</Button>}>
Choose Download on a movie or episode, or download a whole season from its page.
</EmptyState>
<div className="downloads-empty">
<EmptyState icon="download" title="Nothing downloaded yet" />
</div>
)}
{active.length > 0 && (
@ -197,6 +213,11 @@ export default function Downloads({ offline }: { offline?: boolean }) {
<h2>
Movies <small>{movies.length}</small>
</h2>
{movies.length > 1 && (
<Button variant="text" onClick={() => removeMany(movies, 'all downloaded movies')}>
Remove all
</Button>
)}
</div>
{movies.map((d) => (
<DownloadRow key={d.id} d={d} />
@ -209,6 +230,11 @@ export default function Downloads({ offline }: { offline?: boolean }) {
<h2>
{show} <small>{list.length} episode{list.length === 1 ? '' : 's'}</small>
</h2>
{list.length > 1 && (
<Button variant="text" onClick={() => removeMany(list, `all ${show} episodes`)}>
Remove all
</Button>
)}
</div>
{list
.sort((a, b) => (a.meta.raw.parentIndex - b.meta.raw.parentIndex) * 1000 + (a.meta.raw.index - b.meta.raw.index))

View file

@ -1,7 +1,7 @@
import { useEffect, useMemo, useState, type ReactNode } from 'react';
import * as api from '../plex/api';
import type { Item } from '../plex/types';
import { invalidateLibrary, useChildren, useItem, useRelated, useServerQuery } from '../app/queries';
import { useChildren, useItem, useRelated, useServerQuery } from '../app/queries';
import { useServer } from '../app/session';
import { useSettings } from '../app/settings';
import { goBack, navigate, useRouter } from '../app/router';
@ -11,7 +11,7 @@ import { Backdrop } from '../ui/Backdrop';
import { Facts, HubShelf, LandscapeCard, PersonCard, PosterCard, Shelf, TitleArt } from '../ui/media';
import { Artwork, Button, EmptyState, ErrorState, IconButton, PageLoader, Select } from '../ui/primitives';
import { Icon } from '../ui/Icon';
import { openMenu, toastError } from '../ui/overlays';
import { openMenu } from '../ui/overlays';
import { useDownloads } from '../downloads/store';
import { playThemeMusic, stopThemeMusic } from '../player/theme';
@ -40,24 +40,29 @@ export function ItemScreen({ id }: { id: string }) {
// —— Shared pieces ————————————————————————————————————————————————
function Synopsis({ item, text }: { item: Item; text: string }) {
/** Long descriptions open in place when clicked, and close again the same way. */
function Synopsis({ text }: { item: Item; text: string }) {
const [clamped, setClamped] = useState(false);
const [open, setOpen] = useState(false);
useEffect(() => setOpen(false), [text]);
if (!text) return null;
const toggle = () => (clamped || open) && setOpen(!open);
return (
<div className="synopsis-wrap">
<p
className="synopsis"
className={`synopsis${open ? ' open' : ''}${clamped || open ? ' expandable' : ''}`}
role={clamped || open ? 'button' : undefined}
tabIndex={clamped || open ? 0 : undefined}
aria-expanded={clamped || open ? open : undefined}
title={clamped && !open ? 'Show the full description' : undefined}
onClick={toggle}
onKeyDown={(e) => (e.key === 'Enter' || e.key === ' ') && (e.preventDefault(), toggle())}
ref={(el) => {
if (el) setClamped(el.scrollHeight > el.clientHeight + 2);
if (el && !open) setClamped(el.scrollHeight > el.clientHeight + 2);
}}
>
{text}
</p>
{clamped && (
<button className="btn text synopsis-more" onClick={() => openDialog({ kind: 'synopsis', item })}>
More
</button>
)}
</div>
);
}
@ -180,33 +185,6 @@ function RelatedRows({ item }: { item: Item }) {
);
}
function StarRating({ item }: { item: Item }) {
const server = useServer();
const [value, setValue] = useState(item.userRating);
const [hover, setHover] = useState(0);
useEffect(() => setValue(item.userRating), [item.userRating]);
const set = async (stars: number) => {
const rating = stars * 2 === value ? -1 : stars * 2;
setValue(Math.max(0, rating));
try {
await api.rate(server, item.id, rating);
invalidateLibrary();
} catch (e) {
toastError(e);
}
};
const shown = hover || value / 2;
return (
<span className="star-rating" onMouseLeave={() => setHover(0)} aria-label="Your rating">
{[1, 2, 3, 4, 5].map((n) => (
<button key={n} onMouseEnter={() => setHover(n)} onClick={() => set(n)} aria-label={`${n} star${n > 1 ? 's' : ''}`}>
<Icon name={n <= shown ? 'starFill' : 'star'} size={15} />
</button>
))}
</span>
);
}
function AboutPanel({ item }: { item: Item }) {
const m = item.media[0];
const rows: [string, ReactNode][] = [];
@ -248,7 +226,6 @@ function AboutPanel({ item }: { item: Item }) {
<aside className="about-panel">
<div className="about-head">
<h3>About</h3>
{['movie', 'show', 'episode', 'season'].includes(item.type) && <StarRating item={item} />}
</div>
{item.tagline && <p className="about-tagline">“{item.tagline}”</p>}
{rows.map(([k, v]) => (

View file

@ -33,7 +33,8 @@ function useDebounced<T>(value: T, ms: number) {
return v;
}
export function LibraryBrowser({ section, kind }: { section: Section; kind: SectionKind }) {
/** `lockedFilters` (e.g. a category's genre) always apply and aren't shown as removable. */
export function LibraryBrowser({ section, kind, lockedFilters }: { section: Section; kind: SectionKind; lockedFilters?: Record<string, string> }) {
const server = useServer();
const type = kind === 'movie' ? 1 : 2;
const views = useSettings((s) => s.libraryViews);
@ -63,7 +64,7 @@ export function LibraryBrowser({ section, kind }: { section: Section; kind: Sect
const openFilters = async (anchor: HTMLElement) => {
const filters = meta.data?.filters ?? [];
const bools = filters.filter((f) => f.type === 'boolean');
const strings = filters.filter((f) => f.type !== 'boolean' && QUICK_FILTERS.includes(f.filter));
const strings = filters.filter((f) => f.type !== 'boolean' && QUICK_FILTERS.includes(f.filter) && !lockedFilters?.[f.filter]);
const options = await Promise.all(strings.map((f) => loadOptions(f).catch(() => [])));
const items: MenuItem[] = [
...bools.map((f) => ({
@ -117,7 +118,8 @@ export function LibraryBrowser({ section, kind }: { section: Section; kind: Sect
if (meta.isError && !meta.data) return <ErrorState error={meta.error} onRetry={() => meta.refetch()} />;
const activeFilters = Object.entries(view.filters);
const activeFilters = Object.entries(view.filters).filter(([k]) => !lockedFilters?.[k]);
const gridFilters = { ...view.filters, ...lockedFilters };
return (
<div className="library">
<div className="lib-toolbar">
@ -182,7 +184,7 @@ export function LibraryBrowser({ section, kind }: { section: Section; kind: Sect
</button>
</div>
)}
<LibraryGrid key={`${section.id}|${view.sort}|${JSON.stringify(view.filters)}|${title}`} section={section} type={type} sort={view.sort} filters={view.filters} title={title} sortTitle={sortTitle} />
<LibraryGrid key={`${section.id}|${view.sort}|${JSON.stringify(gridFilters)}|${title}`} section={section} type={type} sort={view.sort} filters={gridFilters} title={title} sortTitle={sortTitle} />
</div>
);
}
@ -276,6 +278,22 @@ function LibraryGrid({ section, type, sort, filters, title, sortTitle }: { secti
virtualizer.scrollToIndex(Math.floor(offset / cols), { align: 'start' });
};
// The letter of the first title in view, highlighted on the rail.
let current = '';
if (alpha && letters.data && vrows.length) {
const scrollTop = (scrollEl?.scrollTop ?? 0) - virtualizer.options.scrollMargin + 150;
const firstRow = vrows.find((r) => r.end > scrollTop) ?? vrows[0];
const list = sort.endsWith(':desc') ? [...letters.data].reverse() : letters.data;
let offset = 0;
for (const l of list) {
offset += l.size;
if (firstRow.index * cols < offset) {
current = l.title;
break;
}
}
}
if (error && total === null) return <ErrorState error={error} onRetry={() => (setError(null), loadPage(0))} />;
return (
<div className="library-body">
@ -314,7 +332,7 @@ function LibraryGrid({ section, type, sort, filters, title, sortTitle }: { secti
{alpha && letters.data && letters.data.length > 3 && (
<div className="alpha-rail" aria-label="Jump to letter">
{letters.data.map((l) => (
<button key={l.title} onClick={() => jump(l.title)} title={`${l.title} · ${l.size}`}>
<button key={l.title} className={l.title === current ? 'current' : ''} onClick={() => jump(l.title)} title={`${l.title} · ${l.size}`}>
{l.title}
</button>
))}

View file

@ -1,4 +1,5 @@
import { useEffect, useRef, useState } from 'react';
import { keepPreviousData } from '@tanstack/react-query';
import * as api from '../plex/api';
import { useServerQuery } from '../app/queries';
import { navigate, useRouter } from '../app/router';
@ -40,12 +41,12 @@ export default function Search({ initial }: { initial?: string }) {
input.current?.focus();
}, []);
useEffect(() => {
const t = setTimeout(() => setDebounced(query.trim()), 250);
const t = setTimeout(() => setDebounced(query.trim()), 160);
useRouter.getState().setState({ query });
return () => clearTimeout(t);
}, [query]);
const results = useServerQuery(['search', debounced], (s) => api.search(s, debounced), { enabled: debounced.length > 0, staleTime: 60_000 });
const results = useServerQuery(['search', debounced], (s) => api.search(s, debounced), { enabled: debounced.length > 0, staleTime: 60_000, placeholderData: keepPreviousData });
const recentlyAdded = useServerQuery(['homeHubs'], (s) => api.homeHubs(s), { enabled: !debounced });
const remember = (q: string) => {

View file

@ -1,19 +1,22 @@
import { useMemo } from 'react';
import * as api from '../plex/api';
import { useSectionFor, useServerQuery } from '../app/queries';
import { navigate, type SectionKind, type SectionTab } from '../app/router';
import { navigate, useRouter, type SectionKind, type SectionTab } from '../app/router';
import { useSettings } from '../app/settings';
import type { Section } from '../plex/types';
import { Hero } from '../ui/Hero';
import { HubShelf, PosterCard } from '../ui/media';
import { EmptyState, ErrorState, PageLoader, Select } from '../ui/primitives';
import { HubShelf } from '../ui/media';
import { useServer } from '../app/session';
import { Icon } from '../ui/Icon';
import { categoryArtwork } from './categories';
import { Artwork, EmptyState, ErrorState, PageLoader, Select } from '../ui/primitives';
import { buildFeatures, HIDDEN_HUBS, recentSeasons } from './discover';
import { LibraryBrowser } from './LibraryBrowser';
const TABS: { id: SectionTab; label: string }[] = [
{ id: 'discover', label: 'Discover' },
{ id: 'library', label: 'Library' },
{ id: 'collections', label: 'Collections' },
{ id: 'categories', label: 'Categories' },
];
function SectionHeader({ kind, tab, section, all, overlay }: { kind: SectionKind; tab: SectionTab; section: Section; all: Section[]; overlay: boolean }) {
@ -67,29 +70,65 @@ function Discover({ kind, section }: { kind: SectionKind; section: Section }) {
);
}
function Collections({ section }: { section: Section }) {
const q = useServerQuery(['collections', section.id], (s) => api.collections(s, section.id));
if (q.isError) return <ErrorState error={q.error} onRetry={() => q.refetch()} />;
if (!q.data) return <PageLoader />;
if (!q.data.length)
/** Genres as artwork tiles, as on Kaleido for TV; each opens the library filtered to it. */
function Categories({ kind, section }: { kind: SectionKind; section: Section }) {
const server = useServer();
const type = kind === 'movie' ? 1 : 2;
const genres = useServerQuery(['genres', section.id, type], (s) => api.genres(s, section.id, type), { staleTime: 30 * 60_000 });
const artwork = useServerQuery(['categoryArtwork', section.id, type, genres.data?.map((g) => g.key).join(',')], (s) => categoryArtwork(s, section.id, type, genres.data ?? []), {
enabled: !!genres.data?.length,
staleTime: 30 * 60_000,
});
if (genres.isError) return <ErrorState error={genres.error} onRetry={() => genres.refetch()} />;
if (!genres.data) return <PageLoader />;
if (!genres.data.length)
return (
<EmptyState icon="collection" title="No collections yet">
Collections created in Plex for {section.title} appear here.
<EmptyState icon="grid" title="No categories">
{section.title} has no genres yet.
</EmptyState>
);
return (
<div className="page-pad">
<div className="grid-count">{q.data.length.toLocaleString()} collections</div>
<div className="poster-grid auto">
{q.data.map((c) => (
<PosterCard key={c.id} item={c} />
))}
<div className="category-grid">
{genres.data.map((g) => {
const path = artwork.data?.[g.key];
return (
<button key={g.key} className="category-tile" onClick={() => navigate({ name: 'section', kind, tab: 'categories', genre: g.key, genreTitle: g.title })}>
{path && <Artwork src={server.image(path, 540, 304)} />}
<span className="category-scrim" />
<span className="category-title">{g.title}</span>
</button>
);
})}
</div>
</div>
);
}
export function SectionScreen({ kind, tab }: { kind: SectionKind; tab: SectionTab }) {
/** Back to the grid: pop the history entry when that's where the genre was opened from. */
function backToCategories(kind: SectionKind) {
const { entries, index, back } = useRouter.getState();
const prev = entries[index - 1]?.route;
if (prev?.name === 'section' && prev.tab === 'categories' && !prev.genre) back();
else navigate({ name: 'section', kind, tab: 'categories' }, { replace: true });
}
function CategoryLibrary({ kind, section, genre, title }: { kind: SectionKind; section: Section; genre: string; title: string }) {
return (
<>
<div className="category-head">
<button className="category-back" onClick={() => backToCategories(kind)}>
<Icon name="back" size={16} />
Categories
</button>
<h2>{title}</h2>
</div>
<LibraryBrowser section={section} kind={kind} lockedFilters={{ genre }} />
</>
);
}
export function SectionScreen({ kind, tab, genre, genreTitle }: { kind: SectionKind; tab: SectionTab; genre?: string; genreTitle?: string }) {
const { section, all, loading } = useSectionFor(kind);
if (loading) return <PageLoader />;
if (!section)
@ -105,7 +144,7 @@ export function SectionScreen({ kind, tab }: { kind: SectionKind; tab: SectionTa
<SectionHeader kind={kind} tab={tab} section={section} all={all} overlay={tab === 'discover'} />
{tab === 'discover' && <Discover kind={kind} section={section} />}
{tab === 'library' && <LibraryBrowser section={section} kind={kind} />}
{tab === 'collections' && <Collections section={section} />}
{tab === 'categories' && (genre ? <CategoryLibrary kind={kind} section={section} genre={genre} title={genreTitle ?? ''} /> : <Categories kind={kind} section={section} />)}
</div>
);
}

View file

@ -1,44 +1,407 @@
import { useEffect, useState } from 'react';
import { useEffect, useRef } from 'react';
import { useSettings } from '../app/settings';
const FACETS = [
{ fill: '#C3E8D3', d: 'M33,4 L55.5,17 L42.5,24.5 L33,19 Z' },
{ fill: '#71B9B0', d: 'M56.5,19 L56.5,45 L43.5,37.5 L43.5,26.5 Z' },
{ fill: '#3D7C7B', d: 'M55.5,47 L33,60 L33,45 L42.5,39.5 Z' },
{ fill: '#D0A977', d: 'M31,60 L8.5,47 L21.5,39.5 L31,45 Z' },
{ fill: '#E9D8AE', d: 'M7.5,45 L7.5,19 L20.5,26.5 L20.5,37.5 Z' },
{ fill: '#EEF2DD', d: 'M8.5,17 L31,4 L31,19 L21.5,24.5 Z' },
];
/**
* The cold-start aperture: the six facets twist open around the dark center,
* hold until startup data is ready, then the view flies through the aperture.
* The cold-start brand sequence, the same as Kaleido for TV: a closed iris lit
* from behind twists open, light catches the facets and the wordmark slides out
* of the mark. Once startup is ready the camera flies through the aperture's
* dark centre, revealing the app drawn beneath (which settles from a slight
* zoom, `html.splash-arrival`).
*/
type Point = { x: number; y: number };
/** CSS-style cubic-bezier easing (x → y). */
function bezier(x1: number, y1: number, x2: number, y2: number) {
const cx = 3 * x1;
const bx = 3 * (x2 - x1) - cx;
const ax = 1 - cx - bx;
const cy = 3 * y1;
const by = 3 * (y2 - y1) - cy;
const ay = 1 - cy - by;
const sx = (t: number) => ((ax * t + bx) * t + cx) * t;
const sy = (t: number) => ((ay * t + by) * t + cy) * t;
const dx = (t: number) => (3 * ax * t + 2 * bx) * t + cx;
return (x: number) => {
if (x <= 0) return 0;
if (x >= 1) return 1;
let t = x;
for (let i = 0; i < 8; i++) {
const err = sx(t) - x;
const d = dx(t);
if (Math.abs(err) < 1e-5 || Math.abs(d) < 1e-6) break;
t -= err / d;
}
t = Math.min(1, Math.max(0, t));
return sy(t);
};
}
const Emphasized = bezier(0.2, 0, 0, 1);
const EmphasizedDecelerate = bezier(0.05, 0.7, 0.1, 1);
const Standard = bezier(0.4, 0, 0.2, 1);
const InOut = bezier(0.45, 0, 0.55, 1);
// A mechanical iris: the blades gather, snap open and overshoot slightly as they lock.
const IrisOpen = bezier(0.55, 0, 0.15, 1);
const IrisTwist = bezier(0.5, 0, 0.18, 1.1);
// Applied in log space: a brief pull back, then an accelerating flight.
const Flight = bezier(0.55, -0.06, 0.8, 0.36);
const phase = (time: number, start: number, end: number) => Math.min(1, Math.max(0, (time - start) / (end - start)));
const mix = (from: number, to: number, amount: number) => from + (to - from) * amount;
// The brand mark's facets, centred on its 64-unit viewport, each with the
// outward normal of its hexagon edge for the iris motion.
const FACETS = (
[
[[33, 4, 55.5, 17, 42.5, 24.5, 33, 19], '#C3E8D3'],
[[56.5, 19, 56.5, 45, 43.5, 37.5, 43.5, 26.5], '#71B9B0'],
[[55.5, 47, 33, 60, 33, 45, 42.5, 39.5], '#3D7C7B'],
[[31, 60, 8.5, 47, 21.5, 39.5, 31, 45], '#D0A977'],
[[7.5, 45, 7.5, 19, 20.5, 26.5, 20.5, 37.5], '#E9D8AE'],
[[8.5, 17, 31, 4, 31, 19, 21.5, 24.5], '#EEF2DD'],
] as [number[], string][]
).map(([pts, color], i) => {
const angle = ((-60 + 60 * i) * Math.PI) / 180;
const points: Point[] = [];
for (let k = 0; k < pts.length; k += 2) points.push({ x: pts[k] - 32, y: pts[k + 1] - 32 });
return { points, color, normal: { x: Math.cos(angle), y: Math.sin(angle) } };
});
// The inner hexagon traced by the facets' inner edges: the aperture the exit flies through.
const INNER_RADIUS = 13.6;
const INNER_APOTHEM = 11.8;
const INTRO_BOX = 132;
// The settled lockup is the header brand scaled up, so it reads as the same mark.
const LOCK_SCALE = 2.75;
const LOCK_BOX = 29 * LOCK_SCALE;
const LOCK_GAP = 7 * LOCK_SCALE;
// Timeline (ms): held at GATHER_END until startup is ready (at most HOLD_MAX),
// complete at INTRO_END; the slow settle runs on to TIMELINE_END.
const GATHER_END = 260;
const INTRO_END = 2260;
const TIMELINE_END = 2900;
const HOLD_MAX = 700;
const EXIT_MS = 640;
const INK = '#090a0c';
const WORDMARK = '#F1F1F1';
const SEA_GLASS = [113, 185, 176];
const rgba = (c: number[], a: number) => `rgba(${c[0]}, ${c[1]}, ${c[2]}, ${Math.max(0, a)})`;
interface Iris {
inward: number;
theta: number;
grow: number;
}
function irisAt(time: number): Iris {
const p = phase(time, 140, 1180);
return { inward: INNER_APOTHEM * (1 - IrisOpen(p)), theta: ((-44 * (1 - IrisTwist(p))) * Math.PI) / 180, grow: mix(0.64, 1, Emphasized(p)) };
}
function facetPath(ctx: CanvasRenderingContext2D, facet: (typeof FACETS)[number], iris: Iris, unit: number, o: Point) {
const c = Math.cos(iris.theta);
const s = Math.sin(iris.theta);
const k = unit * iris.grow;
facet.points.forEach((p, i) => {
const x = p.x - facet.normal.x * iris.inward;
const y = p.y - facet.normal.y * iris.inward;
const px = o.x + (x * c - y * s) * k;
const py = o.y + (x * s + y * c) * k;
if (i === 0) ctx.moveTo(px, py);
else ctx.lineTo(px, py);
});
ctx.closePath();
}
function hexagon(ctx: CanvasRenderingContext2D, o: Point, radius: number) {
for (let i = 0; i < 6; i++) {
const a = ((-90 + 60 * i) * Math.PI) / 180;
const x = o.x + Math.cos(a) * radius;
const y = o.y + Math.sin(a) * radius;
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.closePath();
}
interface Letters {
font: string;
chars: string[];
x: number[];
width: number;
cap: number;
}
function draw(ctx: CanvasRenderingContext2D, w: number, h: number, time: number, q: number, letters: Letters) {
const center = { x: w / 2, y: h / 2 };
ctx.clearRect(0, 0, w, h);
const lockup = Emphasized(phase(time, 1250, 2000));
const lockWidth = LOCK_BOX + LOCK_GAP + letters.width;
const box = mix(INTRO_BOX, LOCK_BOX, lockup);
// A slow push-in keeps the settled frame alive.
const drift = 1 + 0.025 * InOut(phase(time, 1900, 2900));
let cx = mix(center.x, center.x - lockWidth / 2 + LOCK_BOX / 2, lockup);
let cy = center.y;
let zoom = 1;
let textAlpha = 1;
let textShift = 0;
let hole = 0;
if (q > 0) {
zoom = Math.exp(Math.log(52) * Flight(q));
const recenter = Standard(Math.min(1, q / 0.75));
cx = mix(cx, center.x, recenter);
cy = mix(cy, center.y, recenter);
textAlpha = 1 - Standard(phase(q, 0, 0.4));
textShift = -14 * Standard(phase(q, 0, 0.4));
hole = InOut(phase(q, 0.12, 0.5));
}
const unit = (box / 64) * drift * zoom;
const o = { x: cx, y: cy };
// The surface: ink everywhere, with the aperture's centre cut away on exit.
ctx.globalCompositeOperation = 'source-over';
ctx.globalAlpha = 1;
ctx.fillStyle = INK;
ctx.beginPath();
ctx.rect(0, 0, w, h);
if (hole > 0) hexagon(ctx, o, INNER_RADIUS * unit);
ctx.fill('evenodd');
if (hole > 0 && hole < 1) {
ctx.globalAlpha = 1 - hole;
ctx.beginPath();
hexagon(ctx, o, INNER_RADIUS * unit);
ctx.fill();
ctx.globalAlpha = 1;
}
const iris = irisAt(time);
const lightUp = EmphasizedDecelerate(phase(time, 0, 620));
const light = lightUp * (1 - Standard(phase(time, 620, 1250)));
const ambient = 0.03 * InOut(phase(time, 300, 900)) * (1 - Standard(phase(time, 1500, 2300)));
// Light behind the blades: a soft bloom, a hot core, and rays leaking
// through the six gaps while the iris turns.
if (light > 0.001 || ambient > 0.001) {
ctx.globalCompositeOperation = 'lighter';
const bloom = 250;
let g = ctx.createRadialGradient(o.x, o.y, 0, o.x, o.y, bloom);
g.addColorStop(0, rgba(SEA_GLASS, 0.16 * light + ambient));
g.addColorStop(0.45, rgba(SEA_GLASS, 0.04 * light + ambient * 0.3));
g.addColorStop(1, rgba(SEA_GLASS, 0));
ctx.fillStyle = g;
ctx.beginPath();
ctx.arc(o.x, o.y, bloom, 0, Math.PI * 2);
ctx.fill();
if (light > 0.001) {
const core = ((26 * unit) / 2.0625) * mix(0.6, 1, light);
g = ctx.createRadialGradient(o.x, o.y, 0, o.x, o.y, core);
g.addColorStop(0, `rgba(255, 250, 236, ${0.95 * light})`);
g.addColorStop(0.35, `rgba(238, 242, 221, ${0.55 * light})`);
g.addColorStop(1, 'rgba(238, 242, 221, 0)');
ctx.fillStyle = g;
ctx.beginPath();
ctx.arc(o.x, o.y, core, 0, Math.PI * 2);
ctx.fill();
const rays = light * Math.min(1, IrisOpen(phase(time, 140, 1180)) * 2.5);
for (let i = 0; i < 6; i++) {
const angle = ((-90 + 60 * i) * Math.PI) / 180 + iris.theta;
const length = mix(40, 250, lightUp) * (0.75 + 0.25 * Math.sin(i * 2.1 + 1));
const end = { x: o.x + Math.cos(angle) * length, y: o.y + Math.sin(angle) * length };
g = ctx.createLinearGradient(o.x, o.y, end.x, end.y);
g.addColorStop(0, `rgba(255, 248, 230, ${0.42 * rays})`);
g.addColorStop(0.25, `rgba(214, 236, 226, ${0.12 * rays})`);
g.addColorStop(1, 'rgba(214, 236, 226, 0)');
ctx.fillStyle = g;
ctx.beginPath();
ctx.moveTo(o.x, o.y);
ctx.lineTo(o.x + Math.cos(angle - 0.014) * length, o.y + Math.sin(angle - 0.014) * length);
ctx.lineTo(o.x + Math.cos(angle + 0.014) * length, o.y + Math.sin(angle + 0.014) * length);
ctx.closePath();
ctx.fill();
}
}
ctx.globalCompositeOperation = 'source-over';
}
// Facets. Short echoes of earlier frames act as motion blur while the
// blades turn; they disappear beneath the facets once the iris is still.
const facetAlpha = (i: number) => EmphasizedDecelerate(phase(time, 40 + i * 34, 380 + i * 34));
if (time < 1400) {
for (const [delay, alpha] of [
[84, 0.07],
[56, 0.12],
[28, 0.2],
]) {
const echo = irisAt(time - delay);
FACETS.forEach((f, i) => {
ctx.globalAlpha = alpha * facetAlpha(i);
ctx.fillStyle = f.color;
ctx.beginPath();
facetPath(ctx, f, echo, unit, o);
ctx.fill();
});
}
}
FACETS.forEach((f, i) => {
ctx.globalAlpha = facetAlpha(i);
ctx.fillStyle = f.color;
ctx.beginPath();
facetPath(ctx, f, iris, unit, o);
ctx.fill();
});
ctx.globalAlpha = 1;
const sheen = phase(time, 980, 1560);
if (light > 0.01 || (sheen > 0 && sheen < 1)) {
ctx.save();
ctx.beginPath();
FACETS.forEach((f) => facetPath(ctx, f, iris, unit, o));
ctx.clip();
// Backlight tints the blades while the core is hot, so they read as glass.
if (light > 0.01) {
const radius = (36 * unit) / 2.0625;
const g = ctx.createRadialGradient(o.x, o.y, 0, o.x, o.y, radius);
g.addColorStop(0, `rgba(255, 252, 240, ${0.26 * light})`);
g.addColorStop(1, 'rgba(255, 252, 240, 0)');
ctx.fillStyle = g;
ctx.fillRect(o.x - radius, o.y - radius, radius * 2, radius * 2);
}
// One diagonal band of light crosses the settled mark.
if (sheen > 0 && sheen < 1) {
const reach = 34 * unit;
const a = (36 * Math.PI) / 180;
const d = { x: Math.cos(a), y: Math.sin(a) };
const pos = mix(-1.25, 1.25, InOut(sheen)) * reach;
const width = 10 * unit;
const peak = 0.42 * Math.sin(Math.min(1, sheen * 1.1) * Math.PI);
const g = ctx.createLinearGradient(o.x + d.x * (pos - width), o.y + d.y * (pos - width), o.x + d.x * (pos + width), o.y + d.y * (pos + width));
g.addColorStop(0, 'rgba(255, 255, 255, 0)');
g.addColorStop(0.5, `rgba(255, 255, 255, ${peak})`);
g.addColorStop(1, 'rgba(255, 255, 255, 0)');
ctx.fillStyle = g;
ctx.fillRect(o.x - reach, o.y - reach, reach * 2, reach * 2);
}
ctx.restore();
}
// The wordmark slides out from behind the mark as it moves into the lockup.
if (time >= 1400 && textAlpha > 0) {
const scale = (box / LOCK_BOX) * drift;
const textLeft = cx - (box * drift) / 2 + (LOCK_BOX + LOCK_GAP) * scale;
const slide = EmphasizedDecelerate(phase(time, 1400, 2050));
const baseline = cy + (letters.cap / 2) * scale;
ctx.save();
ctx.beginPath();
const clipLeft = cx + 24.5 * unit + 2 * scale;
ctx.rect(clipLeft, 0, w - clipLeft, h);
ctx.clip();
ctx.font = letters.font;
ctx.fillStyle = WORDMARK;
ctx.textBaseline = 'alphabetic';
letters.chars.forEach((ch, i) => {
const start = 1460 + i * 45;
const reveal = Standard(phase(time, start, start + 320));
if (reveal <= 0) return;
ctx.save();
ctx.globalAlpha = reveal * textAlpha;
ctx.translate(textLeft + (letters.x[i] - (1 - slide) * letters.width * 0.42) * scale + textShift, baseline);
ctx.scale(scale, scale);
ctx.fillText(ch, 0, 0);
ctx.restore();
});
ctx.restore();
}
}
async function measureLetters(): Promise<Letters> {
const size = 19 * LOCK_SCALE;
const font = `700 ${size}px 'Inter Variable', 'Segoe UI', sans-serif`;
await document.fonts?.load(font).catch(() => {});
const ctx = document.createElement('canvas').getContext('2d')!;
ctx.font = font;
const tracking = 1.4 * LOCK_SCALE;
const chars = 'KALEIDO'.split('');
const x: number[] = [];
let at = 0;
for (const ch of chars) {
x.push(at);
at += ctx.measureText(ch).width + tracking;
}
return { font, chars, x, width: at - tracking, cap: size * 0.711 };
}
export function Splash({ ready, onDone }: { ready: boolean; onDone: () => void }) {
const reduced = useSettings((s) => s.reducedMotion);
const [phase, setPhase] = useState<'opening' | 'held' | 'leaving'>('opening');
const canvas = useRef<HTMLCanvasElement>(null);
const readyRef = useRef(ready);
readyRef.current = ready;
const done = useRef(onDone);
done.current = onDone;
useEffect(() => {
const t = setTimeout(() => setPhase('held'), reduced ? 0 : 1100);
return () => clearTimeout(t);
const el = canvas.current;
if (!el) return;
if (reduced) {
// No sequence: wait for startup, then hand straight over.
const t = setInterval(() => readyRef.current && (clearInterval(t), done.current()), 50);
return () => clearInterval(t);
}
const ctx = el.getContext('2d')!;
let raf = 0;
let stopped = false;
let letters: Letters | null = null;
const size = () => {
const dpr = window.devicePixelRatio || 1;
el.width = Math.round(window.innerWidth * dpr);
el.height = Math.round(window.innerHeight * dpr);
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
};
size();
window.addEventListener('resize', size);
// Timeline time advances with the clock, except while held at GATHER_END.
let last = 0;
let time = 0;
let held = 0;
let exitStart = 0;
const frame = (now: number) => {
if (stopped) return;
const dt = last ? Math.min(64, now - last) : 0;
last = now;
if (time < GATHER_END) time = Math.min(GATHER_END, time + dt);
else if (time === GATHER_END && !readyRef.current && held < HOLD_MAX) held += dt;
else time = Math.min(TIMELINE_END, time + dt);
if (!exitStart && time >= INTRO_END && readyRef.current) {
exitStart = now;
document.documentElement.classList.add('splash-arrival');
}
const q = exitStart ? Math.min(1, (now - exitStart) / EXIT_MS) : 0;
if (letters) draw(ctx, window.innerWidth, window.innerHeight, time, q, letters);
if (q >= 1) {
done.current();
return;
}
raf = requestAnimationFrame(frame);
};
// Draw the first (dark) frame at once; start the clock once the wordmark's font is ready.
ctx.fillStyle = INK;
ctx.fillRect(0, 0, window.innerWidth, window.innerHeight);
measureLetters().then((l) => {
letters = l;
if (!stopped) raf = requestAnimationFrame(frame);
});
return () => {
stopped = true;
cancelAnimationFrame(raf);
window.removeEventListener('resize', size);
// Let the arrival settle finish after the splash is gone.
setTimeout(() => document.documentElement.classList.remove('splash-arrival'), 700);
};
}, [reduced]);
useEffect(() => {
if (phase === 'held' && ready) setPhase('leaving');
}, [phase, ready]);
useEffect(() => {
if (phase !== 'leaving') return;
const t = setTimeout(onDone, reduced ? 0 : 620);
return () => clearTimeout(t);
}, [phase]);
return (
<div className={`splash ${phase}`} data-tauri-drag-region>
<div className="splash-mark">
<svg viewBox="0 0 64 64" width="92" height="92" aria-hidden="true">
{FACETS.map((f, i) => (
<path key={i} d={f.d} fill={f.fill} style={{ ['--i' as string]: i }} />
))}
</svg>
<span className="splash-word">KALEIDO</span>
</div>
<div className="splash" data-tauri-drag-region aria-label="Kaleido starting" role="img">
<canvas ref={canvas} />
</div>
);
}

78
src/screens/categories.ts Normal file
View file

@ -0,0 +1,78 @@
import * as api from '../plex/api';
import type { PlexServer } from '../plex/client';
import type { Item } from '../plex/types';
/** Plex timestamps or query strings don't make a refreshed image a different picture. */
export function artworkIdentity(path: string): string {
return path.split('?')[0].replace(/(\/(?:art|thumb))\/\d+$/, '$1');
}
/**
* Matches genres to distinct artwork, moving an earlier choice when a later
* genre needs it (augmenting paths), so two tiles never share a picture.
* Narrow genres choose first so a broad one can't take their only source.
*/
export function selectCategoryArtwork<T>(candidates: Map<string, T[]>, identity: (t: T) => string): Map<string, T> {
const options = new Map<string, T[]>();
for (const [genre, items] of candidates) {
const seen = new Set<string>();
options.set(
genre,
items.filter((i) => {
const id = identity(i);
if (!id || seen.has(id)) return false;
seen.add(id);
return true;
}),
);
}
const owners = new Map<string, string>();
const selected = new Map<string, T>();
const assign = (genre: string, visited: Set<string>): boolean => {
const choices = options.get(genre) ?? [];
const free = choices.find((i) => !owners.has(identity(i)) && !visited.has(identity(i)));
if (free) {
owners.set(identity(free), genre);
selected.set(genre, free);
return true;
}
for (const item of choices) {
const key = identity(item);
if (visited.has(key)) continue;
visited.add(key);
const previous = owners.get(key);
if (previous && assign(previous, visited)) {
owners.set(key, genre);
selected.set(genre, item);
return true;
}
}
return false;
};
[...options.keys()].sort((a, b) => options.get(a)!.length - options.get(b)!.length).forEach((g) => assign(g, new Set()));
return selected;
}
const backdropOf = (i: Item) => i.art || i.thumb;
/** One distinct, well-liked title's artwork per genre, fetched a few genres at a time. */
export async function categoryArtwork(s: PlexServer, sectionId: string, type: number, genres: { key: string; title: string }[]): Promise<Record<string, string>> {
const candidates = new Map<string, Item[]>();
const queue = [...genres];
const worker = async () => {
for (let g = queue.shift(); g; g = queue.shift()) {
const page = await api
.libraryPage(s, sectionId, { type, sort: 'audienceRating:desc', filters: { genre: g.key }, start: 0, size: 24 })
.catch(() => api.libraryPage(s, sectionId, { type, filters: { genre: g.key }, start: 0, size: 24 }))
.catch(() => null);
candidates.set(g.key, (page?.items ?? []).filter((i) => i.art));
}
};
await Promise.all(Array.from({ length: 4 }, worker));
const chosen = selectCategoryArtwork(candidates, (i) => artworkIdentity(backdropOf(i)));
const out: Record<string, string> = {};
for (const [genre, item] of chosen) out[genre] = backdropOf(item);
// Genres whose only titles were all taken still get a picture.
for (const [genre, items] of candidates) if (!out[genre] && items[0]) out[genre] = backdropOf(items[0]);
return out;
}

View file

@ -1,11 +1,13 @@
import { useEffect, useState } from 'react';
import { useSettings, QUALITY_LABEL, type Quality, type SkipMode, type SubtitleMode } from '../../app/settings';
import { useSettings, QUALITY_LABEL, SUBTITLE_COLORS, SUBTITLE_MARGIN, type Preferences, type Quality, type SkipMode, type SubtitleBox, type SubtitleEdge, type SubtitleMode, type SubtitlePosition } from '../../app/settings';
import { useSession } from '../../app/session';
import { useSections } from '../../app/queries';
import { useSections, useServerQuery } from '../../app/queries';
import * as api from '../../plex/api';
import { art } from '../../app/format';
import { useDownloads } from '../../downloads/store';
import { appInfo, isNative, openExternal, pickFolder, revealPath, type AppInfo } from '../../platform/native';
import { checkForUpdate, installUpdate, useUpdater } from '../../app/updater';
import { Button, Select, Switch } from '../../ui/primitives';
import { Button, Segmented, Select, Switch } from '../../ui/primitives';
import { confirmDialog } from '../../ui/overlays';
import { Pref, SettingsSection } from './parts';
import { KaleidoMark } from '../../ui/primitives';
@ -61,10 +63,45 @@ const SHORTCUTS: [string, string][][] = [
['C', 'Next subtitle track'],
['Shift + N', 'Next episode'],
['0–9', 'Jump to 0–90%'],
['Esc', 'Exit full screen, then the player'],
['Esc or Backspace', 'Exit full screen, then keep playing in the corner'],
],
];
/**
* A frame from the library with a sample line drawn the way mpv will draw it:
* sizes are in mpv's scaled pixels, where the frame height is 720.
*/
function SubtitlePreview({ prefs }: { prefs: Preferences }) {
const session = useSession();
const cw = useServerQuery(['continue'], (srv) => api.continueWatching(srv), { enabled: !!session.server, staleTime: 15_000 });
const still = cw.data?.find((i) => art.backdrop(i));
const px = (n: number) => `calc(${n} / 720 * 100cqh)`;
const edge = prefs.subtitleBox === 'none' ? prefs.subtitleEdge : 'none';
const outline = edge === 'outline' ? 1.8 : edge === 'raised' ? 1.3 : 0;
const shadow = edge === 'shadow' ? 2.2 : edge === 'raised' ? 1.6 : 0;
return (
<div className="subtitle-preview">
{still && session.server && <img src={session.server.image(art.backdrop(still), 960, 540)} alt="" draggable={false} />}
<div className="subtitle-preview-line" style={{ bottom: px(SUBTITLE_MARGIN[prefs.subtitlePosition]) }}>
<span
className={prefs.subtitleBox}
style={{
color: prefs.subtitleColor,
fontSize: px(38 * prefs.subtitleScale),
fontWeight: prefs.subtitleBold ? 700 : 400,
WebkitTextStroke: outline ? `${px(outline * 2)} #000` : undefined,
textShadow: shadow ? `${px(shadow)} ${px(shadow)} 0 rgba(0, 0, 0, 0.7)` : undefined,
}}
>
The night is darkest just before the dawn.
<br />
And I promise you, the dawn is coming.
</span>
</div>
</div>
);
}
export function AppSettings({ tab }: { tab: string }) {
const s = useSettings();
const set = s.set;
@ -190,6 +227,9 @@ export function AppSettings({ tab }: { tab: string }) {
<Pref label="Subtitle language" description="Automatic uses the language of the audio track.">
<Select value={s.subtitleLanguage} onChange={(v) => set('subtitleLanguage', v)} options={LANGUAGES.map(([value, label]) => ({ value, label }))} />
</Pref>
</SettingsSection>
<SettingsSection title="Subtitle style" description="How text subtitles look. Image subtitles (Blu-ray, DVD) and styled ASS subtitles keep their own look. Changes apply to a playing video straight away.">
<SubtitlePreview prefs={s} />
<Pref label="Size">
<Select
value={s.subtitleScale}
@ -202,8 +242,58 @@ export function AppSettings({ tab }: { tab: string }) {
]}
/>
</Pref>
<Pref label="Background box" description="Draws text subtitles on a dark box for contrast.">
<Switch checked={s.subtitleBackground} onChange={(v) => set('subtitleBackground', v)} />
<Pref label="Text colour">
<div className="swatches" role="radiogroup" aria-label="Text colour">
{SUBTITLE_COLORS.map((c) => (
<button
key={c.value}
role="radio"
aria-checked={s.subtitleColor === c.value}
aria-label={c.label}
title={c.label}
className={s.subtitleColor === c.value ? 'selected' : ''}
style={{ background: c.value }}
onClick={() => set('subtitleColor', c.value)}
/>
))}
</div>
</Pref>
<Pref label="Edge">
<Segmented<SubtitleEdge>
value={s.subtitleEdge}
onChange={(v) => set('subtitleEdge', v)}
options={[
{ value: 'outline', label: 'Outline' },
{ value: 'shadow', label: 'Shadow' },
{ value: 'raised', label: 'Both' },
{ value: 'none', label: 'None' },
]}
/>
</Pref>
<Pref label="Background">
<Segmented<SubtitleBox>
value={s.subtitleBox}
onChange={(v) => set('subtitleBox', v)}
options={[
{ value: 'none', label: 'None' },
{ value: 'translucent', label: 'Translucent' },
{ value: 'solid', label: 'Solid' },
]}
/>
</Pref>
<Pref label="Bold">
<Switch checked={s.subtitleBold} onChange={(v) => set('subtitleBold', v)} />
</Pref>
<Pref label="Position">
<Segmented<SubtitlePosition>
value={s.subtitlePosition}
onChange={(v) => set('subtitlePosition', v)}
options={[
{ value: 'low', label: 'Low' },
{ value: 'normal', label: 'Normal' },
{ value: 'high', label: 'Raised' },
]}
/>
</Pref>
</SettingsSection>
</>
@ -214,7 +304,7 @@ export function AppSettings({ tab }: { tab: string }) {
<Pref label="Artwork colour wash" description="Tints pages with colors from the title’s artwork.">
<Switch checked={s.colorWash} onChange={(v) => set('colorWash', v)} />
</Pref>
<Pref label="Rotate featured titles" description="Cycles the featured title on Home and Discover every 12 seconds.">
<Pref label="Rotate featured titles" description="Cycles the featured title on Home and Discover every 8 seconds.">
<Switch checked={s.heroRotation} onChange={(v) => set('heroRotation', v)} />
</Pref>
<Pref label="Poster size" description="Card size in library grids.">

View file

@ -57,14 +57,12 @@ function PrefsEditor({ tab }: { tab: string }) {
const server = useServer();
const cfg = GROUPS[tab];
const q = useServerQuery(['serverPrefs'], (s) => admin.prefs(s), { staleTime: 0 });
const [advanced, setAdvanced] = useState(false);
const [edits, setEdits] = useState<Record<string, string | number | boolean>>({});
const [busy, setBusy] = useState(false);
const settings = useMemo(
() => (q.data ?? []).filter((x) => cfg.groups.includes(x.group) && !x.hidden && (advanced || !x.advanced) && !(cfg.exclude && cfg.exclude.test(x.id))),
[q.data, tab, advanced],
() => (q.data ?? []).filter((x) => cfg.groups.includes(x.group) && !x.hidden && !(cfg.exclude && cfg.exclude.test(x.id))),
[q.data, tab],
);
const advancedCount = (q.data ?? []).filter((x) => cfg.groups.includes(x.group) && !x.hidden && x.advanced).length;
const dirty = Object.keys(edits).length > 0;
const save = async () => {
@ -85,18 +83,7 @@ function PrefsEditor({ tab }: { tab: string }) {
if (!q.data) return <PageLoader />;
return (
<>
<SettingsSection
title={cfg.title}
description={cfg.description}
actions={
advancedCount > 0 && (
<label className="inline-toggle">
Show advanced
<Switch checked={advanced} onChange={setAdvanced} />
</label>
)
}
>
<SettingsSection title={cfg.title} description={cfg.description}>
{settings.map((s) => (
<Pref key={s.id} label={s.label} description={s.summary}>
<SettingControl setting={s} value={s.id in edits ? edits[s.id] : s.value} onChange={(v) => setEdits((e) => (v === s.value ? (({ [s.id]: _, ...rest }) => rest)(e) : { ...e, [s.id]: v }))} />