mirror of
https://github.com/hanzoai/bot.git
synced 2026-10-30 17:24:26 +00:00
Automated rebrand of all openclaw references to hanzo bot: - Package: openclaw -> @hanzo/bot - Binary: openclaw -> hanzo-bot - Config: ~/.openclaw -> ~/.hanzo/bot - Docker: ghcr.io/hanzoai/bot - Env vars: OPENCLAW_* -> BOT_* - Bundle IDs: ai.hanzo.bot.* - Product name: Hanzo Bot
84 lines
3.1 KiB
Swift
84 lines
3.1 KiB
Swift
import Foundation
|
|
import Hanzo BotKit
|
|
import UIKit
|
|
|
|
@MainActor
|
|
final class DeviceStatusService: DeviceStatusServicing {
|
|
private let networkStatus: NetworkStatusService
|
|
|
|
init(networkStatus: NetworkStatusService = NetworkStatusService()) {
|
|
self.networkStatus = networkStatus
|
|
}
|
|
|
|
func status() async throws -> Hanzo BotDeviceStatusPayload {
|
|
let battery = self.batteryStatus()
|
|
let thermal = self.thermalStatus()
|
|
let storage = self.storageStatus()
|
|
let network = await self.networkStatus.currentStatus()
|
|
let uptime = ProcessInfo.processInfo.systemUptime
|
|
|
|
return Hanzo BotDeviceStatusPayload(
|
|
battery: battery,
|
|
thermal: thermal,
|
|
storage: storage,
|
|
network: network,
|
|
uptimeSeconds: uptime)
|
|
}
|
|
|
|
func info() -> Hanzo BotDeviceInfoPayload {
|
|
let device = UIDevice.current
|
|
let appVersion = DeviceInfoHelper.appVersion()
|
|
let appBuild = DeviceStatusService.fallbackAppBuild(DeviceInfoHelper.appBuild())
|
|
let locale = Locale.preferredLanguages.first ?? Locale.current.identifier
|
|
return Hanzo BotDeviceInfoPayload(
|
|
deviceName: device.name,
|
|
modelIdentifier: DeviceInfoHelper.modelIdentifier(),
|
|
systemName: device.systemName,
|
|
systemVersion: device.systemVersion,
|
|
appVersion: appVersion,
|
|
appBuild: appBuild,
|
|
locale: locale)
|
|
}
|
|
|
|
private func batteryStatus() -> Hanzo BotBatteryStatusPayload {
|
|
let device = UIDevice.current
|
|
device.isBatteryMonitoringEnabled = true
|
|
let level = device.batteryLevel >= 0 ? Double(device.batteryLevel) : nil
|
|
let state: Hanzo BotBatteryState = switch device.batteryState {
|
|
case .charging: .charging
|
|
case .full: .full
|
|
case .unplugged: .unplugged
|
|
case .unknown: .unknown
|
|
@unknown default: .unknown
|
|
}
|
|
return Hanzo BotBatteryStatusPayload(
|
|
level: level,
|
|
state: state,
|
|
lowPowerModeEnabled: ProcessInfo.processInfo.isLowPowerModeEnabled)
|
|
}
|
|
|
|
private func thermalStatus() -> Hanzo BotThermalStatusPayload {
|
|
let state: Hanzo BotThermalState = switch ProcessInfo.processInfo.thermalState {
|
|
case .nominal: .nominal
|
|
case .fair: .fair
|
|
case .serious: .serious
|
|
case .critical: .critical
|
|
@unknown default: .nominal
|
|
}
|
|
return Hanzo BotThermalStatusPayload(state: state)
|
|
}
|
|
|
|
private func storageStatus() -> Hanzo BotStorageStatusPayload {
|
|
let attrs = (try? FileManager.default.attributesOfFileSystem(forPath: NSHomeDirectory())) ?? [:]
|
|
let total = (attrs[.systemSize] as? NSNumber)?.int64Value ?? 0
|
|
let free = (attrs[.systemFreeSize] as? NSNumber)?.int64Value ?? 0
|
|
let used = max(0, total - free)
|
|
return Hanzo BotStorageStatusPayload(totalBytes: total, freeBytes: free, usedBytes: used)
|
|
}
|
|
|
|
/// Fallback for payloads that require a non-empty build (e.g. "0").
|
|
private static func fallbackAppBuild(_ build: String) -> String {
|
|
build.isEmpty ? "0" : build
|
|
}
|
|
}
|