Make Crystal an installable web app with an offline shell (#39)
Checks / web (push) Failing after 16s
Private ROM checks / private-rom (push) Failing after 17m47s

A manifest and icons rendered from icon.svg make the app installable.
The native build emits a service worker that precaches exactly the
built files and passes everything else to the network, so ROMs never
reach its cache. New versions wait for the player's Update, which saves
before reloading. Savegames offers installation, iPhone steps and
persistent storage, and a full disk gets its own save error.

Acceptance on physical iPhone and Android devices remains.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
samyandClaude Opus 5.5 committed 2026-10-03 20:51:57 +02:00
1 parent f289615bd2
commit ce8129703f
20 files changed
+661 -15

No files matched your search

+33 -2
View File
@@ -1,6 +1,13 @@
import { readdirSync, readFileSync, statSync } from "node:fs";
import { join } from "node:path";
import { listFiles } from "./service-worker.mjs";
const ICONS = new Set([
"icon-192.png",
"icon-512.png",
"icon-maskable-512.png",
"apple-touch-icon.png",
]);
let files = 0,
size = 0;
function inspect(directory) {
@@ -10,7 +17,15 @@ function inspect(directory) {
inspect(path);
continue;
}
if (!/\.(html|js|css|svg)$/.test(name))
// The app icons are the only images: rendered from icon.svg, small.
if (ICONS.has(name)) {
if (statSync(path).size > 32_000)
throw new Error(`App icon is unexpectedly large: ${path}`);
files++;
size += statSync(path).size;
continue;
}
if (!/\.(html|js|css|svg|webmanifest)$/.test(name))
throw new Error(`Unexpected production asset: ${path}`);
if (/reference|vendor|binjgb/i.test(path))
throw new Error(`Reference tool in production: ${path}`);
@@ -25,6 +40,22 @@ function inspect(directory) {
}
}
inspect("dist");
// The service worker precaches exactly the shell: every built file, and
// nothing that could hold game data.
const worker = readFileSync("dist/sw.js", "utf8");
const shell = JSON.parse(/const SHELL = (\[.*\]);/.exec(worker)?.[1] ?? "null");
if (!Array.isArray(shell)) throw new Error("dist/sw.js has no app shell list.");
const expected = [
"./",
...listFiles("dist")
.filter((file) => file !== "sw.js" && file !== "index.html")
.map((file) => `./${file}`),
].sort();
if (JSON.stringify([...shell].sort()) !== JSON.stringify(expected))
throw new Error("The service worker's shell does not match the build.");
if (shell.some((file) => /\.(gbc?|rom|sav)$|crystal-save/i.test(file)))
throw new Error("The service worker would cache game data.");
console.log(
`Native release verified: ${files} HTML/JS/CSS/SVG files, ${size} bytes; no emulator, ROM, extracted binary assets or reference checkout.`,
`Native release verified: ${files} files (HTML, JS, CSS, SVG, manifest, service worker and ${ICONS.size} icons), ${size} bytes; no emulator, ROM, extracted binary assets or reference checkout.`,
);