Files
divkit/client/ios/DivKitPlayground/WebPreview/Networking/UIStatePayloadFactory.swift
T
akhmetsafin 1088f876e1 Add showing rendering time in playgroung
Add showing rendering time in playgroung
2022-10-21 15:18:08 +03:00

57 lines
1.4 KiB
Swift

import Foundation
import CommonCore
struct ScreenshotInfo {
let data: Data
let density: Double
let height: Double
let width: Double
}
final class UIStatePayloadFactory {
typealias Errors = [(message: String, stack: [String]?)]
private let deviceInfo: DeviceInfo
private let clientId = UUID().uuidString
@ObservableVariable
private var errors: Errors?
init(
deviceInfo: DeviceInfo,
errors: ObservableVariable<Errors?>
) {
self.deviceInfo = deviceInfo
_errors = errors
}
func makePayload(
screenshotInfo: ScreenshotInfo,
renderingTime: UIStatePayload.RenderingTime
) -> UIStatePayload {
let bundleInfo = Bundle.main.infoDictionary
return UIStatePayload(
device: UIStatePayload.Device(
client_id: clientId,
app_name: bundleInfo?["CFBundleDisplayName"] as? String,
app_version: bundleInfo?["CFBundleShortVersionString"] as? String,
os_name: deviceInfo.osName,
os_version: deviceInfo.osVersion,
device: deviceInfo.deviceModel,
orientation: deviceInfo.orientation,
density: screenshotInfo.density,
width: screenshotInfo.width,
height: screenshotInfo.height
),
screenshot: screenshotInfo.data,
errors: (errors ?? []).map {
UIStatePayload.Error(
message: $0.message,
stack: $0.stack
)
},
renderingTime: renderingTime
)
}
}