diff --git a/Makefile b/Makefile index b596339..03c8216 100644 --- a/Makefile +++ b/Makefile @@ -90,6 +90,20 @@ $(PLAYWRIGHT) $(QR_READER) &: # service worker actif), copié dans un dossier temporaire que le parcours # modifie pour publier une « deuxième version » (bandeau de mise à jour). Le # conteneur partage le réseau de l'hôte pour joindre le serveur. +# Icônes PNG de l'écran d'accueil (192, 512, maskable 512, apple-touch-icon 180), +# dessinées depuis les SVG de app/icons/ par le Chromium de l'image Playwright +# (scripts/icons.cjs), puis allégées par optipng s'il est installé. Les PNG sont +# commités : à relancer seulement quand un SVG change. +.PHONY: icons +icons: $(PLAYWRIGHT) ## Régénère les icônes PNG depuis app/icons/*.svg (Docker) + @docker run --rm --init --ipc=host -u "$$(id -u):$$(id -g)" -e HOME=/tmp \ + -v "$(CURDIR)/$(APP_DIR)/icons:/icons" -v "$(CURDIR)/scripts:/scripts:ro" \ + -v "$(CURDIR)/$(BROWSER_TOOLS):/tools:ro" \ + $(PLAYWRIGHT_IMAGE) node /scripts/icons.cjs /icons + @if command -v optipng >/dev/null; then optipng -quiet -o7 -strip all $(APP_DIR)/icons/*.png; \ + else echo "optipng absent : PNG non optimisés."; fi + @ls -l $(APP_DIR)/icons/*.png + .PHONY: test-browser test-browser: $(PLAYWRIGHT) $(QR_READER) ## Parcours Playwright de l'app, captures dans build/shots/ (Docker) @mkdir -p build/shots diff --git a/app/icons/apple-touch-icon.png b/app/icons/apple-touch-icon.png new file mode 100644 index 0000000..b094776 Binary files /dev/null and b/app/icons/apple-touch-icon.png differ diff --git a/app/icons/icon-192.png b/app/icons/icon-192.png new file mode 100644 index 0000000..c11ce88 Binary files /dev/null and b/app/icons/icon-192.png differ diff --git a/app/icons/icon-512.png b/app/icons/icon-512.png new file mode 100644 index 0000000..d99cae1 Binary files /dev/null and b/app/icons/icon-512.png differ diff --git a/app/icons/icon-maskable-512.png b/app/icons/icon-maskable-512.png new file mode 100644 index 0000000..afa51d4 Binary files /dev/null and b/app/icons/icon-maskable-512.png differ diff --git a/app/index.html b/app/index.html index 5c2d4a3..c941af6 100644 --- a/app/index.html +++ b/app/index.html @@ -10,6 +10,7 @@ IA-Fit + diff --git a/app/manifest.webmanifest b/app/manifest.webmanifest index d38f07b..924c0ab 100644 --- a/app/manifest.webmanifest +++ b/app/manifest.webmanifest @@ -10,6 +10,9 @@ "background_color": "#000000", "theme_color": "#000000", "icons": [ + { "src": "icons/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any" }, + { "src": "icons/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any" }, + { "src": "icons/icon-maskable-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }, { "src": "icons/icon.svg", "sizes": "any", "type": "image/svg+xml", "purpose": "any" }, { "src": "icons/icon-maskable.svg", "sizes": "any", "type": "image/svg+xml", "purpose": "maskable" } ] diff --git a/scripts/icons.cjs b/scripts/icons.cjs new file mode 100644 index 0000000..fe8b4f5 --- /dev/null +++ b/scripts/icons.cjs @@ -0,0 +1,38 @@ +// Génère les icônes PNG de l'app à partir des SVG de app/icons/ : iOS n'accepte +// pas le SVG pour l'écran d'accueil, et Android en veut en 192 et 512 px. +// Lancé par `make icons` dans l'image Docker de Playwright (Chromium dessine le +// SVG, puis une capture à la taille exacte) : +// node icons.cjs +// Les PNG produits sont commités : on ne relance ce script que si un SVG change. + +const fs = require("node:fs"); +const path = require("node:path"); +const { chromium } = require("/tools/node_modules/playwright"); + +const dir = path.resolve(process.argv[2] ?? "app/icons"); + +/** Fichier produit, SVG source, côté en pixels. */ +const ICONS = [ + ["icon-192.png", "icon.svg", 192], + ["icon-512.png", "icon.svg", 512], + ["icon-maskable-512.png", "icon-maskable.svg", 512], + ["apple-touch-icon.png", "icon.svg", 180], +]; + +(async () => { + const browser = await chromium.launch(); + for (const [out, src, size] of ICONS) { + const page = await browser.newPage({ viewport: { width: size, height: size }, deviceScaleFactor: 1 }); + const svg = fs.readFileSync(path.join(dir, src)).toString("base64"); + await page.setContent(`` + + ``); + await page.locator("img").evaluate((img) => img.decode()); + await page.screenshot({ path: path.join(dir, out), clip: { x: 0, y: 0, width: size, height: size } }); + await page.close(); + console.log(`${out} : ${src} en ${size} px`); + } + await browser.close(); +})().catch((e) => { + console.error(e); + process.exit(1); +}); diff --git a/tests/test_site.sh b/tests/test_site.sh index c2d0d31..7289de1 100755 --- a/tests/test_site.sh +++ b/tests/test_site.sh @@ -108,6 +108,11 @@ while read -r module; do done < <(cd "$site" && find . -name '*.js' | sed 's|^\./||') check "sw.js" "text/javascript" check "manifest.webmanifest" "application/manifest\+json" +# Chaque icône du manifeste est servie avec le type qu'il déclare. +while read -r src type; do + check "$src" "${type//+/\\+}" +done < <(curl -s "$base/manifest.webmanifest" | grep -oE '"src": "[^"]+",[^}]*"type": "[^"]+"' \ + | sed -E 's/^"src": "([^"]+)".*"type": "([^"]+)"$/\1 \2/') check "__essai__/police.woff2" "font/woff2" check "version.json" "application/json" # Prompt d'accueil pour une IA qui navigue, s'il existe déjà dans app/.