diff --git a/VoiceInk/MiniRecorderShortcutManager.swift b/VoiceInk/MiniRecorderShortcutManager.swift index ca756b1..06f97f0 100644 --- a/VoiceInk/MiniRecorderShortcutManager.swift +++ b/VoiceInk/MiniRecorderShortcutManager.swift @@ -88,8 +88,7 @@ class MiniRecorderShortcutManager: ObservableObject { if let firstTime = self.escFirstPressTime, now.timeIntervalSince(firstTime) <= self.escSecondPressThreshold { self.escFirstPressTime = nil - SoundManager.shared.playEscSound() - await self.whisperState.dismissMiniRecorder() + await self.whisperState.cancelRecording() } else { self.escFirstPressTime = now SoundManager.shared.playEscSound() @@ -125,9 +124,8 @@ class MiniRecorderShortcutManager: ObservableObject { guard let self = self, await self.whisperState.isMiniRecorderVisible, KeyboardShortcuts.getShortcut(for: .cancelRecorder) != nil else { return } - - SoundManager.shared.playEscSound() - await self.whisperState.dismissMiniRecorder() + + await self.whisperState.cancelRecording() } } } diff --git a/VoiceInk/Whisper/WhisperState+UI.swift b/VoiceInk/Whisper/WhisperState+UI.swift index b0b7a03..09f0116 100644 --- a/VoiceInk/Whisper/WhisperState+UI.swift +++ b/VoiceInk/Whisper/WhisperState+UI.swift @@ -54,11 +54,9 @@ extension WhisperState { func dismissMiniRecorder() async { if recordingState == .busy { return } - + let wasRecording = recordingState == .recording - - logger.notice("📱 Dismissing \(self.recorderType) recorder") - + await MainActor.run { self.recordingState = .busy } diff --git a/VoiceInk/Whisper/WhisperState.swift b/VoiceInk/Whisper/WhisperState.swift index 23d883c..652bda2 100644 --- a/VoiceInk/Whisper/WhisperState.swift +++ b/VoiceInk/Whisper/WhisperState.swift @@ -351,12 +351,8 @@ class WhisperState: NSObject, ObservableObject { finalPastedText = enhancedText } catch { transcription.enhancedText = "Enhancement failed: \(error)" - await MainActor.run { - NotificationManager.shared.showNotification( - title: "AI enhancement failed", - type: .error - ) - } + + if await checkCancellationAndCleanup() { return } } } @@ -374,7 +370,9 @@ class WhisperState: NSObject, ObservableObject { // --- Finalize and save --- try? modelContext.save() NotificationCenter.default.post(name: .transcriptionCreated, object: transcription) - + + if await checkCancellationAndCleanup() { return } + if var textToPaste = finalPastedText, transcription.transcriptionStatus == TranscriptionStatus.completed.rawValue { if case .trialExpired = licenseViewModel.licenseState { textToPaste = """ @@ -382,14 +380,12 @@ class WhisperState: NSObject, ObservableObject { \n\(textToPaste) """ } - + let shouldAddSpace = UserDefaults.standard.object(forKey: "AppendTrailingSpace") as? Bool ?? true if shouldAddSpace { textToPaste += " " } - - if await checkCancellationAndCleanup() { return } - + DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { CursorPaster.pasteAtCursor(textToPaste) @@ -402,14 +398,16 @@ class WhisperState: NSObject, ObservableObject { } } } - + if let result = promptDetectionResult, let enhancementService = enhancementService, result.shouldEnableAI { await promptDetectionService.restoreOriginalSettings(result, to: enhancementService) } - + await self.dismissMiniRecorder() + + shouldCancelRecording = false } func getEnhancementService() -> AIEnhancementService? { @@ -418,12 +416,12 @@ class WhisperState: NSObject, ObservableObject { private func checkCancellationAndCleanup() async -> Bool { if shouldCancelRecording { - await dismissMiniRecorder() + await cleanupModelResources() return true } return false } - + private func cleanupAndDismiss() async { await dismissMiniRecorder() }