@expo/serve-sim 0.1.52 → 0.1.54
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/README.md +74 -3
- package/dist/middleware.js +56 -55
- package/dist/native/serve-sim-native.node +0 -0
- package/dist/serve-sim.js +74 -73
- package/dist/state.js +1 -1
- package/package.json +5 -2
- package/src/ax.ts +12 -0
- package/src/native.ts +10 -0
- package/src/state.ts +13 -1
package/dist/state.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{tmpdir as
|
|
1
|
+
import{tmpdir as Q}from"os";import{join as H}from"path";import{readdirSync as U,mkdirSync as V,writeFileSync as W,renameSync as X,readFileSync as Y,unlinkSync as Z}from"fs";var G=H(Q(),"serve-sim"),k=H(G,"server.json");function O(q){return H(G,`server-${q}.json`)}function x(q,z,B="/",C="127.0.0.1",K){let J=C==="0.0.0.0"||C==="::"?"127.0.0.1":C,M=B.replace(/^\/+/,"").replace(/\/+$/,""),N=M===""?"":`/${M}`;return{pid:process.pid,port:z,device:q,url:`http://${J}:${z}`,streamUrl:`http://${J}:${z}${N}/helper/${q}/stream.mjpeg`,wsUrl:`ws://${J}:${z}${N}/helper/${q}/ws`,...K?{streamSettings:K}:{}}}function P(q){V(G,{recursive:!0});let z=O(q.device),B=`${z}.${process.pid}.tmp`;W(B,JSON.stringify(q,null,2),{mode:384}),X(B,z)}function v(q,z){let B=O(q),C;try{C=JSON.parse(Y(B,"utf-8"))}catch{return}if(C.pid!==z)return;try{Z(B)}catch{}}function w(){try{return U(G).filter((q)=>q.startsWith("server-")&&q.endsWith(".json")).map((q)=>H(G,q))}catch{return[]}}export{P as writeServeSimState,O as stateFileForDevice,w as listStateFiles,x as inProcessServeSimState,v as clearServeSimState,k as STATE_FILE,G as STATE_DIR};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/serve-sim",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.54",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Evan Bacon",
|
|
@@ -73,7 +73,10 @@
|
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
75
|
"build": "bun run build.ts",
|
|
76
|
-
"dev": "bun run dev.ts"
|
|
76
|
+
"dev": "bun run dev.ts",
|
|
77
|
+
"tart": "bun scripts/tart/cli.ts",
|
|
78
|
+
"tart-test": "bun scripts/tart/cli.ts test",
|
|
79
|
+
"tart-dev": "bun scripts/tart/cli.ts dev"
|
|
77
80
|
},
|
|
78
81
|
"devDependencies": {
|
|
79
82
|
"@types/bun": "latest",
|
package/src/ax.ts
CHANGED
|
@@ -79,6 +79,18 @@ function normalizeAxTree(roots: RawAxeNode[]): AxSnapshot {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
const SOFTWARE_KEYBOARD_KEY_IDS = ["delete", "shift", "space", "more", "dictation"];
|
|
83
|
+
|
|
84
|
+
export async function isSoftwareKeyboardVisible(udid: string): Promise<boolean> {
|
|
85
|
+
const snapshot = await snapshotFromNative(udid);
|
|
86
|
+
if (snapshot.errors?.length) return false;
|
|
87
|
+
const keys = new Set<string>();
|
|
88
|
+
for (const el of snapshot.elements) {
|
|
89
|
+
if (SOFTWARE_KEYBOARD_KEY_IDS.includes(el.id)) keys.add(el.id);
|
|
90
|
+
}
|
|
91
|
+
return keys.size >= 2;
|
|
92
|
+
}
|
|
93
|
+
|
|
82
94
|
async function snapshotFromNative(udid: string): Promise<AxSnapshot> {
|
|
83
95
|
let raw: RawAxeNode[];
|
|
84
96
|
try {
|
package/src/native.ts
CHANGED
|
@@ -66,6 +66,7 @@ interface NativeAddon {
|
|
|
66
66
|
) => SimCaptureHandle;
|
|
67
67
|
axDescribe(udid: string): Promise<string>;
|
|
68
68
|
axFrontmost(udid: string): Promise<string>;
|
|
69
|
+
setHardwareKeyboard(udid: string, enabled: boolean): Promise<boolean>;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
// (codec, data, width, height, flags) — codec 0=MJPEG 1=AVCC; flags bit0=desc bit1=keyframe.
|
|
@@ -303,3 +304,12 @@ export function axDescribeAsync(udid: string): Promise<string> {
|
|
|
303
304
|
export function axFrontmostAsync(udid: string): Promise<string> {
|
|
304
305
|
return load().axFrontmost(udid);
|
|
305
306
|
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Connect/disconnect the device's hardware keyboard (⌘⇧K). Disconnecting makes
|
|
310
|
+
* the guest show its on-screen keyboard. Per-device; resolves true when the
|
|
311
|
+
* CoreSimulator call succeeds (not a read-back of the resulting state).
|
|
312
|
+
*/
|
|
313
|
+
export function setHardwareKeyboard(udid: string, enabled: boolean): Promise<boolean> {
|
|
314
|
+
return load().setHardwareKeyboard(udid, enabled);
|
|
315
|
+
}
|
package/src/state.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { tmpdir } from "os";
|
|
2
2
|
import { join } from "path";
|
|
3
|
-
import { readdirSync, mkdirSync, writeFileSync, renameSync } from "fs";
|
|
3
|
+
import { readdirSync, mkdirSync, writeFileSync, renameSync, readFileSync, unlinkSync } from "fs";
|
|
4
4
|
import type { StreamSettings } from "./stream-settings";
|
|
5
5
|
export type {
|
|
6
6
|
HttpStreamCodec,
|
|
@@ -74,6 +74,18 @@ export function writeServeSimState(state: ServeSimDeviceState): void {
|
|
|
74
74
|
renameSync(tmp, file);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
export function clearServeSimState(udid: string, ownerPid: number): void {
|
|
78
|
+
const file = stateFileForDevice(udid);
|
|
79
|
+
let state: ServeSimDeviceState;
|
|
80
|
+
try {
|
|
81
|
+
state = JSON.parse(readFileSync(file, "utf-8")) as ServeSimDeviceState;
|
|
82
|
+
} catch {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (state.pid !== ownerPid) return;
|
|
86
|
+
try { unlinkSync(file); } catch {}
|
|
87
|
+
}
|
|
88
|
+
|
|
77
89
|
/** List all per-device state files in the state directory. */
|
|
78
90
|
export function listStateFiles(): string[] {
|
|
79
91
|
try {
|