Files
OSGKeyboard/OSGKeyboardMac/MacICloudSyncBootstrap.swift
T
Rocky 937ce33f05 feat(polish): add configurable style packs
Add shared prompt composition, custom style management, iCloud sync, and native iOS/macOS selection interfaces so users can keep a consistent writing voice across devices.
2026-07-26 12:34:43 +08:00

45 lines
1.4 KiB
Swift

// MacICloudSyncBootstrap.swift
// OSGKeyboard · Mac
//
// Wires the shared iCloud KVS sync layer to macOS UserDefaults so settings
// and personal dictionary stay aligned with the iOS app.
import Foundation
@MainActor
enum MacICloudSyncBootstrap {
private static var configured = false
private static var cloudSync: AppCloudSync?
static func configure(defaults: UserDefaults) {
guard !configured else { return }
configured = true
let makeStore = { AppGroupStore(defaults: defaults) }
cloudSync = AppCloudSync(makeStore: makeStore, historyDefaults: { defaults })
cloudSync?.startObservingExternalChanges()
}
static func pullIfEnabled() async {
await cloudSync?.pullAllIfEnabled()
}
static var settingsSync: SettingsCloudSync {
if let cloudSync {
return cloudSync.settingsSyncService
}
return SettingsCloudSync(makeStore: { AppGroupStore(defaults: .standard) })
}
static var dictionarySync: PersonalDictionaryCloudSync {
cloudSync?.dictionarySyncService ?? PersonalDictionaryCloudSync(makeStore: { AppGroupStore(defaults: .standard) })
}
static var polishStyleSync: PolishStyleCloudSync {
cloudSync?.polishStyleSyncService ?? PolishStyleCloudSync(makeStore: { AppGroupStore(defaults: .standard) })
}
static var appCloudSync: AppCloudSync {
cloudSync ?? AppCloudSync.shared
}
}