Files
shotdeck/Sources/Shotdeck/MenuBarView.swift
T
Claude Fable 5 3061e45bcb feat(ui): rebuild the UX around two surfaces — a glance popover and a session window
The menu-bar popover was being used as a session manager: status, five text fields,
thumbnails, three buttons, a history list and eight more flat rows in 320 pt. The
redesign splits the product by job, from a UX pass whose mockups are kept under
design/ux-rework/.

- Popover: only the current session. Review details as one line plus a pencil that
  opens the window with the Lane field focused, at most three thumbnails, a Capture
  and a Send row, a New Session and Open Redline row, one status line when something
  happened, and a footer with the send channel, the retention policy and a ... menu
  for Settings / updates / quit.
- Window: sidebar of sessions grouped Today / Yesterday / This week / by month with
  a Current tag and each session's state, the selected session's pages as cards
  (select, Delete or Remove Page, sent sessions read-only), and an inspector with
  editable review details, the PDF facts (file name, pages, channel, status) and the
  session facts (started, id, files). Past sessions show their details read-only.
- Settings: three labelled groups (Capture, Sending, Sessions) replacing the
  headings-plus-grid layout.
- Sessions list/search/grouping/state live on the model, so the window and the popover
  read the same truth (came-back-marked state comes from the return ledger).
- Verification: 159 tests, the headless panel self-test, and an end-to-end run against
  the active app (scripts/run-e2e-ui.sh) which opens the real window, types into the
  Lane field with key events and clicks New Session, reporting what the launch mode
  could and could not deliver.
2026-10-31 13:03:08 +04:00

296 lines
10 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)
}
}