37 lines
2.0 KiB
Swift
37 lines
2.0 KiB
Swift
import AppKit
|
|
import SwiftUI
|
|
|
|
@main struct FanRotorChecks {
|
|
@MainActor static func main() {
|
|
_ = NSApplication.shared; NSApp.setActivationPolicy(.accessory)
|
|
Task { @MainActor in
|
|
let window = NSWindow(contentRect: NSRect(x: 30, y: 30, width: 40, height: 40), styleMask: [.borderless], backing: .buffered, defer: false)
|
|
window.isReleasedWhenClosed = false
|
|
let rotor = FanRotor.RotorView(); rotor.frame = NSRect(x: 4, y: 4, width: 20, height: 20)
|
|
window.contentView!.addSubview(rotor); window.orderFrontRegardless()
|
|
try? await Task.sleep(for: .milliseconds(100))
|
|
for (rpm, duration) in [(1000.0,4.0),(2000,2),(4000,1.2),(6000,0.8)] {
|
|
rotor.configure(rpm: rpm, active: true, reducedMotion: false)
|
|
precondition(abs(rotor.layer!.animation(forKey: FanRotor.RotorView.animationKey)!.duration - duration) < 1e-9)
|
|
}
|
|
for rpm: Double? in [0,nil,.nan,-1] {
|
|
rotor.configure(rpm: rpm, active: true, reducedMotion: false)
|
|
precondition(rotor.layer!.animationKeys()?.isEmpty != false)
|
|
}
|
|
rotor.configure(rpm: 3000, active: true, reducedMotion: false)
|
|
precondition(rotor.layer!.animationKeys()?.isEmpty == false)
|
|
rotor.configure(rpm: 3000, active: false, reducedMotion: false)
|
|
precondition(rotor.layer!.animationKeys()?.isEmpty != false)
|
|
rotor.configure(rpm: 3000, active: true, reducedMotion: true)
|
|
precondition(rotor.layer!.animationKeys()?.isEmpty != false)
|
|
rotor.configure(rpm: 3000, active: true, reducedMotion: false)
|
|
rotor.removeFromSuperview()
|
|
precondition(rotor.layer!.animationKeys()?.isEmpty != false, "Detached fans must stop rotating")
|
|
window.orderOut(nil); window.close()
|
|
print("PASS: native rotor speed tiers, nil/zero/invalid readings, inactive/reduced motion and detach stop")
|
|
NSApp.terminate(nil)
|
|
}
|
|
NSApp.run()
|
|
}
|
|
}
|