fix: maintain cancellation state until cleanup is complete to prevent unwanted sound playback

This commit is contained in:
Beingpax 2025-03-06 20:26:20 +05:45
parent 9173264407
commit f33de6b5a8
3 changed files with 19 additions and 11 deletions

View File

@ -48,4 +48,4 @@ class CursorPaster {
}
}
}
}
}

View File

@ -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: {

View File

@ -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 {