#!/bin/bash # Captures the watch app's screens from watchOS simulators, in screenshot mode # (client/ios/App/TREKWatch/DemoMode.swift), for review and the App Store: # every screen and its states in English, German and Russian on the newest # Ultra, the largest other watch and the smallest one, and the main screens in # every language on the smallest, where text is tightest. # .github/workflows/native.yml runs it after building the app. # # watch-screens.sh set -euo pipefail APP="$1" OUT="$2" BUNDLE=com.liketrek.trek.watchkitapp mkdir -p "$OUT" # The newest watchOS runtime, its newest Ultra, the largest other watch and the # smallest one it still runs on. read -r RUNTIME LARGE MEDIUM SMALL < <(xcrun simctl list runtimes -j | python3 -c ' import json, re, sys runtimes = [r for r in json.load(sys.stdin)["runtimes"] if r["platform"] == "watchOS" and r["isAvailable"]] runtime = sorted(runtimes, key=lambda r: [int(x) for x in r["version"].split(".")])[-1] names = [t["name"] for t in runtime["supportedDeviceTypes"]] def mm(n): m = re.search(r"(\d+)mm", n); return int(m.group(1)) if m else 0 def gen(n): m = re.search(r"(?:Series|Ultra|SE) ?(\d+)?", n); return int(m.group(1) or 1) if m else 0 ultra = sorted([n for n in names if "Ultra" in n], key=gen)[-1] rest = sorted([n for n in names if "Ultra" not in n], key=lambda n: (mm(n), gen(n))) print(runtime["identifier"], *[n.replace(" ", "_") for n in (ultra, rest[-1], rest[0])])') LARGE=${LARGE//_/ } MEDIUM=${MEDIUM//_/ } SMALL=${SMALL//_/ } echo "runtime $RUNTIME; large: $LARGE, medium: $MEDIUM, small: $SMALL" boot() { local udid udid=$(xcrun simctl create "$1" "$1" "$RUNTIME") xcrun simctl boot "$udid" xcrun simctl bootstatus "$udid" -b >/dev/null xcrun simctl install "$udid" "$APP" echo "$udid" } # The watch draws the Mac's clock in its corner, so the Mac goes to a zone in # which it is about one o'clock: the hour the sample trip's screens are made for # (WatchSample.swift), and the clock and the countdowns agree. set_clock() { local offset=$(( (13 - 10#$(date -u +%H) + 36) % 24 - 12 )) local zone if [ "$offset" -ge 0 ]; then zone="Etc/GMT-$offset"; else zone="Etc/GMT+$(( -offset ))"; fi sudo ln -sf "/usr/share/zoneinfo/$zone" /etc/localtime echo "clock: $zone, $(date +%H:%M)" } # Waits for the ready file the app writes once the screen has drawn (DemoMode.signalReady). wait_ready() { local udid=$1 token=$2 container for _ in $(seq 1 40); do container=$(xcrun simctl get_app_container "$udid" "$BUNDLE" data 2>/dev/null || true) [ -n "$container" ] && [ -f "$container/Documents/ready-$token" ] && return 0 sleep 0.25 done return 1 } TOKEN=0 # shot