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

Replaces Garmin watchface switch cooldown with confirmation dialog

Removes the fixed 20-second lockout when switching watchfaces in favor of a manual confirmation flow. Users are now prompted to resume data transmission via a dialog after they have finished updating the watchface on their Garmin device, providing a more flexible and user-driven experience.
Robert 1 месяц назад
Родитель
Сommit
358f79ad68

+ 9 - 0
Trio/Sources/Localizations/Main/Localizable.xcstrings

@@ -77906,6 +77906,9 @@
     "Data Choice 2" : {
 
     },
+    "Data transmission has been disabled. Now select the new watchface on your Garmin device and resume data transmission once done." : {
+
+    },
     "Datafield Selection" : {
 
     },
@@ -200317,6 +200320,9 @@
         }
       }
     },
+    "Resume Data Transmission" : {
+
+    },
     "Resume Insulin Delivery" : {
       "comment" : "Text for suspend resume button when insulin delivery is suspended",
       "extractionState" : "manual",
@@ -268375,6 +268381,9 @@
         }
       }
     },
+    "Watchface Changed" : {
+
+    },
     "Watchface Selection" : {
 
     },

+ 17 - 20
Trio/Sources/Modules/WatchConfig/View/WatchConfigGarminAppConfigView.swift

@@ -8,6 +8,7 @@ struct WatchConfigGarminAppConfigView: View {
     @State private var shouldDisplayHint3: Bool = false
     @State private var shouldDisplayHint4: Bool = false
     @State var hintDetent = PresentationDetent.large
+    @State private var showWatchfaceSwitchConfirmDialog: Bool = false
 
     @Environment(\.colorScheme) var colorScheme
     @Environment(AppState.self) var appState
@@ -29,8 +30,11 @@ struct WatchConfigGarminAppConfigView: View {
                             }
                         }
                         .padding(.top)
-                        .onChange(of: state.garminSettings.watchface) { _ in
-                            state.handleWatchfaceChange()
+                        .onChange(of: state.garminSettings.watchface) { oldValue, newValue in
+                            if oldValue != newValue {
+                                state.handleWatchfaceChange()
+                                showWatchfaceSwitchConfirmDialog = true
+                            }
                         }
 
                         HStack(alignment: .center) {
@@ -60,22 +64,6 @@ struct WatchConfigGarminAppConfigView: View {
                             get: { !state.garminSettings.isWatchfaceDataEnabled },
                             set: { state.garminSettings.isWatchfaceDataEnabled = !$0 }
                         ))
-                            .disabled(state.isWatchfaceDataCooldownActive)
-
-                        // Display cooldown warning when toggle is locked
-                        if state.isWatchfaceDataCooldownActive {
-                            HStack {
-                                Text(
-                                    "Please wait \(state.watchfaceSwitchCooldownSeconds) seconds!\n\n" +
-                                        "After the lockout you can re-enable watchface data transmission, but you need to change to the new watchface on your Garmin watch before that - e.g. now!"
-                                )
-                                .font(.footnote)
-                                .foregroundColor(.orange)
-                                .multilineTextAlignment(.leading)
-                                .lineLimit(nil)
-                                Spacer()
-                            }
-                        }
 
                         HStack(alignment: .center) {
                             Text(
@@ -200,7 +188,7 @@ struct WatchConfigGarminAppConfigView: View {
                         "• Trio – The original Trio watchface, developed by Ivan Valkou.\n" +
                         "• Swissalpine – Originally developed for AAPS, adapted to work with Trio.\n\n" +
                         "You must use this configuration setting here BEFORE you switch the watchface on your Garmin device to another watchface.\n\n" +
-                        "⚠️ Changing the watchface will automatically disable data transmission and lock that setting for 20 seconds to allow time for you to switch the watchface on your Garmin device."
+                        "⚠️ Changing the watchface will automatically disable data transmission. You will be prompted to resume data transmission after you have changed the watchface on your Garmin device."
                 ),
                 sheetTitle: String(localized: "Help", comment: "Help sheet title")
             )
@@ -226,7 +214,7 @@ struct WatchConfigGarminAppConfigView: View {
                 hintLabel: "Disable watchface data transmission",
                 hintText: Text(
                     "Important: If you want to use a different watchface on your Garmin device that has no data requirement from this app, disable data transmission to the Garmin watchface app! Otherwise you will not be able to get current data once you re-enable the supported watchface that shows Trio data and you will have to re-install it on your Garmin device.\n\n" +
-                        "Note: When switching between supported watchfaces, data transmission is automatically disabled for 20 seconds. You would manually need to re-enable it."
+                        "Note: When switching between supported watchfaces, data transmission is automatically disabled. You will be prompted to resume data transmission after you have changed the watchface on your Garmin device."
                 ),
                 sheetTitle: String(localized: "Help", comment: "Help sheet title")
             )
@@ -249,5 +237,14 @@ struct WatchConfigGarminAppConfigView: View {
                 sheetTitle: String(localized: "Help", comment: "Help sheet title")
             )
         }
+        .confirmationDialog("Watchface Changed", isPresented: $showWatchfaceSwitchConfirmDialog) {
+            Button("Resume Data Transmission") {
+                state.resumeDataTransmission()
+            }
+        } message: {
+            Text(
+                "Data transmission has been disabled. Now select the new watchface on your Garmin device and resume data transmission once done."
+            )
+        }
     }
 }

