Shots capture: iOS Simulator, Android emulator / device and folder sources

simctl / adb / ffmpeg argv builders in devices.ts; capture.ts runs them with
per-shot progress, --dry, clear errors when xcrun / adb / ffmpeg are missing,
status bar restore, and shuts down only a simulator it booted (--keep-booted).
This commit is contained in:
CRTkafa 2026-10-10 13:28:39 +00:00
parent bd89eb748a
commit 81f0632ca2
2 changed files with 122 additions and 58 deletions

View file

@ -43,6 +43,23 @@ export function validateCapture(c: ShotsCapture | undefined): string[] {
return e;
}
/** Install hints for the external tools each source needs (shown when the tool is not on PATH). */
export const TOOL_HINTS: Record<string, string> = {
xcrun: 'xcrun not found: the iOS Simulator needs macOS with Xcode (App Store) and its command line tools (xcode-select --install)',
adb: 'adb not found: install the Android SDK platform-tools (Android Studio > SDK Manager) and set ANDROID_HOME, or put adb on PATH',
ffmpeg: 'ffmpeg not found: install it (brew install ffmpeg, apt install ffmpeg, winget install ffmpeg); it crops the status bar off the screenshots',
};
/** Simulator name / UDID for a device class: ios.devices.<device>, phone falls back to ios.device. */
export function simTarget(ios: NonNullable<ShotsCapture['ios']>, device: 'phone' | 'tablet'): string | undefined {
return device === 'tablet' ? ios.devices?.tablet : ios.devices?.phone ?? ios.device;
}
/** adb serial for a device class: android.serials.<device>, phone falls back to android.serial (undefined = the only device). */
export function adbTarget(and: NonNullable<ShotsCapture['android']>, device: 'phone' | 'tablet'): string | undefined {
return device === 'tablet' ? and.serials?.tablet : and.serials?.phone ?? and.serial;
}
/** Which shots run on which device class. */
export function shotsFor(c: ShotsCapture, device: 'phone' | 'tablet', only: string[] = []): [string, ShotSpec][] {
return Object.entries(c.shots ?? {}).filter(([name, s]) => (!only.length || only.includes(name)) && ((s.device ?? 'phone') === 'both' || (s.device ?? 'phone') === device));
@ -80,6 +97,11 @@ export function simLaunchArgs(udid: string, bundleId: string, o: { lang: string;
}
export const simOpenUrlArgs = (udid: string, url: string): string[] => ['simctl', 'openurl', udid, url];
export const simBootArgs = (udid: string): string[] => ['simctl', 'boot', udid];
export const simBootStatusArgs = (udid: string): string[] => ['simctl', 'bootstatus', udid, '-b'];
export const simShutdownArgs = (udid: string): string[] => ['simctl', 'shutdown', udid];
export const simStatusBarClearArgs = (udid: string): string[] => ['simctl', 'status_bar', udid, 'clear'];
export const simInstallArgs = (udid: string, app: string): string[] => ['simctl', 'install', udid, app];
export const simScreenshotArgs = (udid: string, out: string): string[] => ['simctl', 'io', udid, 'screenshot', '--type=png', '--mask=ignored', out];
export const simRecordArgs = (udid: string, out: string): string[] => ['simctl', 'io', udid, 'recordVideo', '--codec=h264', '--mask=ignored', '--force', out];
@ -112,6 +134,8 @@ export const androidLocale = (l: string): string => l.replace('_', '-');
* game from a launch extra instead (see `extras` with "{lang}"). */
export const adbAppLocaleArgs = (pkg: string, lang: string, serial?: string): string[] => adb(serial, 'shell', 'cmd', 'locale', 'set-app-locales', pkg, '--locales', androidLocale(lang));
export const adbStateArgs = (serial?: string): string[] => adb(serial, 'get-state');
export const adbInstallArgs = (apk: string, serial?: string): string[] => adb(serial, 'install', '-r', apk);
export const adbForceStopArgs = (pkg: string, serial?: string): string[] => adb(serial, 'shell', 'am', 'force-stop', pkg);
/** `am start` for one shot: a deep link (VIEW intent to the package) or the launch activity, plus typed extras. */