Jelajahi Sumber

Refactor UI operations to ensure they execute on the main thread across various components, including snooze actions and modal handling. Updated button tap handlers and modal dismissal methods to use weak references and dispatch to the main queue as needed.

Charlie Chrisman 4 bulan lalu
induk
melakukan
62b47e82ed

+ 11 - 2
Trio/Sources/Modules/Snooze/View/SnoozeRootView.swift

@@ -71,7 +71,8 @@ extension Snooze {
                     let snoozeFor = formatter.string(from: interval)!
                     let untilDate = Date() + interval
 
-                    Task { @MainActor in
+                    Task { @MainActor [weak state] in
+                        guard let state = state else { return }
                         await state.applySnooze(interval)
                         debug(.default, "will snooze for \(snoozeFor) until \(dateFormatter.string(from: untilDate))")
                         snoozeDescription = getSnoozeDescription()
@@ -106,7 +107,15 @@ extension Snooze {
             .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
             .navigationBarTitle("Snooze Alerts")
             .navigationBarTitleDisplayMode(.automatic)
-            .navigationBarItems(trailing: Button("Close", action: state.hideModal))
+            .toolbar {
+                ToolbarItem(placement: .topBarTrailing) {
+                    Button("Close") {
+                        Task { @MainActor in
+                            state.hideModal()
+                        }
+                    }
+                }
+            }
             .onAppear {
                 configureView()
                 snoozeDescription = getSnoozeDescription()

+ 17 - 13
Trio/Sources/Services/UserNotifications/UserNotificationsManager.swift

@@ -703,19 +703,23 @@ extension BaseUserNotificationsManager: UNUserNotificationCenterDelegate {
               let action = NotificationAction(rawValue: actionRaw)
         else { return }
 
-        switch action {
-        case .snooze:
-            router.mainModalScreen.send(.snooze)
-        case .pumpConfig:
-            let messageCont = MessageContent(
-                content: response.notification.request.content.body,
-                type: MessageType.other,
-                subtype: .pump,
-                useAPN: false,
-                action: .pumpConfig
-            )
-            router.alertMessage.send(messageCont)
-        default: break
+        // Ensure UI operations happen on main thread
+        DispatchQueue.main.async { [weak self] in
+            guard let self = self else { return }
+            switch action {
+            case .snooze:
+                self.router.mainModalScreen.send(.snooze)
+            case .pumpConfig:
+                let messageCont = MessageContent(
+                    content: response.notification.request.content.body,
+                    type: MessageType.other,
+                    subtype: .pump,
+                    useAPN: false,
+                    action: .pumpConfig
+                )
+                self.router.alertMessage.send(messageCont)
+            default: break
+            }
         }
     }
 }