diff --git a/CHANGELOG.md b/CHANGELOG.md index 39d2fb7..8ef98c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 0.1.0-beta.13 + +A gentler automatic intro skip, and home screens that keep up with your other Plex apps. + +- "Skip automatically" for intros (and credits) now waits a moment first: the Skip button reads "Skipping intro" and fills as it counts down, then skips. Pause, seek or press any key before then to keep watching; the button stays as a regular Skip intro for the rest of the intro. Click it to skip straight away. +- Choose how long it waits in Settings → Playback → Automatic skip delay (3, 5 or 10 seconds, or straight away as before). It's 5 seconds by default. +- Jumping into the middle of an intro yourself no longer skips it automatically. +- Fixed: Continue Watching, a show's next episode, and watched marks didn't update after watching something on another device (a TV, a phone) while Kaleido stayed open. They now refresh when you switch back to Kaleido, and Continue Watching also refreshes every minute while it's on screen. + ## 0.1.0-beta.12 A smoother miniplayer on Windows. diff --git a/package-lock.json b/package-lock.json index ce01497..71aea19 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "kaleido-desktop", - "version": "0.1.0-beta.12", + "version": "0.1.0-beta.13", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "kaleido-desktop", - "version": "0.1.0-beta.12", + "version": "0.1.0-beta.13", "dependencies": { "@fontsource-variable/inter": "^5.3.0", "@tanstack/react-query": "^5.105.0", diff --git a/package.json b/package.json index a14ba1c..758ab7c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "kaleido-desktop", "private": true, - "version": "0.1.0-beta.12", + "version": "0.1.0-beta.13", "type": "module", "scripts": { "dev": "vite", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 8e94ec2..d21aa89 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2173,7 +2173,7 @@ dependencies = [ [[package]] name = "kaleido" -version = "0.1.0-beta.12" +version = "0.1.0-beta.13" dependencies = [ "fs2", "futures-util", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index b105989..6205fe5 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kaleido" -version = "0.1.0-beta.12" +version = "0.1.0-beta.13" description = "Kaleido — a Plex client for Windows" authors = ["Elijah"] edition = "2021" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index ba801ff..9b74fde 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "Kaleido", - "version": "0.1.0-beta.12", + "version": "0.1.0-beta.13", "identifier": "tv.kaleido.desktop", "build": { "beforeDevCommand": "npm run dev", diff --git a/src/app/queries.ts b/src/app/queries.ts index d8fcdd5..80e5bb9 100644 --- a/src/app/queries.ts +++ b/src/app/queries.ts @@ -15,6 +15,18 @@ export const queryClient = new QueryClient({ }, }); +/** + * Watch state changes from other Plex apps too (a TV, a phone), so the queries that show + * it refresh when Kaleido comes back into view and, for the progress rows, every minute + * while it is on screen. Polling pauses while the window is hidden or minimised. + */ +export const WATCH_STATE = { refetchOnWindowFocus: true } as const; +export const PROGRESS = { ...WATCH_STATE, staleTime: 15_000, refetchInterval: 60_000 } as const; + +// React Query treats a visibility change as focus. Switching back to Kaleido from another +// app doesn't change visibility, so a window focus counts as well. +window.addEventListener('focus', () => queryClient.getQueryCache().onFocus()); + /** Every key starts with the server so switching servers never mixes caches. */ export function useKey(...parts: unknown[]) { const server = useServer(); @@ -37,9 +49,9 @@ export function useSectionFor(kind: 'movie' | 'show'): { section: Section | null } export const useItem = (id: string | undefined, opts: Partial> = {}) => - useServerQuery(['item', id], (s) => api.metadata(s, id!), { enabled: !!id, staleTime: 30_000, ...opts }); + useServerQuery(['item', id], (s) => api.metadata(s, id!), { enabled: !!id, staleTime: 30_000, ...WATCH_STATE, ...opts }); -export const useChildren = (id: string | undefined) => useServerQuery(['children', id], (s) => api.children(s, id!), { enabled: !!id, staleTime: 30_000 }); +export const useChildren = (id: string | undefined) => useServerQuery(['children', id], (s) => api.children(s, id!), { enabled: !!id, staleTime: 30_000, ...WATCH_STATE }); export const useRelated = (id: string | undefined) => useServerQuery(['related', id], (s) => api.related(s, id!), { enabled: !!id, staleTime: 10 * 60_000 }); diff --git a/src/app/settings.ts b/src/app/settings.ts index e5ced81..713e80e 100644 --- a/src/app/settings.ts +++ b/src/app/settings.ts @@ -19,6 +19,8 @@ export interface Preferences { countdownSeconds: number; skipIntro: SkipMode; skipCredits: SkipMode; + /** Seconds a "Skip automatically" marker waits, so it can be cancelled; 0 skips at once. */ + autoSkipDelay: number; watchedPercent: number; audioLanguage: string; subtitleMode: SubtitleMode; @@ -62,6 +64,7 @@ export const defaults: Preferences = { countdownSeconds: 8, skipIntro: 'button', skipCredits: 'button', + autoSkipDelay: 5, watchedPercent: 90, audioLanguage: '', subtitleMode: 'auto', diff --git a/src/player/PlayerOverlay.tsx b/src/player/PlayerOverlay.tsx index cdcba2e..10d2760 100644 --- a/src/player/PlayerOverlay.tsx +++ b/src/player/PlayerOverlay.tsx @@ -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()); + 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()); + 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 ( ); diff --git a/src/player/store.ts b/src/player/store.ts index 8780c99..ea32564 100644 --- a/src/player/store.ts +++ b/src/player/store.ts @@ -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((set, get) => ({ paused: false, buffering: false, seeking: false, + lastSeek: 0, volume: 100, muted: false, speed: 1, @@ -588,6 +591,7 @@ export const usePlayer = create((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((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 }); diff --git a/src/screens/Home.tsx b/src/screens/Home.tsx index d652522..5d61656 100644 --- a/src/screens/Home.tsx +++ b/src/screens/Home.tsx @@ -1,7 +1,7 @@ import { useMemo } from 'react'; import { useQuery } from '@tanstack/react-query'; import * as api from '../plex/api'; -import { useSections, useServerQuery } from '../app/queries'; +import { PROGRESS, WATCH_STATE, useSections, useServerQuery } from '../app/queries'; import { useServer } from '../app/session'; import { navigate } from '../app/router'; import { Hero } from '../ui/Hero'; @@ -14,8 +14,8 @@ export function Home() { const sections = useSections(); const video = (sections.data ?? []).filter((s) => (s.type === 'movie' || s.type === 'show') && !s.hidden); - const home = useServerQuery(['homeHubs'], (s) => api.homeHubs(s)); - const continueWatching = useServerQuery(['continue'], (s) => api.continueWatching(s), { staleTime: 15_000 }); + const home = useServerQuery(['homeHubs'], (s) => api.homeHubs(s), WATCH_STATE); + const continueWatching = useServerQuery(['continue'], (s) => api.continueWatching(s), PROGRESS); // Section hubs feed the hero and the release shelves; shared with Discover. const sectionHubs = useQuery({ queryKey: [server.machineId, 'sectionHubsAll', video.map((s) => s.id).join(',')], diff --git a/src/screens/Item.tsx b/src/screens/Item.tsx index ed6879d..ebaf887 100644 --- a/src/screens/Item.tsx +++ b/src/screens/Item.tsx @@ -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 { useChildren, useItem, useRelated, useServerQuery } from '../app/queries'; +import { PROGRESS, useChildren, useItem, useRelated, useServerQuery } from '../app/queries'; import { useServer } from '../app/session'; import { useSettings } from '../app/settings'; import { goBack, navigate, useRouter } from '../app/router'; @@ -401,7 +401,7 @@ function Episodes({ seasons, initialSeason, showPicker = true }: { seasons: Item function ShowDetail({ item }: { item: Item }) { const seasons = useChildren(item.id); const server = useServer(); - const next = useServerQuery(['onDeck', item.id], (s) => api.onDeckFor(s, item), { staleTime: 15_000 }); + const next = useServerQuery(['onDeck', item.id], (s) => api.onDeckFor(s, item), PROGRESS); const nextEp = next.data; const seasonList = (seasons.data ?? []).filter((s) => s.type === 'season'); const percent = useSettings((s) => s.watchedPercent); diff --git a/src/screens/Section.tsx b/src/screens/Section.tsx index 7fa4e76..252354a 100644 --- a/src/screens/Section.tsx +++ b/src/screens/Section.tsx @@ -1,6 +1,6 @@ import { useMemo } from 'react'; import * as api from '../plex/api'; -import { useSectionFor, useServerQuery } from '../app/queries'; +import { PROGRESS, useSectionFor, useServerQuery } from '../app/queries'; import { navigate, useRouter, type SectionKind, type SectionTab } from '../app/router'; import { useSettings } from '../app/settings'; import type { Section } from '../plex/types'; @@ -46,7 +46,7 @@ function SectionHeader({ kind, tab, section, all, overlay }: { kind: SectionKind function Discover({ kind, section }: { kind: SectionKind; section: Section }) { const hubs = useServerQuery(['sectionHubs', section.id], (s) => api.sectionHubs(s, section.id)); - const cw = useServerQuery(['continue', section.id], (s) => api.continueWatching(s, section.id), { staleTime: 15_000 }); + const cw = useServerQuery(['continue', section.id], (s) => api.continueWatching(s, section.id), PROGRESS); const seasons = useServerQuery(['recentSeasons', section.id], (s) => recentSeasons(s, section.id), { enabled: kind === 'show', staleTime: 120_000 }); const features = useMemo(() => buildFeatures(hubs.data ?? [], 7, kind === 'movie' ? 1 : 2), [hubs.data, kind]); diff --git a/src/screens/settings/AppSettings.tsx b/src/screens/settings/AppSettings.tsx index a5abd3e..5ef80b9 100644 --- a/src/screens/settings/AppSettings.tsx +++ b/src/screens/settings/AppSettings.tsx @@ -195,6 +195,14 @@ export function AppSettings({ tab }: { tab: string }) { set('autoSkipDelay', v)} + options={[0, 3, 5, 10].map((v) => ({ value: v, label: v ? `${v} seconds` : 'Skip straight away' }))} + /> + set('autoplayNext', v)} /> diff --git a/src/styles/player.css b/src/styles/player.css index df74507..8233fec 100644 --- a/src/styles/player.css +++ b/src/styles/player.css @@ -687,6 +687,24 @@ html.os-macos:not(.window-fullscreen) .player-top { background: #f3f5f4; color: #111; } +/* An automatic skip fills the button as it counts down. */ +.skip-button.counting { + overflow: hidden; +} +.skip-button.counting::before { + content: ''; + position: absolute; + inset: 0 auto 0 0; + width: var(--p, 0%); + background: rgba(255, 255, 255, 0.18); + transition: width 260ms linear; +} +.skip-button.counting:hover::before { + background: rgba(0, 0, 0, 0.1); +} +.skip-button > * { + position: relative; +} .post-play { position: absolute; right: clamp(24px, 3.5vw, 56px);