werkstaetten-app/mobile/scripts/fetch-assets.mjs
Friederich Loheide 856559f830 Native Apps für iOS und Android (Capacitor) mit Push über Firebase
Apps (mobile/):
- Capacitor-8-Hülle, lädt die Web-App von APP_URL – Inhalte ohne App-Update
- Android- und iOS-Projekt (Swift Package Manager) mit Firebase Messaging,
  nativer Sprachausgabe, Teilen, App, Statusleiste, Startbildschirm
- `npm run sync` überträgt APP_ID, Name, Adresse und Farbe aus mobile/.env
  in beide Projekte und richtet ein: App-Links (Android intent-filter,
  iOS Associated Domains), Push (Entitlements, Background Mode,
  AppDelegate, Benachrichtigungssymbol/-farbe), Offline-Seite;
  idempotent, prüft Eingaben, warnt bei fehlenden Firebase-Dateien
- `npm run assets` erzeugt Symbole und Startbildschirme aus Logo und
  Markenfarbe der Redaktion, dazu das Android-Benachrichtigungssymbol
- Schritt-für-Schritt-Anleitung für den Mac (mobile/README.md)

Server:
- Versand an App-Geräte über FCM HTTP v1 (signiertes JWT, ohne
  firebase-admin), eingebunden in alle Benachrichtigungen; abgemeldete
  Geräte werden entfernt (nur bei UNREGISTERED, nicht bei anderen Fehlern)
- Firebase-Dienstkonto in den Einstellungen hochladen (verschlüsselt),
  App-ID, Team-ID, SHA-256, Store-Links; /.well-known/apple-app-site-
  association und assetlinks.json; Smart-App-Banner, Store-Hinweis
- Server erkennt die App am User-Agent (kein Aufblitzen von
  „Als App installieren“); Datenschutz-Vorlage um Firebase ergänzt

Web-App in der App: Push über Firebase statt Web-Push, Vorlesen nativ,
Teilen nativ, Zurück-Taste (schließt erst Dialoge), Antippen einer
Benachrichtigung und App-Links öffnen die Seite (nur eigene Adressen).

Getestet mit nachgebauter Capacitor-Brücke und nachgebautem Firebase-Dienst.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-03 07:03:26 +00:00

61 lines
2.5 KiB
JavaScript

/**
* Holt App-Symbol und Benachrichtigungssymbole vom Server (aus Logo und Markenfarbe
* in der Redaktion) und erzeugt daraus alle Größen für iOS und Android.
* npm run assets
* Optional: ASSET_URL=http://localhost:5173 npm run assets (andere Quelle als APP_URL)
*/
import fs from 'node:fs';
import path from 'node:path';
import { execFileSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import sharp from 'sharp';
import { loadEnv } from '../env.mjs';
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const env = loadEnv();
const base = (process.env.ASSET_URL || env.appUrl).replace(/\/+$/, '');
async function download(url) {
const res = await fetch(url);
if (!res.ok) throw new Error(`${url} → ${res.status}. Läuft die Web-App unter dieser Adresse?`);
return Buffer.from(await res.arrayBuffer());
}
// 1) Symbol in voller Größe (randlos, für App-Symbol und Startbildschirm)
fs.mkdirSync(path.join(root, 'assets'), { recursive: true });
const icon = await download(`${base}/app-icon/1024?maskable`);
fs.writeFileSync(path.join(root, 'assets', 'logo.png'), icon);
// Hintergrundfarbe aus der Ecke des Symbols lesen (Markenfarbe oder Weiß bei hochgeladenem Logo)
const { data } = await sharp(icon).extract({ left: 2, top: 2, width: 1, height: 1 }).raw().toBuffer({ resolveWithObject: true });
const bg = `#${[data[0], data[1], data[2]].map((v) => v.toString(16).padStart(2, '0')).join('')}`;
console.log(`Hintergrundfarbe: ${bg}`);
// 2) Android-Benachrichtigungssymbol (weiß auf transparent) in allen Dichten
const densities = { mdpi: 24, hdpi: 36, xhdpi: 48, xxhdpi: 72, xxxhdpi: 96 };
if (fs.existsSync(path.join(root, 'android'))) {
for (const [density, size] of Object.entries(densities)) {
const dir = path.join(root, 'android', 'app', 'src', 'main', 'res', `drawable-${density}`);
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(path.join(dir, 'ic_stat_notify.png'), await download(`${base}/app-icon/${size}?notification`));
}
console.log('✔ Android-Benachrichtigungssymbol');
}
// 3) Alle Symbole und Startbildschirme erzeugen
execFileSync(
'npx',
[
'capacitor-assets',
'generate',
'--ios',
'--android',
'--iconBackgroundColor', bg,
'--iconBackgroundColorDark', bg,
'--splashBackgroundColor', env.brandColor,
'--splashBackgroundColorDark', env.brandColor,
'--logoSplashScale', '0.25'
],
{ cwd: root, stdio: 'inherit' }
);
console.log('✔ Symbole und Startbildschirme erzeugt. Danach `npm run sync`.');