48 lines
2.9 KiB
Swift
48 lines
2.9 KiB
Swift
import Foundation
|
|
import AppKit
|
|
import CoreGraphics
|
|
|
|
@main struct PresentationChecks {
|
|
@MainActor static func main() {
|
|
let screen = CGRect(x: 0, y: 0, width: 1440, height: 900)
|
|
let parent = CGRect(x: 400, y: 400, width: 320, height: 240)
|
|
let anchor = CGRect(x: 410, y: 600, width: 300, height: 40)
|
|
let size = CGSize(width: 280, height: 180)
|
|
let right = DetailPlacement.frame(anchor: anchor, parent: parent, content: size, visible: screen)
|
|
precondition(right.minX == parent.maxX + 4 && right.maxY == anchor.maxY)
|
|
let edgeParent = CGRect(x: 1100, y: 400, width: 320, height: 240)
|
|
let left = DetailPlacement.frame(anchor: anchor, parent: edgeParent, content: size, visible: screen)
|
|
precondition(left.maxX == edgeParent.minX - 4)
|
|
for visible in [screen, CGRect(x: -1440, y: -200, width: 1440, height: 900), CGRect(x: 0, y: 0, width: 200, height: 100)] {
|
|
let result = DetailPlacement.frame(anchor: anchor, parent: parent, content: size, visible: visible)
|
|
precondition(visible.contains(result))
|
|
}
|
|
let highAnchor = CGRect(x: 400, y: 1100, width: 300, height: 40)
|
|
precondition(DetailPlacement.frame(anchor: highAnchor, parent: parent, content: size, visible: screen).maxY == screen.maxY)
|
|
let lowAnchor = CGRect(x: 400, y: -200, width: 300, height: 40)
|
|
precondition(DetailPlacement.frame(anchor: lowAnchor, parent: parent, content: size, visible: screen).minY == screen.minY)
|
|
precondition(AppAppearance.system.resolved(systemIsDark: true) == .dark)
|
|
precondition(AppAppearance.system.resolved(systemIsDark: false) == .light)
|
|
precondition(AppAppearance.light.resolved(systemIsDark: true) == .light)
|
|
precondition(AppAppearance.dark.resolved(systemIsDark: false) == .dark)
|
|
precondition(SystemAppearanceObserver.isDark(globalDomain: ["AppleInterfaceStyle": "Dark"]))
|
|
precondition(!SystemAppearanceObserver.isDark(globalDomain: [:]))
|
|
_ = NSApplication.shared
|
|
let global = NSApp.appearance
|
|
let window = NSWindow(contentRect: .zero, styleMask: .borderless, backing: .buffered, defer: true)
|
|
window.isReleasedWhenClosed = false
|
|
for choice in [AppAppearance.light, .system, .dark, .system] {
|
|
WindowAppearance.apply(choice, to: window)
|
|
if choice == .system {
|
|
precondition(window.appearance == nil)
|
|
precondition(window.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]) == NSApp.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]))
|
|
} else {
|
|
precondition(window.appearance?.name == choice.windowAppearance?.name)
|
|
}
|
|
precondition(NSApp.appearance === global)
|
|
}
|
|
window.close()
|
|
print("PASS: outward placement, edge fallback, negative screen origins, vertical limits, explicit/system window appearance reset, independent system resolution")
|
|
}
|
|
}
|