Browse Source

Auto-off + disable Use CGM App Alerts toggle when no companion owns alerts

A LibreLoop user upgrading from an older build saw the toggle stuck
ON for Libre 3 — but LibreLoop has no companion app and Trio is
always the alerter for it. The toggle visible state was just the
inverted stored bool, regardless of which CGM was active, so it
misled users into thinking another app was handling alarms when
nothing was.

When the active CGM is not in CGMManagerAlertOwnership's table,
display the toggle as OFF and disable interaction, and swap the
footer to "Your CGM has no companion app, so Trio handles alarms."
The stored preference is preserved, so swapping back to a G6 / G7 /
xDrip restores the user's prior choice.
trioneer 2 tuần trước cách đây
mục cha
commit
679a8a0430

+ 27 - 4
Trio/Sources/Modules/GlucoseAlerts/View/GlucoseAlertsRootView.swift

@@ -67,15 +67,21 @@ extension GlucoseAlerts {
                         .navigationLink(to: .alarmWindows, from: self)
                 }.listRowBackground(Color.chart)
 
-                Section(footer: Text(
-                    "Your CGM app handles alerts (Dexcom G6 / One, G7 / One+, or xDrip4iOS). Turn off to let Trio alert you."
-                )) {
+                Section(footer: Text(useCGMAlertsFooter)) {
                     Toggle(isOn: Binding(
-                        get: { !store.configuration.forceTrioAlertsWhenCGMProvidesOwn },
+                        // When the active CGM has no companion app to defer
+                        // to, force the visible state OFF regardless of the
+                        // stored preference — there's nothing for the toggle
+                        // to control, so showing it ON would mislead.
+                        get: {
+                            guard state.cgmProvidesOwnAlerts else { return false }
+                            return !store.configuration.forceTrioAlertsWhenCGMProvidesOwn
+                        },
                         set: { store.configuration.forceTrioAlertsWhenCGMProvidesOwn = !$0 }
                     )) {
                         Text("Use CGM App Alerts")
                     }
+                    .disabled(!state.cgmProvidesOwnAlerts)
                 }.listRowBackground(Color.chart)
 
                 SettingInputSection(
@@ -179,6 +185,23 @@ extension GlucoseAlerts {
                 }
         }
 
+        /// Footer for the "Use CGM App Alerts" toggle. Names the eligible
+        /// CGMs when one of them is active and the user can decide; when
+        /// the active CGM has no companion app the toggle is disabled and
+        /// the footer says Trio is handling alarms.
+        private var useCGMAlertsFooter: String {
+            if state.cgmProvidesOwnAlerts {
+                return String(
+                    localized:
+                    "Your CGM app handles alerts (Dexcom G6 / One, G7 / One+, or xDrip4iOS). Turn off to let Trio alert you."
+                )
+            }
+            return String(
+                localized:
+                "Your CGM has no companion app, so Trio handles alarms."
+            )
+        }
+
         /// Footer for the "Handled by CGM App" section. Names the specific
         /// companion app, and renders its name as a deep link when a URL
         /// scheme is known for that app (see CGMManagerAlertOwnership).