#if DEBUG import AppKit import EquipoKit import SwiftUI struct MacNeedsFixture: View { @State private var model = NeedsViewFixture.makeModel() var body: some View { if let session = model.session { MacMainView(model: model, session: session) .modifier(NeedsCapture()) .preferredColorScheme(.light) .task { await session.refresh() } } } } private struct NeedsCapture: ViewModifier { func body(content: Content) -> some View { content.task { guard let path = ProcessInfo.processInfo.environment["EQUIPO_FIXTURE_CAPTURE"] else { return } try? await Task.sleep(for: .seconds(2)) guard let window = NSApp.windows.first(where: { $0.isVisible && !$0.isSheet }), let view = window.contentView?.superview else { return } window.appearance = NSAppearance(named: .aqua) window.makeKeyAndOrderFront(nil) NSApp.activate() // The sidebar's composited material is excluded from AppKit bitmap // capture. Use the app's native toggle, keeping a real window state. NSApp.sendAction(#selector(NSSplitViewController.toggleSidebar(_:)), to: nil, from: nil) window.setContentSize(NSSize(width: 1100, height: 1080)) try? await Task.sleep(for: .milliseconds(300)) // Include the native toolbar in the captured window. view.layoutSubtreeIfNeeded(); window.displayIfNeeded() _ = FileManager.default.createFile(atPath: path + ".window", contents: Data(String(window.windowNumber).utf8)) _ = FileManager.default.createFile(atPath: path + ".pid", contents: Data(String(ProcessInfo.processInfo.processIdentifier).utf8)) if let bitmap = view.bitmapImageRepForCachingDisplay(in: view.bounds) { view.cacheDisplay(in: view.bounds, to: bitmap) _ = FileManager.default.createFile(atPath: path, contents: bitmap.representation(using: .png, properties: [:])) } } } } #endif