feat(menubar): 新增保持唤醒开关并统一底部透明按钮样式
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import Foundation
|
||||
import IOKit.pwr_mgt
|
||||
|
||||
@main struct KeepAwakeChecks {
|
||||
@MainActor static func main() {
|
||||
let service = KeepAwakeService()
|
||||
precondition(!service.isEnabled)
|
||||
precondition(ownAssertions().isEmpty)
|
||||
for _ in 0..<3 {
|
||||
service.toggle()
|
||||
precondition(service.isEnabled && !service.didFail)
|
||||
let types = Set(ownAssertions().compactMap { $0[kIOPMAssertionTypeKey] as? String })
|
||||
precondition(types == Set([kIOPMAssertionTypePreventUserIdleDisplaySleep, kIOPMAssertionTypePreventUserIdleSystemSleep]))
|
||||
service.toggle()
|
||||
precondition(!service.isEnabled && !service.didFail)
|
||||
precondition(ownAssertions().isEmpty)
|
||||
}
|
||||
var temporary: KeepAwakeService? = KeepAwakeService()
|
||||
temporary?.toggle()
|
||||
precondition(ownAssertions().count == 2)
|
||||
temporary = nil
|
||||
precondition(ownAssertions().isEmpty)
|
||||
print("KeepAwakeChecks passed: real assertions, repeated toggle and lifetime release")
|
||||
}
|
||||
|
||||
static func ownAssertions() -> [[String: Any]] {
|
||||
var value: Unmanaged<CFDictionary>?
|
||||
precondition(IOPMCopyAssertionsByProcess(&value) == kIOReturnSuccess)
|
||||
let processes = value!.takeRetainedValue() as NSDictionary
|
||||
let assertions = processes[NSNumber(value: getpid())] as? [[String: Any]] ?? []
|
||||
return assertions.filter { $0[kIOPMAssertionNameKey] as? String == "Kymo Keep Awake" }
|
||||
}
|
||||
}
|
||||
@@ -84,3 +84,14 @@ swiftc -module-cache-path /private/tmp/kymo-identity-cache kymo/Core/Services/Co
|
||||
```
|
||||
|
||||
验证各自合法签名通过、对方身份要求拒绝及缺失代码降级;不替代主应用与 XPC 的实际端到端采样。方案与进程生命周期见 [辅助服务实施方案](../docs/disk-smart-helper-plan.md)。
|
||||
|
||||
## 保持唤醒实际断言检查
|
||||
|
||||
```bash
|
||||
swiftc -module-cache-path /private/tmp/kymo-check-cache \
|
||||
kymo/Core/Services/KeepAwakeService.swift kymoTests/KeepAwakeChecks.swift \
|
||||
-o /private/tmp/kymo-awake-checks
|
||||
/private/tmp/kymo-awake-checks
|
||||
```
|
||||
|
||||
检查真实 IOKit 请求的创建、重复开关与生命周期释放;测试结束不保留唤醒断言。不能替代实际空闲锁屏、息屏及面板视觉验收。
|
||||
|
||||
Reference in New Issue
Block a user