Suppress photo-frame idle while Media overlay is open

Jellyfin runs in a cross-origin iframe so we can't observe the video
element's play state directly — using overlay-open as the proxy. Any
user activity still resets the timer, and Controls / Cameras / Settings
overlays still fall to idle as before.
This commit is contained in:
root
2026-04-16 06:40:53 -05:00
parent 9315374944
commit 55dd117520

View File

@@ -4,6 +4,9 @@ import { useUIStore } from '@/stores/uiStore';
/**
* Tracks touch/mouse/keyboard activity. After `timeoutMs` of no activity,
* flips the UI into idle mode (photo frame). Any activity exits idle.
* Idle is also suppressed while the Media overlay is open (Jellyfin runs
* in a cross-origin iframe, so we can't observe the video element's
* play state directly — the overlay being open is our proxy).
*/
export function useIdle(timeoutMs: number) {
const isIdle = useUIStore((s) => s.isIdle);
@@ -14,10 +17,21 @@ export function useIdle(timeoutMs: number) {
let timer: ReturnType<typeof setTimeout> | null = null;
const reset = () => {
const schedule = () => {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
// Re-check at fire time so "media overlay open" is always current
if (useUIStore.getState().mediaOverlayOpen) {
schedule();
return;
}
setIdle(true);
}, timeoutMs);
};
const reset = () => {
if (useUIStore.getState().isIdle) setIdle(false);
timer = setTimeout(() => setIdle(true), timeoutMs);
schedule();
};
const events: Array<keyof DocumentEventMap> = [
@@ -29,7 +43,7 @@ export function useIdle(timeoutMs: number) {
];
for (const e of events) document.addEventListener(e, reset, { passive: true });
reset();
schedule();
return () => {
if (timer) clearTimeout(timer);