52 lines
3.2 KiB
Swift
52 lines
3.2 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 size: CGFloat in [11,20,32] {
|
|
rotor.setFrameSize(NSSize(width: size, height: size)); rotor.layoutSubtreeIfNeeded()
|
|
precondition(rotor.rotorLayer.anchorPoint == CGPoint(x: 0.5, y: 0.5))
|
|
precondition(rotor.rotorLayer.contents != nil)
|
|
precondition(CATransform3DIsIdentity(rotor.layer!.transform), "AppKit's host layer must never rotate")
|
|
CATransaction.begin(); CATransaction.setDisableActions(true)
|
|
for degrees in [0.0,45,90,180,270] {
|
|
rotor.rotorLayer.transform = CATransform3DMakeRotation(degrees * .pi / 180, 0, 0, 1)
|
|
let center = rotor.rotorLayer.convert(CGPoint(x: size / 2, y: size / 2), to: rotor.layer!)
|
|
precondition(abs(center.x - rotor.bounds.midX) < 1e-9 && abs(center.y - rotor.bounds.midY) < 1e-9,
|
|
"The icon center must not orbit at any angle or size")
|
|
}
|
|
rotor.rotorLayer.transform = CATransform3DIdentity
|
|
CATransaction.commit()
|
|
}
|
|
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.rotorLayer.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.rotorLayer.animationKeys()?.isEmpty != false)
|
|
}
|
|
rotor.configure(rpm: 3000, active: true, reducedMotion: false)
|
|
precondition(rotor.rotorLayer.animationKeys()?.isEmpty == false)
|
|
rotor.configure(rpm: 3000, active: false, reducedMotion: false)
|
|
precondition(rotor.rotorLayer.animationKeys()?.isEmpty != false)
|
|
rotor.configure(rpm: 3000, active: true, reducedMotion: true)
|
|
precondition(rotor.rotorLayer.animationKeys()?.isEmpty != false)
|
|
rotor.configure(rpm: 3000, active: true, reducedMotion: false)
|
|
rotor.removeFromSuperview()
|
|
precondition(rotor.rotorLayer.animationKeys()?.isEmpty != false, "Detached fans must stop rotating")
|
|
window.orderOut(nil); window.close()
|
|
print("PASS: centered child-layer rotation at multiple angles/sizes, native rotor speed tiers, nil/zero/invalid readings, inactive/reduced motion and detach stop")
|
|
NSApp.terminate(nil)
|
|
}
|
|
NSApp.run()
|
|
}
|
|
}
|