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.
261 lines
9.4 KiB
Swift
261 lines
9.4 KiB
Swift
import AppKit
|
|
import SwiftUI
|
|
import ShotdeckCore
|
|
|
|
/// "Past sessions" window: every retained session, whose captures they were, and
|
|
/// which PDF (if any) went out for them. Read-and-reveal only — the current session
|
|
/// is started/closed from the menu-bar panel and the button on the row below.
|
|
struct PastSubmissionsView: View {
|
|
@Environment(AppModel.self) private var model
|
|
@State private var searchText = ""
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
currentSessionRow
|
|
Divider()
|
|
if model.pastSessions.isEmpty {
|
|
emptyState
|
|
} else {
|
|
searchField
|
|
sessionList
|
|
}
|
|
Divider()
|
|
footer
|
|
}
|
|
.padding(12)
|
|
.frame(width: 460, alignment: .leading)
|
|
.controlSize(.small)
|
|
.task {
|
|
if let problem = await model.reloadFromSpool() {
|
|
model.setStatus(problem)
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Current session
|
|
|
|
private var currentSessionRow: some View {
|
|
HStack(alignment: .top, spacing: 8) {
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
HStack(spacing: 6) {
|
|
Text("Current session")
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
Spacer(minLength: 6)
|
|
Text(SessionDisplay.fullLabel(for: model.session))
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
.monospacedDigit()
|
|
}
|
|
Text(currentSessionSummary)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
Text(contextSummary)
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
Spacer(minLength: 8)
|
|
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.")
|
|
}
|
|
}
|
|
|
|
private var currentSessionSummary: String {
|
|
let count = model.session.captures.count
|
|
if count == 0 {
|
|
return "Nothing captured yet."
|
|
}
|
|
return "\(count) capture\(count == 1 ? "" : "s") · started \(DubaiTime.stamp(model.session.createdAt))"
|
|
}
|
|
|
|
private var contextSummary: String {
|
|
let summary = model.sessionContext.summaryLine
|
|
return summary.isEmpty ? "No lane or build recorded — add details in the menu panel." : summary
|
|
}
|
|
|
|
// MARK: - List
|
|
|
|
private var emptyState: some View {
|
|
Text("No past sessions yet. “New session” keeps the current captures and starts a fresh one.")
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.padding(.vertical, 12)
|
|
}
|
|
|
|
private var searchField: some View {
|
|
HStack(spacing: 6) {
|
|
Image(systemName: "magnifyingglass")
|
|
.foregroundStyle(.secondary)
|
|
TextField("Search lane, build, commit, reviewer or file name", text: $searchText)
|
|
.textFieldStyle(.plain)
|
|
.font(.caption)
|
|
.onSubmit { }
|
|
if !searchText.isEmpty {
|
|
Button {
|
|
searchText = ""
|
|
} label: {
|
|
Image(systemName: "xmark.circle.fill")
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
.buttonStyle(.plain)
|
|
.accessibilityLabel("Clear search")
|
|
}
|
|
}
|
|
.padding(.horizontal, 6)
|
|
.padding(.vertical, 4)
|
|
.background(.quaternary.opacity(0.5), in: RoundedRectangle(cornerRadius: 5, style: .continuous))
|
|
}
|
|
|
|
private var filteredSessions: [CaptureSession] {
|
|
let needle = searchText.trimmingCharacters(in: .whitespaces).lowercased()
|
|
guard !needle.isEmpty else { return model.pastSessions }
|
|
return model.pastSessions.filter { session in
|
|
let haystack = [
|
|
session.context.lane,
|
|
session.context.deployedVersion,
|
|
session.context.commit,
|
|
session.context.reviewer,
|
|
session.context.note,
|
|
session.pdfFileName ?? "",
|
|
SessionDisplay.fullLabel(for: session),
|
|
DubaiTime.stamp(session.createdAt),
|
|
].joined(separator: " ").lowercased()
|
|
return haystack.contains(needle)
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var sessionList: some View {
|
|
let sessions = filteredSessions
|
|
if sessions.isEmpty {
|
|
Text("No session matches “\(searchText)”.")
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
} else {
|
|
ScrollView {
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
ForEach(sessions) { session in
|
|
PastSessionRow(session: session)
|
|
Divider()
|
|
}
|
|
}
|
|
}
|
|
.frame(maxHeight: 340)
|
|
}
|
|
}
|
|
|
|
// MARK: - Footer
|
|
|
|
private var footer: some View {
|
|
HStack(alignment: .center, spacing: 8) {
|
|
VStack(alignment: .leading, spacing: 1) {
|
|
Text(model.retentionSummary)
|
|
.font(.caption)
|
|
Text("Sent PDFs are never deleted.")
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
Spacer(minLength: 8)
|
|
Button("Sessions folder") {
|
|
model.openSessionsFolder()
|
|
}
|
|
.help("Open the folder that holds every kept session")
|
|
}
|
|
}
|
|
}
|
|
|
|
private struct PastSessionRow: View {
|
|
@Environment(AppModel.self) private var model
|
|
let session: CaptureSession
|
|
|
|
var body: some View {
|
|
HStack(alignment: .top, spacing: 10) {
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
HStack(spacing: 6) {
|
|
Text(DubaiTime.stamp(session.createdAt))
|
|
.monospacedDigit()
|
|
Text(SessionDisplay.fullLabel(for: session))
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
.monospacedDigit()
|
|
}
|
|
Text(contextLine)
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
Text(submissionLabel)
|
|
.font(.caption)
|
|
}
|
|
Spacer(minLength: 8)
|
|
VStack(alignment: .trailing, spacing: 4) {
|
|
Button("Reveal PDF") {
|
|
model.revealSentPDF(session)
|
|
}
|
|
.disabled(model.sentPDFURL(for: session) == nil)
|
|
.help(pdfHelpText)
|
|
Button("Captures") {
|
|
model.revealSessionCaptures(session)
|
|
}
|
|
.help("Reveal this session's screenshots")
|
|
}
|
|
}
|
|
.padding(.vertical, 6)
|
|
}
|
|
|
|
/// Everything recorded for the session except the lane, which the row's label
|
|
/// already shows: deployed build, commit, reviewer, note.
|
|
private var contextLine: String {
|
|
let context = session.context
|
|
var parts: [String] = []
|
|
if !context.deployedVersion.isEmpty { parts.append(context.deployedVersion) }
|
|
if !context.commit.isEmpty { parts.append(context.commit) }
|
|
if !context.reviewer.isEmpty { parts.append(context.reviewer) }
|
|
if !context.note.isEmpty { parts.append("Note: \(context.note)") }
|
|
return parts.isEmpty ? "No build or commit recorded" : parts.joined(separator: " · ")
|
|
}
|
|
|
|
private var submissionLabel: String {
|
|
let pages = "\(session.captures.count) page\(session.captures.count == 1 ? "" : "s")"
|
|
guard let name = session.pdfFileName else {
|
|
return "\(pages) · not sent"
|
|
}
|
|
return "\(pages) · sent as \(name)"
|
|
}
|
|
|
|
private var pdfHelpText: String {
|
|
guard let name = session.pdfFileName else { return "This session was never sent." }
|
|
guard model.sentPDFURL(for: session) != nil else {
|
|
return "The PDF \(name) is no longer in the output folder."
|
|
}
|
|
return "Reveal \(name)"
|
|
}
|
|
}
|
|
|
|
extension AppModel: SubmissionsWindowPresenting {
|
|
private static var submissionsWindowController: NSWindowController?
|
|
|
|
public func presentSubmissionsWindow() {
|
|
if let existing = Self.submissionsWindowController {
|
|
existing.window?.makeKeyAndOrderFront(nil)
|
|
NSApp.activate()
|
|
return
|
|
}
|
|
let hosting = NSHostingController(rootView: PastSubmissionsView().environment(self))
|
|
let window = NSWindow(contentViewController: hosting)
|
|
window.title = "Redline — Past sessions"
|
|
window.styleMask = [.titled, .closable]
|
|
window.isReleasedWhenClosed = false
|
|
window.center()
|
|
let controller = NSWindowController(window: window)
|
|
Self.submissionsWindowController = controller
|
|
controller.showWindow(nil)
|
|
NSApp.activate()
|
|
}
|
|
}
|