file-show: autoplay first file

Massimo Melina committed Jan 24, 2025 at 00:07 UTC 0e72ee526dd41e489ffa02f260717b82b9621ed2
1 file changed +7 -1
frontend/src/show.ts
+7 -1
@@ -25,6 +25,7 @@ export function fileShow(entry: DirEntry, { startPlaying=false, startShuffle=fal
25 let onClose: any
26 let firstUri: string
27 let playMsgOnce = true
28 + let justOpen = true
29 const { close } = newDialog({
30 noFrame: true,
31 className: 'file-show',
@@ -105,11 +106,16 @@ export function fileShow(entry: DirEntry, { startPlaying=false, startShuffle=fal
106 }
107 useEffect(() => {
108 const showElement = getShowElement()
108 - if (!autoPlaying || !showElement) return
109 + try {
110 + if (!autoPlaying && !justOpen || !showElement) return
111 + } finally {
112 + justOpen = false
113 + }
114 if (showElement instanceof HTMLMediaElement) {
115 showElement.play().catch(playFailed)
116 return domOn('ended', goNext, { target: showElement as any })
117 }
118 + if (!autoPlaying) return // we reached here because of the justOpen, but we are not interested in images
119 // we are supposedly showing an image
120 const h = setTimeout(goNext, state.auto_play_seconds * 1000)
121 return () => clearTimeout(h)