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:
@@ -4,6 +4,9 @@ import { useUIStore } from '@/stores/uiStore';
|
|||||||
/**
|
/**
|
||||||
* Tracks touch/mouse/keyboard activity. After `timeoutMs` of no activity,
|
* Tracks touch/mouse/keyboard activity. After `timeoutMs` of no activity,
|
||||||
* flips the UI into idle mode (photo frame). Any activity exits idle.
|
* 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) {
|
export function useIdle(timeoutMs: number) {
|
||||||
const isIdle = useUIStore((s) => s.isIdle);
|
const isIdle = useUIStore((s) => s.isIdle);
|
||||||
@@ -14,10 +17,21 @@ export function useIdle(timeoutMs: number) {
|
|||||||
|
|
||||||
let timer: ReturnType<typeof setTimeout> | null = null;
|
let timer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
||||||
const reset = () => {
|
const schedule = () => {
|
||||||
if (timer) clearTimeout(timer);
|
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);
|
if (useUIStore.getState().isIdle) setIdle(false);
|
||||||
timer = setTimeout(() => setIdle(true), timeoutMs);
|
schedule();
|
||||||
};
|
};
|
||||||
|
|
||||||
const events: Array<keyof DocumentEventMap> = [
|
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 });
|
for (const e of events) document.addEventListener(e, reset, { passive: true });
|
||||||
|
|
||||||
reset();
|
schedule();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (timer) clearTimeout(timer);
|
if (timer) clearTimeout(timer);
|
||||||
|
|||||||
Reference in New Issue
Block a user