Files
TREK/client/ios/scripts/watch-screens.sh
T
Maurice e59af6dcb3 feat(native): TREK on Apple Watch, with complications
A watchOS app embedded in the iPhone app: today's next stop with its
countdown, the next booking with reference, seat and platform, the trip
with its days and places (Directions into Apple Maps), and the packing
list and to-dos to tick off. The phone sends the snapshot through
WatchConnectivity; ticks go back as queued user info. Three
complications (next stop, countdown, trip day) in every accessory family,
scored for the Smart Stack. 28 languages.

The native workflow captures every screen from watchOS simulators in a
screenshot mode, on the largest and the smallest watch.
2026-11-07 17:14:09 +01:00

83 lines
3.1 KiB
Bash

#!/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 in English and German on the largest and the smallest watch,
# 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 <TREKWatch.app> <output directory>
set -euo pipefail
APP="$1"
OUT="$2"
BUNDLE=com.liketrek.trek.watchkitapp
mkdir -p "$OUT"
RUNTIME=$(xcrun simctl list runtimes -j | python3 -c '
import json, sys
runtimes = [r for r in json.load(sys.stdin)["runtimes"] if r["platform"] == "watchOS" and r["isAvailable"]]
print(sorted(runtimes, key=lambda r: [int(x) for x in r["version"].split(".")])[-1]["identifier"])')
echo "runtime $RUNTIME"
# The newest Ultra, and the smallest watch the runtime still supports.
read -r LARGE SMALL < <(xcrun simctl list devicetypes -j | python3 -c '
import json, re, sys
names = [t["name"] for t in json.load(sys.stdin)["devicetypes"] if t["name"].startswith("Apple Watch")]
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]
small = sorted([n for n in names if "Ultra" not in n], key=lambda n: (mm(n), -gen(n)))
print(ultra.replace(" ", "_"), small[0].replace(" ", "_"))')
LARGE=${LARGE//_/ }
SMALL=${SMALL//_/ }
echo "large: $LARGE, 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 status_bar "$udid" override --time "13:05" >/dev/null 2>&1 || true
xcrun simctl install "$udid" "$APP"
echo "$udid"
}
# shot <udid> <file> <screen> <language> [extra launch arguments]
shot() {
local udid=$1 file=$2 screen=$3 lang=$4
shift 4
local locale=${lang//-/_}
xcrun simctl launch --terminate-running-process "$udid" "$BUNDLE" \
-AppleLanguages "($lang)" -AppleLocale "$locale" -TrekDemo "$screen" "$@" >/dev/null
case "$screen" in place) sleep 9 ;; *) sleep 4 ;; esac
xcrun simctl io "$udid" screenshot --type=png "$file" >/dev/null 2>&1
}
ALL="today day place booking bookings trip days packing todos lists countdown empty nosync faces"
MAIN="today booking countdown trip lists packing"
LANGS="ar az ca cs de el en es et fr he hu id it ja ko nl pl pt-BR ru sk sv th tr uk vi zh-Hans zh-Hant"
run() {
local size=$1 name=$2 udid
udid=$(boot "$name" | tail -1)
for lang in en de; do
for screen in $ALL; do shot "$udid" "$OUT/$size-$lang-$screen.png" "$screen" "$lang"; done
done
if [ "$size" = small ]; then
for lang in $LANGS; do
[ "$lang" = en ] || [ "$lang" = de ] && continue
for screen in $MAIN; do shot "$udid" "$OUT/$size-$lang-$screen.png" "$screen" "$lang"; done
done
fi
xcrun simctl shutdown "$udid" || true
}
run large "$LARGE" &
run small "$SMALL" &
wait
echo "$LARGE" > "$OUT/devices.txt"
echo "$SMALL" >> "$OUT/devices.txt"
ls "$OUT" | wc -l