diff --git a/VoiceInk/Whisper/WhisperState.swift b/VoiceInk/Whisper/WhisperState.swift index 1a85380..508202b 100644 --- a/VoiceInk/Whisper/WhisperState.swift +++ b/VoiceInk/Whisper/WhisperState.swift @@ -386,18 +386,14 @@ class WhisperState: NSObject, ObservableObject, AVAudioRecorderDelegate { messageLog += "Done: \(text)\n" - if !shouldCancelRecording { - SoundManager.shared.playStopSound() - - if AXIsProcessTrusted() { - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { - if !self.shouldCancelRecording { - CursorPaster.pasteAtCursor(text) - } - } - } else { - messageLog += "Accessibility permissions not granted. Transcription not pasted automatically.\n" + SoundManager.shared.playStopSound() + + if AXIsProcessTrusted() { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { + CursorPaster.pasteAtCursor(text) } + } else { + messageLog += "Accessibility permissions not granted. Transcription not pasted automatically.\n" } if isAutoCopyEnabled { @@ -561,15 +557,11 @@ class WhisperState: NSObject, ObservableObject, AVAudioRecorderDelegate { isTranscribing = false canTranscribe = true isMiniRecorderVisible = false + shouldCancelRecording = false } try? await Task.sleep(nanoseconds: 150_000_000) await cleanupResources() - - // Reset cancellation flag only after all cleanup is done - await MainActor.run { - shouldCancelRecording = false - } } func cancelRecording() async { @@ -646,4 +638,3 @@ private class TaskDelegate: NSObject, URLSessionTaskDelegate { extension Notification.Name { static let toggleMiniRecorder = Notification.Name("toggleMiniRecorder") } -