Selaa lähdekoodia

Watch app fixes

Ivan Valkou 4 vuotta sitten
vanhempi
commit
828327d2c4

+ 8 - 2
FreeAPS/Sources/APS/CGM/CGMType.swift

@@ -68,7 +68,10 @@ enum CGMType: String, JSON, CaseIterable, Identifiable {
         case .nightscout:
             return NSLocalizedString("Online or internal server", comment: "Online or internal server")
         case .xdrip:
-            return NSLocalizedString("Shared app group for direct connection with Libre 1 transmitters or European Libre 2 sensors", comment: "Shared app group for direct connection with Libre 1 transmitters or European Libre 2 sensors")
+            return NSLocalizedString(
+                "Shared app group for direct connection with Libre 1 transmitters or European Libre 2 sensors",
+                comment: "Shared app group for direct connection with Libre 1 transmitters or European Libre 2 sensors"
+            )
         case .dexcomG6:
             return NSLocalizedString("Native G6 app", comment: "Native G6 app")
         case .dexcomG5:
@@ -81,7 +84,10 @@ enum CGMType: String, JSON, CaseIterable, Identifiable {
                 comment: "Direct connection with Libre 1 transmitters or European Libre 2 sensors"
             )
         case .glucoseDirect:
-            return NSLocalizedString("Shared app group for direct connection with Libre 1 transmitters or European Libre 2 sensors", comment: "Shared app group for direct connection with Libre 1 transmitters or European Libre 2 sensors")
+            return NSLocalizedString(
+                "Shared app group for direct connection with Libre 1 transmitters or European Libre 2 sensors",
+                comment: "Shared app group for direct connection with Libre 1 transmitters or European Libre 2 sensors"
+            )
         case .enlite:
             return NSLocalizedString("Minilink transmitter", comment: "Minilink transmitter")
         }

+ 3 - 1
FreeAPSWatch WatchKit Extension/Views/CarbsView.swift

@@ -50,7 +50,9 @@ struct CarbsView: View {
                 }
                 Button {
                     WKInterfaceDevice.current().play(.click)
-                    state.addCarbs(Int(amount))
+                    // Get amount from displayed string
+                    let amount = Int(numberFormatter.string(from: amount as NSNumber)!) ?? Int(amount.rounded())
+                    state.addCarbs(amount)
                 }
                 label: {
                     HStack {

+ 15 - 2
FreeAPSWatch WatchKit Extension/WatchStateModel.swift

@@ -25,7 +25,20 @@ class WatchStateModel: NSObject, ObservableObject {
     @Published var isCarbsViewActive = false
     @Published var isTempTargetViewActive = false
     @Published var isBolusViewActive = false
-    @Published var isConfirmationViewActive = false
+    @Published var isConfirmationViewActive = false {
+        didSet {
+            confirmationTimeout = nil
+            if isConfirmationViewActive {
+                confirmationTimeout = Just(())
+                    .delay(for: 30, scheduler: DispatchQueue.main)
+                    .sink {
+                        WKInterfaceDevice.current().play(.retry)
+                        self.isConfirmationViewActive = false
+                    }
+            }
+        }
+    }
+
     @Published var isConfirmationBolusViewActive = false
     @Published var confirmationSuccess: Bool?
     @Published var lastUpdate: Date = .distantPast
@@ -33,6 +46,7 @@ class WatchStateModel: NSObject, ObservableObject {
     @Published var pendingBolus: Double?
 
     private var lifetime = Set<AnyCancellable>()
+    private var confirmationTimeout: AnyCancellable?
     let timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect()
 
     init(session: WCSession = .default) {
@@ -164,7 +178,6 @@ extension WatchStateModel: WCSessionDelegate {
     func session(_: WCSession, didReceiveMessageData messageData: Data) {
         if let state = try? JSONDecoder().decode(WatchState.self, from: messageData) {
             DispatchQueue.main.async {
-//                WKInterfaceDevice.current().play(.click)
                 self.processState(state)
             }
         }