diff --git a/VoiceInk/HotkeyManager.swift b/VoiceInk/HotkeyManager.swift index 66d2975..ce800a7 100644 --- a/VoiceInk/HotkeyManager.swift +++ b/VoiceInk/HotkeyManager.swift @@ -28,7 +28,7 @@ class HotkeyManager: ObservableObject { // MARK: - Helper Properties private var canProcessHotkeyAction: Bool { - whisperState.recordingState != .transcribing && whisperState.recordingState != .enhancing + whisperState.recordingState != .transcribing && whisperState.recordingState != .enhancing && whisperState.recordingState != .busy } // NSEvent monitoring for modifier keys diff --git a/VoiceInk/Recorder.swift b/VoiceInk/Recorder.swift index 0a5017f..dfc5c64 100644 --- a/VoiceInk/Recorder.swift +++ b/VoiceInk/Recorder.swift @@ -153,7 +153,7 @@ class Recorder: ObservableObject { } deviceManager.isRecordingActive = false } - + private func updateAudioMeter() { guard let recorder = recorder else { return } recorder.updateMeters() diff --git a/VoiceInk/Whisper/WhisperState+UI.swift b/VoiceInk/Whisper/WhisperState+UI.swift index b320434..0bc632a 100644 --- a/VoiceInk/Whisper/WhisperState+UI.swift +++ b/VoiceInk/Whisper/WhisperState+UI.swift @@ -53,23 +53,32 @@ 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 NotificationManager.shared.dismissNotification() } - if recordingState == .recording { + if wasRecording { await recorder.stopRecording() } - - // Hide recorder panel first before doing anything else + hideRecorderPanel() await MainActor.run { - recordingState = .idle isMiniRecorderVisible = false } + + await cleanupModelResources() + + await MainActor.run { + recordingState = .idle + } } func cancelRecording() async { diff --git a/VoiceInk/Whisper/WhisperState.swift b/VoiceInk/Whisper/WhisperState.swift index 6f0f98d..df93871 100644 --- a/VoiceInk/Whisper/WhisperState.swift +++ b/VoiceInk/Whisper/WhisperState.swift @@ -12,6 +12,7 @@ enum RecordingState: Equatable { case recording case transcribing case enhancing + case busy } @MainActor @@ -349,9 +350,6 @@ class WhisperState: NSObject, ObservableObject { } await self.dismissMiniRecorder() - Task.detached(priority: .background) { - await self.cleanupModelResources() - } } catch { do { @@ -377,17 +375,7 @@ class WhisperState: NSObject, ObservableObject { logger.error("❌ Could not create a record for the failed transcription: \(error.localizedDescription)") } - await MainActor.run { - NotificationManager.shared.showNotification( - title: "Transcription Failed", - type: .error - ) - } - await self.dismissMiniRecorder() - Task.detached(priority: .background) { - await self.cleanupModelResources() - } } } @@ -397,7 +385,7 @@ class WhisperState: NSObject, ObservableObject { private func checkCancellationAndCleanup() async -> Bool { if shouldCancelRecording { - await cleanupAndDismiss() + await dismissMiniRecorder() return true } return false @@ -405,9 +393,6 @@ class WhisperState: NSObject, ObservableObject { private func cleanupAndDismiss() async { await dismissMiniRecorder() - Task.detached(priority: .background) { - await self.cleanupModelResources() - } } }