import Foundation import SwiftUI @MainActor extension WhisperState { // Loads the default transcription model from UserDefaults func loadCurrentTranscriptionModel() { if let savedModelName = UserDefaults.standard.string(forKey: "CurrentTranscriptionModel"), let savedModel = allAvailableModels.first(where: { $0.name == savedModelName }) { currentTranscriptionModel = savedModel } } // Function to set any transcription model as default func setDefaultTranscriptionModel(_ model: any TranscriptionModel) { self.currentTranscriptionModel = model UserDefaults.standard.set(model.name, forKey: "CurrentTranscriptionModel") // For cloud models, clear the old loadedLocalModel if model.provider != .local { self.loadedLocalModel = nil } // Enable transcription for cloud models immediately since they don't need loading if model.provider != .local { self.isModelLoaded = true } // Post notification about the model change NotificationCenter.default.post(name: .didChangeModel, object: nil, userInfo: ["modelName": model.name]) NotificationCenter.default.post(name: .AppSettingsDidChange, object: nil) } func refreshAllAvailableModels() { let currentModelId = currentTranscriptionModel?.id allAvailableModels = PredefinedModels.models // If there was a current default model, find its new version in the refreshed list and update it. // This handles cases where the default model was edited. if let currentId = currentModelId, let updatedModel = allAvailableModels.first(where: { $0.id == currentId }) { setDefaultTranscriptionModel(updatedModel) } } }