#!/usr/bin/env node /** * Ensure the correct (stock) MainActivity.java exists in the generated Android * project. * * The AndroidManifest launches org.skatespots.app.MainActivity. If that class is * missing or wrong, the app crashes on launch (black screen). We keep the stock * source of truth in android-templates/MainActivity.java and copy it in on every * build so the launcher class is ALWAYS present and correct — even after * `rm -rf android` or `cap add` regenerate things. * * This version does NOT override the WebViewClient (a previous custom version * did and broke startup). Idempotent. Exits quietly if android/ isn't generated. */ import { readFileSync, writeFileSync, existsSync, mkdirSync, copyFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { dirname, join } from 'node:path'; const root = join(dirname(fileURLToPath(import.meta.url)), '..'); const targetDir = join(root, 'android', 'app', 'src', 'main', 'java', 'org', 'skatespots', 'app'); const templatesDir = join(root, 'android-templates'); // Native Java sources kept as the source of truth in android-templates/ and // copied into the generated project on every build. MainActivity registers the // Amber ActivityResultLauncher; AmberIntentPlugin is the Amethyst-style NIP-55 // foreground signer that opens Amber's Approve/Reject screen and never hangs. const files = ['MainActivity.java', 'AmberIntentPlugin.java']; // If the android/ project hasn't been generated yet, do nothing. if (!existsSync(join(root, 'android', 'app'))) { console.log('[inject-main-activity] android/ not generated yet — skipping.'); process.exit(0); } if (!existsSync(targetDir)) { mkdirSync(targetDir, { recursive: true }); } for (const file of files) { const template = join(templatesDir, file); const target = join(targetDir, file); if (!existsSync(template)) { console.error(`[inject-main-activity] template android-templates/${file} missing — aborting.`); process.exit(1); } const desired = readFileSync(template, 'utf8'); const current = existsSync(target) ? readFileSync(target, 'utf8') : null; if (current === desired) { console.log(`[inject-main-activity] ${file} already correct.`); continue; } copyFileSync(template, target); console.log(`[inject-main-activity] ✓ Ensured ${file} is present (Amber foreground signer + safe launcher).`); }