name: flight-radar
base: core22
adopt-info: app
title: Flight Radar
summary: Real-time US flight tracker with FAA radar center aesthetic
description: |
  Flight Radar is an Electron app that renders OpenSky Network aircraft data and weather in
  a 3D display.
license: MIT
contact: https://github.com/birge/flight-radar/issues
source-code: https://github.com/birge/flight-radar
issues: https://github.com/birge/flight-radar/issues
website: https://flightradar3d.birgefuller.com
grade: stable
confinement: strict

apps:
  flight-radar:
    command: app/node_modules/electron/dist/electron --no-sandbox $SNAP/app
    desktop: snap/gui/flight-radar.desktop
    extensions: [gnome]
    environment:
      ELECTRON_DISABLE_SANDBOX: "true"
      DISABLE_WAYLAND: "1"
    plugs:
      - audio-playback
      - desktop
      - desktop-legacy
      - home
      - network
      - network-bind
      - opengl
      - wayland
      - x11
      - browser-support

parts:
  app:
    plugin: nil
    source: .
    build-snaps:
      - node/22/stable
    build-packages:
      - python3
      - make
      - g++
    override-build: |
      set -eu
      craftctl set version="$(node -p "require('./package.json').version")"

      # Install all deps (postinstall copies Cesium + fonts)
      npm ci --include=dev

      # Build with electron-vite → out/
      npx electron-vite build

      # Obfuscate built JS
      node scripts/obfuscate-snap.js out

      # Assemble the snap payload
      DEST="$CRAFT_PART_INSTALL/app"
      mkdir -p "$DEST"

      # Built output (main, preload, renderer + static assets)
      cp -a out "$DEST/"

      # package.json + lock file (electron reads "main" field; lock ensures reproducible installs)
      cp package.json "$DEST/"
      cp package-lock.json "$DEST/"

      # App icons
      cp -a assets "$DEST/"

      # Install runtime deps + electron into dest
      cd "$DEST"
      ELECTRON_VERSION="$(node -p "require('$CRAFT_PART_BUILD/node_modules/electron/package.json').version")"
      node -e "
        const fs = require('fs');
        const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
        pkg.dependencies = { ...pkg.dependencies, electron: '$ELECTRON_VERSION' };
        delete pkg.devDependencies;
        delete pkg.scripts;
        delete pkg.build;
        fs.writeFileSync('_snap_pkg.json', JSON.stringify(pkg, null, 2));
      "
      mv _snap_pkg.json package.json.tmp
      mv package.json package.json.real
      mv package.json.tmp package.json
      npm install --production
      mv package.json.real package.json
