Files
OSGKeyboard/OSGKeyboardShared/Services/ICloudSync/ICloudSyncPreferences.swift
T
Rocky 128aab1b02 feat: iCloud settings sync and cold-start return redesign
- Add iCloud key-value settings sync (engine/language/polish/Flow prefs);
  API keys stay on-device. New "Sync settings via iCloud" toggle.
- Redesign cold-start handoff: bottom-bar left-to-right swipe guidance,
  auto-dismiss on app switch, tap-anywhere to close, retained return link.
- Harden keyboard->app handoff with host-disconnected hint.
- Include prior Unreleased ASR fixes (route-change crash, fallback warning,
  multi-utterance recognition, local ASR diagnostics).

Release 0.5.0 (build 18).
2026-07-07 17:56:01 +08:00

54 lines
2.2 KiB
Swift

// ICloudSyncPreferences.swift
// OSGKeyboard · Shared
//
// iCloud KVS is the source of truth for cross-device sync toggles
// (scheme A). App Group UserDefaults keeps a local cache so the
// keyboard extension and offline UI can read the last-known state.
import Foundation
public enum ICloudSyncPreferences {
public static let settingsEnabledKey = "iCloudSync.settingsEnabled"
public static let dictionaryEnabledKey = "personalDictionary.syncEnabled"
/// Read sync toggles from KVS, falling back to the App Group cache
/// when a key has not been uploaded yet.
public static func load(from kvs: UbiquitousKeyValueStoreing, store: AppGroupStore) -> (settings: Bool, dictionary: Bool) {
let settings = kvs.object(forKey: settingsEnabledKey) as? Bool
?? store.settingsICloudSyncEnabled
let dictionary = kvs.object(forKey: dictionaryEnabledKey) as? Bool
?? store.personalDictionaryICloudSyncEnabled
return (settings, dictionary)
}
/// Mirror KVS toggles into the App Group cache.
public static func cacheToAppGroup(
settingsEnabled: Bool,
dictionaryEnabled: Bool,
store: AppGroupStore
) {
store.setSettingsICloudSyncEnabled(settingsEnabled)
store.setPersonalDictionaryICloudSyncEnabled(dictionaryEnabled)
}
public static func pushSettingsEnabled(_ enabled: Bool, kvs: UbiquitousKeyValueStoreing) {
kvs.set(enabled, forKey: settingsEnabledKey)
_ = kvs.synchronize()
}
public static func pushDictionaryEnabled(_ enabled: Bool, kvs: UbiquitousKeyValueStoreing) {
kvs.set(enabled, forKey: dictionaryEnabledKey)
_ = kvs.synchronize()
}
/// One-time migration: upload locally cached toggles when KVS has no value yet.
public static func migrateLegacyTogglesIfNeeded(kvs: UbiquitousKeyValueStoreing, store: AppGroupStore) {
if kvs.object(forKey: dictionaryEnabledKey) == nil {
pushDictionaryEnabled(store.personalDictionaryICloudSyncEnabled, kvs: kvs)
}
if kvs.object(forKey: settingsEnabledKey) == nil {
pushSettingsEnabled(store.settingsICloudSyncEnabled, kvs: kvs)
}
}
}