Files
haptika/mobile/scripts/capture-screens.py
T
2026-09-08 09:07:27 +02:00

27 lines
1.5 KiB
Python

"""Capture each implemented mobile frame in its fixed reference state."""
import json, pathlib, subprocess, time, sys
root=pathlib.Path(__file__).resolve().parents[1]
scenes=json.loads((root/'src/design/scenes.json').read_text())
udid='85638E91-52BB-440F-91F9-35604A771A28'
selection=set(json.loads(pathlib.Path(sys.argv[1]).read_text())) if len(sys.argv)>1 else None
frames=[s for s in scenes if s['w']==402 and (selection is None or s['id'] in selection)]
for i,scene in enumerate(frames):
slug=scene['id'].replace(':','-')
log=pathlib.Path('/tmp/haptika-mobile-metro.log')
offset=log.stat().st_size
subprocess.run(['xcrun','simctl','openurl',udid,'haptika-mobile://screen/'+slug+'?preview=1'],check=True,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
deadline=time.time()+12
while time.time()<deadline:
with log.open() as stream:
stream.seek(offset)
ready='HAPTIKA_SCREEN_READY:'+scene['id'] in stream.read()
if ready: break
time.sleep(.15)
if not ready: raise RuntimeError('Frame did not render: '+scene['id'])
time.sleep(.85)
file=root/'qa/screens'/f'{slug}.png'
subprocess.run(['xcrun','simctl','io',udid,'screenshot',str(file)],check=True,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
subprocess.run(['sips','-Z','874',str(file)],check=True,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
if (i+1)%10==0:print(f'{i+1}/{len(frames)} captures',flush=True)
print('Complete',flush=True)