|
1 | | -import type { DaemonResponse } from '../types.ts'; |
| 1 | +import type { DaemonResponse, SessionState } from '../types.ts'; |
2 | 2 | import type { InteractionHandlerParams } from './interaction-common.ts'; |
3 | 3 | import { handleTouchInteractionCommands } from './interaction-touch.ts'; |
4 | 4 | import { captureSnapshotForSession } from './interaction-snapshot.ts'; |
@@ -48,19 +48,37 @@ async function dispatchTypeViaRuntime( |
48 | 48 | captureSnapshotForSession: typeof captureSnapshotForSession; |
49 | 49 | }, |
50 | 50 | ): Promise<DaemonResponse> { |
51 | | - const { req, sessionName, sessionStore } = params; |
| 51 | + const { sessionName, sessionStore } = params; |
52 | 52 | const session = sessionStore.get(sessionName); |
53 | 53 | if (!session) return errorResponse('SESSION_NOT_FOUND', 'No active session. Run open first.'); |
54 | 54 | if (!isCommandSupportedOnDevice(typeCommandDefinition.name, session.device)) { |
55 | 55 | return errorResponse('UNSUPPORTED_OPERATION', 'type is not supported on this device'); |
56 | 56 | } |
| 57 | + const recordingRecoveryResponse = await recoverAndroidRecordingDialogForType(session); |
| 58 | + if (recordingRecoveryResponse) return recordingRecoveryResponse; |
| 59 | + |
| 60 | + return await runTypeTextViaRuntime(params, session); |
| 61 | +} |
| 62 | + |
| 63 | +async function recoverAndroidRecordingDialogForType( |
| 64 | + session: SessionState, |
| 65 | +): Promise<DaemonResponse | null> { |
57 | 66 | if (session.device.platform === 'android' && session.recording) { |
58 | 67 | const androidRecoveryResult = await recoverAndroidBlockingSystemDialog({ session }); |
59 | 68 | if (androidRecoveryResult === 'failed') { |
60 | 69 | return errorResponse('COMMAND_FAILED', 'Android system dialog blocked the recording session'); |
61 | 70 | } |
62 | 71 | } |
| 72 | + return null; |
| 73 | +} |
63 | 74 |
|
| 75 | +async function runTypeTextViaRuntime( |
| 76 | + params: InteractionHandlerParams & { |
| 77 | + captureSnapshotForSession: typeof captureSnapshotForSession; |
| 78 | + }, |
| 79 | + session: SessionState, |
| 80 | +): Promise<DaemonResponse> { |
| 81 | + const { req, sessionName, sessionStore } = params; |
64 | 82 | const text = (req.positionals ?? []).join(' '); |
65 | 83 | const runtime = createInteractionRuntime(params); |
66 | 84 | const actionStartedAt = Date.now(); |
|
0 commit comments