| 1 | #if DEBUG |
| 2 | import AppKit |
| 3 | import SwiftUI |
| 4 | import EquipoKit |
| 5 | |
| 6 | struct MacAttachmentsFixture: NSViewRepresentable { |
| 7 | func makeNSView(context: Context) -> LiveTranscript { |
| 8 | let session = AttachmentsFixture.makeSession() |
| 9 | let view = LiveTranscript(session: session, openTask: { _ in }) |
| 10 | Task { @MainActor [weak view] in |
| 11 | await session.refresh() |
| 12 | guard let view else { return } |
| 13 | view.update(items: Feed.build(session)) |
| 14 | view.composer.setText("Home’s sign-in button is cut off on my phone.") |
| 15 | // Exercise the complete destination lifecycle with synthetic drag info. |
| 16 | let board = NSPasteboard.withUniqueName() |
| 17 | board.setData(AttachmentsFixture.image, forType: .png) |
| 18 | let drag = FixtureAttachmentDrag(board) |
| 19 | if view.composer.editor.draggingEntered(drag) == .copy, |
| 20 | view.composer.editor.draggingUpdated(drag) == .copy, |
| 21 | view.composer.editor.prepareForDragOperation(drag) { |
| 22 | _ = view.composer.editor.performDragOperation(drag) |
| 23 | } |
| 24 | board.releaseGlobally() |
| 25 | try? await Task.sleep(for: .seconds(2)) |
| 26 | guard let path = ProcessInfo.processInfo.environment["EQUIPO_FIXTURE_CAPTURE"], |
| 27 | let window = view.window, let content = window.contentView else { return } |
| 28 | window.appearance = NSAppearance(named: ProcessInfo.processInfo.environment["EQUIPO_FIXTURE_DARK"] == "1" ? .darkAqua : .aqua) |
| 29 | try? await Task.sleep(for: .milliseconds(200)) |
| 30 | window.setContentSize(NSSize(width: 1000, height: 760)) |
| 31 | content.layoutSubtreeIfNeeded(); window.displayIfNeeded() |
| 32 | if let bitmap = content.bitmapImageRepForCachingDisplay(in: content.bounds) { |
| 33 | content.cacheDisplay(in: content.bounds, to: bitmap) |
| 34 | _ = FileManager.default.createFile(atPath: path, contents: bitmap.representation(using: .png, properties: [:])) |
| 35 | } |
| 36 | } |
| 37 | return view |
| 38 | } |
| 39 | func updateNSView(_ view: LiveTranscript, context: Context) {} |
| 40 | } |
| 41 | |
| 42 | @MainActor final class FixtureAttachmentDrag: NSObject, NSDraggingInfo { |
| 43 | let draggingPasteboard: NSPasteboard |
| 44 | init(_ board: NSPasteboard) { draggingPasteboard = board } |
| 45 | var draggingDestinationWindow: NSWindow? { nil } |
| 46 | var draggingSourceOperationMask: NSDragOperation { .copy } |
| 47 | var draggingLocation: NSPoint { .zero } |
| 48 | var draggedImageLocation: NSPoint { .zero } |
| 49 | nonisolated var draggedImage: NSImage? { nil } |
| 50 | var draggingSource: Any? { nil } |
| 51 | var draggingSequenceNumber: Int { 1 } |
| 52 | var draggingFormation: NSDraggingFormation = .none |
| 53 | var animatesToDestination = false |
| 54 | var numberOfValidItemsForDrop = 1 |
| 55 | var springLoadingHighlight: NSSpringLoadingHighlight { .none } |
| 56 | func slideDraggedImage(to screenPoint: NSPoint) {} |
| 57 | nonisolated override func namesOfPromisedFilesDropped(atDestination dropDestination: URL) -> [String]? { nil } |
| 58 | func resetSpringLoading() {} |
| 59 | func enumerateDraggingItems(options: NSDraggingItemEnumerationOptions = [], for view: NSView?, classes classArray: [AnyClass], searchOptions: [NSPasteboard.ReadingOptionKey: Any] = [:], using block: (NSDraggingItem, Int, UnsafeMutablePointer<ObjCBool>) -> Void) {} |
| 60 | } |
| 61 | #endif |
| 62 | |