Просмотр исходного кода

remove cache cleaning, to skip the optimistic watchstate prep

Robert 7 месяцев назад
Родитель
Сommit
b0d34d2c5e
1 измененных файлов с 24 добавлено и 23 удалено
  1. 24 23
      Trio/Sources/Services/WatchManager/GarminManager.swift

+ 24 - 23
Trio/Sources/Services/WatchManager/GarminManager.swift

@@ -1059,42 +1059,43 @@ final class BaseGarminManager: NSObject, GarminManager, Injectable, @unchecked S
     }
     
     /// Checks if any Garmin apps are likely to receive data based on cached status and settings
-    /// Returns true if cache suggests apps will receive data, or if cache is empty/stale (optimistic)
+    /// Returns true if cache suggests apps will receive data, or if cache is empty (optimistic on first check)
     /// Considers both app installation status AND whether watchface data is disabled
+    /// Cache is trusted indefinitely and only cleared on settings changes or device re-registration
     private func areAppsLikelyInstalled() -> Bool {
         appStatusCacheLock.lock()
         defer { appStatusCacheLock.unlock() }
         
-        // If cache is empty, be optimistic and allow data preparation
+        // Get current watchface info for disabled check (always accurate, not cached)
+        let watchface = currentWatchface
+        let watchfaceUUIDString = watchface.watchfaceUUID?.uuidString
+        
+        // If cache is empty, check if we should be optimistic
         guard !appInstallationCache.isEmpty else {
+            // Even with empty cache, check if watchface data is disabled
+            // If disabled and no datafield in cache, we know nothing will receive data
+            if isWatchfaceDataDisabled {
+                // No cache entries and watchface disabled means likely no receivers
+                debugGarmin("[\(formatTimeForLog())] Garmin: ⏩ Skipping data preparation - watchface disabled, no cache for datafield")
+                return false
+            }
+            // Be optimistic on first check - assume datafield might be installed
             return true
         }
         
-        let now = Date()
-        let watchface = currentWatchface
-        let watchfaceUUIDString = watchface.watchfaceUUID?.uuidString
-        
-        // Check if ANY app will actually receive data
+        // Check each app in cache (trust cache indefinitely - no timeout)
         for (uuidString, status) in appInstallationCache {
-            let cacheAge = now.timeIntervalSince(status.lastChecked)
-            
-            // If cache is stale, be optimistic
-            if cacheAge > appStatusCacheTimeout {
-                return true
-            }
-            
-            // Skip if app is not installed
-            guard status.isInstalled else {
-                continue
+            // If this is the watchface and data is disabled, skip it regardless of cache
+            if uuidString == watchfaceUUIDString {
+                if isWatchfaceDataDisabled {
+                    continue // Watchface won't receive data (disabled) - check other apps
+                }
             }
             
-            // If this is the watchface UUID and watchface data is disabled, it won't receive data
-            if uuidString == watchfaceUUIDString, isWatchfaceDataDisabled {
-                continue // Watchface installed but disabled - skip it
+            // If app is installed (per cache), we have a receiver
+            if status.isInstalled {
+                return true // Found a receiver
             }
-            
-            // Found an app that is installed and will receive data!
-            return true
         }
         
         // No apps will receive data (either not installed or watchface is disabled)