diff --git a/Sources/Bedrock/Storage/CloudSyncManager.swift b/Sources/Bedrock/Storage/CloudSyncManager.swift index 43be448..b7b5659 100644 --- a/Sources/Bedrock/Storage/CloudSyncManager.swift +++ b/Sources/Bedrock/Storage/CloudSyncManager.swift @@ -153,6 +153,15 @@ public final class CloudSyncManager { UserDefaults.standard.set(true, forKey: iCloudEnabledKey) } + // Set initial sync status + if !iCloudAvailable { + syncStatus = "iCloud unavailable" + } else if !iCloudEnabled { + syncStatus = "Sync disabled" + } else { + syncStatus = "Ready" + } + // Register for iCloud changes if iCloudAvailable, let store = iCloudStore { NotificationCenter.default.addObserver( @@ -173,6 +182,8 @@ public final class CloudSyncManager { // Trigger iCloud sync if iCloudEnabled { store.synchronize() + lastSyncDate = Date() + syncStatus = "Synced" } } @@ -337,11 +348,15 @@ public final class CloudSyncManager { private func scheduleDelayedCloudCheck() { Design.debugLog("CloudSyncManager[\(T.dataIdentifier)]: Scheduling delayed cloud check...") + isSyncing = true + syncStatus = "Syncing..." Task { @MainActor in try? await Task.sleep(for: .seconds(2)) guard let store = iCloudStore else { + isSyncing = false + syncStatus = "iCloud unavailable" hasCompletedInitialSync = true return } @@ -364,6 +379,9 @@ public final class CloudSyncManager { ) } + isSyncing = false + lastSyncDate = Date() + syncStatus = "Synced" hasCompletedInitialSync = true } } @@ -375,7 +393,6 @@ public final class CloudSyncManager { case NSUbiquitousKeyValueStoreServerChange, NSUbiquitousKeyValueStoreInitialSyncChange: Design.debugLog("CloudSyncManager[\(T.dataIdentifier)]: Data changed from another device") - syncStatus = "Received update" if let cloudData = loadCloud(), cloudData.syncPriority > data.syncPriority { data = cloudData @@ -392,6 +409,9 @@ public final class CloudSyncManager { ) } + lastSyncDate = Date() + syncStatus = "Synced" + case NSUbiquitousKeyValueStoreQuotaViolationChange: Design.debugLog("CloudSyncManager[\(T.dataIdentifier)]: iCloud quota exceeded") syncStatus = "Storage full"