diff --git a/VoiceInk/Whisper/WhisperState.swift b/VoiceInk/Whisper/WhisperState.swift index 42444b4..1dfee51 100644 --- a/VoiceInk/Whisper/WhisperState.swift +++ b/VoiceInk/Whisper/WhisperState.swift @@ -197,23 +197,10 @@ class WhisperState: NSObject, ObservableObject, AVAudioRecorderDelegate { self.recordedFile = file self.transcriptionStartTime = Date() - await ActiveWindowService.shared.applyConfigurationForCurrentApp() - - if let enhancementService = self.enhancementService, - enhancementService.isEnhancementEnabled && - enhancementService.useScreenCaptureContext { - await enhancementService.captureScreenContext() + Task.detached(priority: .background) { + await self.performBackgroundTasks() } - if let currentModel = self.currentModel, self.whisperContext == nil { - do { - try await self.loadModel(currentModel) - } catch { - await MainActor.run { - self.messageLog += "Error preloading model: \(error.localizedDescription)\n" - } - } - } } catch { self.messageLog += "\(error.localizedDescription)\n" self.isRecording = false @@ -227,6 +214,26 @@ class WhisperState: NSObject, ObservableObject, AVAudioRecorderDelegate { } } + private func performBackgroundTasks() async { + if let currentModel = self.currentModel, self.whisperContext == nil { + do { + try await self.loadModel(currentModel) + } catch { + await MainActor.run { + self.messageLog += "Error preloading model: \(error.localizedDescription)\n" + } + } + } + + await ActiveWindowService.shared.applyConfigurationForCurrentApp() + + if let enhancementService = self.enhancementService, + enhancementService.isEnhancementEnabled && + enhancementService.useScreenCaptureContext { + await enhancementService.captureScreenContext() + } + } + private func requestRecordPermission(response: @escaping (Bool) -> Void) { #if os(macOS) response(true)