serve-sim-sjchmiela 0.1.34
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 +241 -0
- package/Sources/SimAXSettings/build.sh +22 -0
- package/Sources/SimAXSettings/sim-ax-settings.m +273 -0
- package/Sources/SimCameraHelper/build.sh +33 -0
- package/Sources/SimCameraHelper/main.m +942 -0
- package/Sources/SimCameraInjector/SimCamFakes.h +88 -0
- package/Sources/SimCameraInjector/SimCamFakes.m +704 -0
- package/Sources/SimCameraInjector/SimCamFrameSource.h +26 -0
- package/Sources/SimCameraInjector/SimCamFrameSource.m +577 -0
- package/Sources/SimCameraInjector/SimCamLog.h +5 -0
- package/Sources/SimCameraInjector/SimCamLog.m +9 -0
- package/Sources/SimCameraInjector/SimCamSwizzles.h +3 -0
- package/Sources/SimCameraInjector/SimCamSwizzles.m +1338 -0
- package/Sources/SimCameraInjector/SimCameraInjector.m +19 -0
- package/Sources/SimCameraInjector/build.sh +39 -0
- package/Sources/SimCameraInjector/include/SimCamShared.h +79 -0
- package/bin/serve-sim-bin +0 -0
- package/dist/middleware.cjs +2 -0
- package/dist/middleware.js +75 -0
- package/dist/serve-sim.js +176 -0
- package/dist/simax/serve-sim-ax-settings +0 -0
- package/dist/simcam/libSimCameraInjector.dylib +0 -0
- package/dist/simcam/serve-sim-camera-helper +0 -0
- package/package.json +98 -0
- package/src/ax-shared.ts +25 -0
- package/src/ax.ts +294 -0
- package/src/middleware.ts +1437 -0
- package/src/state.ts +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# serve-sim
|
|
2
|
+
|
|
3
|
+
The `npx serve` of Apple Simulators.
|
|
4
|
+
|
|
5
|
+
Host your simulator for use with Agent tools like Codex, Cursor, or Claude Desktop — locally, over your LAN, or host on a remote mac and tunnel anywhere.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npx serve-sim
|
|
9
|
+
# → Preview at http://localhost:3200
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
https://github.com/user-attachments/assets/fbf890f4-c8c7-4684-82be-d677b8a188f8
|
|
13
|
+
|
|
14
|
+
`serve-sim` spawns a small Swift helper that captures the simulator's framebuffer via `simctl io`, exposes it as an MJPEG stream + WebSocket control channel, and serves a React preview UI on top. It works with any booted iOS Simulator — no Xcode plugin, no instrumentation in your app.
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- Full 60 FPS video stream in the browser.
|
|
19
|
+
- Swipe from the bottom to go home.
|
|
20
|
+
- gestures like pinch to zoom by holding the option key.
|
|
21
|
+
- Simulator logs are forwarded to the browser for browser-use MCP tools to read from.
|
|
22
|
+
- Drag and drop videos and images to add them to the simulator device.
|
|
23
|
+
- Keyboard commands and hot keys are forwarded to the simulator, including CMD+SHIFT+H to go home.
|
|
24
|
+
- Apple Watch, iPad, and iOS support.
|
|
25
|
+
|
|
26
|
+
## Why?
|
|
27
|
+
|
|
28
|
+
Hosted simulators can be hard to test, `serve-sim` enables you to test the hosted infra locally first for faster iteration. When you're ready to host a simulator remotely, simply tunnel the served URL and users can interact with the simulator as if it were running locally on their device.
|
|
29
|
+
|
|
30
|
+
I develop the Expo framework, but this tool is completely agnostic to React Native and can be used for any iOS interaction you need.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
Requires macOS with Xcode command line tools (`xcrun simctl`) and Node.js 18+. `bun` is **not** required to run the CLI. Camera injection uses a host-side helper built for macOS 14+.
|
|
35
|
+
|
|
36
|
+
> **Note:** Apple Silicon (arm64) only. The bundled `serve-sim-bin` helper ships as an arm64 binary and does not run on Intel (x86_64) Macs.
|
|
37
|
+
|
|
38
|
+
## CLI
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
serve-sim [device...] Start preview server (default: localhost:3200)
|
|
42
|
+
serve-sim --no-preview [device...] Stream in foreground without a preview server
|
|
43
|
+
serve-sim gesture '<json>' [-d udid] Send a touch gesture
|
|
44
|
+
serve-sim button [name] [-d udid] Send a button press (default: home)
|
|
45
|
+
serve-sim type <text> [-d udid] Type text via the simulator keyboard
|
|
46
|
+
(US keyboard only; also --stdin / --file <path>)
|
|
47
|
+
serve-sim rotate <orientation> [-d udid]
|
|
48
|
+
portrait | portrait_upside_down |
|
|
49
|
+
landscape_left | landscape_right
|
|
50
|
+
serve-sim ca-debug <option> <on|off> [-d udid]
|
|
51
|
+
Toggle a CoreAnimation debug flag
|
|
52
|
+
(blended|copies|misaligned|offscreen|slow-animations)
|
|
53
|
+
serve-sim memory-warning [-d udid] Simulate a memory warning
|
|
54
|
+
|
|
55
|
+
serve-sim camera <bundle-id> [-d udid] [source-options]
|
|
56
|
+
Inject a synthetic camera feed and (re)launch the app
|
|
57
|
+
serve-sim camera switch <placeholder|webcam|file> [arg] [-d udid]
|
|
58
|
+
Hot-swap the running helper's source (no relaunch)
|
|
59
|
+
serve-sim camera mirror <auto|on|off> [-d udid]
|
|
60
|
+
Hot-swap preview-layer mirror mode
|
|
61
|
+
serve-sim camera status [-d udid] Print helper state as JSON ({alive, source, ...})
|
|
62
|
+
serve-sim camera --list-webcams List host camera devices
|
|
63
|
+
serve-sim camera --stop-webcam [-d udid]
|
|
64
|
+
Stop the camera helper for a device
|
|
65
|
+
|
|
66
|
+
Options:
|
|
67
|
+
-p, --port <port> Starting port (preview default: 3200, stream default: 3100)
|
|
68
|
+
-d, --detach Spawn helper and exit (daemon mode)
|
|
69
|
+
-q, --quiet JSON-only output
|
|
70
|
+
--no-preview Skip the web UI; stream in foreground only
|
|
71
|
+
--list [device] List running streams
|
|
72
|
+
--kill [device] Kill running stream(s)
|
|
73
|
+
|
|
74
|
+
Camera options (used with `serve-sim camera <bundle-id>`):
|
|
75
|
+
-f, --file <path> Image or video file (kind auto-detected from
|
|
76
|
+
extension/magic bytes; videos loop at native FPS)
|
|
77
|
+
--webcam [name] Live host webcam (defaults to the built-in
|
|
78
|
+
front camera when [name] is omitted)
|
|
79
|
+
--mirror [on|off|auto] Override preview-layer mirroring (default: auto =
|
|
80
|
+
front mirrored, back not). Data-output buffers
|
|
81
|
+
are never auto-mirrored, matching AVF defaults.
|
|
82
|
+
--no-mirror Shortcut for --mirror off
|
|
83
|
+
--build Rebuild the dylib + helper from source
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Examples
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
serve-sim # auto-detect booted sim, open preview
|
|
90
|
+
serve-sim "iPhone 16 Pro" # target a specific device
|
|
91
|
+
serve-sim --detach # start a background helper, return JSON
|
|
92
|
+
serve-sim --list # show running streams
|
|
93
|
+
serve-sim --kill # stop all helpers
|
|
94
|
+
|
|
95
|
+
# Type text into the focused field
|
|
96
|
+
serve-sim type "Hello, world!"
|
|
97
|
+
echo "from stdin" | serve-sim type --stdin
|
|
98
|
+
serve-sim type --file ./snippet.txt
|
|
99
|
+
|
|
100
|
+
# Camera injection
|
|
101
|
+
serve-sim camera com.acme.MyApp # animated placeholder
|
|
102
|
+
serve-sim camera com.acme.MyApp --webcam # default webcam
|
|
103
|
+
serve-sim camera com.acme.MyApp --webcam "MacBook Pro Camera"
|
|
104
|
+
serve-sim camera com.acme.MyApp --file ~/Pictures/face.png # static image
|
|
105
|
+
serve-sim camera com.acme.MyApp --file ~/Movies/loop.mp4 # looping video
|
|
106
|
+
|
|
107
|
+
# Hot-swap source on a running helper (no app relaunch)
|
|
108
|
+
serve-sim camera switch placeholder
|
|
109
|
+
serve-sim camera switch webcam
|
|
110
|
+
serve-sim camera switch ~/Movies/loop.mp4 # auto-detects file kind
|
|
111
|
+
|
|
112
|
+
# Other helpers
|
|
113
|
+
serve-sim camera mirror on
|
|
114
|
+
serve-sim camera status # JSON: alive, source, mirror
|
|
115
|
+
serve-sim camera --list-webcams
|
|
116
|
+
serve-sim camera --stop-webcam
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Multiple booted simulators are supported — pass several device names, or leave it empty to attach to all of them.
|
|
120
|
+
|
|
121
|
+
### Camera
|
|
122
|
+
|
|
123
|
+
`serve-sim camera <bundle-id>` replaces the simulator's camera feed for a single app. A small host-side helper writes BGRA frames into a POSIX shared-memory region; an injected dylib (`DYLD_INSERT_LIBRARIES`) swizzles AVFoundation inside the simulator process so the app reads from that region instead of the simulator's stub camera.
|
|
124
|
+
|
|
125
|
+
The helper is one-per-device and outlives any single app launch, so multiple apps on the same simulator can share the feed — just run `serve-sim camera <other-bundle-id>` again to relaunch the next app with the dylib attached. Source changes (`camera switch`) and mirror changes (`camera mirror`) flow through the helper's control socket and don't relaunch the app.
|
|
126
|
+
|
|
127
|
+
Sources:
|
|
128
|
+
|
|
129
|
+
- **placeholder** — animated programmatic frames (default).
|
|
130
|
+
- **file** — image (PNG/JPEG/HEIC/…) or video (mp4/mov/m4v/webm/…). The CLI sniffs the kind from the extension and falls back to magic bytes for files without an extension.
|
|
131
|
+
- **webcam** — live `AVCaptureDevice` (built-in, Continuity, external).
|
|
132
|
+
|
|
133
|
+
## Connectors
|
|
134
|
+
|
|
135
|
+
`serve-sim` can be used with dev servers, browser, and AI editors for more seamless integration.
|
|
136
|
+
|
|
137
|
+
### Agent Skill
|
|
138
|
+
|
|
139
|
+
An [Agent Skill](https://platform.claude.com/docs/en/agents-and-tools/agent-skills/overview) ships in [`skills/serve-sim`](skills/serve-sim) — it teaches AI coding agents (Claude Code, Cursor, Codex CLI, Gemini CLI, and any host implementing the open Agent Skills standard) how to drive a simulator through the CLI: taps, gestures, hardware buttons, rotation, camera injection, and handing the stream off to the host's preview pane.
|
|
140
|
+
|
|
141
|
+
```sh
|
|
142
|
+
bunx add-skill EvanBacon/serve-sim
|
|
143
|
+
# in Claude Code:
|
|
144
|
+
/plugin marketplace add EvanBacon/serve-sim
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
See [`skills/serve-sim/README.md`](skills/serve-sim/README.md) for the full capability list.
|
|
148
|
+
|
|
149
|
+
### Claude Code Desktop
|
|
150
|
+
|
|
151
|
+
Create a `.claude/launch.json` and define a server:
|
|
152
|
+
|
|
153
|
+
```json
|
|
154
|
+
{
|
|
155
|
+
"version": "0.0.1",
|
|
156
|
+
"configurations": [
|
|
157
|
+
{
|
|
158
|
+
"name": "Apple",
|
|
159
|
+
"runtimeExecutable": "npx",
|
|
160
|
+
"runtimeArgs": ["serve-sim"],
|
|
161
|
+
"port": 3200
|
|
162
|
+
}
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Expo
|
|
168
|
+
|
|
169
|
+
Automatically start the serve-sim process with `npx expo start` and access the URL at `http://localhost:8081/.sim`.
|
|
170
|
+
|
|
171
|
+
First, customize the `metro.config.js` file (`bunx expo customize`):
|
|
172
|
+
|
|
173
|
+
```js
|
|
174
|
+
// Learn more https://docs.expo.io/guides/customizing-metro
|
|
175
|
+
const { getDefaultConfig } = require("expo/metro-config");
|
|
176
|
+
const connect = require("connect");
|
|
177
|
+
const { simMiddleware } = require("serve-sim/middleware");
|
|
178
|
+
|
|
179
|
+
/** @type {import('expo/metro-config').MetroConfig} */
|
|
180
|
+
const config = getDefaultConfig(__dirname);
|
|
181
|
+
|
|
182
|
+
config.server = config.server || {};
|
|
183
|
+
const originalEnhanceMiddleware = config.server.enhanceMiddleware;
|
|
184
|
+
config.server.enhanceMiddleware = (metroMiddleware, server) => {
|
|
185
|
+
const middleware = originalEnhanceMiddleware
|
|
186
|
+
? originalEnhanceMiddleware(metroMiddleware, server)
|
|
187
|
+
: metroMiddleware;
|
|
188
|
+
const app = connect();
|
|
189
|
+
app.use(simMiddleware({ basePath: "/.sim" }));
|
|
190
|
+
app.use(middleware);
|
|
191
|
+
return app;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
module.exports = config;
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Embed in your dev server
|
|
198
|
+
|
|
199
|
+
`serve-sim/middleware` is a Connect-style middleware that mounts the same preview UI inside your existing dev server (Metro, Vite, Next, plain Express, etc.). Run `serve-sim --detach` once to start the streaming helper, then add the middleware:
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
import { simMiddleware } from "serve-sim/middleware";
|
|
203
|
+
|
|
204
|
+
app.use(simMiddleware({ basePath: "/.sim" }));
|
|
205
|
+
// → preview HTML at /.sim
|
|
206
|
+
// → state JSON at /.sim/api
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
The middleware reads the helper's state from `$TMPDIR/serve-sim/` and forwards the user's browser to the live MJPEG + WebSocket endpoints. CORS is wide-open on the helper, so the page renders without a proxy.
|
|
210
|
+
|
|
211
|
+
## How it works
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
┌──────────────┐ simctl io ┌─────────────────┐ MJPEG / WS ┌─────────┐
|
|
215
|
+
│ iOS Simulator│ ────────────► │ serve-sim-bin │ ───────────► │ Browser │
|
|
216
|
+
└──────────────┘ (Swift) │ (per-device) │ └─────────┘
|
|
217
|
+
└─────────────────┘
|
|
218
|
+
▲
|
|
219
|
+
state file in
|
|
220
|
+
$TMPDIR/serve-sim/
|
|
221
|
+
▲
|
|
222
|
+
┌──────────────────┐
|
|
223
|
+
│ serve-sim CLI / │
|
|
224
|
+
│ middleware │
|
|
225
|
+
└──────────────────┘
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
The Swift helper (`bin/serve-sim-bin`) is a tiny standalone binary — no Xcode dependency at runtime. The CLI embeds it via `bun build --compile`, so installing the npm package is enough.
|
|
229
|
+
|
|
230
|
+
## Development
|
|
231
|
+
|
|
232
|
+
```sh
|
|
233
|
+
bun install
|
|
234
|
+
bun run --filter serve-sim build # build the JS bundles
|
|
235
|
+
bun run --filter serve-sim build:swift # rebuild the Swift helper
|
|
236
|
+
bun run --filter serve-sim dev # watch mode
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## License
|
|
240
|
+
|
|
241
|
+
Apache-2.0
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
5
|
+
OUT_DIR="${1:-$HERE/../../dist/simax}"
|
|
6
|
+
mkdir -p "$OUT_DIR"
|
|
7
|
+
|
|
8
|
+
SDK="$(xcrun --sdk iphonesimulator --show-sdk-path)"
|
|
9
|
+
BIN="$OUT_DIR/serve-sim-ax-settings"
|
|
10
|
+
|
|
11
|
+
# Build a fat simulator executable (arm64 + x86_64); it runs inside the sim
|
|
12
|
+
# via `simctl spawn`.
|
|
13
|
+
xcrun --sdk iphonesimulator clang \
|
|
14
|
+
-arch arm64 -arch x86_64 \
|
|
15
|
+
-mios-simulator-version-min=15.0 \
|
|
16
|
+
-isysroot "$SDK" \
|
|
17
|
+
-framework CoreFoundation \
|
|
18
|
+
-o "$BIN" \
|
|
19
|
+
"$HERE/sim-ax-settings.m"
|
|
20
|
+
|
|
21
|
+
echo "Built: $BIN"
|
|
22
|
+
file "$BIN"
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
// sim-ax-settings — tiny CLI that runs *inside* the iOS Simulator (via
|
|
2
|
+
// `simctl spawn`) to read and write the simulator-wide settings that
|
|
3
|
+
// `simctl ui` does not cover. It drives the same private libAccessibility
|
|
4
|
+
// and MediaAccessibility setters the Xcode Devices app uses, which write the
|
|
5
|
+
// backing preference *and* post the darwin notification that makes running
|
|
6
|
+
// apps pick the change up live.
|
|
7
|
+
//
|
|
8
|
+
// Usage:
|
|
9
|
+
// sim-ax-settings get <key>
|
|
10
|
+
// sim-ax-settings set <key> <value>
|
|
11
|
+
// sim-ax-settings status # JSON object of every key
|
|
12
|
+
//
|
|
13
|
+
// Keys / values:
|
|
14
|
+
// reduce-motion on|off -> _AXSSetReduceMotionEnabled
|
|
15
|
+
// show-borders on|off -> _AXSSetButtonShapesEnabled
|
|
16
|
+
// reduce-transparency on|off -> _AXSSetEnhanceBackgroundContrastEnabled
|
|
17
|
+
// voiceover on|off -> _AXSVoiceOverTouchSetEnabled
|
|
18
|
+
// color-filter none|grayscale|red-green|green-red|blue-yellow
|
|
19
|
+
// -> MADisplayFilterPrefSetType/CategoryEnabled
|
|
20
|
+
// liquid-glass clear|tinted
|
|
21
|
+
// -> com.apple.UIKit UIViewGlassLegibilitySetting
|
|
22
|
+
|
|
23
|
+
#include <CoreFoundation/CoreFoundation.h>
|
|
24
|
+
#include <dlfcn.h>
|
|
25
|
+
#include <notify.h>
|
|
26
|
+
#include <stdio.h>
|
|
27
|
+
#include <stdlib.h>
|
|
28
|
+
#include <string.h>
|
|
29
|
+
|
|
30
|
+
typedef int (*GetBoolFn)(void);
|
|
31
|
+
typedef void (*SetBoolFn)(int);
|
|
32
|
+
typedef long (*MAGetTypeFn)(long);
|
|
33
|
+
typedef void (*MASetTypeFn)(long, long);
|
|
34
|
+
typedef int (*MAGetEnabledFn)(long);
|
|
35
|
+
typedef void (*MASetEnabledFn)(long, int);
|
|
36
|
+
|
|
37
|
+
// MADisplayFilterPref* "category" argument: 1 maps to the "__Color__." key
|
|
38
|
+
// prefix in com.apple.mediaaccessibility (the Settings > Color Filters pane).
|
|
39
|
+
static const long kMAColorCategory = 1;
|
|
40
|
+
|
|
41
|
+
// MADisplayFilterType values, confirmed against libAccessibility's
|
|
42
|
+
// _AXS{GreenRed,BlueYellow}FilterSetEnabled disassembly on iOS 26.5.
|
|
43
|
+
enum {
|
|
44
|
+
kFilterNone = 0,
|
|
45
|
+
kFilterGrayscale = 1,
|
|
46
|
+
kFilterRedGreen = 2, // protanopia
|
|
47
|
+
kFilterGreenRed = 4, // deuteranopia
|
|
48
|
+
kFilterBlueYellow = 8, // tritanopia
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
static void *axHandle(void) {
|
|
52
|
+
static void *handle;
|
|
53
|
+
if (!handle) handle = dlopen("/usr/lib/libAccessibility.dylib", RTLD_NOW);
|
|
54
|
+
return handle;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static void *maHandle(void) {
|
|
58
|
+
static void *handle;
|
|
59
|
+
if (!handle) {
|
|
60
|
+
handle = dlopen(
|
|
61
|
+
"/System/Library/Frameworks/MediaAccessibility.framework/MediaAccessibility",
|
|
62
|
+
RTLD_NOW);
|
|
63
|
+
}
|
|
64
|
+
return handle;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static void *requireSym(void *handle, const char *name) {
|
|
68
|
+
void *sym = handle ? dlsym(handle, name) : NULL;
|
|
69
|
+
if (!sym) {
|
|
70
|
+
fprintf(stderr, "sim-ax-settings: missing symbol %s\n", name);
|
|
71
|
+
exit(2);
|
|
72
|
+
}
|
|
73
|
+
return sym;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ─── Boolean AXS settings ───
|
|
77
|
+
|
|
78
|
+
typedef struct {
|
|
79
|
+
const char *key;
|
|
80
|
+
const char *getter;
|
|
81
|
+
const char *setter;
|
|
82
|
+
} BoolSetting;
|
|
83
|
+
|
|
84
|
+
static const BoolSetting kBoolSettings[] = {
|
|
85
|
+
{"reduce-motion", "_AXSReduceMotionEnabled", "_AXSSetReduceMotionEnabled"},
|
|
86
|
+
{"show-borders", "_AXSButtonShapesEnabled", "_AXSSetButtonShapesEnabled"},
|
|
87
|
+
{"reduce-transparency", "_AXSEnhanceBackgroundContrastEnabled",
|
|
88
|
+
"_AXSSetEnhanceBackgroundContrastEnabled"},
|
|
89
|
+
{"voiceover", "_AXSVoiceOverTouchEnabled", "_AXSVoiceOverTouchSetEnabled"},
|
|
90
|
+
};
|
|
91
|
+
static const size_t kBoolSettingCount =
|
|
92
|
+
sizeof(kBoolSettings) / sizeof(kBoolSettings[0]);
|
|
93
|
+
|
|
94
|
+
static const BoolSetting *findBoolSetting(const char *key) {
|
|
95
|
+
for (size_t i = 0; i < kBoolSettingCount; i++) {
|
|
96
|
+
if (strcmp(kBoolSettings[i].key, key) == 0) return &kBoolSettings[i];
|
|
97
|
+
}
|
|
98
|
+
return NULL;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static int getBoolSetting(const BoolSetting *s) {
|
|
102
|
+
GetBoolFn fn = (GetBoolFn)requireSym(axHandle(), s->getter);
|
|
103
|
+
return fn() ? 1 : 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static void setBoolSetting(const BoolSetting *s, int enabled) {
|
|
107
|
+
SetBoolFn fn = (SetBoolFn)requireSym(axHandle(), s->setter);
|
|
108
|
+
fn(enabled);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ─── Color filter ───
|
|
112
|
+
|
|
113
|
+
static const char *filterName(long type, int enabled) {
|
|
114
|
+
if (!enabled) return "none";
|
|
115
|
+
switch (type) {
|
|
116
|
+
case kFilterGrayscale: return "grayscale";
|
|
117
|
+
case kFilterRedGreen: return "red-green";
|
|
118
|
+
case kFilterGreenRed: return "green-red";
|
|
119
|
+
case kFilterBlueYellow: return "blue-yellow";
|
|
120
|
+
default: return "none";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
static long filterTypeForName(const char *name) {
|
|
125
|
+
if (strcmp(name, "grayscale") == 0) return kFilterGrayscale;
|
|
126
|
+
if (strcmp(name, "red-green") == 0) return kFilterRedGreen;
|
|
127
|
+
if (strcmp(name, "green-red") == 0) return kFilterGreenRed;
|
|
128
|
+
if (strcmp(name, "blue-yellow") == 0) return kFilterBlueYellow;
|
|
129
|
+
return kFilterNone;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static const char *getColorFilter(void) {
|
|
133
|
+
MAGetTypeFn getType =
|
|
134
|
+
(MAGetTypeFn)requireSym(maHandle(), "MADisplayFilterPrefGetType");
|
|
135
|
+
MAGetEnabledFn getEnabled = (MAGetEnabledFn)requireSym(
|
|
136
|
+
maHandle(), "MADisplayFilterPrefGetCategoryEnabled");
|
|
137
|
+
return filterName(getType(kMAColorCategory), getEnabled(kMAColorCategory));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
static void setColorFilter(const char *name) {
|
|
141
|
+
MASetTypeFn setType =
|
|
142
|
+
(MASetTypeFn)requireSym(maHandle(), "MADisplayFilterPrefSetType");
|
|
143
|
+
MASetEnabledFn setEnabled = (MASetEnabledFn)requireSym(
|
|
144
|
+
maHandle(), "MADisplayFilterPrefSetCategoryEnabled");
|
|
145
|
+
long type = filterTypeForName(name);
|
|
146
|
+
if (type == kFilterNone) {
|
|
147
|
+
setEnabled(kMAColorCategory, 0);
|
|
148
|
+
} else {
|
|
149
|
+
setType(kMAColorCategory, type);
|
|
150
|
+
setEnabled(kMAColorCategory, 1);
|
|
151
|
+
}
|
|
152
|
+
// Keep the com.apple.Accessibility grayscale flag in sync, matching what
|
|
153
|
+
// the Xcode Devices app writes for the Grayscale filter.
|
|
154
|
+
SetBoolFn setGrayscale =
|
|
155
|
+
(SetBoolFn)requireSym(axHandle(), "_AXSGrayscaleSetEnabled");
|
|
156
|
+
setGrayscale(type == kFilterGrayscale);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// ─── Liquid Glass (iOS 26+) ───
|
|
160
|
+
|
|
161
|
+
static CFStringRef kGlassDomain = CFSTR("com.apple.UIKit");
|
|
162
|
+
static CFStringRef kGlassKey = CFSTR("UIViewGlassLegibilitySetting");
|
|
163
|
+
|
|
164
|
+
static const char *getLiquidGlass(void) {
|
|
165
|
+
CFPropertyListRef value = CFPreferencesCopyValue(
|
|
166
|
+
kGlassKey, kGlassDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
|
167
|
+
int tinted = 0;
|
|
168
|
+
if (value) {
|
|
169
|
+
if (CFGetTypeID(value) == CFNumberGetTypeID()) {
|
|
170
|
+
int n = 0;
|
|
171
|
+
CFNumberGetValue((CFNumberRef)value, kCFNumberIntType, &n);
|
|
172
|
+
tinted = n == 1;
|
|
173
|
+
}
|
|
174
|
+
CFRelease(value);
|
|
175
|
+
}
|
|
176
|
+
return tinted ? "tinted" : "clear";
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
static void setLiquidGlass(const char *name) {
|
|
180
|
+
int tinted = strcmp(name, "tinted") == 0;
|
|
181
|
+
CFNumberRef value = CFNumberCreate(NULL, kCFNumberIntType, &tinted);
|
|
182
|
+
CFPreferencesSetValue(kGlassKey, value, kGlassDomain,
|
|
183
|
+
kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
|
184
|
+
CFRelease(value);
|
|
185
|
+
CFPreferencesSynchronize(kGlassDomain, kCFPreferencesCurrentUser,
|
|
186
|
+
kCFPreferencesAnyHost);
|
|
187
|
+
notify_post("UIViewGlassLegibilityUpdateNotification");
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// ─── Entry point ───
|
|
191
|
+
|
|
192
|
+
static void printStatus(void) {
|
|
193
|
+
printf("{");
|
|
194
|
+
for (size_t i = 0; i < kBoolSettingCount; i++) {
|
|
195
|
+
printf("\"%s\":\"%s\",", kBoolSettings[i].key,
|
|
196
|
+
getBoolSetting(&kBoolSettings[i]) ? "on" : "off");
|
|
197
|
+
}
|
|
198
|
+
printf("\"color-filter\":\"%s\",", getColorFilter());
|
|
199
|
+
printf("\"liquid-glass\":\"%s\"}\n", getLiquidGlass());
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
static int parseOnOff(const char *value) {
|
|
203
|
+
if (strcmp(value, "on") == 0 || strcmp(value, "1") == 0 ||
|
|
204
|
+
strcmp(value, "true") == 0 || strcmp(value, "enabled") == 0)
|
|
205
|
+
return 1;
|
|
206
|
+
if (strcmp(value, "off") == 0 || strcmp(value, "0") == 0 ||
|
|
207
|
+
strcmp(value, "false") == 0 || strcmp(value, "disabled") == 0)
|
|
208
|
+
return 0;
|
|
209
|
+
return -1;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
int main(int argc, char **argv) {
|
|
213
|
+
if (argc >= 2 && strcmp(argv[1], "status") == 0) {
|
|
214
|
+
printStatus();
|
|
215
|
+
return 0;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (argc == 3 && strcmp(argv[1], "get") == 0) {
|
|
219
|
+
const char *key = argv[2];
|
|
220
|
+
const BoolSetting *bs = findBoolSetting(key);
|
|
221
|
+
if (bs) {
|
|
222
|
+
printf("%s\n", getBoolSetting(bs) ? "on" : "off");
|
|
223
|
+
return 0;
|
|
224
|
+
}
|
|
225
|
+
if (strcmp(key, "color-filter") == 0) {
|
|
226
|
+
printf("%s\n", getColorFilter());
|
|
227
|
+
return 0;
|
|
228
|
+
}
|
|
229
|
+
if (strcmp(key, "liquid-glass") == 0) {
|
|
230
|
+
printf("%s\n", getLiquidGlass());
|
|
231
|
+
return 0;
|
|
232
|
+
}
|
|
233
|
+
fprintf(stderr, "sim-ax-settings: unknown key %s\n", key);
|
|
234
|
+
return 1;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (argc == 4 && strcmp(argv[1], "set") == 0) {
|
|
238
|
+
const char *key = argv[2];
|
|
239
|
+
const char *value = argv[3];
|
|
240
|
+
const BoolSetting *bs = findBoolSetting(key);
|
|
241
|
+
if (bs) {
|
|
242
|
+
int enabled = parseOnOff(value);
|
|
243
|
+
if (enabled < 0) {
|
|
244
|
+
fprintf(stderr, "sim-ax-settings: %s wants on|off, got %s\n", key, value);
|
|
245
|
+
return 1;
|
|
246
|
+
}
|
|
247
|
+
setBoolSetting(bs, enabled);
|
|
248
|
+
return 0;
|
|
249
|
+
}
|
|
250
|
+
if (strcmp(key, "color-filter") == 0) {
|
|
251
|
+
if (strcmp(value, "none") != 0 && filterTypeForName(value) == kFilterNone) {
|
|
252
|
+
fprintf(stderr, "sim-ax-settings: unknown color filter %s\n", value);
|
|
253
|
+
return 1;
|
|
254
|
+
}
|
|
255
|
+
setColorFilter(value);
|
|
256
|
+
return 0;
|
|
257
|
+
}
|
|
258
|
+
if (strcmp(key, "liquid-glass") == 0) {
|
|
259
|
+
if (strcmp(value, "clear") != 0 && strcmp(value, "tinted") != 0) {
|
|
260
|
+
fprintf(stderr, "sim-ax-settings: liquid-glass wants clear|tinted\n");
|
|
261
|
+
return 1;
|
|
262
|
+
}
|
|
263
|
+
setLiquidGlass(value);
|
|
264
|
+
return 0;
|
|
265
|
+
}
|
|
266
|
+
fprintf(stderr, "sim-ax-settings: unknown key %s\n", key);
|
|
267
|
+
return 1;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
fprintf(stderr,
|
|
271
|
+
"Usage: sim-ax-settings status | get <key> | set <key> <value>\n");
|
|
272
|
+
return 64;
|
|
273
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
4
|
+
OUT_DIR="${1:-$HERE/../../dist/simcam}"
|
|
5
|
+
mkdir -p "$OUT_DIR"
|
|
6
|
+
|
|
7
|
+
SDK="$(xcrun --sdk macosx --show-sdk-path)"
|
|
8
|
+
BIN="$OUT_DIR/serve-sim-camera-helper"
|
|
9
|
+
|
|
10
|
+
xcrun --sdk macosx clang \
|
|
11
|
+
-arch arm64 -arch x86_64 \
|
|
12
|
+
-mmacosx-version-min=14.0 \
|
|
13
|
+
-isysroot "$SDK" \
|
|
14
|
+
-fobjc-arc -fmodules \
|
|
15
|
+
-framework Foundation \
|
|
16
|
+
-framework AVFoundation \
|
|
17
|
+
-framework CoreMedia \
|
|
18
|
+
-framework CoreVideo \
|
|
19
|
+
-framework CoreGraphics \
|
|
20
|
+
-framework CoreImage \
|
|
21
|
+
-framework CoreText \
|
|
22
|
+
-framework ImageIO \
|
|
23
|
+
-framework IOSurface \
|
|
24
|
+
-framework Accelerate \
|
|
25
|
+
-O2 \
|
|
26
|
+
-o "$BIN" \
|
|
27
|
+
"$HERE/main.m"
|
|
28
|
+
|
|
29
|
+
# Re-sign so the camera privacy prompt persists per-build instead of restarting.
|
|
30
|
+
codesign -s - -f "$BIN" 2>/dev/null || true
|
|
31
|
+
|
|
32
|
+
echo "Built: $BIN"
|
|
33
|
+
file "$BIN"
|