Skip to content

Commit 26b6624

Browse files
authored
Merge pull request #115 from missing-elements/fix/play-save-in-a-frame
fix: Download in a chat's frame that saves nothing opens a tab that saves the package, or says the way by hand (#114)
2 parents d57549b + 256f767 commit 26b6624

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

‎src/h5p/play/play-page.ts‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ import { baseName, compactSource, fragmentFromSource, fragmentWithLinks, kindOf,
3333
* again (#100). A link of this page opens nothing there on a press, so a parent that opens links
3434
* says so too, and is handed the address.
3535
*
36+
* A parent may save no file for the page, in a frame that drops the page's own download all the
37+
* same: in Grok a press on Download did nothing, with nothing said (2026-11-25, #114), and nothing
38+
* tells a page that its frame drops a download. So a framed page does not count on its own: where
39+
* the parent opens links and the source names no file, so that a tab builds the same package from
40+
* the source alone, Download hands the parent a link to a tab that saves it, as below; elsewhere
41+
* the browser is left to try, and the way by hand is said under the stage at the press.
42+
*
3643
* One press is asked for all the same (#102), and a package built in a frame cannot be passed to
3744
* a tab: the browser keeps a framed page's storage apart. But a tab can build it again from what
3845
* the frame had, the source and the files' addresses, where the store behind the addresses answers
@@ -378,6 +385,17 @@ const savingLink = (): string => `${location.origin}${location.pathname}${fragme
378385
*/
379386
const BY_HAND = 'To save it, right-click Download, or press and hold it, and open the link in a new tab.'
380387

388+
/** The way by hand, said after something else: with no "To save it" of its own. */
389+
const BY_HAND_TOO = 'Right-click Download, or press and hold it, and open the link in a new tab.'
390+
391+
/**
392+
* Whether a tab of this page would build the package kept here: only where its source names no
393+
* file. A file it was built with is in this frame, chosen here or brought here, whatever address
394+
* a preview played it from before: a tab would fetch that address again, for a file that may be
395+
* another by now.
396+
*/
397+
const tabBuilds = (): boolean => !wanted.length
398+
381399
/** A package bigger than the parent saves: the browser is left to save it, and the way is said where it may not. */
382400
function tooBig(size: number): void {
383401
saying(`This .h5p is ${sized(size)}, more than the chat saves with one press. ${BY_HAND}`)
@@ -737,7 +755,20 @@ download.addEventListener('click', (event) => {
737755
}
738756
return fetchToKeep()
739757
}
740-
if (hostSaves === null || !kept) return
758+
if (!kept) return
759+
if (hostSaves === null) {
760+
// A tab of the page's own: the browser saves what its link names.
761+
if (!framed) return
762+
// Framed, with no parent that saves: the frame may drop the download with nothing said (#114).
763+
// A tab the parent opens builds the package again and saves it, where a tab builds the same one.
764+
if (hostOpens && tabBuilds()) {
765+
event.preventDefault()
766+
toParent({ type: 'open', href: savingLink() })
767+
return saying(`A new tab builds your .h5p and saves it. No tab? ${BY_HAND_TOO}`)
768+
}
769+
// Else the browser is left to try, and the way that works in any frame is said.
770+
return saying(`Nothing saved? ${BY_HAND_TOO}`)
771+
}
741772
if (kept.size > hostSaves) return tooBig(kept.size)
742773
event.preventDefault()
743774
if (!handed) handOver(kept)

0 commit comments

Comments
 (0)