Skip to content

Commit 91ac745

Browse files
committed
fix(ci): target the requested simulator window
1 parent 27b3bdc commit 91ac745

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

‎scripts/mobile-showcase.ts‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export interface ShowcaseCapture {
8787
}
8888

8989
interface IosCaptureCleanup {
90+
readonly name: string;
9091
readonly udid: string;
9192
readonly startedByRunner: boolean;
9293
readonly createdByRunner: boolean;
@@ -778,17 +779,34 @@ async function normalizeIosSimulator(appearance: ShowcaseAppearance, udid: strin
778779

779780
async function setIosSimulatorOrientation(
780781
orientation: NonNullable<ShowcaseIosDevice["orientation"]>,
781-
udid: string,
782+
simulator: Pick<SimctlDevice, "name" | "udid">,
782783
): Promise<void> {
783-
await runCommand("open", ["-a", "Simulator", "--args", "-CurrentDeviceUDID", udid]);
784+
await runCommand("open", ["-a", "Simulator", "--args", "-CurrentDeviceUDID", simulator.udid]);
784785
const menuItem = orientation === "landscape" ? "Landscape Right" : "Portrait";
785786
await runCommand("osascript", [
787+
"-e",
788+
"on run argv",
789+
"-e",
790+
"set simulatorName to item 1 of argv",
786791
"-e",
787792
'tell application "Simulator" to activate',
788793
"-e",
789-
`tell application "System Events" to tell process "Simulator" to click menu item "${menuItem}" of menu "Orientation" of menu item "Orientation" of menu "Device" of menu bar item "Device" of menu bar 1`,
794+
'tell application "System Events" to tell process "Simulator"',
795+
"-e",
796+
'set simulatorWindows to menu items of menu "Window" of menu bar item "Window" of menu bar 1 whose name starts with simulatorName',
797+
"-e",
798+
'if (count of simulatorWindows) is not 1 then error "Expected exactly one Simulator window for " & simulatorName',
799+
"-e",
800+
"click item 1 of simulatorWindows",
801+
"-e",
802+
`click menu item "${menuItem}" of menu "Orientation" of menu item "Orientation" of menu "Device" of menu bar item "Device" of menu bar 1`,
803+
"-e",
804+
"end tell",
790805
"-e",
791806
"delay 1",
807+
"-e",
808+
"end run",
809+
simulator.name,
792810
]);
793811
}
794812

@@ -829,6 +847,7 @@ async function captureIos(
829847
const { simulator, createdByRunner } = await ensureIosSimulator(capture.device);
830848
const startedByRunner = simulator.state !== "Booted";
831849
registerCleanup({
850+
name: simulator.name,
832851
udid: simulator.udid,
833852
startedByRunner,
834853
createdByRunner,
@@ -893,7 +912,7 @@ async function captureIos(
893912
firstScene,
894913
]);
895914
if (capture.device.orientation === "landscape") {
896-
await setIosSimulatorOrientation("landscape", simulator.udid);
915+
await setIosSimulatorOrientation("landscape", simulator);
897916
}
898917
};
899918
await NodeFSP.rm(readyPath, { force: true });
@@ -1344,7 +1363,7 @@ async function main(): Promise<void> {
13441363
}
13451364
for (const cleanup of iosCleanups) {
13461365
if (cleanup.restorePortrait) {
1347-
await setIosSimulatorOrientation("portrait", cleanup.udid).catch(() => undefined);
1366+
await setIosSimulatorOrientation("portrait", cleanup).catch(() => undefined);
13481367
}
13491368
if (cleanup.startedByRunner || cleanup.createdByRunner) {
13501369
await runCommand("xcrun", ["simctl", "shutdown", cleanup.udid]).catch(() => undefined);

0 commit comments

Comments
 (0)