Release Kaleido Desktop 0.1.0-beta.17
All checks were successful
Validate Kaleido Desktop / validate (push) Successful in 1m36s
All checks were successful
Validate Kaleido Desktop / validate (push) Successful in 1m36s
This commit is contained in:
parent
dfe865d8f4
commit
28e633dad1
13 changed files with 165 additions and 156 deletions
|
|
@ -506,8 +506,8 @@ function SkipButton() {
|
|||
const item = usePlayer((s) => s.item);
|
||||
const position = usePlayer((s) => s.position);
|
||||
const seek = usePlayer((s) => s.seek);
|
||||
const nextUp = usePlayer((s) => s.nextUp);
|
||||
const countdown = usePlayer((s) => s.countdown);
|
||||
const postPlayDismissed = usePlayer((s) => s.postPlayDismissed);
|
||||
const paused = usePlayer((s) => s.paused);
|
||||
const ready = usePlayer((s) => s.firstFrame);
|
||||
const lastSeek = usePlayer((s) => s.lastSeek);
|
||||
|
|
@ -520,8 +520,9 @@ function SkipButton() {
|
|||
const ms = position * 1000;
|
||||
const marker = item?.markers.find((m) => (m.type === 'intro' || m.type === 'credits') && ms >= m.start && ms < m.end - 1000);
|
||||
const key = item && marker ? `${item.id}:${marker.type}:${marker.start}` : '';
|
||||
const mode = marker?.type === 'intro' ? skipIntro : skipCredits;
|
||||
const auto = !!marker && mode === 'auto' && !(marker.type === 'credits' && nextUp);
|
||||
const episodeCredits = marker?.type === 'credits' && item?.type === 'episode';
|
||||
const mode = marker?.type === 'intro' ? skipIntro : episodeCredits ? 'button' : skipCredits;
|
||||
const auto = !!marker && !episodeCredits && mode === 'auto';
|
||||
const counting = pending && pending.key === key ? pending : null;
|
||||
|
||||
const skip = () => {
|
||||
|
|
@ -569,7 +570,7 @@ function SkipButton() {
|
|||
return () => window.removeEventListener('keydown', onKey, true);
|
||||
}, [counting]);
|
||||
|
||||
if (!marker || mode === 'off' || countdown !== null) return null;
|
||||
if (!marker || (episodeCredits && !postPlayDismissed) || mode === 'off' || countdown !== null) return null;
|
||||
const what = marker.type === 'intro' ? 'intro' : 'credits';
|
||||
const elapsed = counting ? Math.max(0, position - counting.from) : 0;
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -4,13 +4,14 @@ import { mpv } from './engine';
|
|||
import { isNative } from '../platform/native';
|
||||
import { useSession } from '../app/session';
|
||||
import { navigate } from '../app/router';
|
||||
import { clock, episodeLabel } from '../app/format';
|
||||
import { 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 { 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. */
|
||||
export function PostPlay() {
|
||||
|
|
@ -53,7 +54,13 @@ export function PostPlay() {
|
|||
useEffect(() => {
|
||||
const previous = document.activeElement as HTMLElement | null;
|
||||
(play.current ?? video.current)?.focus({ preventScroll: true });
|
||||
const cancel = () => usePlayer.getState().cancelCountdown();
|
||||
const cancel = () => {
|
||||
const player = usePlayer.getState();
|
||||
if (!player.postPlayDismissed) player.cancelCountdown();
|
||||
};
|
||||
const move = (event: MouseEvent) => {
|
||||
if (event.movementX !== 0 || event.movementY !== 0) cancel();
|
||||
};
|
||||
const key = (e: KeyboardEvent) => {
|
||||
cancel();
|
||||
if (e.key === 'Escape' || e.key === 'Backspace') {
|
||||
|
|
@ -73,10 +80,12 @@ export function PostPlay() {
|
|||
};
|
||||
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 });
|
||||
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 });
|
||||
};
|
||||
|
|
@ -126,12 +135,12 @@ export function PostPlay() {
|
|||
<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${episodes ? '' : ' poster'}`} onClick={() => episodes ? choose(entry) : void browse(entry)} aria-current={entry.id === item.id ? 'true' : undefined}>
|
||||
<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 && <img src={server.image(entry.thumb, episodes ? 360 : 220, episodes ? 202 : 330)} alt="" loading="lazy" draggable={false} />}
|
||||
{(entry.id === item.id || entry.id === st.nextUp?.id) && <span>{entry.id === item.id ? 'Now playing' : 'Up next'}</span>}
|
||||
{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 ? `${episodeLabel(entry)} · ${entry.title}` : entry.title}</b>
|
||||
<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>
|
||||
|
|
@ -141,33 +150,26 @@ export function PostPlay() {
|
|||
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>
|
||||
<header className="up-next-toolbar" data-tauri-drag-region={isNative ? true : undefined}>
|
||||
<button className="up-next-back" onClick={watch} title="Return to video (Esc)"><Icon name="arrowLeft" size={18} /> Return to video</button>
|
||||
<button className="up-next-back" onClick={() => st.close()}>Done watching</button>
|
||||
{st.fullscreen && <button className="up-next-back" onClick={() => st.toggleFullscreen()} aria-label="Exit full screen" title="Exit full screen (F11)"><Icon name="collapse" size={18} /></button>}
|
||||
{!st.fullscreen && <WindowControls />}
|
||||
</header>
|
||||
<div className="up-next-header">
|
||||
{!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}`}><span><Icon name="expand" size={20} /> Return to video</span></button>
|
||||
<div className="up-next-caption"><span>{episodeLabel(item)} · {item.title}</span><small>{st.ended ? 'Finished' : `−${clock(Math.max(0, st.duration - st.position))}`}</small></div>
|
||||
<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 ? 'Up next' : 'More to watch'}</span>
|
||||
<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} withFormats={false} />
|
||||
<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>
|
||||
{counting && <button className="up-next-cancel" onClick={() => st.cancelCountdown()}>Cancel autoplay</button>}
|
||||
</div>
|
||||
<p className="up-next-hint" role="status">{counting ? 'Autoplay is on · Click, scroll or press any key to cancel' : 'Autoplay is off for this episode'}</p>
|
||||
</> : <p className="up-next-summary">You’ve reached the end of this series.</p>}
|
||||
</> : st.episodeContextReady ? <p className="up-next-summary">You’ve reached the end of this series.</p> : <Spinner size={24} />}
|
||||
</div>
|
||||
</div>
|
||||
<div className="up-next-rows">
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import type { MpvEvent } from './engine';
|
|||
const harness = vi.hoisted(() => {
|
||||
const memory = new Map<string, string>();
|
||||
vi.stubGlobal('localStorage', { getItem: (k: string) => memory.get(k) ?? null, setItem: (k: string, v: string) => memory.set(k, v), removeItem: (k: string) => memory.delete(k) });
|
||||
vi.stubGlobal('document', { hidden: false, hasFocus: () => true, documentElement: { classList: { toggle: vi.fn() } } });
|
||||
vi.stubGlobal('document', Object.assign(new EventTarget(), { hidden: false, hasFocus: () => true, documentElement: { classList: { toggle: vi.fn() } } }));
|
||||
return { event: (_e: MpvEvent) => {}, next: [] as unknown[], focused: true };
|
||||
});
|
||||
|
||||
|
|
@ -67,15 +67,25 @@ describe('Up Next playback lifecycle', () => {
|
|||
time(81);
|
||||
expect(usePlayer.getState()).toMatchObject({ postPlay: true, countdown: 5, countdownTotal: 5 });
|
||||
});
|
||||
it('leaves button-only credits to the viewer, and opens on a deliberate skip', () => {
|
||||
useSettings.setState({ skipCredits: 'button' });
|
||||
time(81);
|
||||
vi.advanceTimersByTime(2000);
|
||||
time(83);
|
||||
it.each(['button', 'off', 'auto'] as const)('opens at the first credits frame with movie credit skipping set to %s', (skipCredits) => {
|
||||
useSettings.setState({ skipCredits });
|
||||
time(79.9);
|
||||
expect(usePlayer.getState().postPlay).toBe(false);
|
||||
usePlayer.getState().showPostPlay();
|
||||
time(80);
|
||||
expect(usePlayer.getState().postPlay).toBe(true);
|
||||
});
|
||||
it('counts while the native video owns focus instead of the webview', () => {
|
||||
harness.focused = false;
|
||||
time(81);
|
||||
vi.advanceTimersByTime(1000);
|
||||
expect(usePlayer.getState().countdown).toBeCloseTo(4);
|
||||
});
|
||||
it('counts elapsed time even when the webview delivers timer callbacks late', () => {
|
||||
time(81);
|
||||
vi.setSystemTime(Date.now() + 2000);
|
||||
vi.advanceTimersByTime(50);
|
||||
expect(usePlayer.getState().countdown).toBeCloseTo(2.95);
|
||||
});
|
||||
it('opens at EOF even when automatic credit skipping is off', () => {
|
||||
useSettings.setState({ skipCredits: 'off' });
|
||||
eof();
|
||||
|
|
@ -106,11 +116,9 @@ describe('Up Next playback lifecycle', () => {
|
|||
eof();
|
||||
expect(usePlayer.getState()).toMatchObject({ postPlay: false, countdown: null });
|
||||
});
|
||||
it.each(['hidden', 'unfocused', 'paused', 'mini'] as const)('holds the countdown while %s', (reason) => {
|
||||
it.each(['hidden', 'mini'] as const)('holds the countdown while %s', (reason) => {
|
||||
time(81);
|
||||
if (reason === 'hidden') Object.assign(document, { hidden: true });
|
||||
if (reason === 'unfocused') harness.focused = false;
|
||||
if (reason === 'paused') usePlayer.setState({ paused: true });
|
||||
if (reason === 'mini') usePlayer.setState({ mini: true });
|
||||
vi.advanceTimersByTime(20000);
|
||||
expect(usePlayer.getState().countdown).toBe(5);
|
||||
|
|
@ -126,6 +134,22 @@ describe('Up Next playback lifecycle', () => {
|
|||
vi.advanceTimersByTime(1000);
|
||||
expect(usePlayer.getState().countdown).toBeCloseTo(4);
|
||||
});
|
||||
it('keeps counting while credits are paused, like Android Up Next', () => {
|
||||
time(81);
|
||||
usePlayer.setState({ paused: true });
|
||||
vi.advanceTimersByTime(1000);
|
||||
expect(usePlayer.getState().countdown).toBeCloseTo(4);
|
||||
});
|
||||
it('does not spend hidden time when the app returns before another timer tick', () => {
|
||||
time(80);
|
||||
Object.assign(document, { hidden: true });
|
||||
document.dispatchEvent(new Event('visibilitychange'));
|
||||
vi.setSystemTime(Date.now() + 60000);
|
||||
Object.assign(document, { hidden: false });
|
||||
document.dispatchEvent(new Event('visibilitychange'));
|
||||
vi.advanceTimersByTime(50);
|
||||
expect(usePlayer.getState().countdown).toBeCloseTo(4.95);
|
||||
});
|
||||
it('shows a finale without an autoplay target', () => {
|
||||
usePlayer.setState({ nextUp: null });
|
||||
eof();
|
||||
|
|
@ -136,30 +160,43 @@ describe('Up Next playback lifecycle', () => {
|
|||
time(81);
|
||||
expect(usePlayer.getState()).toMatchObject({ postPlay: true, countdown: null });
|
||||
});
|
||||
it('treats a seek into credits as a choice to watch them', () => {
|
||||
it('opens when seeking into credits instead of suppressing Up Next', () => {
|
||||
usePlayer.getState().seek(81);
|
||||
time(81);
|
||||
vi.advanceTimersByTime(2000);
|
||||
time(83);
|
||||
expect(usePlayer.getState().postPlay).toBe(false);
|
||||
expect(usePlayer.getState().postPlay).toBe(true);
|
||||
expect(mpv.command).toHaveBeenCalledWith('seek', '81.000', 'absolute+exact');
|
||||
});
|
||||
it.each(['ended', 'button'] as const)('waits for slow episode context after %s', async (reason) => {
|
||||
it.each(['ended', 'credits'] as const)('shows Up Next immediately and loads slow episode context after %s', async (reason) => {
|
||||
let resolve!: (items: ReturnType<typeof episode>[]) => void;
|
||||
vi.mocked(api.allLeaves).mockImplementationOnce(() => new Promise((done) => { resolve = done; }));
|
||||
await usePlayer.getState().play(episode(), { resume: false });
|
||||
usePlayer.setState({ firstFrame: true });
|
||||
useSettings.setState({ skipCredits: 'button' });
|
||||
if (reason === 'ended') eof();
|
||||
else usePlayer.getState().showPostPlay();
|
||||
expect(usePlayer.getState().postPlay).toBe(false);
|
||||
else time(80);
|
||||
expect(usePlayer.getState().postPlay).toBe(true);
|
||||
expect(usePlayer.getState().countdown).toBeNull();
|
||||
resolve([episode(), episode('2')]);
|
||||
await vi.waitFor(() => expect(usePlayer.getState().postPlay).toBe(true));
|
||||
await vi.waitFor(() => expect(usePlayer.getState().episodeContextReady).toBe(true));
|
||||
expect(usePlayer.getState().nextUp?.id).toBe('2');
|
||||
expect(usePlayer.getState().countdownTotal).toBe(5);
|
||||
expect(usePlayer.getState().countdown).toBeGreaterThan(4.9);
|
||||
expect(usePlayer.getState().countdown).toBeLessThanOrEqual(5);
|
||||
});
|
||||
it('keeps autoplay cancelled when episode context arrives after interaction', async () => {
|
||||
let resolve!: (items: ReturnType<typeof episode>[]) => void;
|
||||
vi.mocked(api.allLeaves).mockImplementationOnce(() => new Promise((done) => { resolve = done; }));
|
||||
await usePlayer.getState().play(episode(), { resume: false });
|
||||
usePlayer.setState({ firstFrame: true });
|
||||
time(80);
|
||||
usePlayer.getState().cancelCountdown();
|
||||
resolve([episode(), episode('2')]);
|
||||
await vi.waitFor(() => expect(usePlayer.getState().episodeContextReady).toBe(true));
|
||||
vi.advanceTimersByTime(10000);
|
||||
expect(usePlayer.getState()).toMatchObject({ postPlay: true, countdown: null, postPlayDismissed: true });
|
||||
});
|
||||
it('clears Up Next and its timer when playback closes', async () => {
|
||||
time(81);
|
||||
await usePlayer.getState().close();
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ interface PlayerState {
|
|||
nextUp: Item | null;
|
||||
/** The episode before this one, for the previous-episode button. */
|
||||
prevUp: Item | null;
|
||||
episodeContextReady: boolean;
|
||||
countdown: number | null;
|
||||
countdownTotal: number;
|
||||
postPlay: boolean;
|
||||
|
|
@ -115,13 +116,12 @@ let lastReport = 0;
|
|||
let sessionAnswered = false;
|
||||
let reportTimer: ReturnType<typeof setInterval> | null = null;
|
||||
let countdownTimer: ReturnType<typeof setInterval> | null = null;
|
||||
let unwatchCountdown: (() => void) | null = null;
|
||||
let scrobbled = false;
|
||||
let unlisten: (() => void) | null = null;
|
||||
let loadToken = 0;
|
||||
let wasFullscreenBeforePlay = false;
|
||||
let pendingExternal: Track | null = null;
|
||||
let neighboursReady = false;
|
||||
let postPlayRequested = false;
|
||||
|
||||
/**
|
||||
* The server this playback belongs to, fixed when it starts. Progress, watched state
|
||||
|
|
@ -338,27 +338,33 @@ async function findNeighbours(item: Item): Promise<{ prevUp: Item | null; nextUp
|
|||
}
|
||||
}
|
||||
|
||||
function startCountdown() {
|
||||
function openPostPlay() {
|
||||
const st = usePlayer.getState();
|
||||
if (!st.open || st.error || st.item?.type !== 'episode' || st.postPlay || st.postPlayDismissed) return;
|
||||
usePlayer.setState({ postPlay: true });
|
||||
startCountdown();
|
||||
}
|
||||
|
||||
function startCountdown() {
|
||||
const st = usePlayer.getState();
|
||||
if (!st.open || !st.postPlay || st.error || !st.nextUp || st.postPlayDismissed || st.countdown !== null) return;
|
||||
const settings = useSettings.getState();
|
||||
// Don't mistake a slow context request for the end of the series.
|
||||
if (!neighboursReady) return;
|
||||
postPlayRequested = false;
|
||||
const total = st.nextUp && settings.autoplayNext ? settings.countdownSeconds : 0;
|
||||
usePlayer.setState({ postPlay: true, countdown: total > 0 ? total : null, countdownTotal: total });
|
||||
const total = settings.autoplayNext ? settings.countdownSeconds : 0;
|
||||
if (total <= 0) return;
|
||||
stopCountdown();
|
||||
usePlayer.setState({ countdown: total, countdownTotal: total });
|
||||
let lastTick = performance.now();
|
||||
countdownTimer && clearInterval(countdownTimer);
|
||||
const visibilityChanged = () => { lastTick = performance.now(); };
|
||||
document.addEventListener('visibilitychange', visibilityChanged);
|
||||
unwatchCountdown = () => document.removeEventListener('visibilitychange', visibilityChanged);
|
||||
countdownTimer = setInterval(() => {
|
||||
const now = performance.now();
|
||||
// Never spend time hidden, in the separate miniplayer, or behind another app.
|
||||
// Cap a delayed tick so sleep / a suspended web view cannot skip an episode.
|
||||
const elapsed = Math.min((now - lastTick) / 1000, 0.1);
|
||||
const elapsed = Math.max(0, (now - lastTick) / 1000);
|
||||
lastTick = now;
|
||||
const current = usePlayer.getState();
|
||||
if (!current.open || !current.postPlay || current.error || current.countdown === null) return stopCountdown();
|
||||
if (document.hidden || !document.hasFocus() || current.mini || (current.paused && !current.ended)) return;
|
||||
// Native video can own keyboard focus while the webview is still on screen.
|
||||
if (document.hidden || current.mini) return;
|
||||
const remaining = Math.max(0, current.countdown - elapsed);
|
||||
usePlayer.setState({ countdown: remaining });
|
||||
if (remaining === 0) {
|
||||
|
|
@ -371,6 +377,8 @@ function startCountdown() {
|
|||
function stopCountdown() {
|
||||
if (countdownTimer) clearInterval(countdownTimer);
|
||||
countdownTimer = null;
|
||||
unwatchCountdown?.();
|
||||
unwatchCountdown = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -639,9 +647,8 @@ function fallbackAfterError() {
|
|||
|
||||
function maybeCredits(pos: number) {
|
||||
const st = usePlayer.getState();
|
||||
if (st.item?.type !== 'episode' || !st.firstFrame || st.paused || st.postPlayDismissed || Date.now() - st.lastSeek < 1500) return;
|
||||
const credits = st.item.markers.find((m) => m.type === 'credits');
|
||||
if (credits && pos * 1000 >= credits.start && pos * 1000 < credits.end && useSettings.getState().skipCredits === 'auto') startCountdown();
|
||||
if (st.item?.type !== 'episode' || !st.firstFrame || st.postPlayDismissed) return;
|
||||
if (st.item.markers.some((m) => m.type === 'credits' && pos * 1000 >= m.start && pos * 1000 < m.end)) openPostPlay();
|
||||
}
|
||||
|
||||
function onEnded() {
|
||||
|
|
@ -650,7 +657,7 @@ function onEnded() {
|
|||
usePlayer.setState({ ended: true });
|
||||
report('stopped');
|
||||
checkScrobble();
|
||||
if (st.item?.type === 'episode') startCountdown();
|
||||
if (st.item?.type === 'episode') openPostPlay();
|
||||
}
|
||||
|
||||
export const usePlayer = create<PlayerState>((set, get) => ({
|
||||
|
|
@ -682,6 +689,7 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
ended: false,
|
||||
nextUp: null,
|
||||
prevUp: null,
|
||||
episodeContextReady: false,
|
||||
countdown: null,
|
||||
countdownTotal: 0,
|
||||
postPlay: false,
|
||||
|
|
@ -697,8 +705,6 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
// Closing or starting something else while this one is still setting up wins.
|
||||
const stale = () => token !== loadToken;
|
||||
const prefs = useSettings.getState();
|
||||
neighboursReady = false;
|
||||
postPlayRequested = false;
|
||||
stopThemeMusic();
|
||||
stopCountdown();
|
||||
if (!isNative) {
|
||||
|
|
@ -743,6 +749,7 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
ended: false,
|
||||
nextUp: null,
|
||||
prevUp: null,
|
||||
episodeContextReady: false,
|
||||
countdown: null,
|
||||
countdownTotal: 0,
|
||||
postPlay: false,
|
||||
|
|
@ -818,6 +825,15 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
...(tracks ?? {}),
|
||||
});
|
||||
|
||||
findNeighbours(item).then((n) => {
|
||||
if (token !== loadToken) return;
|
||||
set({ ...n, episodeContextReady: true });
|
||||
const current = get();
|
||||
if (current.postPlay) startCountdown();
|
||||
else if (current.ended) openPostPlay();
|
||||
else maybeCredits(current.position);
|
||||
});
|
||||
|
||||
await mpv.init({ hwdec: prefs.hwdec, hdr: prefs.hdrPassthrough });
|
||||
if (!unlisten) unlisten = await mpv.on(onEvent);
|
||||
if (stale()) return;
|
||||
|
|
@ -850,18 +866,6 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
const st = get();
|
||||
if (st.open && !st.ended) report(st.paused ? 'paused' : st.buffering ? 'buffering' : 'playing');
|
||||
}, 10000);
|
||||
findNeighbours(item).then((n) => {
|
||||
if (token !== loadToken) return;
|
||||
neighboursReady = true;
|
||||
set(n);
|
||||
const current = get();
|
||||
// Metadata may arrive after EOF / the credits. Open only once it is known
|
||||
// whether there is a next episode, without restarting a cancelled timer.
|
||||
if (!current.postPlay) {
|
||||
if (postPlayRequested || current.ended) startCountdown();
|
||||
else maybeCredits(current.position);
|
||||
}
|
||||
});
|
||||
} catch (e: any) {
|
||||
if (token !== loadToken) return;
|
||||
set({ error: e?.message ?? String(e), buffering: false });
|
||||
|
|
@ -911,8 +915,7 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
seek(seconds) {
|
||||
const st = get();
|
||||
const target = Math.max(0, Math.min(seconds, (st.duration || seconds) - 0.5));
|
||||
const choseCredits = st.item?.type === 'episode' && st.item.markers.some((m) => m.type === 'credits' && target * 1000 >= m.start && target * 1000 < m.end);
|
||||
set({ position: target, ended: false, lastSeek: Date.now(), ...(choseCredits ? { postPlayDismissed: true } : {}) });
|
||||
set({ position: target, ended: false, lastSeek: Date.now() });
|
||||
if (st.postPlay) st.dismissPostPlay();
|
||||
mpv.command('seek', target.toFixed(3), 'absolute+exact').catch(() => {});
|
||||
},
|
||||
|
|
@ -1024,9 +1027,8 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
|
||||
showPostPlay() {
|
||||
// A deliberate Skip credits can reopen a screen previously dismissed.
|
||||
postPlayRequested = true;
|
||||
set({ postPlayDismissed: false });
|
||||
startCountdown();
|
||||
openPostPlay();
|
||||
},
|
||||
|
||||
dismissPostPlay() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue