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" }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user