Optimize recorder startup

This commit is contained in:
Beingpax 2025-12-07 09:26:52 +05:45
parent 557ac95478
commit 85e26856df
2 changed files with 29 additions and 22 deletions

View File

@ -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()
}
}

View File

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