Skip to content

Commit a9a100f

Browse files
committed
fix(play): the saving tab counts to its closing only while it is looked at, and builds from files alone once an address is used or passed over (#104)
1 parent 1458493 commit a9a100f

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The site of the [missing-elements](https://github.com/missing-elements) web comp
99
| `/` | The project list, the tools (the build page first, with its how-to), and a footer of links | [src/index.njk](src/index.njk); the lists are in [src/_data/site.js](src/_data/site.js) |
1010
| `/pdfjs-viewer/` | The docs of `<pdfjs-viewer-element>`, with a live preview | [src/pdfjs-viewer/](src/pdfjs-viewer/) |
1111
| `/h5p/build/` | The build page, for people: what it makes, a sample that plays, and the build of a chat's source into a `.h5p`, in the visitor's browser | [src/h5p/build/](src/h5p/build/) |
12-
| `/h5p/play/` | The play page, for a chat app to show in its reply (h5p-toolkit#210); no page links to it. It builds the activity in a link's `#source=` in the visitor's browser, as the build page does, and plays it with nothing beside it but its download and a link to the build page. A file of the visitor's own that the source names is chosen there or given by the page that frames it. A video or a recording can be given as its address: it plays from there at once and is fetched whole only for the download. A framing page that saves files itself is handed the download. A package bigger than that page saves stays behind the Download link, and the page says how to save it from such a frame. A framing page that opens links itself is handed the link to the build page. A link to the page may also carry the files' addresses and a wish to save (`&links=`, `&save=1`): in a tab of its own the page then draws no player: it fetches the files itself, builds the package, tries to save it with no press and closes the tab, or says to press Download where the browser saved nothing. That is how a framing page that opens links gets a package saved that it cannot save itself. | [src/h5p/play/](src/h5p/play/) |
12+
| `/h5p/play/` | The play page, for a chat app to show in its reply (h5p-toolkit#210); no page links to it. It builds the activity in a link's `#source=` in the visitor's browser, as the build page does, and plays it with nothing beside it but its download and a link to the build page. A file of the visitor's own that the source names is chosen there or given by the page that frames it. A video or a recording can be given as its address: it plays from there at once and is fetched whole only for the download. A framing page that saves files itself is handed the download. A package bigger than that page saves stays behind the Download link, and the page says how to save it from such a frame. A framing page that opens links itself is handed the link to the build page. A link to the page may also carry the files' addresses and a wish to save (`&links=`, `&save=1`): in a tab of its own the page then draws no player: it fetches the files itself, builds the package and tries to save it with no press. Saved, it counts five seconds while it is looked at and then tries to close the tab; a tab the browser keeps open says to press Download where nothing was saved. That is how a framing page that opens links gets a package saved that it cannot save itself. | [src/h5p/play/](src/h5p/play/) |
1313
| `/h5p/create-with-ai/` | The how-to, for people: installing the skill, asking a chat, the prompts to start from, the types, and what to do when something goes wrong | [src/h5p/create-with-ai/](src/h5p/create-with-ai/) |
1414
| `/h5p/skill/` | The skill as zips to install: `h5p-author.zip`, installed once in a chat's place for skills, or attached to the message in each new chat where it has none, and `h5p-author-chatgpt.zip`, the same skill laid out as a plugin; and a page that lists them and the bundles' addresses, each in full, which no page links to | [src/h5p/skill/](src/h5p/skill/); the zips written by [vite.config.ts](vite.config.ts) |
1515
| `/h5p/bundles/` | The skill's build tool and a library bundle per content type, for a chat that runs Node but cannot reach npm; and `h5p-author-build.tar.gz`, the tool and every library in one archive, for a person to attach to a chat whose code can download nothing | written by [vite.config.ts](vite.config.ts) |

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,18 @@ import { baseName, compactSource, fragmentFromSource, fragmentWithLinks, kindOf,
4444
*
4545
* Such a tab is there to save a file, not to play one (#104): it draws no player, only the file
4646
* coming, the package being built, and that it is saved, and then it closes itself, which a tab
47-
* with nothing behind it may do. It waits a few seconds first, and longer while something of the
48-
* browser's own is over the page, as a question where to save is. "Keep this tab open" stops it,
49-
* and the activity can then be played there.
47+
* with nothing behind it may do. It waits a few seconds first, counted only while the page is seen
48+
* and has the keyboard: a question of the browser's own, where to save or whether to, may be over
49+
* it otherwise, or waiting in a tab nobody has looked at yet. "Keep this tab open" stops it, and
50+
* the activity can then be played there. Such a tab builds from files only, never from an
51+
* address: what it fetched, or what the person chose in its place.
5052
*
51-
* What is seen is one stage, in one of five states (`data-state` on `main`): `building`, a loader
52-
* over the place the player takes; `fetching`, the loader with how much of a file the parent has
53-
* brought so far; `asking`, for the person's files; `error`, with the one thing to do about it;
54-
* `ready`, the player. The parent is told each as a `status`, in words a screen reader is told too.
53+
* What is seen is one stage, in one of six states (`data-state` on `main`): `building`, a loader
54+
* over the place the player takes; `fetching`, the loader with how much of a file has come so far,
55+
* from the parent or from its address; `asking`, for the person's files; `error`, with the one
56+
* thing to do about it; `ready`, the player; `saved`, in a tab that only saves, the package saved
57+
* and the tab about to close. The parent is told each as a `status`, in words a screen reader is
58+
* told too.
5559
*/
5660

5761
const $ = <T extends HTMLElement>(id: string): T => document.getElementById(id) as T
@@ -304,8 +308,12 @@ function take(files: File[]): void {
304308
// meanwhile, must not start the activity again under them, nor take the place of the file
305309
// the package to keep is being built from.
306310
if (whole || packing) return
307-
// In a tab that only saves, a file chosen while the same one is fetched is the one built from.
308-
if (savingOnly) fetchStop?.abort()
311+
// In a tab that only saves, a file chosen while files are fetched ends the fetch, and with it
312+
// the addresses: the package is built from files alone, and one still missing is asked for.
313+
if (savingOnly) {
314+
fetchStop?.abort()
315+
links.clear()
316+
}
309317
// Where one file is named, a second choice replaces the first.
310318
if (wanted.length === 1) chosen.clear()
311319
for (const file of files) chosen.set(file.name, file)
@@ -472,6 +480,8 @@ async function fetchThenBuild(from: Record<string, string>): Promise<void> {
472480
try {
473481
const files = await fetched(from, stop.signal, fetching)
474482
if (stop.signal.aborted) return
483+
// The addresses are used up: a file still missing is asked for, not played from another's.
484+
links.clear()
475485
take(files)
476486
} catch {
477487
if (stop.signal.aborted) return
@@ -483,8 +493,9 @@ async function fetchThenBuild(from: Record<string, string>): Promise<void> {
483493

484494
/**
485495
* The package saved in a tab that only saves, with no press, and the tab closed a few seconds
486-
* later. The count stops while the page is seen and something else has the keyboard: a question
487-
* of the browser's own, where to save or whether to, is then likely over it.
496+
* later. The seconds are counted only while the page is seen and has the keyboard: otherwise a
497+
* question of the browser's own, where to save or whether to, may be open over it, or waiting
498+
* in a tab that was opened behind another.
488499
*/
489500
function savedHere(file: File): void {
490501
saveUnasked = false
@@ -498,7 +509,7 @@ function savedHere(file: File): void {
498509
show('saved', `Your .h5p is saved: ${named} is in your downloads. This tab closes itself in a few seconds.`)
499510
clearInterval(closing)
500511
closing = setInterval(() => {
501-
if (!document.hidden && !document.hasFocus()) return
512+
if (document.hidden || !document.hasFocus()) return
502513
if (--left > 0) return said()
503514
// A tab the browser lets no page close stays, and says what it would have.
504515
stay()

0 commit comments

Comments
 (0)