Przeglądaj źródła

Cover xDrip4iOS in CGM-owns-alerts gate; expose owning app name and deep link

The xdrip source has no CGMManager instance (it runs through
AppGroupSource), so the previous manager-only check missed it and the
coordinator kept firing Trio alerts even when xDrip4iOS owned them.
Take CGMType in addition to the manager so .xdrip is covered.

Also return an OwningApp { name, deepLink } from the lookup so the
glucose-alarms UI can name the specific companion app and link to it
when its URL scheme is known.
trioneer 2 tygodni temu
rodzic
commit
dadca6b344

+ 30 - 7
Trio/Sources/Services/Alerts/CGMManagerAlertOwnership.swift

@@ -6,15 +6,38 @@ import LoopKit
 /// Trio-side stand-in for LoopKit next-dev's `CGMManager.providesOwnGlucoseAlerts`.
 /// Trio-side stand-in for LoopKit next-dev's `CGMManager.providesOwnGlucoseAlerts`.
 /// Collapses to `manager?.providesOwnGlucoseAlerts ?? false` once the fork bumps.
 /// Collapses to `manager?.providesOwnGlucoseAlerts ?? false` once the fork bumps.
 enum CGMManagerAlertOwnership {
 enum CGMManagerAlertOwnership {
-    static func providesOwnGlucoseAlerts(_ manager: CGMManager?) -> Bool {
+    struct OwningApp {
+        let name: String
+        /// URL scheme registered by the companion app, if known. Schemes
+        /// taken from the corresponding manager UI: `dexcomg6://` from
+        /// CGMBLEKitUI's TransmitterSettingsViewController, `dexcomg7://`
+        /// from G7SensorKitUI's G7SettingsView, `xdripswift://` from
+        /// Trio's own CGMType.appURL. The manager protocol's `appURL`
+        /// returns nil on our forks, so this table is the source of truth.
+        let deepLink: URL?
+    }
+
+    static func providesOwnGlucoseAlerts(manager: CGMManager?, sourceType: CGMType) -> Bool {
+        owningApp(manager: manager, sourceType: sourceType) != nil
+    }
+
+    static func owningApp(manager: CGMManager?, sourceType: CGMType) -> OwningApp? {
+        // `.xdrip` runs without a CGMManager instance (App Group source),
+        // so check the source type first.
+        if sourceType == .xdrip {
+            return OwningApp(name: "xDrip4iOS", deepLink: URL(string: "xdripswift://"))
+        }
         switch manager {
         switch manager {
-        case is G5CGMManager,
-             is G6CGMManager,
-             is G7CGMManager,
-             is LibreTransmitterManagerV3:
-            return true
+        case is G5CGMManager:
+            return OwningApp(name: "Dexcom G5", deepLink: nil)
+        case is G6CGMManager:
+            return OwningApp(name: "Dexcom G6 / One", deepLink: URL(string: "dexcomg6://"))
+        case is G7CGMManager:
+            return OwningApp(name: "Dexcom G7 / One+", deepLink: URL(string: "dexcomg7://"))
+        case is LibreTransmitterManagerV3:
+            return OwningApp(name: "FreeStyle Libre", deepLink: nil)
         default:
         default:
-            return false
+            return nil
         }
         }
     }
     }
 }
 }

+ 4 - 1
Trio/Sources/Services/Alerts/GlucoseAlertCoordinator.swift

@@ -97,7 +97,10 @@ final class GlucoseAlertCoordinator: Injectable {
 
 
     private var effectiveTrioAlertsEnabled: Bool {
     private var effectiveTrioAlertsEnabled: Bool {
         if configurationSnapshot.forceTrioAlertsWhenCGMProvidesOwn { return true }
         if configurationSnapshot.forceTrioAlertsWhenCGMProvidesOwn { return true }
-        return !CGMManagerAlertOwnership.providesOwnGlucoseAlerts(fetchGlucoseManager?.cgmManager)
+        return !CGMManagerAlertOwnership.providesOwnGlucoseAlerts(
+            manager: fetchGlucoseManager?.cgmManager,
+            sourceType: fetchGlucoseManager?.cgmGlucoseSourceType ?? .none
+        )
     }
     }
 
 
     init(resolver: Resolver) {
     init(resolver: Resolver) {