Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use devicectl for iOS 17 if Xcode 15 is available #341

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 51 additions & 16 deletions src/ios/utils/device.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { spawn } from 'child_process';
import * as Debug from 'debug';
import { readFileSync } from 'fs';
import * as path from 'path';
Expand All @@ -13,7 +14,7 @@ import {
UsbmuxdClient,
} from '../lib';

import { getDeveloperDiskImagePath } from './xcode';
import { getDeveloperDiskImagePath, getXcodeVersionInfo } from './xcode';

const debug = Debug('native-run:ios:utils:device');

Expand Down Expand Up @@ -56,21 +57,55 @@ export async function runOnDevice(
const { [bundleId]: appInfo } = await installer.lookupApp([bundleId]);
// launch fails with EBusy or ENotFound if you try to launch immediately after install
await wait(200);
const debugServerClient = await launchApp(clientManager, appInfo);
if (waitForApp) {
onBeforeExit(async () => {
// causes continue() to return
debugServerClient.halt();
// give continue() time to return response
await wait(64);
});

debug(`Waiting for app to close...\n`);
const result = await debugServerClient.continue();
// TODO: I have no idea what this packet means yet (successful close?)
// if not a close (ie, most likely due to halt from onBeforeExit), then kill the app
if (result !== 'W00') {
await debugServerClient.kill();
try {
const debugServerClient = await launchApp(clientManager, appInfo);
if (waitForApp) {
onBeforeExit(async () => {
// causes continue() to return
debugServerClient.halt();
// give continue() time to return response
await wait(64);
});

debug(`Waiting for app to close...\n`);
const result = await debugServerClient.continue();
// TODO: I have no idea what this packet means yet (successful close?)
// if not a close (ie, most likely due to halt from onBeforeExit), then kill the app
if (result !== 'W00') {
await debugServerClient.kill();
}
}
} catch {
// if launching app throws, try with devicectl, but requires Xcode 15
const [xcodeVersion] = getXcodeVersionInfo();
if (Number(xcodeVersion) >= 15) {
const launchResult = spawn('xcrun', [
'devicectl',
'device',
'process',
'launch',
'--device',
udid,
bundleId,
]);
return new Promise<void>((resolve, reject) => {
launchResult.on('close', code => {
if (code === 0) {
resolve();
} else {
reject(
new Exception(`There was an error launching app on device`),
);
}
});
launchResult.on('error', err => {
reject(err);
});
});
} else {
throw new Exception(
`running on iOS 17 devices requires Xcode 15 and later`,
);
}
}
} finally {
Expand Down