Radroots.swift (1526B)
1 import Foundation 2 3 @MainActor 4 public final class Radroots: ObservableObject { 5 public private(set) var runtime: RadrootsRuntime? 6 public private(set) var runtimeService: FieldRuntimeService? 7 8 public init() {} 9 10 func start( 11 bundleId: String = Bundle.main.bundleIdentifier ?? "unknown", 12 version: String = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String) ?? "0", 13 build: String = (Bundle.main.infoDictionary?["CFBundleVersion"] as? String) ?? "0", 14 buildSha: String? = nil, 15 telemetry: FieldTelemetry = .shared 16 ) throws -> FieldRuntimeService { 17 let settings = LoggingSettings.load() 18 do { 19 try settings.apply(bundleIdentifier: bundleId) 20 } catch { 21 throw FieldRuntimeLoggingError.initializationFailed(error.fieldRuntimeMessage) 22 } 23 telemetry.runtimeLoggingInitialized(settings: settings) 24 25 let rt = try RadrootsRuntime() 26 let resolvedSha = buildSha ?? (Bundle.main.object(forInfoDictionaryKey: "GIT_SHA") as? String) 27 rt.setAppInfoPlatform( 28 platform: "iOS", 29 bundleId: bundleId, 30 version: version, 31 buildNumber: build, 32 buildSha: resolvedSha 33 ) 34 self.runtime = rt 35 let service = FieldRuntimeService(runtime: rt) 36 self.runtimeService = service 37 return service 38 } 39 40 deinit { 41 runtime?.stop() 42 } 43 44 public func info() -> RuntimeInfo? { 45 runtime?.info() 46 } 47 }