@@ -26,9 +26,10 @@ import { baseName, kindOf, matchFiles, matchNamed, namedFiles, packageName, pars
2626 * A frame may be let save nothing: a chat's card was found to drop the download of this page's own
2727 * link with nothing said (ChatGPT, 2026-11-23), while the card itself could ask the chat to save a
2828 * file. So a parent that saves files says so (#98), with the most it takes, and Download then hands
29- * it the package and says under the stage how that went. A package bigger than that is not handed
30- * over, and a video that would make one is not fetched for it: the build page, in a tab of its
31- * own, is offered, where the person chooses the file and downloads as anywhere.
29+ * it the package, numbered, and says under the stage how the parent says that one went. A package
30+ * bigger than that is not handed over, and a video that would make one is not fetched for it: the
31+ * build page, in a tab of its own, is offered, where the person chooses the file and downloads as
32+ * anywhere.
3233 *
3334 * What is seen is one stage, in one of five states (`data-state` on `main`): `building`, a loader
3435 * over the place the player takes; `fetching`, the loader with how much of a file the parent has
@@ -103,8 +104,8 @@ let kept: File | null = null
103104let hostSaves : number | null = null
104105/** Whether a file was handed to the parent to save, and it has not said how that went. */
105106let handed = false
106- /** Whether one ever was: a yes that comes after the wait for it ended is still said . */
107- let everHanded = false
107+ /** The number of the last one handed, which the parent's word on it carries: word on an earlier one says nothing of this one . */
108+ let handedId = 0
108109let handedTimer : ReturnType < typeof setTimeout > | undefined
109110/** The address each file of the preview plays from, by its path in the source, and the sizes the parent gave, by address. */
110111let shownFrom : Record < string , string > = { }
@@ -317,14 +318,14 @@ function tooBig(size: number, atLeast = false): void {
317318/** The package handed to a parent that saves files itself, which says how that went; no word in a minute is taken as no. */
318319function handOver ( file : File ) : void {
319320 if ( hostSaves !== null && file . size > hostSaves ) return tooBig ( file . size )
320- handed = everHanded = true
321+ handed = true
321322 saying ( 'The chat is saving the .h5p…' , { busy : true } )
322- toParent ( { type : 'save' , file } )
323+ toParent ( { type : 'save' , id : ++ handedId , file } )
323324 clearTimeout ( handedTimer )
324325 handedTimer = setTimeout ( ( ) => saveDone ( false ) , 60_000 )
325326}
326327
327- /** How the parent's save went. A yes that comes after the minute is still said. */
328+ /** How the parent's save of the last package handed went. A yes that comes after the minute is still said. */
328329function saveDone ( ok : boolean ) : void {
329330 clearTimeout ( handedTimer )
330331 handed = false
@@ -566,12 +567,12 @@ function takeLinks(given: Record<string, unknown>, sizes: Record<string, unknown
566567// that saves files itself: that it does, with the most it takes, and how a save went.
567568window . addEventListener ( 'message' , ( event ) => {
568569 if ( ! framed || event . source !== window . parent ) return
569- const message = event . data as { source ?: unknown , type ?: unknown , files ?: unknown , links ?: unknown , sizes ?: unknown , name ?: unknown , received ?: unknown , total ?: unknown , theme ?: unknown , max ?: unknown , ok ?: unknown } | null
570+ const message = event . data as { source ?: unknown , type ?: unknown , files ?: unknown , links ?: unknown , sizes ?: unknown , name ?: unknown , received ?: unknown , total ?: unknown , theme ?: unknown , max ?: unknown , id ?: unknown , ok ?: unknown } | null
570571 if ( message ?. source !== 'h5p-play-host' ) return
571572 if ( message . type === 'files' && Array . isArray ( message . files ) ) take ( message . files . filter ( ( file ) : file is File => file instanceof File ) )
572573 else if ( message . type === 'links' && message . links && typeof message . links === 'object' ) takeLinks ( message . links as Record < string , unknown > , message . sizes && typeof message . sizes === 'object' ? message . sizes as Record < string , unknown > : { } )
573574 else if ( message . type === 'saves' ) hostSaves = amount ( message . max ) ?? Infinity
574- else if ( message . type === 'saved' && ( handed || ( everHanded && message . ok === true ) ) ) saveDone ( message . ok !== false )
575+ else if ( message . type === 'saved' && handedId && message . id === handedId && typeof message . ok === 'boolean' && ( handed || message . ok ) ) saveDone ( message . ok )
575576 else if ( message . type === 'progress' && amount ( message . received ) !== null ) fetching ( typeof message . name === 'string' ? message . name : '' , amount ( message . received ) ! , amount ( message . total ) ?? 0 )
576577 else if ( message . type === 'theme' && ( message . theme === 'light' || message . theme === 'dark' ) ) document . querySelector < HTMLMetaElement > ( 'meta[name="color-scheme"]' ) ! . content = message . theme
577578} )
0 commit comments