MCPcopy Index your code
hub / github.com/getsentry/XcodeBuildMCP / startXcodeStateWatcher

Function startXcodeStateWatcher

src/utils/xcode-state-watcher.ts:189–246  ·  view source on GitHub ↗
(options: StartWatcherOptions = {})

Source from the content-addressed store, hash-verified

187 * Start watching the xcuserstate file for changes
188 */
189export async function startXcodeStateWatcher(options: StartWatcherOptions = {}): Promise<boolean> {
190 if (state.watcher) {
191 log('debug', '[xcode-watcher] Watcher already running');
192 return true;
193 }
194
195 const executor = options.executor ?? getDefaultCommandExecutor();
196 const cwd = options.cwd ?? process.cwd();
197
198 const xcuserstatePath = await findXcodeStateFile({
199 executor,
200 cwd,
201 searchRoot: options.searchRoot,
202 workspacePath: options.workspacePath,
203 projectPath: options.projectPath,
204 });
205
206 if (!xcuserstatePath) {
207 log('debug', '[xcode-watcher] No xcuserstate file found, watcher not started');
208 return false;
209 }
210
211 // Initialize cached state
212 const initialState = extractState(xcuserstatePath);
213 state.cachedScheme = initialState.scheme;
214 state.cachedSimulatorId = initialState.simulatorId;
215 state.watchedPath = xcuserstatePath;
216 state.executor = executor;
217 state.cwd = cwd;
218 state.projectPath = options.projectPath ?? null;
219 state.workspacePath = options.workspacePath ?? null;
220
221 log(
222 'info',
223 `[xcode-watcher] Starting watcher for ${xcuserstatePath} (scheme="${initialState.scheme}", sim="${initialState.simulatorId}")`,
224 );
225
226 state.watcher = watch(xcuserstatePath, {
227 persistent: true,
228 ignoreInitial: true,
229 awaitWriteFinish: {
230 stabilityThreshold: 100,
231 pollInterval: 50,
232 },
233 });
234
235 state.watcher.on('change', () => {
236 log('debug', '[xcode-watcher] File change detected');
237 handleFileChange();
238 });
239
240 state.watcher.on('error', (error: unknown) => {
241 const message = error instanceof Error ? error.message : String(error);
242 log('warn', `[xcode-watcher] Watcher error: ${message}`);
243 });
244
245 return true;
246}

Callers 2

bootstrapServerFunction · 0.90

Calls 5

logFunction · 0.90
findXcodeStateFileFunction · 0.90
extractStateFunction · 0.85
handleFileChangeFunction · 0.85

Tested by

no test coverage detected