From 8add0a801afc115e3b635c4f578bb2d6d4982f6f Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Sun, 4 Jan 2026 13:28:20 -0600 Subject: [PATCH] Fix CloudSyncManager sync status getting stuck on 'Syncing...' - Set initial sync status on init based on iCloud availability - Update status after initial synchronize call in init - Properly set isSyncing and syncStatus in scheduleDelayedCloudCheck - Update syncStatus to 'Synced' after handling cloud changes --- .../Bedrock/Storage/CloudSyncManager.swift | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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"