Reactive CoreSimulator device state (replace simctl list polling)#121
Draft
EvanBacon wants to merge 3 commits into
Draft
Reactive CoreSimulator device state (replace simctl list polling)#121EvanBacon wants to merge 3 commits into
EvanBacon wants to merge 3 commits into
Conversation
Introduces a new native CoreSimulator device monitor and exposes `listDevices`/`SimWatch` through the addon, then wires TypeScript to use that live snapshot instead of repeatedly spawning `xcrun simctl list`. Device resolution, booted checks, and simulator listing now share this reactive source with `simctl` fallback when native access fails. The client grid hook is switched from interval polling to server-pushed SSE updates, and middleware now serves `/grid/api/events` plus native device-change subscriptions so external boot/shutdown changes propagate immediately.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Move booted-UDID lookup logic into `device.ts` as `listBootedUdids()` and export `eachDevice()` for shared iteration, then update CLI and middleware to use the centralized helpers. This removes duplicate fallback logic around device-set reads, keeps the null-on-read-failure behavior for destructive paths, and slightly simplifies simulator listing by spreading existing device fields.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Device enumeration went through
xcrun simctl list devices, spawned per call across the CLI and middleware (~50ms each), and the web grid polled/grid/apion a fixed 750ms–3s interval.simctlis a thin CLI over CoreSimulator.framework, which already holds a live, XPC-subscribed view of the device set from thecom.apple.CoreSimulator.CoreSimulatorServicedaemon. We can read and subscribe to that directly, in process, and push changes to the UI instead of polling.How
SimDeviceMonitor(Sources/SimNative), a process-global subscriber that drives CoreSimulator through the Objective-C runtime (dlopen +@objcprotocol shims, no linking). It holds the default device set, registers set-level handlers (add/remove) plus per-device handlers (state changes), and keeps a live snapshot. Exposed over N-API as a synchronouslistDevices()and aSimWatchpush class.device.tsnow serves thesimctl list devices -jshape from that reactive snapshot vialistDevicesByRuntime/tryListDevicesByRuntime, with a one-shotsimctlfallback when the native addon is unavailable. The null-returning variant preserves the lookup-failed vs empty distinction so stale-helper pruning stays safe.findBootedDevice,resolveDevice, and the per-request reads inindex.ts/middleware.tsroute through it; the old time-based booted-set caches are gone./grid/api/eventsSSE endpoint pushes the same payload asGET /grid/apiwhenever the device set changes (reactive subscriber) or a helper starts/stops (state-file watch). The clientuseGridDeviceshook subscribes over the existing exec websocket instead of polling. Changes made outside serve-sim (Simulator.app,simctl, Xcode) now reflect in the UI immediately./api/eventsand/grid/api/eventsinto onestreamDeviceStateSsehelper.Test Plan
tsc --noEmitandoxlintclean; native addon builds (build.ts).listDevices()output matchessimctl list devices -jexactly (52/52 devices); first call ~600ms (subscribe), cached reads ~0.3ms./grid/api/eventsstream while driving a device throughsimctl: observed live pushesShutdown -> Booting -> Booted -> Shutting Down -> Shutdownwith no polling, before and after the SSE refactor.