Files
cindy/apps/mobile/scripts/sim-open.mjs
Dash 200bf3e64c feat(mobile): 模拟器脚本默认优先 Cindy 模拟器,没有再用系统模拟器
mobile:sim:whoami / rebuild / open 不再固定系统(Xcode)设备目录:默认先找 Cindy
模拟器(官方 Baguette 插件的独立设备目录)中已启动的设备,未安装、插件关闭运行或
没有已启动设备时用系统模拟器;--udid 跟随设备所在目录。个人选择放在仓库外的
CINDY_MOBILE_SIMULATOR=auto|cindy|system|<设备目录绝对路径>。

非系统目录的设备用通用目标编译、simctl --set 安装启动;它们没有外部窗口,open 拒绝、
whoami --viewer 报不可用。

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
2026-10-19 16:43:08 +13:00

45 lines
1.7 KiB
JavaScript

#!/usr/bin/env node
import { execFileSync } from "node:child_process";
import {
extractSimWhoamiUdidArgs,
resolveSimulatorDeviceSets,
selectBootedSimulator,
simctlArgs,
} from "./lib/sim-whoami.mjs";
import { openSimulatorViewer } from "./lib/simulator-viewer.mjs";
try {
const args = process.argv.slice(2).filter((arg) => arg !== "--");
const { simulatorUdid, passthrough } = extractSimWhoamiUdidArgs(args);
if (passthrough.length)
throw new Error(`Unsupported arguments: ${passthrough.join(" ")}`);
// Do not boot an arbitrary default device or change the user's current target.
const { deviceSet, targetBooted } = selectBootedSimulator(
resolveSimulatorDeviceSets(),
(set) =>
execFileSync("xcrun", simctlArgs(set, ["list", "devices", "booted"]), {
encoding: "utf8",
timeout: 10000,
}),
simulatorUdid,
);
if (targetBooted.length !== 1)
throw new Error(
"Select one booted simulator with --udid; no device was changed.",
);
// Device Hub only shows the system device set; Cindy's simulator has its own sidebar viewer.
if (deviceSet.path)
throw new Error(
`The booted device belongs to the ${deviceSet.name} simulator; open it in Cindy's sidebar instead of an external window.`,
);
const udid = targetBooted[0].match(/\(([0-9A-F-]{36})\)/i)[1].toUpperCase();
const viewer = await openSimulatorViewer(udid);
console.log(JSON.stringify({ ...viewer, udid, launchRequested: true }));
console.log(
"Viewer process is running. Verify the device window and fresh App bundle separately.",
);
} catch (error) {
console.error(`Simulator viewer launch failed: ${error.message}`);
process.exitCode = 1;
}