Skip to content

Commit 839219f

Browse files
authored
feat: simplify iOS metro URL passing (#1829)
Simplifies how the Metro server URL is passed to the application. We make use of a mechanism of `simctl` where extra arguments for the `launch` command are passed to the application as `UserDefaults` entries, which is how `react-native` gets the JS bundle URL. ### How Has This Been Tested: - open react-native-(75-83) apps in Radon on iOS simulator - if the app was previously installed, use the "Reinstall App" reload option to clear the existing `UserDefaults` entries created by Radon before this change - verify the app loads and connects to Metro - [BONUS POINTS] -- you can check that the option is not persistent by opening the App Switcher, killing the app and restarting it from Springboard -- the Application should fail to fetch the bundle now ### How Has This Change Been Documented: INTERNAL
1 parent f97af3d commit 839219f

File tree

1 file changed

+6
-88
lines changed

1 file changed

+6
-88
lines changed

packages/vscode-extension/src/devices/IosSimulatorDevice.ts

Lines changed: 6 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -317,92 +317,6 @@ export class IosSimulatorDevice extends DeviceBase {
317317
return true;
318318
}
319319

320-
async configureMetroPort(bundleID: string, metroPort: number) {
321-
const deviceSetLocation = getOrCreateDeviceSet(this.deviceUDID);
322-
const { stdout: appDataLocation } = await exec("xcrun", [
323-
"simctl",
324-
"--set",
325-
deviceSetLocation,
326-
"get_app_container",
327-
this.deviceUDID,
328-
bundleID,
329-
"data",
330-
]);
331-
const userDefaultsLocation = path.join(
332-
appDataLocation,
333-
"Library",
334-
"Preferences",
335-
`${bundleID}.plist`
336-
);
337-
Logger.debug(`Defaults location ${userDefaultsLocation}`);
338-
await exec(
339-
"/usr/libexec/PlistBuddy",
340-
[
341-
"-c",
342-
"Delete :RCT_jsLocation",
343-
"-c",
344-
`Add :RCT_jsLocation string localhost:${metroPort}`,
345-
userDefaultsLocation,
346-
],
347-
{ allowNonZeroExit: true, reject: false }
348-
);
349-
350-
// Simulator may keep the defaults in memory with cfprefsd, we restart the daemon to make sure
351-
// it reads the latest values from disk.
352-
// We'd normally try to use defaults command that would write the updates via the daemon, however
353-
// for some reason that doesn't work with custom device sets.
354-
await exec(
355-
"xcrun",
356-
[
357-
"simctl",
358-
"--set",
359-
deviceSetLocation,
360-
"spawn",
361-
this.deviceUDID,
362-
"launchctl",
363-
"stop",
364-
"com.apple.cfprefsd.xpc.daemon",
365-
],
366-
{ reject: false }
367-
);
368-
369-
// Restarting cfprefsd breaks the SpringBoard process which in particular controls things like
370-
// the appearance settings. We need to restart it following the cfprefsd reset.
371-
await exec(
372-
"xcrun",
373-
[
374-
"simctl",
375-
"--set",
376-
deviceSetLocation,
377-
"spawn",
378-
this.deviceUDID,
379-
"launchctl",
380-
"kickstart",
381-
"-k",
382-
"system/com.apple.SpringBoard",
383-
],
384-
{ reject: false }
385-
);
386-
387-
// Restarting SpringBoard process breaks the backboardd which in particular controls things like
388-
// the rotation settings. We need to restart it following the cfprefsd springboard reset.
389-
await exec(
390-
"xcrun",
391-
[
392-
"simctl",
393-
"--set",
394-
deviceSetLocation,
395-
"spawn",
396-
this.deviceUDID,
397-
"launchctl",
398-
"kickstart",
399-
"-k",
400-
"system/com.apple.backboardd",
401-
],
402-
{ reject: false }
403-
);
404-
}
405-
406320
async terminateApp(bundleID: string) {
407321
const deviceSetLocation = getOrCreateDeviceSet(this.deviceUDID);
408322

@@ -551,8 +465,12 @@ export class IosSimulatorDevice extends DeviceBase {
551465
}
552466
} else {
553467
Logger.info("Launching app using bundle ID without deeplink");
554-
await this.configureMetroPort(build.bundleID, metroPort);
555-
await this.launchWithBuild(build, launchArguments);
468+
const launchArgsWithJsLocation = [
469+
...launchArguments,
470+
"-RCT_jsLocation",
471+
`localhost:${metroPort}`,
472+
];
473+
await this.launchWithBuild(build, launchArgsWithJsLocation);
556474
}
557475
}
558476

0 commit comments

Comments
 (0)