serve-sim 0.1.21 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/serve-sim-bin +0 -0
- package/dist/middleware.js +19 -19
- package/dist/serve-sim.js +27 -27
- package/package.json +1 -1
- package/src/middleware.ts +25 -11
package/package.json
CHANGED
package/src/middleware.ts
CHANGED
|
@@ -1051,6 +1051,31 @@ export function simMiddleware(options?: SimMiddlewareOptions) {
|
|
|
1051
1051
|
});
|
|
1052
1052
|
res.write(":\n\n");
|
|
1053
1053
|
|
|
1054
|
+
// Bootstrap: SpringBoard's log feed is edge-triggered, so a fresh
|
|
1055
|
+
// subscriber would otherwise see nothing until the user re-foregrounds
|
|
1056
|
+
// an app (the bug: tools couldn't reconnect after a page reload). Ask
|
|
1057
|
+
// the helper's AX bridge for the current frontmost app via
|
|
1058
|
+
// `proc_pidpath`+Info.plist resolution and emit it before tailing.
|
|
1059
|
+
let lastBundle = "";
|
|
1060
|
+
void (async () => {
|
|
1061
|
+
try {
|
|
1062
|
+
const ctrl = new AbortController();
|
|
1063
|
+
const timer = setTimeout(() => ctrl.abort(), 1500);
|
|
1064
|
+
const r = await fetch(`http://127.0.0.1:${state.port}/foreground`, { signal: ctrl.signal });
|
|
1065
|
+
clearTimeout(timer);
|
|
1066
|
+
if (!r.ok) return;
|
|
1067
|
+
const info = await r.json() as { bundleId?: string; pid?: number };
|
|
1068
|
+
if (!info.bundleId || !isUserFacingBundle(info.bundleId)) return;
|
|
1069
|
+
if (res.writableEnded) return;
|
|
1070
|
+
lastBundle = info.bundleId;
|
|
1071
|
+
const isReactNative = await detectReactNative(udid, info.bundleId);
|
|
1072
|
+
if (res.writableEnded) return;
|
|
1073
|
+
res.write("data: " + JSON.stringify({ bundleId: info.bundleId, pid: info.pid, isReactNative }) + "\n\n");
|
|
1074
|
+
} catch {
|
|
1075
|
+
// Helper may be coming up — log tail will fill in once anything moves.
|
|
1076
|
+
}
|
|
1077
|
+
})();
|
|
1078
|
+
|
|
1054
1079
|
const child: ChildProcess = spawn("xcrun", [
|
|
1055
1080
|
"simctl", "spawn", udid, "log", "stream",
|
|
1056
1081
|
"--style", "ndjson",
|
|
@@ -1059,28 +1084,17 @@ export function simMiddleware(options?: SimMiddlewareOptions) {
|
|
|
1059
1084
|
'process == "SpringBoard" AND eventMessage CONTAINS "Setting process visibility to: Foreground"',
|
|
1060
1085
|
], { stdio: ["ignore", "pipe", "ignore"] });
|
|
1061
1086
|
|
|
1062
|
-
let lastBundle = "";
|
|
1063
|
-
let hasEmitted = false;
|
|
1064
1087
|
let closed = false;
|
|
1065
1088
|
const emitApp = async (bundleId: string, pid?: number) => {
|
|
1066
1089
|
if (!isUserFacingBundle(bundleId)) return;
|
|
1067
1090
|
if (bundleId === lastBundle) return;
|
|
1068
1091
|
lastBundle = bundleId;
|
|
1069
|
-
hasEmitted = true;
|
|
1070
1092
|
const isReactNative = await detectReactNative(udid, bundleId);
|
|
1071
1093
|
if (!closed) {
|
|
1072
1094
|
res.write("data: " + JSON.stringify({ bundleId, pid, isReactNative }) + "\n\n");
|
|
1073
1095
|
}
|
|
1074
1096
|
};
|
|
1075
1097
|
|
|
1076
|
-
// The seed loses to any live log event — a SpringBoard log that fires
|
|
1077
|
-
// while the AX call is in flight is fresher than the AX snapshot.
|
|
1078
|
-
detectCurrentForegroundApp(udid, state.url).then((app) => {
|
|
1079
|
-
if (!app || closed || hasEmitted) return;
|
|
1080
|
-
lastBundle = app.bundleId;
|
|
1081
|
-
hasEmitted = true;
|
|
1082
|
-
res.write("data: " + JSON.stringify(app) + "\n\n");
|
|
1083
|
-
});
|
|
1084
1098
|
|
|
1085
1099
|
let buf = "";
|
|
1086
1100
|
child.stdout!.on("data", (chunk: Buffer) => {
|