oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1#if DEBUG
2import AppKit
3import EquipoKit
4import SwiftUI
5
6struct MacNeedsFixture: View {
7 @State private var model = NeedsViewFixture.makeModel()
8 var body: some View {
9 if let session = model.session {
10 MacMainView(model: model, session: session)
11 .modifier(NeedsCapture())
12 .preferredColorScheme(.light)
13 .task { await session.refresh() }
14 }
15 }
16}
17
18private struct NeedsCapture: ViewModifier {
19 func body(content: Content) -> some View {
20 content.task {
21 guard let path = ProcessInfo.processInfo.environment["EQUIPO_FIXTURE_CAPTURE"] else { return }
22 try? await Task.sleep(for: .seconds(2))
23 guard let window = NSApp.windows.first(where: { $0.isVisible && !$0.isSheet }), let view = window.contentView?.superview else { return }
24 window.appearance = NSAppearance(named: .aqua)
25 window.makeKeyAndOrderFront(nil)
26 NSApp.activate()
27 // The sidebar's composited material is excluded from AppKit bitmap
28 // capture. Use the app's native toggle, keeping a real window state.
29 NSApp.sendAction(#selector(NSSplitViewController.toggleSidebar(_:)), to: nil, from: nil)
30 window.setContentSize(NSSize(width: 1100, height: 1080))
31 try? await Task.sleep(for: .milliseconds(300))
32 // Include the native toolbar in the captured window.
33 view.layoutSubtreeIfNeeded(); window.displayIfNeeded()
34 _ = FileManager.default.createFile(atPath: path + ".window", contents: Data(String(window.windowNumber).utf8))
35 _ = FileManager.default.createFile(atPath: path + ".pid", contents: Data(String(ProcessInfo.processInfo.processIdentifier).utf8))
36 if let bitmap = view.bitmapImageRepForCachingDisplay(in: view.bounds) {
37 view.cacheDisplay(in: view.bounds, to: bitmap)
38 _ = FileManager.default.createFile(atPath: path, contents: bitmap.representation(using: .png, properties: [:]))
39 }
40 }
41 }
42}
43#endif
44