- 清理:应用缓存、日志、浏览器缓存、Xcode/模拟器/npm 缓存、下载残留、安装包、废纸篓; 白名单目录 + 安全守卫,运行中的应用自动跳过,执行前逐项复核,操作日志 - 系统维护:刷新 DNS 缓存、释放内存(辅助工具或管理员授权) - 面板:去掉打开后的二次调整高度与窗口高度动画,内容放得下时不回弹, 修复点击菜单栏图标关闭时被重新打开 - 更换应用图标,面板与关于页使用应用图标作为 Logo - 清理未使用的组件、格式化方法、设计 token 与辅助工具接口
29 lines
1.3 KiB
Swift
29 lines
1.3 KiB
Swift
import Foundation
|
|
import SMC
|
|
|
|
/// 温度与风扇(只读,普通权限即可)。
|
|
public final class SensorSampler {
|
|
private let smc: SMCConnection?
|
|
private let fans: FanControl?
|
|
private lazy var catalog: [TemperatureGroup: [SMCKey]] = smc.map(TemperatureCatalog.discover) ?? [:]
|
|
|
|
public init() {
|
|
smc = try? SMCConnection()
|
|
fans = smc.map(FanControl.init)
|
|
}
|
|
|
|
public func sample(groups: Set<TemperatureGroup> = Set(TemperatureGroup.allCases), includeFans: Bool = true) -> SensorReadings? {
|
|
guard let smc else { return nil }
|
|
var summaries: [TemperatureSummary] = []
|
|
for group in TemperatureGroup.allCases where groups.contains(group) {
|
|
let values = (catalog[group] ?? []).compactMap(smc.double).filter(TemperatureCatalog.plausibleRange.contains)
|
|
guard !values.isEmpty else { continue }
|
|
summaries.append(TemperatureSummary(group: group,
|
|
average: values.reduce(0, +) / Double(values.count),
|
|
maximum: values.max() ?? 0,
|
|
sensorCount: values.count))
|
|
}
|
|
return SensorReadings(temperatures: summaries, fans: includeFans ? (fans?.read() ?? []) : [])
|
|
}
|
|
}
|