scaffolding hermes flow and audit logging
This commit is contained in:
@@ -1,15 +1,59 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import SwiftUI
|
||||
|
||||
@main
|
||||
struct HermesApp: App {
|
||||
@StateObject private var repository = HermesRepository(
|
||||
apiClient: HermesAPIClient(
|
||||
environment: APIEnvironment(baseURL: URL(string: "http://localhost:3000/")!)
|
||||
)
|
||||
)
|
||||
@StateObject private var analytics = HermesAnalyticsClient()
|
||||
@StateObject private var playerCoordinator = PlayerCoordinator()
|
||||
@State private var isBootstrapping = false
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
RootView()
|
||||
RootView(onStartSession: { localeCode in
|
||||
if repository.currentSession != nil, repository.currentRound != nil {
|
||||
return
|
||||
}
|
||||
|
||||
guard !isBootstrapping else {
|
||||
return
|
||||
}
|
||||
|
||||
isBootstrapping = true
|
||||
let request = HermesSessionStartRequest(
|
||||
localeCode: localeCode,
|
||||
devicePlatform: "ios",
|
||||
deviceModel: UIDevice.current.model,
|
||||
osVersion: UIDevice.current.systemVersion,
|
||||
appVersion: Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "0.1.0"
|
||||
)
|
||||
|
||||
analytics.track("session_start_requested", attributes: ["screen_name": "session", "locale_code": localeCode])
|
||||
|
||||
Task { @MainActor in
|
||||
defer {
|
||||
isBootstrapping = false
|
||||
}
|
||||
|
||||
do {
|
||||
_ = try await repository.bootstrap(request)
|
||||
analytics.track("session_started", attributes: ["screen_name": "session", "locale_code": localeCode])
|
||||
await analytics.flush(using: repository)
|
||||
} catch {
|
||||
analytics.track("session_start_failed", attributes: ["screen_name": "session", "locale_code": localeCode])
|
||||
}
|
||||
}
|
||||
})
|
||||
.preferredColorScheme(.dark)
|
||||
.tint(HermesTheme.accent)
|
||||
.environmentObject(analytics)
|
||||
.environmentObject(repository)
|
||||
.environmentObject(playerCoordinator)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user