+ 4 - 44
Trio/Sources/Modules/WatchConfig/WatchConfigStateModel.swift

@@ -13,20 +13,8 @@ extension WatchConfig {
         /// Garmin watch settings containing all watch-related configuration
         @Published var garminSettings = GarminWatchSettings()
 
-        /// Indicates if the enable/disable toggle is locked during cooldown period
-        @Published var isWatchfaceDataCooldownActive: Bool = false
-
-        /// Remaining seconds in the cooldown period
-        @Published var watchfaceSwitchCooldownSeconds: Int = 0
-
         private(set) var preferences = Preferences()
 
-        /// Timer for managing the 20-second cooldown after watchface changes
-        private var watchfaceSwitchTimer: Timer?
-
-        /// The timestamp when the current cooldown period will end
-        private var watchfaceSwitchCooldownEndTime: Date?
-
         override func subscribe() {
             preferences = provider.preferences
             units = settingsManager.settings.units
@@ -52,42 +40,14 @@ extension WatchConfig {
         }
 
         /// Handles watchface selection changes by automatically disabling data transmission
-        /// and starting a 20-second cooldown period to allow the user to switch watchfaces
-        /// on their Garmin device without data conflicts
+        /// to allow the user to switch watchfaces on their Garmin device without data conflicts
         func handleWatchfaceChange() {
             garminSettings.isWatchfaceDataEnabled = false
-            startCooldownTimer()
-        }
-
-        /// Starts a 20-second countdown timer that locks the enable/disable toggle and updates
-        /// the remaining seconds display every second until the cooldown period expires
-        private func startCooldownTimer() {
-            watchfaceSwitchTimer?.invalidate()
-
-            watchfaceSwitchCooldownEndTime = Date().addingTimeInterval(20)
-            isWatchfaceDataCooldownActive = true
-            watchfaceSwitchCooldownSeconds = 20
-
-            watchfaceSwitchTimer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] _ in
-                guard let self = self else { return }
-
-                if let endTime = self.watchfaceSwitchCooldownEndTime {
-                    let remaining = Int(endTime.timeIntervalSinceNow)
-                    if remaining <= 0 {
-                        self.isWatchfaceDataCooldownActive = false
-                        self.watchfaceSwitchCooldownSeconds = 0
-                        self.watchfaceSwitchTimer?.invalidate()
-                        self.watchfaceSwitchTimer = nil
-                        self.watchfaceSwitchCooldownEndTime = nil
-                    } else {
-                        self.watchfaceSwitchCooldownSeconds = remaining
-                    }
-                }
-            }
         }
 
-        deinit {
-            watchfaceSwitchTimer?.invalidate()
+        /// Resumes data transmission after user confirms they have switched watchface on their device
+        func resumeDataTransmission() {
+            garminSettings.isWatchfaceDataEnabled = true
         }
     }
 }