Files
telegram-tui/scripts/smoke-ios-simulator-ui.sh
2026-05-20 23:09:20 +03:00

40 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
if [[ -z "${DEVELOPER_DIR:-}" && -d /Applications/Xcode.app/Contents/Developer ]]; then
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
fi
screenshot_path="${IOS_SCREENSHOT_PATH:-/private/tmp/tele-tui-ios-simulator-smoke.png}"
simulator_udid="${IOS_SIMULATOR_UDID:-}"
if [[ -z "${simulator_udid}" ]]; then
simulator_udid="$(xcrun simctl list devices available | awk -F '[()]' '/iPhone/ { print $2; exit }')"
fi
if [[ -z "${simulator_udid}" ]]; then
printf 'No available iPhone simulator found. Run scripts/check-ios-prereqs.sh for details.\n' >&2
exit 1
fi
"${repo_root}/scripts/run-ios-simulator-app.sh"
# Give SwiftUI a short render window after launch returns.
sleep "${IOS_SCREENSHOT_DELAY_SECONDS:-2}"
xcrun simctl io "${simulator_udid}" screenshot "${screenshot_path}"
width="$(sips -g pixelWidth "${screenshot_path}" | awk '/pixelWidth/ { print $2 }')"
height="$(sips -g pixelHeight "${screenshot_path}" | awk '/pixelHeight/ { print $2 }')"
bytes="$(wc -c < "${screenshot_path}" | tr -d ' ')"
if [[ "${width}" -lt 300 || "${height}" -lt 600 || "${bytes}" -lt 10000 ]]; then
printf 'Simulator screenshot failed sanity checks: width=%s height=%s bytes=%s path=%s\n' \
"${width}" "${height}" "${bytes}" "${screenshot_path}" >&2
exit 1
fi
printf 'Simulator UI smoke screenshot: %s (%sx%s, %s bytes)\n' \
"${screenshot_path}" "${width}" "${height}" "${bytes}"