Sessions are now the unit of the product instead of an implicit capture run. - Nothing is deleted by default: the fixed 10-session cap is gone. An age limit (Never / 7 / 14 / 30 / 90 / 180 / 365 days) is chosen in Settings > Sessions and applied on launch, after archiving, and by "Clean up now". Sent PDFs are never touched. - Each session carries review details: lane, deployed version, commit, reviewer (pre-filled with the Mac user) and a free note. They persist in session.json and are inherited by the next session, so a review run is typed once. - PDF file names are Redline-<yyyyMMdd-HHmm>-<LANE>-<SHORTID>.pdf, and every page carries a two-line reference footer (tool, build time, session / lane, deployed build, commit, reviewer, note). The PDF document info carries the same values in Author and Keywords. - Verification: 159 tests, a headless panel self-test, and a LaunchServices-driven end-to-end run that types and clicks the real panel.
410 lines
15 KiB
Swift
410 lines
15 KiB
Swift
import AppKit
|
||
import SwiftUI
|
||
import ShotdeckCore
|
||
|
||
/// The menu-bar panel. Hierarchy: what is being worked on first, the three core
|
||
/// verbs second, recent sessions third, housekeeping last.
|
||
struct MenuBarView: View {
|
||
@Environment(AppModel.self) private var model
|
||
/// Snapshot-only: opens the details editor on first render.
|
||
private let startsWithDetailsOpen: Bool
|
||
@State private var showsDetails = false
|
||
|
||
init(showsContextEditor: Bool = false) {
|
||
self.startsWithDetailsOpen = showsContextEditor
|
||
}
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 10) {
|
||
statusRow
|
||
sessionBlock
|
||
Divider()
|
||
recentSessionsBlock
|
||
Divider()
|
||
secondaryActions
|
||
if !model.allReturns.isEmpty {
|
||
Divider()
|
||
returnsBlock
|
||
}
|
||
Divider()
|
||
footer
|
||
}
|
||
.padding(10)
|
||
.frame(width: 320, alignment: .leading)
|
||
.controlSize(.small)
|
||
.onAppear { showsDetails = startsWithDetailsOpen }
|
||
}
|
||
|
||
// MARK: - Status
|
||
|
||
@ViewBuilder
|
||
private var statusRow: some View {
|
||
if !model.screenRecordingGranted {
|
||
HStack(alignment: .top, spacing: 6) {
|
||
Image(systemName: "exclamationmark.triangle")
|
||
.foregroundStyle(.yellow)
|
||
VStack(alignment: .leading, spacing: 4) {
|
||
Text(
|
||
ShotdeckError.screenRecordingNotGranted.errorDescription
|
||
?? "Screen Recording is turned off."
|
||
)
|
||
.font(.caption)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
Button("Open Screen Recording settings") {
|
||
model.openScreenRecordingSettings()
|
||
}
|
||
}
|
||
}
|
||
} else if let status = model.statusLine {
|
||
Text(status)
|
||
.font(.caption)
|
||
.foregroundStyle(.primary)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
} else {
|
||
Text(defaultStatusText)
|
||
.font(.caption)
|
||
.foregroundStyle(.secondary)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
}
|
||
}
|
||
|
||
private var defaultStatusText: String {
|
||
guard let region = model.region else {
|
||
return "No area selected yet — press \(model.hotkeyDisplayString) to pick one."
|
||
}
|
||
let w = Int(region.rect.width)
|
||
let h = Int(region.rect.height)
|
||
return "Capturing \(w) × \(h) 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"
|
||
}
|
||
|
||
// MARK: - Current session
|
||
|
||
private var sessionBlock: some View {
|
||
VStack(alignment: .leading, spacing: 6) {
|
||
HStack(alignment: .firstTextBaseline, spacing: 6) {
|
||
Text("Current session")
|
||
.font(.caption.weight(.semibold))
|
||
Spacer(minLength: 6)
|
||
Text(captureCountText)
|
||
.font(.caption)
|
||
.foregroundStyle(.secondary)
|
||
.monospacedDigit()
|
||
}
|
||
|
||
HStack(alignment: .firstTextBaseline, spacing: 6) {
|
||
Text(contextSummary)
|
||
.font(.caption)
|
||
.foregroundStyle(model.sessionContext.summaryLine.isEmpty ? .secondary : .primary)
|
||
.lineLimit(1)
|
||
.truncationMode(.tail)
|
||
.help(contextSummary)
|
||
Spacer(minLength: 4)
|
||
// A bordered control, not a link: in a menu panel the row of text is
|
||
// the value, and the thing you press has to look pressable.
|
||
Button {
|
||
showsDetails.toggle()
|
||
} label: {
|
||
HStack(spacing: 2) {
|
||
Text(showsDetails ? "Hide" : "Details")
|
||
Image(systemName: showsDetails ? "chevron.up" : "chevron.down")
|
||
.font(.system(size: 9, weight: .semibold))
|
||
}
|
||
}
|
||
.buttonStyle(.bordered)
|
||
.accessibilityLabel(showsDetails ? "Hide details" : "Show details")
|
||
}
|
||
|
||
if showsDetails {
|
||
SessionContextEditor()
|
||
}
|
||
|
||
SessionStrip()
|
||
|
||
HStack(spacing: 6) {
|
||
Button("Capture") {
|
||
Task { await model.captureNow() }
|
||
}
|
||
.disabled(model.isCapturing)
|
||
|
||
Button(model.transport == .oneDrive ? "Send to OneDrive" : "Send…") {
|
||
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) }
|
||
}
|
||
.buttonStyle(.borderedProminent)
|
||
.disabled(model.session.isEmpty || model.isSending)
|
||
|
||
Button("New session") {
|
||
Task { await model.startNewSession() }
|
||
}
|
||
.disabled(!model.canStartNewSession)
|
||
.help("Keeps these captures as a past session and starts a fresh one. Nothing is deleted.")
|
||
}
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
}
|
||
}
|
||
|
||
private var captureCountText: String {
|
||
let count = model.session.captures.count
|
||
if count == 0 { return "empty" }
|
||
return "\(count) capture\(count == 1 ? "" : "s")"
|
||
}
|
||
|
||
private var contextSummary: String {
|
||
let summary = model.sessionContext.summaryLine
|
||
return summary.isEmpty ? "No lane or build recorded — add details" : summary
|
||
}
|
||
|
||
// MARK: - Recent sessions
|
||
|
||
private var recentSessionsBlock: some View {
|
||
VStack(alignment: .leading, spacing: 3) {
|
||
HStack(alignment: .firstTextBaseline, spacing: 6) {
|
||
Text("Recent sessions")
|
||
.font(.caption.weight(.semibold))
|
||
if !model.pastSessions.isEmpty {
|
||
Text("\(model.pastSessions.count)")
|
||
.font(.caption)
|
||
.foregroundStyle(.secondary)
|
||
.monospacedDigit()
|
||
}
|
||
Spacer(minLength: 6)
|
||
Button("Show all…") {
|
||
if let presenter = model as? SubmissionsWindowPresenting {
|
||
presenter.presentSubmissionsWindow()
|
||
} else {
|
||
model.setStatus("Past sessions are not available in this build.")
|
||
}
|
||
}
|
||
.buttonStyle(.link)
|
||
}
|
||
|
||
if model.pastSessions.isEmpty {
|
||
Text("Nothing yet. “New session” keeps this one and starts a fresh one.")
|
||
.font(.caption)
|
||
.foregroundStyle(.secondary)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
} else {
|
||
ForEach(model.pastSessions.prefix(4)) { session in
|
||
RecentSessionRow(session: session)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// MARK: - Secondary actions
|
||
|
||
private var secondaryActions: some View {
|
||
VStack(alignment: .leading, spacing: 2) {
|
||
if let update = model.updateAvailable {
|
||
Button {
|
||
model.installUpdate()
|
||
} label: {
|
||
actionLabel("Update to \(update.version)")
|
||
.foregroundStyle(Color.accentColor)
|
||
}
|
||
}
|
||
|
||
if let previous = model.previousVersion {
|
||
Button {
|
||
model.revertToPreviousVersion()
|
||
} label: {
|
||
actionLabel("Revert to \(previous)")
|
||
}
|
||
}
|
||
|
||
Button {
|
||
model.revealLastPDF()
|
||
} label: {
|
||
actionLabel("Reveal last PDF")
|
||
}
|
||
.disabled(!model.canRevealLastPDF)
|
||
|
||
Button {
|
||
Task { await model.copyCommentedLinks() }
|
||
} label: {
|
||
actionLabel(
|
||
"Copy commented links",
|
||
trailing: model.commentedReturns.isEmpty ? nil : "\(model.commentedReturns.count)"
|
||
)
|
||
}
|
||
.disabled(model.commentedReturns.isEmpty)
|
||
|
||
Button {
|
||
Task { await model.rePickRegion() }
|
||
} label: {
|
||
actionLabel("Re-select area")
|
||
}
|
||
|
||
Button {
|
||
Task { await model.captureNow() }
|
||
} label: {
|
||
actionLabel("Capture now", trailing: model.hotkeyDisplayString)
|
||
}
|
||
.disabled(model.isCapturing)
|
||
}
|
||
.buttonStyle(.plain)
|
||
}
|
||
|
||
private func actionLabel(_ title: String, trailing: String? = nil) -> some View {
|
||
HStack(spacing: 8) {
|
||
Text(title)
|
||
Spacer(minLength: 8)
|
||
if let trailing {
|
||
Text(trailing)
|
||
.foregroundStyle(.secondary)
|
||
.monospacedDigit()
|
||
}
|
||
}
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
.contentShape(Rectangle())
|
||
.padding(.vertical, 3)
|
||
}
|
||
|
||
@ViewBuilder
|
||
private var returnsBlock: some View {
|
||
if let provider = model as? ReturnsSectionProviding {
|
||
provider.returnsSection()
|
||
} else {
|
||
VStack(alignment: .leading, spacing: 4) {
|
||
Text("Came back from your device")
|
||
.font(.caption.weight(.semibold))
|
||
ForEach(newestReturns.prefix(6)) { doc in
|
||
HStack(spacing: 8) {
|
||
Text(doc.fileURL.lastPathComponent)
|
||
.lineLimit(1)
|
||
Spacer(minLength: 8)
|
||
Text(doc.isCommented
|
||
? "\(doc.annotatedPages.count) page\(doc.annotatedPages.count == 1 ? "" : "s") marked"
|
||
: "not marked")
|
||
.font(.caption)
|
||
.foregroundStyle(doc.isCommented ? .primary : .secondary)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private var newestReturns: [ReturnedDocument] {
|
||
model.allReturns.sorted { $0.detectedAt > $1.detectedAt }
|
||
}
|
||
|
||
// MARK: - Footer
|
||
|
||
private var footer: some View {
|
||
VStack(alignment: .leading, spacing: 3) {
|
||
HStack(spacing: 6) {
|
||
Button("Settings…") {
|
||
if let presenter = model as? SettingsWindowPresenting {
|
||
presenter.presentSettingsWindow()
|
||
} else {
|
||
model.setStatus("Settings is not available in this build.")
|
||
}
|
||
}
|
||
.buttonStyle(.link)
|
||
Button("Check for updates") {
|
||
model.checkForUpdates()
|
||
}
|
||
.buttonStyle(.link)
|
||
.disabled(model.isCheckingForUpdates)
|
||
Spacer(minLength: 6)
|
||
Button("Quit") {
|
||
NSApp.terminate(nil)
|
||
}
|
||
.buttonStyle(.link)
|
||
}
|
||
Text("Redline \(model.appVersion) · \(model.retentionSummary)")
|
||
.font(.caption)
|
||
.foregroundStyle(.secondary)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
if let message = model.updateStatusMessage {
|
||
Text(message)
|
||
.font(.caption)
|
||
.foregroundStyle(.secondary)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// One row of the panel's recent-sessions list: timestamp, readable session label,
|
||
/// page count and sent state. Clicking reveals the sent PDF when there is one,
|
||
/// otherwise that session's captures.
|
||
private struct RecentSessionRow: View {
|
||
@Environment(AppModel.self) private var model
|
||
let session: CaptureSession
|
||
@State private var hovering = false
|
||
|
||
var body: some View {
|
||
Button {
|
||
if model.sentPDFURL(for: session) != nil {
|
||
model.revealSentPDF(session)
|
||
} else {
|
||
model.revealSessionCaptures(session)
|
||
}
|
||
} label: {
|
||
HStack(spacing: 6) {
|
||
Text(DubaiTime.shortStamp(session.createdAt))
|
||
.font(.caption)
|
||
.monospacedDigit()
|
||
.foregroundStyle(.secondary)
|
||
Text(SessionDisplay.label(for: session))
|
||
.font(.caption)
|
||
.lineLimit(1)
|
||
.truncationMode(.tail)
|
||
Spacer(minLength: 6)
|
||
Text(session.pdfFileName == nil ? "Not sent" : "Sent")
|
||
.font(.caption)
|
||
.foregroundStyle(session.pdfFileName == nil ? .secondary : .primary)
|
||
}
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
.padding(.vertical, 2)
|
||
.contentShape(Rectangle())
|
||
.background(hovering ? AnyShapeStyle(.quaternary) : AnyShapeStyle(.clear))
|
||
}
|
||
.buttonStyle(.plain)
|
||
.onHover { hovering = $0 }
|
||
.help(helpText)
|
||
}
|
||
|
||
private var helpText: String {
|
||
let pages = "\(session.captures.count) page\(session.captures.count == 1 ? "" : "s")"
|
||
let context = session.context.summaryLine
|
||
let detail = context.isEmpty ? pages : "\(pages) · \(context)"
|
||
if let name = session.pdfFileName {
|
||
return "\(detail)\nSent as \(name)"
|
||
}
|
||
return "\(detail)\nNever sent — opens the captures"
|
||
}
|
||
}
|
||
|
||
/// Readable labels for sessions, shared by the panel and the Past sessions window.
|
||
///
|
||
/// The label is what the user typed plus the session's short id — never the
|
||
/// upper-cased file-name slug, which is for filesystems, not people.
|
||
enum SessionDisplay {
|
||
static func label(for session: CaptureSession) -> String {
|
||
let lane = session.context.lane
|
||
return lane.isEmpty ? session.shortID : lane
|
||
}
|
||
|
||
static func fullLabel(for session: CaptureSession) -> String {
|
||
let lane = session.context.lane
|
||
return lane.isEmpty ? session.shortID : "\(lane) · \(session.shortID)"
|
||
}
|
||
}
|