import AppKit import SwiftUI import ShotdeckCore /// The menu-bar popover: decide what to capture, see the pages, then capture or send. /// History, editable details and file facts live in the Redline window; Settings has /// exactly one door — the gear here (⌘, works anywhere). struct MenuBarView: View { @Environment(AppModel.self) private var model var body: some View { VStack(alignment: .leading, spacing: 8) { if model.screenRecordingGranted { header scopeControl pageStrip newsRow verbs } else { permissionBlock } } .padding(10) .frame(width: 340, alignment: .leading) .controlSize(.small) } // MARK: - Header private var header: some View { HStack(alignment: .top, spacing: 8) { VStack(alignment: .leading, spacing: 1) { HStack(spacing: 5) { Text(laneTitle) .font(.system(size: 13, weight: .semibold)) .lineLimit(1) if let version = versionTitle { Text(version) .font(.system(size: 13)) .foregroundStyle(.secondary) .lineLimit(1) } } Text(detailLine) .font(.caption) .foregroundStyle(.secondary) .lineLimit(1) .truncationMode(.tail) } Spacer(minLength: 4) Button { presentWindow(focusLane: true) } label: { Image(systemName: "square.and.pencil") .font(.system(size: 12, weight: .semibold)) } .buttonStyle(.borderless) .help("Edit review details") .accessibilityLabel("Edit review details") Button { (model as? SettingsWindowPresenting)?.presentSettingsWindow() } label: { Image(systemName: "gearshape") .font(.system(size: 12, weight: .semibold)) } .buttonStyle(.borderless) .keyboardShortcut(",", modifiers: .command) .help("Settings (⌘,)") .accessibilityLabel("Settings") } } private var laneTitle: String { let lane = model.session.context.lane return lane.isEmpty ? "No lane" : lane } private var versionTitle: String? { let version = model.session.context.deployedVersion return version.isEmpty ? nil : version } private var detailLine: String { let context = model.session.context var parts: [String] = [] if !context.commit.isEmpty { parts.append(context.commit) } if !context.reviewer.isEmpty { parts.append(context.reviewer) } let pages = model.session.captures.count parts.append(pages == 0 ? "no pages" : "\(pages) page\(pages == 1 ? "" : "s")") return parts.joined(separator: " · ") } // MARK: - What to capture private var scopeControl: some View { VStack(alignment: .leading, spacing: 4) { Picker("Capture", selection: scopeBinding) { ForEach(CaptureScope.allCases, id: \.self) { scope in Text(scope.displayName).tag(scope) } } .pickerStyle(.segmented) .labelsHidden() .accessibilityLabel("Capture") HStack(spacing: 6) { Text(model.captureTargetDescription) .font(.caption) .foregroundStyle(.secondary) .lineLimit(1) .truncationMode(.tail) Spacer(minLength: 4) if model.captureScope == .area { Button("Choose Area…") { Task { await model.rePickRegion() } } .buttonStyle(.link) } } } } private var scopeBinding: Binding { Binding( get: { model.captureScope }, set: { scope in Task { await model.chooseCaptureScope(scope) } } ) } // MARK: - Pages @ViewBuilder private var pageStrip: some View { if model.session.isEmpty { VStack(spacing: 2) { Text("No pages yet") .font(.callout) .foregroundStyle(.secondary) Text(emptyHint) .font(.caption) .foregroundStyle(.tertiary) } .frame(maxWidth: .infinity, minHeight: 62) .background(.quaternary.opacity(0.4), in: RoundedRectangle(cornerRadius: 6, style: .continuous)) } else { SessionStrip(limit: 3) } } private var emptyHint: String { "\(model.hotkeyDisplayString) captures the \(model.captureScope.displayName.lowercased())" } // MARK: - News @ViewBuilder private var newsRow: some View { if let update = model.updateAvailable { HStack(spacing: 6) { Circle().fill(.green).frame(width: 6, height: 6) Text(model.autoInstallUpdates ? "Redline \(update.version) is ready — restarts when nothing is unsent" : "Redline \(update.version) is ready") .font(.caption) .lineLimit(2) Spacer(minLength: 4) Button("Restart Now") { model.installUpdate() } .buttonStyle(.link) } } else if let status = model.statusLine, !status.isEmpty { Text(status) .font(.caption) .foregroundStyle(.secondary) .lineLimit(2) .fixedSize(horizontal: false, vertical: true) } } // MARK: - Verbs private var verbs: some View { VStack(spacing: 6) { HStack(spacing: 6) { Button { Task { await model.captureNow() } } label: { HStack(spacing: 4) { Image(systemName: "viewfinder") Text(model.isCapturing ? "Capturing…" : "Capture") Text(model.hotkeyDisplayString) .foregroundStyle(.secondary) } .frame(maxWidth: .infinity) } .controlSize(.regular) .disabled(model.isCapturing) Button { guard let sender = model as? SendCapable else { return } let anchor = NSApp.keyWindow?.contentView Task { await sender.send(anchor: anchor) } } label: { HStack(spacing: 4) { Image(systemName: "paperplane.fill") Text(sendTitle) } .frame(maxWidth: .infinity) } .buttonStyle(.borderedProminent) .controlSize(.regular) .disabled(model.session.isEmpty || model.isSending) } HStack(spacing: 6) { Button { Task { await model.newSession() } } label: { HStack(spacing: 4) { Image(systemName: "plus.square.on.square") Text("New Session") } .frame(maxWidth: .infinity) } .controlSize(.regular) .disabled(model.isSending) .help("Keeps this session and starts a fresh one, then asks where to capture.") Button { presentWindow(focusLane: false) } label: { HStack(spacing: 4) { Image(systemName: "macwindow") Text("Open Redline") } .frame(maxWidth: .infinity) } .buttonStyle(.bordered) .controlSize(.regular) } } } private var sendTitle: String { let count = model.session.captures.count guard count > 0 else { return "Send…" } let pages = "\(count) page\(count == 1 ? "" : "s")" return model.transport == .oneDrive ? "Save \(pages)…" : "Send \(pages)…" } // MARK: - Permission private var permissionBlock: some View { HStack(alignment: .top, spacing: 6) { Image(systemName: "exclamationmark.triangle") .foregroundStyle(.yellow) VStack(alignment: .leading, spacing: 6) { Text( ShotdeckError.screenRecordingNotGranted.errorDescription ?? "Screen Recording is turned off." ) .font(.caption) .fixedSize(horizontal: false, vertical: true) Button("Open Screen Recording settings") { model.openScreenRecordingSettings() } } } } private func presentWindow(focusLane: Bool) { guard let presenter = model as? SessionsWindowPresenting else { model.setStatus("The Redline window is not available in this build.") return } presenter.presentSessionsWindow(focusLane: focusLane) } }