@@ -3,9 +3,13 @@ import { useCallback, useEffect, useRef, useState } from 'react'
33import { getCurrentChatId } from '../project-files'
44import { flushAnalytics } from '../utils/analytics'
55import { cleanupRenderer } from '../utils/renderer-cleanup'
6+ import { withTimeout } from '../utils/terminal-color-detection'
67
78import type { InputValue } from '../state/chat-store'
89
10+ // Timeout for analytics flush during exit - don't block exit for too long
11+ const EXIT_FLUSH_TIMEOUT_MS = 1000
12+
913interface UseExitHandlerOptions {
1014 inputValue : string
1115 setInputValue : ( value : InputValue ) => void
@@ -65,7 +69,7 @@ export const useExitHandler = ({
6569 exitWarningTimeoutRef . current = null
6670 }
6771
68- flushAnalytics ( ) . then ( ( ) => {
72+ withTimeout ( flushAnalytics ( ) , EXIT_FLUSH_TIMEOUT_MS , undefined ) . then ( ( ) => {
6973 cleanupRenderer ( )
7074 process . exit ( 0 )
7175 } )
@@ -79,16 +83,12 @@ export const useExitHandler = ({
7983 exitWarningTimeoutRef . current = null
8084 }
8185
82- const flushed = flushAnalytics ( )
83- if ( flushed && typeof ( flushed as Promise < void > ) . finally === 'function' ) {
84- ; ( flushed as Promise < void > ) . finally ( ( ) => {
86+ withTimeout ( flushAnalytics ( ) , EXIT_FLUSH_TIMEOUT_MS , undefined ) . finally (
87+ ( ) => {
8588 cleanupRenderer ( )
8689 process . exit ( 0 )
87- } )
88- } else {
89- cleanupRenderer ( )
90- process . exit ( 0 )
91- }
90+ } ,
91+ )
9292 }
9393
9494 process . on ( 'SIGINT' , handleSigint )
0 commit comments