(params: {
req: DaemonRequest;
sessionName: string;
logPath: string;
sessionStore: SessionStore;
})
| 412 | |
| 413 | // fallow-ignore-next-line complexity |
| 414 | export async function handleOpenCommand(params: { |
| 415 | req: DaemonRequest; |
| 416 | sessionName: string; |
| 417 | logPath: string; |
| 418 | sessionStore: SessionStore; |
| 419 | }): Promise<DaemonResponse> { |
| 420 | const { req, sessionName, logPath, sessionStore } = params; |
| 421 | |
| 422 | const session = sessionStore.get(sessionName); |
| 423 | if (session) { |
| 424 | const shouldRelaunch = req.flags?.relaunch === true; |
| 425 | const requestedOpenTarget = req.positionals?.[0]; |
| 426 | const openTarget = requestedOpenTarget ?? (shouldRelaunch ? session.appName : undefined); |
| 427 | const surfaceResult = resolveOpenSurfaceResponse( |
| 428 | session.device, |
| 429 | req.flags?.surface, |
| 430 | openTarget, |
| 431 | session.surface, |
| 432 | ); |
| 433 | if (typeof surfaceResult !== 'string') { |
| 434 | return surfaceResult; |
| 435 | } |
| 436 | if (!openTarget && surfaceResult === 'app') { |
| 437 | return shouldRelaunch |
| 438 | ? invalidOpenArgs('open --relaunch requires an app name or an active session app.') |
| 439 | : invalidOpenArgs('Session already active. Close it first or pass a new --session name.'); |
| 440 | } |
| 441 | |
| 442 | const validation = validateResolvedOpenRequest({ |
| 443 | shouldRelaunch, |
| 444 | openTarget, |
| 445 | surface: surfaceResult, |
| 446 | device: session.device, |
| 447 | }); |
| 448 | if (validation) { |
| 449 | return validation; |
| 450 | } |
| 451 | |
| 452 | const device = await refreshSessionDeviceIfNeeded(session.device); |
| 453 | const details = await prepareOpenCommandDetails({ |
| 454 | req, |
| 455 | sessionName, |
| 456 | sessionStore, |
| 457 | device, |
| 458 | surface: surfaceResult, |
| 459 | openTarget, |
| 460 | existingSession: session, |
| 461 | onIosSimulatorColdBootStart: createAppleRunnerCacheColdBootPrewarmForOpen({ |
| 462 | req, |
| 463 | logPath, |
| 464 | device, |
| 465 | surface: surfaceResult, |
| 466 | openTarget, |
| 467 | traceLogPath: session.trace?.outPath, |
| 468 | }), |
| 469 | }); |
| 470 | if (details.type === 'response') { |
| 471 | return details.response; |
no test coverage detected