| import SwiftUI | |
| @main | |
| struct DolphinCoreMLTestApp: App { | |
| (\.scenePhase) private var scenePhase | |
| private var session = AssistantSession() | |
| var body: some Scene { | |
| WindowGroup { | |
| AssistantAppView(session: session) | |
| .task { | |
| consumeIntentHandoff() | |
| } | |
| .onReceive( | |
| NotificationCenter.default.publisher( | |
| for: .dolphinIntentHandoffAvailable | |
| ) | |
| ) { _ in | |
| consumeIntentHandoff() | |
| } | |
| .onChange(of: scenePhase) { _, phase in | |
| if phase == .active { | |
| session.enteredForeground() | |
| consumeIntentHandoff() | |
| } else { | |
| session.enteredBackground() | |
| } | |
| } | |
| } | |
| } | |
| private func consumeIntentHandoff() { | |
| guard let request = IntentHandoffStore.consumePendingRequest() else { | |
| return | |
| } | |
| let existingDraft = session.draft.trimmingCharacters( | |
| in: .whitespacesAndNewlines | |
| ) | |
| session.draft = existingDraft.isEmpty | |
| ? request | |
| : "\(existingDraft)\n\n\(request)" | |
| NotificationCenter.default.post( | |
| name: .dolphinIntentHandoffConsumed, | |
| object: nil | |
| ) | |
| } | |
| } | |