Files
MatchLiveTv/native/ios/MatchLiveTv/Core/DeviceTelemetry.swift
Emiliano FrascaroandCursor ea5da1eb86 Allinea iOS a i18n Android 2.0.5 e aggiunge monitoraggio termico nativo.
Completa L10n su login/hub/wizard/broadcast e introduce ThermalStateManager su iOS/Android con degradazione qualità e indicatore in overlay.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-24 11:19:37 +02:00

44 lines
1.5 KiB
Swift

import Foundation
import UIKit
import Network
struct DeviceHealth: Sendable {
let batteryPercent: Int
let thermalState: ThermalState
let networkType: String
}
enum DeviceTelemetry {
static func snapshot(thermalState: ThermalState? = nil) -> DeviceHealth {
UIDevice.current.isBatteryMonitoringEnabled = true
let level = Int((UIDevice.current.batteryLevel >= 0 ? UIDevice.current.batteryLevel : 1) * 100)
let thermal = thermalState ?? ThermalState.from(ProcessInfo.processInfo.thermalState)
return DeviceHealth(
batteryPercent: level,
thermalState: thermal,
networkType: currentNetworkType()
)
}
private static func currentNetworkType() -> String {
let monitor = NWPathMonitor()
let semaphore = DispatchSemaphore(value: 0)
var result = L10n.t("network.type.unknown")
monitor.pathUpdateHandler = { path in
if path.usesInterfaceType(.wifi) {
result = L10n.t("network.type.wifi")
} else if path.usesInterfaceType(.cellular) {
result = L10n.t("network.type.cellular")
} else if path.usesInterfaceType(.wiredEthernet) {
result = L10n.t("network.type.ethernet")
}
semaphore.signal()
}
let queue = DispatchQueue(label: "network.type")
monitor.start(queue: queue)
_ = semaphore.wait(timeout: .now() + 0.5)
monitor.cancel()
return result
}
}