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

- Player controls centred under the timeline: previous episode, back 10 s,
  play/pause, forward 10 s, next episode; volume and time on the left.
- Previous episode button and Shift+P.
- Draggable miniplayer, kept inside the window and remembered.
- Fix the next-episode card's buttons and the skip button being covered by
  the player's title row, and skip buttons also pausing playback.
- Drop the "Highly rated"/"Recommended" label from the hero and restore the
  gap between its logo and the details line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-04 16:33:34 -07:00
parent 10103d0e77
commit a38db53161
15 changed files with 220 additions and 61 deletions

View file

@ -1,4 +1,4 @@
import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react';
import { useCallback, useEffect, useRef, useState, type PointerEvent as ReactPointerEvent, type ReactNode } from 'react';
import { usePlayer } from './store';
import { useSession } from '../app/session';
import { useSettings, QUALITY_LABEL, UPSCALING, type Quality, type SubtitleBox, type Upscaling } from '../app/settings';
@ -512,7 +512,14 @@ function SkipButton() {
if (!marker || mode === 'off' || countdown !== null) return null;
if (marker.type === 'credits' && nextUp) return null;
return (
<button className="skip-button" onClick={() => seek(marker.end / 1000)}>
<button
className="skip-button"
onClick={(e) => {
e.stopPropagation();
seek(marker.end / 1000);
}}
onDoubleClick={(e) => e.stopPropagation()}
>
{marker.type === 'intro' ? 'Skip intro' : 'Skip credits'}
<Icon name="skipNext" size={16} />
</button>
@ -583,18 +590,62 @@ function TitleBlock({ item }: { item: Item }) {
);
}
/** Where the miniplayer was dragged to: its distance from the window's right and bottom edges. */
type MiniPos = { x: number; y: number };
const MINI_POS_KEY = 'kaleido.miniPosition';
const MINI_MARGIN = 8;
let miniPos: MiniPos | null | undefined;
function savedMiniPos(): MiniPos | null {
if (miniPos === undefined) {
try {
const p = JSON.parse(localStorage.getItem(MINI_POS_KEY) ?? 'null');
miniPos = p && Number.isFinite(p.x) && Number.isFinite(p.y) ? p : null;
} catch {
miniPos = null;
}
}
return miniPos ?? null;
}
/** Keeps the whole box inside the window. */
function clampMini(el: HTMLElement, pos: MiniPos): MiniPos {
const cs = getComputedStyle(el);
const maxX = window.innerWidth - parseFloat(cs.width) - MINI_MARGIN;
const maxY = window.innerHeight - parseFloat(cs.height) - MINI_MARGIN;
return { x: Math.round(Math.max(MINI_MARGIN, Math.min(maxX, pos.x))), y: Math.round(Math.max(MINI_MARGIN, Math.min(maxY, pos.y))) };
}
/** The box and the page's hole for the video (base.css) both follow these. */
function applyMiniPos(pos: MiniPos | null) {
const root = document.documentElement.style;
if (!pos) {
root.removeProperty('--mini-x');
root.removeProperty('--mini-y');
return;
}
root.setProperty('--mini-x', `${pos.x}px`);
root.setProperty('--mini-y', `${pos.y}px`);
}
/**
* Playing in the corner while browsing. The native video is drawn into this
* box's rectangle and the page has a matching hole (see `html.player-mini`).
* Playing in the corner while browsing, and draggable anywhere in the window.
* The native video is drawn into this box's rectangle and the page has a
* matching hole (see `html.player-mini`).
*/
function MiniPlayer() {
const st = usePlayer();
const box = useRef<HTMLDivElement>(null);
const placeVideo = useRef(() => {});
useEffect(() => {
const el = box.current;
if (!el) return;
let frame = 0;
const fit = () => {
const saved = savedMiniPos();
applyMiniPos(saved && clampMini(el, saved));
};
const place = () => {
cancelAnimationFrame(frame);
frame = requestAnimationFrame(() => {
@ -610,23 +661,64 @@ function MiniPlayer() {
if (isNative) mpv.rect({ x: x * dpr - 1, y: y * dpr - 1, width: width * dpr + 2, height: height * dpr + 2 }).catch(() => {});
});
};
place();
placeVideo.current = place;
const onResize = () => {
fit();
place();
};
onResize();
const ro = new ResizeObserver(place);
ro.observe(el);
window.addEventListener('resize', place);
window.addEventListener('resize', onResize);
return () => {
cancelAnimationFrame(frame);
ro.disconnect();
window.removeEventListener('resize', place);
window.removeEventListener('resize', onResize);
};
}, []);
const startDrag = (e: ReactPointerEvent) => {
const el = box.current;
if (e.button !== 0 || !el) return;
const cs = getComputedStyle(el);
const start = { px: e.clientX, py: e.clientY, x: parseFloat(cs.right), y: parseFloat(cs.bottom) };
let dragging = false;
const move = (ev: PointerEvent) => {
const dx = ev.clientX - start.px;
const dy = ev.clientY - start.py;
if (!dragging && Math.hypot(dx, dy) < 5) return;
dragging = true;
el.classList.add('dragging');
miniPos = clampMini(el, { x: start.x - dx, y: start.y - dy });
applyMiniPos(miniPos);
placeVideo.current();
};
const up = () => {
window.removeEventListener('pointermove', move);
window.removeEventListener('pointerup', up);
window.removeEventListener('pointercancel', up);
if (!dragging) return;
el.classList.remove('dragging');
localStorage.setItem(MINI_POS_KEY, JSON.stringify(miniPos));
// Letting go after a drag isn't a click on the button under the pointer.
const swallow = (c: MouseEvent) => {
c.stopPropagation();
c.preventDefault();
};
window.addEventListener('click', swallow, { capture: true, once: true });
setTimeout(() => window.removeEventListener('click', swallow, { capture: true }), 0);
};
window.addEventListener('pointermove', move);
window.addEventListener('pointerup', up);
window.addEventListener('pointercancel', up);
};
if (!st.item) return null;
const item = st.item;
const loading = !st.firstFrame && !st.error;
const pct = st.duration ? Math.min(100, (st.position / st.duration) * 100) : 0;
return (
<div ref={box} className={`mini-player${loading || st.error ? ' loading' : ''}`} onDoubleClick={() => st.expand()}>
<div ref={box} className={`mini-player${loading || st.error ? ' loading' : ''}`} onPointerDown={startDrag} onDoubleClick={() => st.expand()}>
<div className="mini-scrim" />
<div className="mini-top">
<button className="mini-icon" aria-label="Back to full screen player" title="Expand" onClick={() => st.expand()}>
@ -732,6 +824,11 @@ export function PlayerOverlay() {
if (e.shiftKey && p.nextUp) p.playNext();
else handled = false;
break;
case 'p':
case 'P':
if (e.shiftKey && p.prevUp) p.playPrevious();
else handled = false;
break;
case 'u':
case 'U': {
const prefs = useSettings.getState();
@ -887,25 +984,45 @@ export function PlayerOverlay() {
<Timeline onScrub={setScrubbing} />
<div className="player-controls">
<div className="player-controls-left">
<button className="player-icon big" aria-label={st.paused ? 'Play' : 'Pause'} onClick={() => st.togglePause()}>
<Icon name={st.paused || st.ended ? 'play' : 'pause'} size={26} />
</button>
<button className="player-icon" aria-label="Back 10 seconds" onClick={() => st.seekBy(-10)}>
<Icon name="replay10" size={24} />
</button>
<button className="player-icon" aria-label="Forward 10 seconds" onClick={() => st.seekBy(10)}>
<Icon name="forward10" size={24} />
</button>
{st.nextUp && (
<button className="player-icon" aria-label="Next episode" title={`Next: ${episodeLabel(st.nextUp)} ${st.nextUp.title}`} onClick={() => st.playNext()}>
<Icon name="skipNext" size={22} />
</button>
)}
<Volume />
<span className="player-time">
{clock(st.position, st.duration >= 3600)} <span className="dim">/ {clock(st.duration, st.duration >= 3600)}</span>
</span>
</div>
<div className="player-controls-center">
{/* Both episode buttons stay for episodes (dimmed at either end) so play/pause holds its place. */}
{item.type === 'episode' && (
<button
className="player-icon"
aria-label="Previous episode"
title={st.prevUp ? `Previous: ${episodeLabel(st.prevUp)} ${st.prevUp.title}` : undefined}
disabled={!st.prevUp}
onClick={() => st.playPrevious()}
>
<Icon name="skipPrev" size={22} />
</button>
)}
<button className="player-icon" aria-label="Back 10 seconds" onClick={() => st.seekBy(-10)}>
<Icon name="replay10" size={24} />
</button>
<button className="player-icon big" aria-label={st.paused ? 'Play' : 'Pause'} onClick={() => st.togglePause()}>
<Icon name={st.paused || st.ended ? 'play' : 'pause'} size={28} />
</button>
<button className="player-icon" aria-label="Forward 10 seconds" onClick={() => st.seekBy(10)}>
<Icon name="forward10" size={24} />
</button>
{item.type === 'episode' && (
<button
className="player-icon"
aria-label="Next episode"
title={st.nextUp ? `Next: ${episodeLabel(st.nextUp)} ${st.nextUp.title}` : undefined}
disabled={!st.nextUp}
onClick={() => st.playNext()}
>
<Icon name="skipNext" size={22} />
</button>
)}
</div>
<div className="player-controls-right">
<button className={`player-icon${panel === 'tracks' ? ' on' : ''}${st.subKey ? ' lit' : ''}`} aria-label="Audio and subtitles" onClick={() => setPanel(panel === 'tracks' ? '' : 'tracks')}>
<Icon name="captions" size={23} />

View file

@ -61,6 +61,8 @@ interface PlayerState {
video: { width: number; height: number; hwdec: string; codec: string } | null;
ended: boolean;
nextUp: Item | null;
/** The episode before this one, for the previous-episode button. */
prevUp: Item | null;
countdown: number | null;
postPlayDismissed: boolean;
fullscreen: boolean;
@ -89,6 +91,7 @@ interface PlayerState {
setQuality(q: Quality): Promise<void>;
selectVersion(index: number): Promise<void>;
playNext(): Promise<void>;
playPrevious(): Promise<void>;
cancelCountdown(): void;
toggleFullscreen(): Promise<void>;
previewAt(seconds: number): string;
@ -271,15 +274,17 @@ function checkScrobble() {
}
}
async function findNext(item: Item): Promise<Item | null> {
/** The episodes either side of this one in the show. */
async function findNeighbours(item: Item): Promise<{ prevUp: Item | null; nextUp: Item | null }> {
const none = { prevUp: null, nextUp: null };
const s = server();
if (!s || item.type !== 'episode' || !item.grandparentId) return null;
if (!s || item.type !== 'episode' || !item.grandparentId) return none;
try {
const leaves = await api.allLeaves(s, item.grandparentId);
const i = leaves.findIndex((e) => e.id === item.id);
return i >= 0 ? (leaves[i + 1] ?? null) : null;
return i >= 0 ? { prevUp: leaves[i - 1] ?? null, nextUp: leaves[i + 1] ?? null } : none;
} catch {
return null;
return none;
}
}
@ -547,6 +552,7 @@ export const usePlayer = create<PlayerState>((set, get) => ({
video: null,
ended: false,
nextUp: null,
prevUp: null,
countdown: null,
postPlayDismissed: false,
fullscreen: false,
@ -587,6 +593,7 @@ export const usePlayer = create<PlayerState>((set, get) => ({
buffering: true,
ended: false,
nextUp: null,
prevUp: null,
countdown: null,
postPlayDismissed: false,
chapters: [],
@ -674,7 +681,7 @@ export const usePlayer = create<PlayerState>((set, get) => ({
const st = get();
if (st.open && !st.ended) report(st.paused ? 'paused' : st.buffering ? 'buffering' : 'playing');
}, 10000);
findNext(item).then((next) => token === loadToken && set({ nextUp: next }));
findNeighbours(item).then((n) => token === loadToken && set(n));
} catch (e: any) {
if (token !== loadToken) return;
set({ error: e?.message ?? String(e), buffering: false });
@ -696,7 +703,7 @@ export const usePlayer = create<PlayerState>((set, get) => ({
await mpv.command('stop').catch(() => {});
await mpv.show(false).catch(() => {});
}
set({ open: false, mini: false, item: null, delivery: null, error: '', terminated: false, countdown: null, nextUp: null, firstFrame: false });
set({ open: false, mini: false, item: null, delivery: null, error: '', terminated: false, countdown: null, nextUp: null, prevUp: null, firstFrame: false });
const fs = await win.isFullscreen().catch(() => false);
if (fs && !wasFullscreenBeforePlay) win.setFullscreen(false);
if (st.item) invalidateLibrary();
@ -815,6 +822,12 @@ export const usePlayer = create<PlayerState>((set, get) => ({
await st.play(st.nextUp, { resume: true, quality: st.quality });
},
async playPrevious() {
const st = get();
if (!st.prevUp) return;
await st.play(st.prevUp, { resume: true, quality: st.quality });
},
cancelCountdown() {
stopCountdown();
set({ countdown: null, postPlayDismissed: true });