Release Kaleido Desktop 0.1.0-beta.15
All checks were successful
Validate Kaleido Desktop / validate (push) Successful in 2m7s
All checks were successful
Validate Kaleido Desktop / validate (push) Successful in 2m7s
This commit is contained in:
parent
59e00cde4b
commit
0361a98fa4
13 changed files with 711 additions and 128 deletions
|
|
@ -71,6 +71,8 @@ interface PlayerState {
|
|||
/** The episode before this one, for the previous-episode button. */
|
||||
prevUp: Item | null;
|
||||
countdown: number | null;
|
||||
countdownTotal: number;
|
||||
postPlay: boolean;
|
||||
postPlayDismissed: boolean;
|
||||
fullscreen: boolean;
|
||||
/** Playing in the corner while browsing. */
|
||||
|
|
@ -100,6 +102,8 @@ interface PlayerState {
|
|||
playNext(): Promise<void>;
|
||||
playPrevious(): Promise<void>;
|
||||
cancelCountdown(): void;
|
||||
showPostPlay(): void;
|
||||
dismissPostPlay(): void;
|
||||
toggleFullscreen(): Promise<void>;
|
||||
previewAt(seconds: number): string;
|
||||
}
|
||||
|
|
@ -116,6 +120,8 @@ 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
|
||||
|
|
@ -334,23 +340,32 @@ async function findNeighbours(item: Item): Promise<{ prevUp: Item | null; nextUp
|
|||
|
||||
function startCountdown() {
|
||||
const st = usePlayer.getState();
|
||||
if (!st.nextUp || st.countdown !== null || st.postPlayDismissed) return;
|
||||
if (!st.open || st.error || st.item?.type !== 'episode' || st.postPlay || st.postPlayDismissed) return;
|
||||
const settings = useSettings.getState();
|
||||
if (!settings.autoplayNext) {
|
||||
usePlayer.setState({ countdown: -1 });
|
||||
return;
|
||||
}
|
||||
usePlayer.setState({ countdown: settings.countdownSeconds });
|
||||
// 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 });
|
||||
if (total <= 0) return;
|
||||
let lastTick = performance.now();
|
||||
countdownTimer && clearInterval(countdownTimer);
|
||||
countdownTimer = setInterval(() => {
|
||||
const c = usePlayer.getState().countdown;
|
||||
if (c === null || c < 0) return;
|
||||
if (c <= 1) {
|
||||
clearInterval(countdownTimer!);
|
||||
countdownTimer = null;
|
||||
usePlayer.getState().playNext();
|
||||
} else usePlayer.setState({ countdown: c - 1 });
|
||||
}, 1000);
|
||||
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);
|
||||
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;
|
||||
const remaining = Math.max(0, current.countdown - elapsed);
|
||||
usePlayer.setState({ countdown: remaining });
|
||||
if (remaining === 0) {
|
||||
stopCountdown();
|
||||
current.playNext();
|
||||
}
|
||||
}, 50);
|
||||
}
|
||||
|
||||
function stopCountdown() {
|
||||
|
|
@ -624,9 +639,9 @@ function fallbackAfterError() {
|
|||
|
||||
function maybeCredits(pos: number) {
|
||||
const st = usePlayer.getState();
|
||||
if (st.item?.type !== 'episode' || !st.nextUp || st.countdown !== null) return;
|
||||
const credits = st.item.markers.find((m) => m.type === 'credits' && (m.final || m.end >= st.item!.duration - 5000));
|
||||
if (credits && pos * 1000 >= credits.start && pos * 1000 < credits.end && useSettings.getState().skipCredits !== 'off') startCountdown();
|
||||
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();
|
||||
}
|
||||
|
||||
function onEnded() {
|
||||
|
|
@ -635,7 +650,7 @@ function onEnded() {
|
|||
usePlayer.setState({ ended: true });
|
||||
report('stopped');
|
||||
checkScrobble();
|
||||
if (st.nextUp) startCountdown();
|
||||
if (st.item?.type === 'episode') startCountdown();
|
||||
}
|
||||
|
||||
export const usePlayer = create<PlayerState>((set, get) => ({
|
||||
|
|
@ -668,6 +683,8 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
nextUp: null,
|
||||
prevUp: null,
|
||||
countdown: null,
|
||||
countdownTotal: 0,
|
||||
postPlay: false,
|
||||
postPlayDismissed: false,
|
||||
fullscreen: false,
|
||||
mini: false,
|
||||
|
|
@ -680,6 +697,8 @@ 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) {
|
||||
|
|
@ -725,6 +744,8 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
nextUp: null,
|
||||
prevUp: null,
|
||||
countdown: null,
|
||||
countdownTotal: 0,
|
||||
postPlay: false,
|
||||
postPlayDismissed: false,
|
||||
chapters: [],
|
||||
audioTracks: [],
|
||||
|
|
@ -829,7 +850,18 @@ 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) => token === loadToken && set(n));
|
||||
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 });
|
||||
|
|
@ -857,7 +889,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, prevUp: null, firstFrame: false });
|
||||
set({ open: false, mini: false, postPlay: false, item: null, delivery: null, error: '', terminated: false, countdown: null, nextUp: null, prevUp: null, firstFrame: false });
|
||||
// Closing the full player hands back the window it found; closing the
|
||||
// miniplayer leaves browsing as it is, full screen or not.
|
||||
if (!st.mini) {
|
||||
|
|
@ -879,11 +911,9 @@ 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, lastSeek: Date.now() });
|
||||
if (st.countdown !== null) {
|
||||
stopCountdown();
|
||||
set({ countdown: null });
|
||||
}
|
||||
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 } : {}) });
|
||||
if (st.postPlay) st.dismissPostPlay();
|
||||
mpv.command('seek', target.toFixed(3), 'absolute+exact').catch(() => {});
|
||||
},
|
||||
|
||||
|
|
@ -919,6 +949,7 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
async minimize() {
|
||||
const st = get();
|
||||
if (!st.open || st.mini) return;
|
||||
if (st.postPlay) st.dismissPostPlay();
|
||||
// Full screen stays for browsing; Esc or the window controls leave it.
|
||||
set({ mini: true });
|
||||
if (separateMini) {
|
||||
|
|
@ -991,6 +1022,18 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
set({ countdown: null, postPlayDismissed: true });
|
||||
},
|
||||
|
||||
showPostPlay() {
|
||||
// A deliberate Skip credits can reopen a screen previously dismissed.
|
||||
postPlayRequested = true;
|
||||
set({ postPlayDismissed: false });
|
||||
startCountdown();
|
||||
},
|
||||
|
||||
dismissPostPlay() {
|
||||
stopCountdown();
|
||||
set({ countdown: null, postPlay: false, postPlayDismissed: true });
|
||||
},
|
||||
|
||||
async toggleFullscreen() {
|
||||
const fs = await win.isFullscreen().catch(() => false);
|
||||
await win.setFullscreen(!fs);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue