Explorar el Código

Replace custom notification with combine publisher for Determination inthe LA bridge

polscm32 aka Marvout hace 1 año
padre
commit
ef15c98ec1

+ 0 - 31
FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift

@@ -86,37 +86,6 @@ final class OpenAPS {
 
         // First save the current Determination to Core Data
         await attemptToSaveContext()
-
-        // After that check for changes in iob and cob and if there are any post a custom Notification
-        /// this is currently used to update Live Activity so that it stays up to date and not one loop cycle behind
-        await checkForCobIobUpdate(determination)
-    }
-
-    func checkForCobIobUpdate(_ determination: Determination) async {
-        let results = await CoreDataStack.shared.fetchEntitiesAsync(
-            ofType: OrefDetermination.self,
-            onContext: context,
-            predicate: NSPredicate.predicateFor30MinAgoForDetermination,
-            key: "deliverAt",
-            ascending: false,
-            fetchLimit: 2
-        )
-
-        await context.perform {
-            guard let previousDeterminations = results as? [OrefDetermination] else {
-                return
-            }
-
-            // We need to get the second last Determination for this comparison because we have saved the current Determination already to Core Data
-            if let previousDetermination = previousDeterminations.dropFirst().first {
-                let iobChanged = previousDetermination.iob != self.decimalToNSDecimalNumber(determination.iob)
-                let cobChanged = previousDetermination.cob != Int16(Int(determination.cob ?? 0))
-
-                if iobChanged || cobChanged {
-                    Foundation.NotificationCenter.default.post(name: .didUpdateCobIob, object: nil)
-                }
-            }
-        }
     }
 
     func attemptToSaveContext() async {

+ 0 - 1
FreeAPS/Sources/Services/LiveActivity/LiveActivityBridge.swift

@@ -68,7 +68,6 @@ import UIKit
 
     private func setupNotifications() {
         let notificationCenter = Foundation.NotificationCenter.default
-        notificationCenter.addObserver(self, selector: #selector(cobOrIobDidUpdate), name: .didUpdateCobIob, object: nil)
         notificationCenter
             .addObserver(forName: UIApplication.didEnterBackgroundNotification, object: nil, queue: nil) { [weak self] _ in
                 self?.forceActivityUpdate()

+ 0 - 1
Model/Helper/CustomNotification.swift

@@ -2,5 +2,4 @@ import Foundation
 
 extension Notification.Name {
     static let didUpdateOverrideConfiguration = Notification.Name("didUpdateOverrideConfiguration")
-    static let didUpdateCobIob = Notification.Name("didUpdateCobIob")
 }