Update WhisperState.swift

This commit is contained in:
Prakash Joshi Pax 2025-03-06 21:49:20 +05:45 committed by GitHub
parent f33de6b5a8
commit 61453740cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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")
}