diff --git a/VoiceInk/Whisper/WhisperState+UI.swift b/VoiceInk/Whisper/WhisperState+UI.swift index 7cebeda..c13d7dc 100644 --- a/VoiceInk/Whisper/WhisperState+UI.swift +++ b/VoiceInk/Whisper/WhisperState+UI.swift @@ -42,11 +42,11 @@ extension WhisperState { } else { SoundManager.shared.playStartSound() - await toggleRecord() - await MainActor.run { isMiniRecorderVisible = true // This will call showRecorderPanel() via didSet } + + await toggleRecord() } } diff --git a/VoiceInk/Whisper/WhisperState.swift b/VoiceInk/Whisper/WhisperState.swift index 76b0f48..273beac 100644 --- a/VoiceInk/Whisper/WhisperState.swift +++ b/VoiceInk/Whisper/WhisperState.swift @@ -192,34 +192,41 @@ class WhisperState: NSObject, ObservableObject { let fileName = "\(UUID().uuidString).wav" let permanentURL = self.recordingsDirectory.appendingPathComponent(fileName) self.recordedFile = permanentURL - + try await self.recorder.startRecording(toOutputFile: permanentURL) - + await MainActor.run { self.recordingState = .recording } - + await ActiveWindowService.shared.applyConfigurationForCurrentApp() - - // Only load model if it's a local model and not already loaded - if let model = self.currentTranscriptionModel, model.provider == .local { - if let localWhisperModel = self.availableModels.first(where: { $0.name == model.name }), - self.whisperContext == nil { - do { - try await self.loadModel(localWhisperModel) - } catch { - self.logger.error("❌ Model loading failed: \(error.localizedDescription)") + + // Load model and capture context in background without blocking + Task.detached { [weak self] in + guard let self = self else { return } + + // Only load model if it's a local model and not already loaded + if let model = await self.currentTranscriptionModel, model.provider == .local { + if let localWhisperModel = await self.availableModels.first(where: { $0.name == model.name }), + await self.whisperContext == nil { + do { + try await self.loadModel(localWhisperModel) + } catch { + await self.logger.error("❌ Model loading failed: \(error.localizedDescription)") + } } + } else if let parakeetModel = await self.currentTranscriptionModel as? ParakeetModel { + try? await self.parakeetTranscriptionService.loadModel(for: parakeetModel) + } + + if let enhancementService = await self.enhancementService { + await MainActor.run { + enhancementService.captureClipboardContext() + } + await enhancementService.captureScreenContext() } - } else if let parakeetModel = self.currentTranscriptionModel as? ParakeetModel { - try? await self.parakeetTranscriptionService.loadModel(for: parakeetModel) } - - if let enhancementService = self.enhancementService { - enhancementService.captureClipboardContext() - await enhancementService.captureScreenContext() - } - + } catch { self.logger.error("❌ Failed to start recording: \(error.localizedDescription)") await NotificationManager.shared.showNotification(title: "Recording failed to start", type: .error)