| 1 | import AppKit |
| 2 | @_spi(Fixtures) import CallsKit |
| 3 | import SwiftUI |
| 4 | |
| 5 | /// The stage and every tile's placeholder (2026-10-05), drawn off screen |
| 6 | /// (no glass and no Metal video, as the other offline fixtures), with a busy frame as the picture on the stage's |
| 7 | /// tile so the filmstrip, the names and the bar show over a picture: |
| 8 | /// Speaker view with a camera on the stage, with a camera that is off on |
| 9 | /// it, and with a shared screen on it, controls shown and hidden, at the |
| 10 | /// default window and the smallest; Grid; and the mini window at 200, 320 |
| 11 | /// and 480 with someone whose camera is off, and its tab. |
| 12 | @MainActor enum StageSnapshots { |
| 13 | static func save(to folder: URL) async throws { |
| 14 | NSApplication.shared.setActivationPolicy(.prohibited) |
| 15 | try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true) |
| 16 | func shot( |
| 17 | _ name: String, _ fixture: CallFixture = .grid, grid: Bool = false, shown: Bool, |
| 18 | size: CGSize = CGSize(width: 1000, height: 640), speaker: String? |
| 19 | ) async throws { |
| 20 | let call = Call(playAudio: false) |
| 21 | fixture.apply(to: call) |
| 22 | call.levels.speaker.showFixture(speaker) |
| 23 | try await draw( |
| 24 | MacCallView( |
| 25 | call: call, grid: grid, style: .fullWindow, controlsShown: shown, leave: {}, rejoin: {} |
| 26 | ) |
| 27 | .tint(CallsAppearance.accent) |
| 28 | .environment(\.fixtureStagePicture, .busy), |
| 29 | size: size, to: folder.appendingPathComponent("mac-\(name).png")) |
| 30 | } |
| 31 | for shown in [true, false] { |
| 32 | let state = shown ? "controls" : "hidden" |
| 33 | try await shot("stage-camera-\(state)", shown: shown, speaker: "ana") |
| 34 | try await shot("stage-camera-off-\(state)", shown: shown, speaker: "tom") |
| 35 | try await shot("stage-screen-\(state)", .screen, shown: shown, speaker: "ana") |
| 36 | try await shot( |
| 37 | "stage-camera-760x540-\(state)", shown: shown, size: CGSize(width: 760, height: 540), |
| 38 | speaker: "ana") |
| 39 | try await shot( |
| 40 | "stage-screen-900x800-\(state)", .screen, shown: shown, size: CGSize(width: 900, height: 800), |
| 41 | speaker: "ana") |
| 42 | try await shot("grid-\(state)", grid: true, shown: shown, speaker: "ana") |
| 43 | } |
| 44 | for width in [MiniWindowRules.minimumWidth, MiniWindowRules.size.width, 480] { |
| 45 | for (who, label) in [("tom", "camera-off"), (nil, "self")] as [(String?, String)] { |
| 46 | let call = Call(playAudio: false) |
| 47 | CallFixture.grid.apply(to: call) |
| 48 | call.levels.speaker.showFixture(who) |
| 49 | if who == nil { call.showFixtureSelf(muted: false, cameraOff: true, sharingScreen: false) } |
| 50 | try await draw( |
| 51 | MiniWindowSnapshot.window(call: call, hovering: false), |
| 52 | size: CGSize(width: width, height: width / MiniWindowRules.aspect), |
| 53 | to: folder.appendingPathComponent("mini-\(Int(width))-\(label).png")) |
| 54 | } |
| 55 | } |
| 56 | let call = Call(playAudio: false) |
| 57 | CallFixture.grid.apply(to: call) |
| 58 | try await draw( |
| 59 | MiniWindowSnapshot.tab(call: call), size: MiniWindowTab.size, |
| 60 | to: folder.appendingPathComponent("mini-tab.png")) |
| 61 | } |
| 62 | |
| 63 | private static func draw(_ content: some View, size: CGSize, to file: URL) async throws { |
| 64 | try await LobbySnapshots.render(content, scheme: .dark, size: size, to: file) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /// Portrait video (2026-10-21), before and after: a phone held upright |
| 69 | /// (Ana, 720 × 1280) and a laptop (Li, 1280 × 720) as the stage, in the |
| 70 | /// filmstrip, in Grid and in the mini window. `before` draws 0.4.10's |
| 71 | /// placement, every camera filling; after, a camera of another shape than |
| 72 | /// its tile is fitted whole with its picture soft behind it. After also |
| 73 | /// has an upright self view, floating upright. |
| 74 | @MainActor enum PortraitSnapshots { |
| 75 | static func save(to folder: URL, before: Bool) async throws { |
| 76 | NSApplication.shared.setActivationPolicy(.prohibited) |
| 77 | try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true) |
| 78 | FixtureVideo.fillsEveryCamera = before |
| 79 | defer { FixtureVideo.fillsEveryCamera = false } |
| 80 | let tag = before ? "before" : "after" |
| 81 | let feeds = FixtureFeeds.parse("ana=720x1280,li=1280x720,me=1280x720") |
| 82 | func shot( |
| 83 | _ name: String, _ fixture: CallFixture = .grid, grid: Bool = false, speaker: String?, |
| 84 | feeds: [String: CGSize] = feeds, size: CGSize = CGSize(width: 1000, height: 640) |
| 85 | ) async throws { |
| 86 | let call = Call(playAudio: false) |
| 87 | fixture.apply(to: call) |
| 88 | call.levels.speaker.showFixture(speaker) |
| 89 | try await LobbySnapshots.render( |
| 90 | MacCallView( |
| 91 | call: call, grid: grid, style: .fullWindow, controlsShown: false, leave: {}, rejoin: {} |
| 92 | ) |
| 93 | .tint(CallsAppearance.accent) |
| 94 | .environment(\.fixtureStagePicture, .busy) |
| 95 | .environment(\.fixtureFeeds, feeds), |
| 96 | scheme: .dark, size: size, to: folder.appendingPathComponent("mac-\(name)-\(tag).png")) |
| 97 | } |
| 98 | // The stage: Ana's upright phone, with Li's laptop in the filmstrip; |
| 99 | // then Li's laptop on the stage, with Ana in the filmstrip. |
| 100 | try await shot("stage-portrait", speaker: "ana") |
| 101 | try await shot("stage-landscape-filmstrip-portrait", speaker: "li") |
| 102 | try await shot("grid", grid: true, speaker: "ana") |
| 103 | // A call of two: Ana fills the window's stage, and you float. |
| 104 | try await shot("stage-portrait-two", .focus, speaker: "ana") |
| 105 | if !before { |
| 106 | var upright = feeds |
| 107 | upright["me"] = CGSize(width: 720, height: 1280) |
| 108 | try await shot("self-portrait", .focus, speaker: "ana", feeds: upright) |
| 109 | } |
| 110 | for (who, label) in [("ana", "portrait"), ("li", "landscape")] { |
| 111 | let call = Call(playAudio: false) |
| 112 | CallFixture.grid.apply(to: call) |
| 113 | call.levels.speaker.showFixture(who) |
| 114 | try await LobbySnapshots.render( |
| 115 | MiniWindowSnapshot.window(call: call, hovering: false).environment(\.fixtureFeeds, feeds), |
| 116 | scheme: .dark, |
| 117 | size: CGSize(width: MiniWindowRules.size.width, height: MiniWindowRules.size.width / MiniWindowRules.aspect), |
| 118 | to: folder.appendingPathComponent("mac-mini-\(label)-\(tag).png")) |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | /// The floating self view against the control bar (2026-10-30, Paul on |
| 124 | /// 0.4.15: "The picture-in-picture is weirdly close to the in-call |
| 125 | /// chrome"): a call of two, and a call of one waiting for others, with the |
| 126 | /// controls shown and hidden, at the smallest window and a large one, in |
| 127 | /// the bottom right and the bottom left, and beside an open chat. Run once |
| 128 | /// on the code before a change and once after, with `tag` naming which. |
| 129 | @MainActor enum PiPSnapshots { |
| 130 | static func save(to folder: URL, tag: String) async throws { |
| 131 | NSApplication.shared.setActivationPolicy(.prohibited) |
| 132 | try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true) |
| 133 | let suite = "CallsInterop.PiPSnapshots" |
| 134 | guard let defaults = UserDefaults(suiteName: suite) else { return } |
| 135 | defaults.removePersistentDomain(forName: suite) |
| 136 | defer { defaults.removePersistentDomain(forName: suite) } |
| 137 | func shot( |
| 138 | _ name: String, _ fixture: CallFixture = .focus, corner: PiPCorner = .bottomTrailing, |
| 139 | chat: Bool = false, shown: Bool, size: CGSize |
| 140 | ) async throws { |
| 141 | defaults.set(corner.rawValue, forKey: PiPCorner.key) |
| 142 | let file = folder.appendingPathComponent( |
| 143 | "pip-\(name)-\(Int(size.width))x\(Int(size.height))-\(shown ? "shown" : "hidden")-\(tag).png") |
| 144 | let call = Call(playAudio: false) |
| 145 | fixture.apply(to: call) |
| 146 | call.levels.speaker.showFixture(fixture == .alone ? nil : "ana") |
| 147 | try await LobbySnapshots.render( |
| 148 | MacCallView( |
| 149 | call: call, grid: false, showingChat: chat, style: .fullWindow, controlsShown: shown, |
| 150 | leave: {}, rejoin: {} |
| 151 | ) |
| 152 | .tint(CallsAppearance.accent) |
| 153 | .environment(\.fixtureStagePicture, .busy) |
| 154 | .defaultAppStorage(defaults), |
| 155 | scheme: .dark, size: size, to: file) |
| 156 | // Off screen there is no glass, so the pane is outlined where it |
| 157 | // laid out: what the self view is kept clear of. |
| 158 | if shown { outline(CallBarProbe.pane, in: file, size: size) } |
| 159 | } |
| 160 | for size in [CGSize(width: 760, height: 540), CGSize(width: 1440, height: 900)] { |
| 161 | for shown in [true, false] { |
| 162 | try await shot("two-bottom-right", shown: shown, size: size) |
| 163 | try await shot("alone-bottom-right", .alone, shown: shown, size: size) |
| 164 | try await shot("two-bottom-left", corner: .bottomLeading, shown: shown, size: size) |
| 165 | } |
| 166 | try await shot("two-chat", chat: true, shown: true, size: size) |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | /// Strokes `rect` (top-left origin, points) as a capsule onto the PNG |
| 171 | /// at `file`, drawn for a view `size` points large. |
| 172 | private static func outline(_ rect: CGRect, in file: URL, size: CGSize) { |
| 173 | guard rect.width > 1, let image = NSImage(contentsOf: file), |
| 174 | let rep = image.representations.first as? NSBitmapImageRep ?? NSBitmapImageRep( |
| 175 | data: image.tiffRepresentation ?? Data()), |
| 176 | let context = NSGraphicsContext(bitmapImageRep: rep) |
| 177 | else { return } |
| 178 | let scale = CGFloat(rep.pixelsWide) / size.width |
| 179 | NSGraphicsContext.saveGraphicsState() |
| 180 | NSGraphicsContext.current = context |
| 181 | let flipped = CGRect( |
| 182 | x: rect.minX * scale, y: (size.height - rect.maxY) * scale, width: rect.width * scale, |
| 183 | height: rect.height * scale) |
| 184 | let path = NSBezierPath( |
| 185 | roundedRect: flipped, xRadius: flipped.height / 2, yRadius: flipped.height / 2) |
| 186 | NSColor(white: 1, alpha: 0.08).setFill() |
| 187 | path.fill() |
| 188 | NSColor(white: 1, alpha: 0.45).setStroke() |
| 189 | path.lineWidth = 1.5 * scale |
| 190 | path.stroke() |
| 191 | NSGraphicsContext.restoreGraphicsState() |
| 192 | try? rep.representation(using: .png, properties: [:])?.write(to: file) |
| 193 | } |
| 194 | } |
| 195 | |