From d47e32e07456048b8f649a6756e993d6f72ca2ca Mon Sep 17 00:00:00 2001 From: Beingpax Date: Tue, 17 Jun 2025 14:15:29 +0545 Subject: [PATCH] feat: Add custom model import/export --- VoiceInk/Services/CustomModelManager.swift | 2 +- VoiceInk/Services/ImportExportService.swift | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/VoiceInk/Services/CustomModelManager.swift b/VoiceInk/Services/CustomModelManager.swift index 1a9b910..41886f5 100644 --- a/VoiceInk/Services/CustomModelManager.swift +++ b/VoiceInk/Services/CustomModelManager.swift @@ -52,7 +52,7 @@ class CustomModelManager: ObservableObject { } } - private func saveCustomModels() { + func saveCustomModels() { do { let data = try JSONEncoder().encode(customModels) userDefaults.set(data, forKey: customModelsKey) diff --git a/VoiceInk/Services/ImportExportService.swift b/VoiceInk/Services/ImportExportService.swift index 14f5983..8ead1c5 100644 --- a/VoiceInk/Services/ImportExportService.swift +++ b/VoiceInk/Services/ImportExportService.swift @@ -28,6 +28,7 @@ struct VoiceInkExportedSettings: Codable { let wordReplacements: [String: String]? let generalSettings: GeneralSettings? let customEmojis: [String]? + let customCloudModels: [CustomCloudModel]? } class ImportExportService { @@ -64,6 +65,9 @@ class ImportExportService { let powerConfigs = powerModeManager.configurations let defaultPowerConfig = powerModeManager.defaultConfig + + // Export custom models + let customModels = CustomModelManager.shared.customModels var exportedDictionaryItems: [DictionaryItem]? = nil if let data = UserDefaults.standard.data(forKey: dictionaryItemsKey), @@ -96,7 +100,8 @@ class ImportExportService { dictionaryItems: exportedDictionaryItems, wordReplacements: exportedWordReplacements, generalSettings: generalSettingsToExport, - customEmojis: emojiManager.customEmojis + customEmojis: emojiManager.customEmojis, + customCloudModels: customModels ) let encoder = JSONEncoder() @@ -165,6 +170,17 @@ class ImportExportService { powerModeManager.saveConfigurations() powerModeManager.updateConfiguration(powerModeManager.defaultConfig) + // Import Custom Models + if let modelsToImport = importedSettings.customCloudModels { + let customModelManager = CustomModelManager.shared + customModelManager.customModels = modelsToImport + customModelManager.saveCustomModels() // Ensure they are persisted + whisperState.refreshAllAvailableModels() // Refresh the UI + print("Successfully imported \(modelsToImport.count) custom models.") + } else { + print("No custom models found in the imported file.") + } + if let customEmojis = importedSettings.customEmojis { let emojiManager = EmojiManager.shared for emoji in customEmojis {