import AppKit import SwiftUI import ShotdeckCore /// The menu-bar popover: the current session, and the two things you do with it. /// /// Everything else — history, review details, PDF facts — lives in the Redline /// window, which stays open and has room for it. struct MenuBarView: View { @Environment(AppModel.self) private var model var body: some View { VStack(alignment: .leading, spacing: 8) { if model.screenRecordingGranted { sessionHeader thumbnailRow statusRow actionRows Divider() footer } else { permissionBlock Divider() footer } } .padding(10) .frame(width: 340, alignment: .leading) .controlSize(.small) } // MARK: - Header private var sessionHeader: 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) .help(detailLine) } Spacer(minLength: 4) if !model.session.isEmpty { Text("\(model.session.captures.count) page\(model.session.captures.count == 1 ? "" : "s")") .font(.caption) .foregroundStyle(.secondary) .monospacedDigit() .padding(.horizontal, 6) .padding(.vertical, 2) .background(.quaternary, in: Capsule()) } 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") } } 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 started = DubaiTime.checkTime(model.session.createdAt) if parts.isEmpty { return "No review details yet · started \(started)" } return parts.joined(separator: " · ") + " · started \(started)" } // MARK: - Body @ViewBuilder private var thumbnailRow: some View { if model.session.isEmpty { VStack(spacing: 2) { Text("Nothing captured 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 { guard let region = model.region else { return "\(model.hotkeyDisplayString) picks an area, then captures it" } return "\(model.hotkeyDisplayString) captures \(Int(region.rect.width)) × \(Int(region.rect.height)) on \(displayName(for: region))" } private func displayName(for region: CaptureRegion) -> String { for (index, screen) in NSScreen.screens.enumerated() { let id = (screen.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as? NSNumber)? .uint32Value if id == region.displayID { return "Display \(index + 1)" } } return "Display 1" } /// One line, only when there is something to say: the last action's result, or a /// PDF that came back with marks. @ViewBuilder private var statusRow: some View { if let status = model.statusLine, !status.isEmpty { Text(status) .font(.caption) .foregroundStyle(.secondary) .lineLimit(2) .fixedSize(horizontal: false, vertical: true) } } private var actionRows: 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 { model.setStatus("Send is not available in this build.") 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.startNewSession() } } label: { HStack(spacing: 4) { Image(systemName: "plus.square.on.square") Text("New Session") } .frame(maxWidth: .infinity) } .controlSize(.regular) .disabled(!model.canStartNewSession) .help("Keeps this session and starts a fresh one. Nothing is deleted.") 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: - Footer private var footer: some View { HStack(spacing: 6) { Text("\(sendChannel) · \(model.retentionSummary)") .font(.caption) .foregroundStyle(.secondary) .lineLimit(1) .truncationMode(.tail) Spacer(minLength: 4) Menu { Button("Settings…") { (model as? SettingsWindowPresenting)?.presentSettingsWindow() } .keyboardShortcut(",", modifiers: .command) Button(model.isCheckingForUpdates ? "Checking for Updates…" : "Check for Updates…") { model.checkForUpdates() } .disabled(model.isCheckingForUpdates) if let update = model.updateAvailable { Button("Update to \(update.version)") { model.installUpdate() } } if let previous = model.previousVersion { Button("Revert to \(previous)") { model.revertToPreviousVersion() } } Divider() Button("Quit Redline") { NSApp.terminate(nil) } .keyboardShortcut("q", modifiers: .command) } label: { Image(systemName: "ellipsis.circle") } .menuStyle(.borderlessButton) .menuIndicator(.hidden) .fixedSize() .help("More Redline actions") .accessibilityLabel("More") } .overlay(alignment: .topTrailing) { EmptyView() } } private var sendChannel: String { model.transport == .oneDrive ? "Saves to OneDrive" : "Sends via AirDrop" } // MARK: - Not granted 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) } }