Review verdict FAIL raised 7 defects; this addresses 1-5 and 7. 6 is
accepted as-is (see below).
1. Retention failure after a COMPLETED archive no longer throws: a failed
prune is logged loudly with the exact path and otherwise ignored, so a
successful send can never be reported as "The screenshot could not be
saved". The visible symptom of a failed prune is simply more than 10
sessions listed.
2. handleDidShareItems now refreshes the current session AND the
past-submissions list from the store on both the success and the
failure path (previously the menu count and any open window went stale
after every send). Any refresh problem is appended to the status line.
3. "Start new session" and send() now guard against each other
synchronously before their first await (isStartingNewSession flag on
both sides), instead of relying on the SwiftUI .disabled state alone —
a queued Task could otherwise rename the session directory out from
under an in-flight PDF compose.
4. Contract decision, documented in code: session retention prunes the
whole session folder INCLUDING removed/ parked captures. That is the
requested retention policy ("retain the past 10 sessions"), and the
D-11 never-delete note on remove() now says so explicitly.
5. Session ordering tie-break chain extended: manifest createdAt, then the
folder creation date, then the folder content-modification date, then
the id — so retention stays on real creation order even on a volume
that reports no creation date.
7. The PDF button's help text now distinguishes never-sent from
sent-but-no-longer-on-disk (the button was already disabled in both).
6 (empty close leaves the old empty spool/ folder behind) is left exactly
as the pinned SpoolStoreTests contract has it (startNewSession test 16
asserts the folder remains); it is pre-existing behavior, harmless (the
store reconciles and picks the newest candidate), and out of scope here.
Tests: 2 new app-target regression tests (send refreshes past
submissions; start/send refuse to overlap) — 134 tests pass.
147 lines
5.1 KiB
Swift
147 lines
5.1 KiB
Swift
import AppKit
|
|
import SwiftUI
|
|
import ShotdeckCore
|
|
|
|
/// "Past submissions…" window: every retained session and what was sent for it.
|
|
/// Read-and-reveal only — keeping/starting sessions is driven from the menu rows
|
|
/// (and the button on the current-session row below).
|
|
struct PastSubmissionsView: View {
|
|
@Environment(AppModel.self) private var model
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
currentSessionRow
|
|
Divider()
|
|
if model.pastSessions.isEmpty {
|
|
Text("No past sessions yet. Use “Start new session” to keep the current captures.")
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
} else {
|
|
ScrollView {
|
|
VStack(alignment: .leading, spacing: 6) {
|
|
ForEach(model.pastSessions) { session in
|
|
PastSessionRow(session: session)
|
|
}
|
|
}
|
|
}
|
|
.frame(maxHeight: 320)
|
|
}
|
|
Divider()
|
|
footer
|
|
}
|
|
.padding(10)
|
|
.frame(width: 420, alignment: .leading)
|
|
.controlSize(.small)
|
|
.task {
|
|
if let problem = await model.reloadFromSpool() {
|
|
model.setStatus(problem)
|
|
}
|
|
}
|
|
}
|
|
|
|
private var currentSessionRow: some View {
|
|
HStack(alignment: .center, spacing: 8) {
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text("Current session")
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
Text(currentSessionSummary)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
Spacer(minLength: 8)
|
|
Button("Start new session") {
|
|
Task { await model.startNewSession() }
|
|
}
|
|
.disabled(!model.canStartNewSession)
|
|
.help("Keeps these captures as a past session and starts a fresh one.")
|
|
}
|
|
}
|
|
|
|
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 footer: some View {
|
|
HStack(spacing: 8) {
|
|
Text("Sessions are kept in one folder — the newest \(SpoolStore.defaultRetainedSessionCount).")
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
Spacer(minLength: 8)
|
|
Button("Open sessions folder") {
|
|
model.openSessionsFolder()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private struct PastSessionRow: View {
|
|
@Environment(AppModel.self) private var model
|
|
let session: CaptureSession
|
|
|
|
var body: some View {
|
|
HStack(alignment: .center, spacing: 8) {
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text(DubaiTime.stamp(session.createdAt))
|
|
Text(submissionLabel)
|
|
.font(.caption)
|
|
.foregroundStyle(session.pdfFileName == nil ? .secondary : .primary)
|
|
.lineLimit(1)
|
|
}
|
|
Spacer(minLength: 8)
|
|
Button("PDF") {
|
|
model.revealSentPDF(session)
|
|
}
|
|
.disabled(model.sentPDFURL(for: session) == nil)
|
|
.help(pdfHelpText)
|
|
Button("Captures") {
|
|
model.revealSessionCaptures(session)
|
|
}
|
|
.help("Reveal this session's screenshots")
|
|
}
|
|
}
|
|
|
|
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)"
|
|
}
|
|
|
|
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)"
|
|
}
|
|
}
|
|
|
|
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 submissions"
|
|
window.styleMask = [.titled, .closable]
|
|
window.isReleasedWhenClosed = false
|
|
window.center()
|
|
let controller = NSWindowController(window: window)
|
|
Self.submissionsWindowController = controller
|
|
controller.showWindow(nil)
|
|
NSApp.activate()
|
|
}
|
|
}
|