#!/bin/bash set -euo pipefail cd "$(dirname "$0")/.." usage() { printf '%s\n' \ 'Usage: Scripts/capture-media.sh --record --appearance light|dark [--scene SCENE]' \ ' Scripts/capture-media.sh --check | --list | --help' \ 'Scenes: all, icon, hero, layouts, stacks, snap-undo, shortcuts, accessibility, tour.' \ 'Light all: hero, layouts, stacks, shortcuts, tour. Dark all: hero, snap-undo, shortcuts.' \ 'Outputs go to docs/media. Existing captures are never overwritten.' \ 'Use an empty 2× desktop with default wallpaper; the full fixture display is captured.' \ 'Quit Parcel first. Grant build/Parcel.app Accessibility and the capture host Screen Recording.' \ 'ffmpeg is required for export. UI scenes ask you to prepare the menu, settings, or tour.' \ 'No build, launch, or capture occurs with --help or --list; --check never launches apps.' } mode=${1:-} case "$mode" in --help|-h) [[ $# == 1 ]] || { usage >&2; exit 2; }; usage; exit 0 ;; --list) [[ $# == 1 ]] || { usage >&2; exit 2; } printf '%s\n' icon hero layouts stacks snap-undo shortcuts accessibility tour exit 0 ;; --check|--record) shift ;; *) usage >&2; exit 2 ;; esac appearance= scene=all while (( $# > 0 )); do case "$1" in --appearance) (( $# >= 2 )) || { usage >&2; exit 2; }; appearance=$2; shift 2 ;; --scene) (( $# >= 2 )) || { usage >&2; exit 2; }; scene=$2; shift 2 ;; *) usage >&2; exit 2 ;; esac done if [[ $mode == --check && ( -n $appearance || $scene != all ) ]]; then usage >&2 exit 2 fi if [[ $mode == --record ]]; then [[ $appearance == light || $appearance == dark ]] || { usage >&2; exit 2; } case "$scene" in all|icon|hero|layouts|stacks|snap-undo|shortcuts|accessibility|tour) ;; *) usage >&2; exit 2 ;; esac if [[ $appearance == dark && ( $scene == layouts || $scene == stacks || $scene == tour ) ]] || [[ $appearance == light && $scene == snap-undo ]]; then printf 'That scene uses the other appearance. See --help.\n' >&2 exit 2 fi [[ ${PARCEL_E2E_PREFLIGHT_ONLY:-0} != 1 ]] || { printf 'Unset PARCEL_E2E_PREFLIGHT_ONLY to record media.\n' >&2; exit 2; } scenes=("$scene") if [[ $scene == all ]]; then if [[ $appearance == light ]]; then scenes=(hero layouts stacks shortcuts tour); else scenes=(hero snap-undo shortcuts); fi fi outputs=() for selected in "${scenes[@]}"; do case "$selected" in icon) outputs+=(icon-readme.png) ;; hero) outputs+=("hero-$appearance.png") ;; layouts|stacks|snap-undo) outputs+=("$selected.gif" "$selected-reduced.png") ;; shortcuts) outputs+=("settings-shortcuts-$appearance.png") ;; accessibility) outputs+=(settings-accessibility.png) ;; tour) outputs+=(tour.png) ;; esac done for output in "${outputs[@]}"; do if [[ -e docs/media/$output || -L docs/media/$output ]]; then printf 'Move the existing capture aside first: docs/media/%s\n' "$output" >&2 exit 1 fi done if [[ ! -t 0 ]]; then printf 'Recording requires an interactive terminal.\n' >&2 exit 2 fi ffmpeg=$(command -v ffmpeg) || { printf 'Install ffmpeg before recording.\n' >&2; exit 1; } fi mkdir -p build work=$(mktemp -d "$PWD/build/media-driver.XXXXXX") trap 'rm -rf "$work"' EXIT cp Scripts/MediaCapture/Package.swift "$work/Package.swift" ln -s "$PWD/Sources/ParcelCore" "$work/Core" ln -s "$PWD/Tests/ParcelTestSupport" "$work/TestSupport" mkdir "$work/Tests" cp Scripts/MediaCapture/Scenes.swift "$work/Tests/Scenes.swift" cp Tests/ParcelE2ETests/ParcelE2ETests.swift "$work/Tests/" if [[ $mode == --check ]]; then PARCEL_E2E=0 PARCEL_CAPTURE_MEDIA=0 mise exec -- swift test --package-path "$work" exit 0 fi mise run app mise exec -- Scripts/swift-build.sh --quiet --product FixtureApp bin_dir=$(mise exec -- swift build --show-bin-path) PARCEL_E2E=1 PARCEL_CAPTURE_MEDIA=1 \ PARCEL_APP_PATH="$PWD/build/Parcel.app" \ PARCEL_FIXTURE_PATH="$bin_dir/FixtureApp" \ PARCEL_MEDIA_APPEARANCE="$appearance" PARCEL_MEDIA_SCENE="$scene" \ PARCEL_MEDIA_OUTPUT="$PWD/docs/media" PARCEL_MEDIA_FFMPEG="$ffmpeg" \ PARCEL_MEDIA_ICON="$PWD/Resources/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png" \ mise exec -- swift test --package-path "$work" --filter 'RealAppEndToEndTestsPreflight|captureRequestedScenes' printf 'Review every capture for private content before committing it.\n'