From a115d90da745b7fa5aff7a3dd7102911ba0392c3 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 3 Jul 2026 08:19:28 +0000 Subject: [PATCH] fix: PersonalDictionaryView preview and AppGroupStore dictionary writes Use ThemedRoot in preview instead of inaccessible ThemePalette(). Add setPersonalDictionary(_:) for let AppGroupStore bindings; use it from PersonalDictionaryView and DictionaryLearner. Co-authored-by: Rocky --- OSGKeyboard/Services/DictionaryLearner.swift | 2 +- .../Views/PersonalDictionaryView.swift | 9 ++++++--- .../Services/AppGroupStore.swift | 20 +++++++++++-------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/OSGKeyboard/Services/DictionaryLearner.swift b/OSGKeyboard/Services/DictionaryLearner.swift index 0815f03..e11f84f 100644 --- a/OSGKeyboard/Services/DictionaryLearner.swift +++ b/OSGKeyboard/Services/DictionaryLearner.swift @@ -144,7 +144,7 @@ final class DictionaryLearner { if didChange { dictionary.version += 1 - store.personalDictionary = dictionary + store.setPersonalDictionary(dictionary) } // Suppress the "did not change" path; we still return the // bumped-counts view so the caller can refresh a UI label. diff --git a/OSGKeyboard/Views/PersonalDictionaryView.swift b/OSGKeyboard/Views/PersonalDictionaryView.swift index 922db10..50f5e30 100644 --- a/OSGKeyboard/Views/PersonalDictionaryView.swift +++ b/OSGKeyboard/Views/PersonalDictionaryView.swift @@ -224,11 +224,14 @@ struct PersonalDictionaryView: View { private func persist() { dictionary.version += 1 - store.personalDictionary = dictionary + store.setPersonalDictionary(dictionary) } } +#if DEBUG #Preview { - PersonalDictionaryView() - .environment(\.themePalette, ThemePalette()) + ThemedRoot { + PersonalDictionaryView() + } } +#endif diff --git a/OSGKeyboardShared/Services/AppGroupStore.swift b/OSGKeyboardShared/Services/AppGroupStore.swift index 0879835..b99b5f4 100644 --- a/OSGKeyboardShared/Services/AppGroupStore.swift +++ b/OSGKeyboardShared/Services/AppGroupStore.swift @@ -341,14 +341,18 @@ public struct AppGroupStore: @unchecked Sendable { } } set { - do { - let data = try JSONEncoder().encode(newValue) - defaults.set(data, forKey: Key.personalDictionary) - } catch { - #if DEBUG - print("⚠️ [AppGroupStore] personalDictionary encode failed: \(error)") - #endif - } + setPersonalDictionary(newValue) + } + } + + public func setPersonalDictionary(_ dictionary: PersonalDictionary) { + do { + let data = try JSONEncoder().encode(dictionary) + defaults.set(data, forKey: Key.personalDictionary) + } catch { + #if DEBUG + print("⚠️ [AppGroupStore] personalDictionary encode failed: \(error)") + #endif } }