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

- Automatic intro/credits skip waits a configurable delay (default 5 s) with a filling
  "Skipping intro" button; pausing, seeking or pressing a key cancels it, and seeking
  into an intro never auto-skips it.
- Watch-state queries refetch on window focus, and Continue Watching / next episode
  poll every minute while visible, so progress from other Plex apps shows up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-04 21:57:23 -07:00
parent 9729755dc9
commit 328a93695a
15 changed files with 139 additions and 24 deletions

View file

@ -492,36 +492,97 @@ function Volume() {
);
}
/** A seek that lands inside a marker this recently means the viewer chose to be there. */
const SEEK_GRACE_MS = 1500;
const MODIFIER_KEYS = new Set(['Shift', 'Control', 'Alt', 'Meta', 'AltGraph', 'CapsLock']);
/**
* Skip intro / Skip credits. With "Skip automatically" the button counts down for the
* chosen delay, filling as it goes, then skips. Pausing, seeking or pressing a key
* before then keeps watching: the button stays as a plain skip for the rest of the marker.
*/
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 paused = usePlayer((s) => s.paused);
const ready = usePlayer((s) => s.firstFrame);
const lastSeek = usePlayer((s) => s.lastSeek);
const skipIntro = useSettings((s) => s.skipIntro);
const skipCredits = useSettings((s) => s.skipCredits);
const autoSkipped = useRef(new Set<string>());
const delay = useSettings((s) => s.autoSkipDelay);
// Markers already skipped, or whose automatic skip was cancelled, don't count down again.
const settled = useRef(new Set<string>());
const [pending, setPending] = useState<{ key: string; from: number } | null>(null);
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 counting = pending && pending.key === key ? pending : null;
const skip = () => {
if (!marker) return;
settled.current.add(key);
setPending(null);
seek(marker.end / 1000);
};
const cancel = () => {
if (!pending) return;
settled.current.add(pending.key);
setPending(null);
};
// Start counting once an automatic marker is playing.
useEffect(() => {
if (marker && mode === 'auto' && !autoSkipped.current.has(marker.id + marker.start) && !(marker.type === 'credits' && nextUp)) {
autoSkipped.current.add(marker.id + marker.start);
seek(marker.end / 1000);
if (!auto || !ready || paused || settled.current.has(key) || pending?.key === key) return;
if (Date.now() - usePlayer.getState().lastSeek < SEEK_GRACE_MS) {
settled.current.add(key);
return;
}
}, [marker?.id, marker?.start, mode]);
if (delay <= 0) return skip();
setPending({ key, from: usePlayer.getState().position });
}, [key, auto, ready, paused, delay]);
// Count playback time, so buffering doesn't eat into the delay.
useEffect(() => {
if (counting && position - counting.from >= delay) skip();
else if (pending && !counting) setPending(null);
}, [position, key]);
// Pausing or seeking means the viewer is watching.
useEffect(() => {
if (paused) cancel();
}, [paused]);
useEffect(cancel, [lastSeek]);
useEffect(() => {
if (!counting) return;
const onKey = (e: KeyboardEvent) => {
if (!MODIFIER_KEYS.has(e.key)) cancel();
};
window.addEventListener('keydown', onKey, true);
return () => window.removeEventListener('keydown', onKey, true);
}, [counting]);
if (!marker || mode === 'off' || countdown !== null) return null;
if (marker.type === 'credits' && nextUp) return null;
const what = marker.type === 'intro' ? 'intro' : 'credits';
const elapsed = counting ? Math.max(0, position - counting.from) : 0;
return (
<button
className="skip-button"
className={`skip-button${counting ? ' counting' : ''}`}
style={counting ? { ['--p' as string]: `${Math.min(1, elapsed / delay) * 100}%` } : undefined}
title={counting ? 'Click to skip now. Pause, seek or press any key to keep watching.' : undefined}
onClick={(e) => {
e.stopPropagation();
seek(marker.end / 1000);
skip();
}}
onDoubleClick={(e) => e.stopPropagation()}
>
{marker.type === 'intro' ? 'Skip intro' : 'Skip credits'}
<span>{counting ? `Skipping ${what}` : `Skip ${what}`}</span>
<Icon name="skipNext" size={16} />
</button>
);

View file

@ -50,6 +50,8 @@ interface PlayerState {
paused: boolean;
buffering: boolean;
seeking: boolean;
/** When the last seek was asked for (Date.now()), so a pending auto-skip can step aside. */
lastSeek: number;
volume: number;
muted: boolean;
speed: number;
@ -541,6 +543,7 @@ export const usePlayer = create<PlayerState>((set, get) => ({
paused: false,
buffering: false,
seeking: false,
lastSeek: 0,
volume: 100,
muted: false,
speed: 1,
@ -588,6 +591,7 @@ export const usePlayer = create<PlayerState>((set, get) => ({
error: '',
terminated: false,
position: (opts.offsetMs ?? 0) / 1000,
lastSeek: 0,
duration: input.duration / 1000,
cacheTime: 0,
paused: false,
@ -724,7 +728,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));
set({ position: target, ended: false });
set({ position: target, ended: false, lastSeek: Date.now() });
if (st.countdown !== null) {
stopCountdown();
set({ countdown: null });