From f33de6b5a841f2c844ec12779a33dc6c85af62d2 Mon Sep 17 00:00:00 2001 From: Beingpax Date: Thu, 6 Mar 2025 20:26:20 +0545 Subject: [PATCH] fix: maintain cancellation state until cleanup is complete to prevent unwanted sound playback --- VoiceInk/CursorPaster.swift | 2 +- VoiceInk/Views/LicenseManagementView.swift | 4 ++-- VoiceInk/Whisper/WhisperState.swift | 24 ++++++++++++++-------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/VoiceInk/CursorPaster.swift b/VoiceInk/CursorPaster.swift index 3faa140..bfa8284 100644 --- a/VoiceInk/CursorPaster.swift +++ b/VoiceInk/CursorPaster.swift @@ -48,4 +48,4 @@ class CursorPaster { } } } -} \ No newline at end of file +} diff --git a/VoiceInk/Views/LicenseManagementView.swift b/VoiceInk/Views/LicenseManagementView.swift index fe3da0c..d4f017b 100644 --- a/VoiceInk/Views/LicenseManagementView.swift +++ b/VoiceInk/Views/LicenseManagementView.swift @@ -57,7 +57,7 @@ struct LicenseManagementView: View { if case .licensed = licenseViewModel.licenseState { HStack(spacing: 40) { Button { - if let url = URL(string: "https://voiceink.featurebase.app/changelog") { + if let url = URL(string: "https://github.com/Beingpax/VoiceInk/releases") { NSWorkspace.shared.open(url) } } label: { @@ -84,7 +84,7 @@ struct LicenseManagementView: View { .buttonStyle(.plain) Button { - if let url = URL(string: "https://voiceink.featurebase.app") { + if let url = URL(string: "https://github.com/Beingpax/VoiceInk/issues") { NSWorkspace.shared.open(url) } } label: { diff --git a/VoiceInk/Whisper/WhisperState.swift b/VoiceInk/Whisper/WhisperState.swift index 28c8115..1a85380 100644 --- a/VoiceInk/Whisper/WhisperState.swift +++ b/VoiceInk/Whisper/WhisperState.swift @@ -386,14 +386,18 @@ class WhisperState: NSObject, ObservableObject, AVAudioRecorderDelegate { messageLog += "Done: \(text)\n" - SoundManager.shared.playStopSound() - - if AXIsProcessTrusted() { - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { - CursorPaster.pasteAtCursor(text) + 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" } - } else { - messageLog += "Accessibility permissions not granted. Transcription not pasted automatically.\n" } if isAutoCopyEnabled { @@ -557,11 +561,15 @@ 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 {