mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
1088f876e1
Add showing rendering time in playgroung
57 lines
1.4 KiB
Swift
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
|
|
)
|
|
}
|
|
}
|