fix(app): keep dictation running when agent tab loses focus
Previously, dictation was cancelled the moment the user switched away from the active agent tab, losing any in-progress recording. Drop the auto-stop-on-blur behavior so users can start dictating, switch tabs, and come back to finalize.
This commit is contained in:
@@ -1328,7 +1328,6 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
onError: handleDictationError,
|
||||
canStart: canStartDictation,
|
||||
canConfirm: canConfirmDictation,
|
||||
autoStopWhenHidden: { isVisible: isPaneFocused },
|
||||
enableDuration: true,
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ export interface UseDictationOptions {
|
||||
onPermanentFailure?: (error: Error, context: { requestId: string }) => void;
|
||||
canStart?: () => boolean;
|
||||
canConfirm?: () => boolean;
|
||||
autoStopWhenHidden?: { isVisible: boolean };
|
||||
enableDuration?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ export function useDictation(options: UseDictationOptions): UseDictationResult {
|
||||
onPermanentFailure,
|
||||
canStart,
|
||||
canConfirm,
|
||||
autoStopWhenHidden,
|
||||
enableDuration = false,
|
||||
} = options;
|
||||
|
||||
@@ -425,46 +424,6 @@ export function useDictation(options: UseDictationOptions): UseDictationResult {
|
||||
clearStreamingState();
|
||||
}, [clearStreamingState, stopDurationTracking]);
|
||||
|
||||
const cancelRef = useRef<(() => void) | null>(null);
|
||||
useEffect(() => {
|
||||
cancelRef.current = () => {
|
||||
void cancelDictation();
|
||||
};
|
||||
}, [cancelDictation]);
|
||||
|
||||
const visibilityRef = useRef<boolean | null>(
|
||||
typeof autoStopWhenHidden?.isVisible === "boolean" ? autoStopWhenHidden.isVisible : null,
|
||||
);
|
||||
useEffect(() => {
|
||||
const nextVisible =
|
||||
typeof autoStopWhenHidden?.isVisible === "boolean" ? autoStopWhenHidden.isVisible : null;
|
||||
const prevVisible = visibilityRef.current;
|
||||
visibilityRef.current = nextVisible;
|
||||
|
||||
if (prevVisible === true && nextVisible === false) {
|
||||
attemptGuardRef.current.cancel();
|
||||
|
||||
if (isRecordingRef.current) {
|
||||
cancelRef.current?.();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isProcessingRef.current) {
|
||||
stopDurationTracking();
|
||||
setDuration(0);
|
||||
setIsProcessing(false);
|
||||
isProcessingRef.current = false;
|
||||
setError(null);
|
||||
if (senderRef.current?.hasSegments()) {
|
||||
setStatus("failed");
|
||||
} else {
|
||||
setStatus("idle");
|
||||
clearStreamingState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [autoStopWhenHidden?.isVisible, clearStreamingState, stopDurationTracking]);
|
||||
|
||||
useEffect(() => {
|
||||
const attemptGuard = attemptGuardRef.current;
|
||||
const audioStop = audioStopRef;
|
||||
|
||||
Reference in New Issue
Block a user