diff --git a/VoiceInk/AppDelegate.swift b/VoiceInk/AppDelegate.swift index 20cd81e..6fa851e 100644 --- a/VoiceInk/AppDelegate.swift +++ b/VoiceInk/AppDelegate.swift @@ -5,7 +5,6 @@ import UniformTypeIdentifiers class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ notification: Notification) { updateActivationPolicy() - cleanupLegacyUserDefaults() } func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { @@ -45,12 +44,6 @@ class AppDelegate: NSObject, NSApplicationDelegate { } } - private func cleanupLegacyUserDefaults() { - let defaults = UserDefaults.standard - defaults.removeObject(forKey: "defaultPowerModeConfigV2") - defaults.removeObject(forKey: "isPowerModeEnabled") - } - // Stash URL when app cold-starts to avoid spawning a new window/tab var pendingOpenFileURL: URL? diff --git a/VoiceInk/HotkeyManager.swift b/VoiceInk/HotkeyManager.swift index 1f0aa34..2c8681c 100644 --- a/VoiceInk/HotkeyManager.swift +++ b/VoiceInk/HotkeyManager.swift @@ -117,22 +117,6 @@ class HotkeyManager: ObservableObject { } init(whisperState: WhisperState) { - // One-time migration from legacy single-hotkey settings - if UserDefaults.standard.object(forKey: "didMigrateHotkeys_v2") == nil { - // If legacy push-to-talk modifier key was enabled, carry it over - if UserDefaults.standard.bool(forKey: "isPushToTalkEnabled"), - let legacyRaw = UserDefaults.standard.string(forKey: "pushToTalkKey"), - let legacyKey = HotkeyOption(rawValue: legacyRaw) { - UserDefaults.standard.set(legacyKey.rawValue, forKey: "selectedHotkey1") - } - // If a custom shortcut existed, mark hotkey-1 as custom (shortcut itself already persisted) - if KeyboardShortcuts.getShortcut(for: .toggleMiniRecorder) != nil { - UserDefaults.standard.set(HotkeyOption.custom.rawValue, forKey: "selectedHotkey1") - } - // Leave second hotkey as .none - UserDefaults.standard.set(true, forKey: "didMigrateHotkeys_v2") - } - // ---- normal initialisation ---- self.selectedHotkey1 = HotkeyOption(rawValue: UserDefaults.standard.string(forKey: "selectedHotkey1") ?? "") ?? .rightCommand self.selectedHotkey2 = HotkeyOption(rawValue: UserDefaults.standard.string(forKey: "selectedHotkey2") ?? "") ?? .none diff --git a/VoiceInk/Services/AIEnhancementService.swift b/VoiceInk/Services/AIEnhancementService.swift index 70b0b2a..bbab7f1 100644 --- a/VoiceInk/Services/AIEnhancementService.swift +++ b/VoiceInk/Services/AIEnhancementService.swift @@ -80,7 +80,12 @@ class AIEnhancementService: ObservableObject { self.useClipboardContext = UserDefaults.standard.bool(forKey: "useClipboardContext") self.useScreenCaptureContext = UserDefaults.standard.bool(forKey: "useScreenCaptureContext") - self.customPrompts = PromptMigrationService.migratePromptsIfNeeded() + if let savedPromptsData = UserDefaults.standard.data(forKey: "customPrompts"), + let decodedPrompts = try? JSONDecoder().decode([CustomPrompt].self, from: savedPromptsData) { + self.customPrompts = decodedPrompts + } else { + self.customPrompts = [] + } if let savedPromptId = UserDefaults.standard.string(forKey: "selectedPromptId") { self.selectedPromptId = UUID(uuidString: savedPromptId) diff --git a/VoiceInk/Services/PromptMigrationService.swift b/VoiceInk/Services/PromptMigrationService.swift deleted file mode 100644 index 907645f..0000000 --- a/VoiceInk/Services/PromptMigrationService.swift +++ /dev/null @@ -1,104 +0,0 @@ -import Foundation -import os - -class PromptMigrationService { - private let logger = Logger( - subsystem: "com.prakashjoshipax.VoiceInk", - category: "migration" - ) - - private static let migrationVersionKey = "PromptMigrationVersion" - private static let currentMigrationVersion = 1 - - // Legacy CustomPrompt structure for migration - private struct LegacyCustomPrompt: Codable { - let id: UUID - let title: String - let promptText: String - var isActive: Bool - let icon: PromptIcon - let description: String? - let isPredefined: Bool - let triggerWord: String? - } - - static func migratePromptsIfNeeded() -> [CustomPrompt] { - let currentVersion = UserDefaults.standard.integer(forKey: migrationVersionKey) - - if currentVersion < currentMigrationVersion { - let logger = Logger(subsystem: "com.prakashjoshipax.VoiceInk", category: "migration") - logger.notice("Starting prompt migration from version \(currentVersion) to \(currentMigrationVersion)") - - let migratedPrompts = migrateLegacyPrompts() - - // Update migration version - UserDefaults.standard.set(currentMigrationVersion, forKey: migrationVersionKey) - - logger.notice("Prompt migration completed successfully. Migrated \(migratedPrompts.count) prompts") - return migratedPrompts - } - - // No migration needed, load current format - if let savedPromptsData = UserDefaults.standard.data(forKey: "customPrompts"), - let decodedPrompts = try? JSONDecoder().decode([CustomPrompt].self, from: savedPromptsData) { - return decodedPrompts - } - - return [] - } - - private static func migrateLegacyPrompts() -> [CustomPrompt] { - let logger = Logger(subsystem: "com.prakashjoshipax.VoiceInk", category: "migration") - - // Try to load legacy prompts - guard let savedPromptsData = UserDefaults.standard.data(forKey: "customPrompts") else { - logger.notice("No existing prompts found to migrate") - return [] - } - - // First try to decode as new format (in case migration already happened) - if let newFormatPrompts = try? JSONDecoder().decode([CustomPrompt].self, from: savedPromptsData) { - logger.notice("Prompts are already in new format, no migration needed") - return newFormatPrompts - } - - // Try to decode as legacy format - guard let legacyPrompts = try? JSONDecoder().decode([LegacyCustomPrompt].self, from: savedPromptsData) else { - logger.error("Failed to decode legacy prompts, starting with empty array") - return [] - } - - logger.notice("Migrating \(legacyPrompts.count) legacy prompts") - - // Convert legacy prompts to new format - let migratedPrompts = legacyPrompts.map { legacyPrompt in - let triggerWords: [String] = if let triggerWord = legacyPrompt.triggerWord?.trimmingCharacters(in: .whitespacesAndNewlines), - !triggerWord.isEmpty { - [triggerWord] - } else { - [] - } - - return CustomPrompt( - id: legacyPrompt.id, - title: legacyPrompt.title, - promptText: legacyPrompt.promptText, - isActive: legacyPrompt.isActive, - icon: legacyPrompt.icon, - description: legacyPrompt.description, - isPredefined: legacyPrompt.isPredefined, - triggerWords: triggerWords - ) - } - - // Save migrated prompts in new format - if let encoded = try? JSONEncoder().encode(migratedPrompts) { - UserDefaults.standard.set(encoded, forKey: "customPrompts") - logger.notice("Successfully saved migrated prompts") - } else { - logger.error("Failed to save migrated prompts") - } - - return migratedPrompts - } -} \ No newline at end of file