Pārlūkot izejas kodu

Attempt to fix stuck processing view WIP

Deniz Cengiz 1 gadu atpakaļ
vecāks
revīzija
2f233ccfb0

+ 11 - 0
Trio Watch App Extension/Views/AcknowledgementPendingView.swift

@@ -43,6 +43,17 @@ struct AcknowledgementPendingView: View {
         .navigationBarBackButtonHidden(true)
         .toolbar(.hidden)
         .background(trioBackgroundColor)
+        .onChange(of: state.showCommsAnimation) { oldValue, newValue in
+            if newValue && !oldValue {
+                DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
+                    // If after 5 seconds there is still no acknowledgement banner, return to root
+                    if !state.showAcknowledgmentBanner {
+                        // Navigate back to the root
+                        navigationPath.removeLast(navigationPath.count)
+                    }
+                }
+            }
+        }
         .onChange(of: state.showAcknowledgmentBanner) { _, newValue in
             if !newValue {
                 // Navigate back to the root when acknowledgment banner disappears

+ 3 - 5
Trio Watch App Extension/WatchState.swift

@@ -110,15 +110,13 @@ import WatchConnectivity
             acknowledgmentMessage = "\(message)"
         } else {
             print("⌚️ Acknowledgment failed: \(message)")
+            DispatchQueue.main.async {
+                self.showCommsAnimation = false // Hide progress animation
+            }
             acknowledgementStatus = .failure
             acknowledgmentMessage = "\(message)"
         }
 
-        DispatchQueue.main.async {
-            self.showCommsAnimation = false // Hide progress animation
-            self.showSyncingAnimation = false // Just ensure this is 100% set to false
-        }
-
         if isFinal {
             showAcknowledgmentBanner = true
             DispatchQueue.main.asyncAfter(deadline: .now() + 2) {

+ 17 - 1
Trio/Sources/APS/OpenAPS/OpenAPS.swift

@@ -732,13 +732,29 @@ final class OpenAPS {
         }
     }
 
+//    private func middlewareScript(name: String) -> Script? {
+//        if let body = storage.retrieveRaw(name) {
+//            return Script(name: name, body: body)
+//        }
+//
+//        if let url = Foundation.Bundle.main.url(forResource: "javascript/\(name)", withExtension: "") {
+//            return Script(name: name, body: try! String(contentsOf: url))
+//        }
+//
+//        return nil
+//    }
     private func middlewareScript(name: String) -> Script? {
         if let body = storage.retrieveRaw(name) {
             return Script(name: name, body: body)
         }
 
         if let url = Foundation.Bundle.main.url(forResource: "javascript/\(name)", withExtension: "") {
-            return Script(name: name, body: try! String(contentsOf: url))
+            do {
+                let body = try String(contentsOf: url)
+                return Script(name: name, body: body)
+            } catch {
+                print("Failed to load script \(name): \(error)")
+            }
         }
 
         return nil