(taskId: string, setAppState: SetAppState)
| 489 | * Unregister a foreground task when the command completes without being backgrounded. |
| 490 | */ |
| 491 | export function unregisterForeground(taskId: string, setAppState: SetAppState): void { |
| 492 | let cleanupFn: (() => void) | undefined; |
| 493 | setAppState(prev => { |
| 494 | const task = prev.tasks[taskId]; |
| 495 | // Only remove if it's a foreground task (not backgrounded) |
| 496 | if (!isLocalShellTask(task) || task.isBackgrounded) { |
| 497 | return prev; |
| 498 | } |
| 499 | |
| 500 | // Capture cleanup function to call outside of updater |
| 501 | cleanupFn = task.unregisterCleanup; |
| 502 | const { |
| 503 | [taskId]: removed, |
| 504 | ...rest |
| 505 | } = prev.tasks; |
| 506 | return { |
| 507 | ...prev, |
| 508 | tasks: rest |
| 509 | }; |
| 510 | }); |
| 511 | |
| 512 | // Call cleanup outside of the state updater (avoid side effects in updater) |
| 513 | cleanupFn?.(); |
| 514 | } |
| 515 | async function flushAndCleanup(shellCommand: ShellCommand): Promise<void> { |
| 516 | try { |
| 517 | await shellCommand.taskOutput.flush(); |
no test coverage detected