Skip to content

Commit

Permalink
fix: sleep and make this script more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
siddarthkay committed Feb 16, 2024
1 parent 801d142 commit 4e538e3
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions scripts/run-ios-device.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,31 @@ else
fi

BUILD_DIR="${GIT_ROOT}/build"
XCRUN_LOG_DIR="${GIT_ROOT}/build/XcrunLog"

#iOS build of debug scheme
xcodebuild -workspace "ios/StatusIm.xcworkspace" -configuration Debug -scheme StatusIm -destination id="$DEVICE_UUID" -derivedDataPath "${BUILD_DIR}" | xcbeautify

APP_PATH="${BUILD_DIR}/Build/Products/Debug-iphoneos/StatusIm.app"

# Install on the connected device
DEVICECTL_OUTPUT=$(xcrun devicectl device install app --device "$DEVICE_UUID" "$APP_PATH" 2>&1 | tee >(cat 1>&2))
xcrun devicectl device install app --device "$DEVICE_UUID" "$APP_PATH" --json-output "$XCRUN_LOG_DIR"

# Extract installationURL
INSTALLATION_URL=$(echo "$DEVICECTL_OUTPUT" | grep "installationURL:" | sed -E 's/.*installationURL: (.*)/\1/')
INSTALLATION_URL=$(jq -r '.result.installedApplications[0].installationURL' "$XCRUN_LOG_DIR")

# launch the app and put it in background
xcrun devicectl device process launch --no-activate --verbose --device "$DEVICE_UUID" "$INSTALLATION_URL" --json-output "$XCRUN_LOG_DIR"

# Extract background PID of status app
STATUS_PID=$(jq -r '.result.process.processIdentifier' "$XCRUN_LOG_DIR")

trap cleanupMetro EXIT ERR INT QUIT
runMetro &
waitForMetro

# wait a bit after installation for the iPhone to calm down
sleep 3

# launch the app when metro is ready
xcrun devicectl device process launch --device "$DEVICE_UUID" "$INSTALLATION_URL"
# now that metro is ready, resume the app from background
xcrun devicectl device process resume --device "$DEVICE_UUID" --pid "$STATUS_PID"

# bring metro job to foreground
fg 'runMetro'

0 comments on commit 4e538e3

Please sign in to comment.