(ctx: XcodeStateReaderContext)
| 231 | } |
| 232 | |
| 233 | export async function readXcodeIdeState(ctx: XcodeStateReaderContext): Promise<XcodeStateResult> { |
| 234 | try { |
| 235 | const xcuserstatePath = await findXcodeStateFile(ctx); |
| 236 | if (!xcuserstatePath) { |
| 237 | return { error: 'No Xcode project/workspace found in working directory' }; |
| 238 | } |
| 239 | |
| 240 | const state = parseXcuserstate(xcuserstatePath); |
| 241 | |
| 242 | const result: XcodeStateResult = {}; |
| 243 | |
| 244 | if (state.scheme) { |
| 245 | result.scheme = state.scheme; |
| 246 | log('info', `[xcode-state] Detected active scheme: ${state.scheme}`); |
| 247 | } |
| 248 | |
| 249 | if (state.simulatorId) { |
| 250 | result.simulatorId = state.simulatorId; |
| 251 | |
| 252 | const name = await lookupSimulatorName(ctx, state.simulatorId); |
| 253 | if (name) { |
| 254 | result.simulatorName = name; |
| 255 | log('info', `[xcode-state] Detected active simulator: ${name} (${state.simulatorId})`); |
| 256 | } else { |
| 257 | log('info', `[xcode-state] Detected active destination: ${state.simulatorId}`); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | if (!result.scheme && !result.simulatorId) { |
| 262 | return { error: 'Could not extract active scheme or destination from Xcode state' }; |
| 263 | } |
| 264 | |
| 265 | return result; |
| 266 | } catch (e) { |
| 267 | const message = e instanceof Error ? e.message : String(e); |
| 268 | log('warn', `[xcode-state] Failed to read Xcode IDE state: ${message}`); |
| 269 | return { error: message }; |
| 270 | } |
| 271 | } |
no test coverage detected