60 lines
2.2 KiB
Swift
60 lines
2.2 KiB
Swift
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(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)
|
|
}
|
|
}
|
|
}
|