#if DEBUG import AppKit /// Debug-only proof capture that works while the Mac is locked: draws the real desk window (or the /// sheet in front of it) into a PNG. `JOBLEY_SNAPSHOT=/path/shot.png` captures once the window has /// loaded, then quits. The glass sidebar is drawn by the window server, so it needs a live capture. @MainActor enum Snapshot { static func runIfRequested() { guard let path = ProcessInfo.processInfo.environment["JOBLEY_SNAPSHOT"] else { return } let delay = Double(ProcessInfo.processInfo.environment["JOBLEY_SNAPSHOT_DELAY"] ?? "") ?? 5 DispatchQueue.main.asyncAfter(deadline: .now() + delay) { let main = NSApp.windows.first { $0.isVisible && $0.contentView != nil && $0.sheetParent == nil } let window = main?.sheets.first ?? main guard let window, let view = window.contentView?.superview ?? window.contentView, let rep = view.bitmapImageRepForCachingDisplay(in: view.bounds) else { exit(2) } view.cacheDisplay(in: view.bounds, to: rep) try? rep.representation(using: .png, properties: [:])?.write(to: URL(fileURLWithPath: path)) exit(0) } } } #endif