feat(sessions): past submissions list + start-new-session with 10-session retention
MMDB-2925. Two new menu functions in the Redline app: - "Start new session" keeps the current screenshots as a past session (moved into the single archive/ folder — never deleted on close) and opens a fresh empty session. Sessions closed without ever sending keep pdfFileName nil and show as "Not sent" in the list. - "Past submissions…" opens a window listing every retained session (timestamp, page count, what was sent) with actions to reveal the sent PDF and the session's screenshot folder. Retention (Ben's rule 2026-10-11: "retain the past 10 sessions"): both archive paths (send and close) keep the newest 10 archived session folders in archive/ and remove the rest. Any PDF a pruned session produced is untouched — it lives in the outbox/OneDrive folder. archivedSessions() ordering now tie-breaks same-second sessions by the session folder's creation date, so listing and pruning are deterministic (manifest timestamps are whole-second ISO8601 — format pinned in AtomicFileTests). Tests: 6 core tests in SessionRetentionTests (close/keep/reconcile, sent-vs-unsent, retention of 10, explicit prune, send-path retention) and 3 app-target tests in SessionWorkflowTests driving the real AppModel menu actions through AppDelegate.makeLaunchModel(). PanelSnapshot renders the new window as panel-06b-past-submissions.png.
This commit is contained in:
@@ -14,6 +14,11 @@ public protocol SettingsWindowPresenting: AnyObject {
|
||||
func presentSettingsWindow()
|
||||
}
|
||||
|
||||
@MainActor
|
||||
public protocol SubmissionsWindowPresenting: AnyObject {
|
||||
func presentSubmissionsWindow()
|
||||
}
|
||||
|
||||
@MainActor
|
||||
public protocol ReturnsSectionProviding: AnyObject {
|
||||
@ViewBuilder func returnsSection() -> AnyView
|
||||
@@ -27,6 +32,8 @@ public final class AppModel {
|
||||
public private(set) var screenRecordingGranted: Bool
|
||||
public private(set) var allReturns: [ReturnedDocument] = []
|
||||
public private(set) var commentedReturns: [ReturnedDocument] = []
|
||||
/// Retained past sessions (newest first) — what the Past submissions window lists.
|
||||
public private(set) var pastSessions: [CaptureSession] = []
|
||||
public private(set) var statusLine: String?
|
||||
public private(set) var isCapturing: Bool = false
|
||||
public private(set) var isSending: Bool = false
|
||||
@@ -134,6 +141,7 @@ public final class AppModel {
|
||||
allReturns = all
|
||||
commentedReturns = commented
|
||||
}
|
||||
func setPastSessions(_ value: [CaptureSession]) { pastSessions = value }
|
||||
func setFolderDisplayNames(outbox: String, watch: String) {
|
||||
outboxDisplayName = outbox
|
||||
watchFolderDisplayName = watch
|
||||
@@ -227,6 +235,12 @@ public final class AppModel {
|
||||
// Empty ledger on first run is not an error.
|
||||
}
|
||||
|
||||
do {
|
||||
setPastSessions(try await spool.archivedSessions())
|
||||
} catch {
|
||||
setStatus((error as? ShotdeckError)?.errorDescription ?? "Could not load past sessions.")
|
||||
}
|
||||
|
||||
// OneDrive mode: outbox == watch folder, so a freshly written, unmarked PDF must
|
||||
// never show up as a return; only a document that already carries a mark does.
|
||||
// Also make sure the resolved OneDrive folder actually exists before the
|
||||
@@ -389,6 +403,88 @@ public final class AppModel {
|
||||
}
|
||||
}
|
||||
|
||||
/// True when "Start new session" applies: there is something to keep and no send
|
||||
/// in flight that would archive the session on its own.
|
||||
public var canStartNewSession: Bool { !session.isEmpty && !isSending }
|
||||
|
||||
/// Menu "Start new session": keeps the current screenshots as a past session
|
||||
/// (moved into the single archive folder — never deleted) and opens a fresh empty
|
||||
/// session. Session retention (newest 10 kept) is applied inside the store, on
|
||||
/// this path and on the send path alike.
|
||||
public func startNewSession() async {
|
||||
var message: String
|
||||
do {
|
||||
if let archived = try await spool.closeCurrentSession() {
|
||||
let count = archived.captures.count
|
||||
message = "New session — \(count) capture\(count == 1 ? "" : "s") kept as a past session."
|
||||
} else {
|
||||
message = "New session started."
|
||||
}
|
||||
} catch {
|
||||
message = (error as? ShotdeckError)?.errorDescription ?? "Could not start a new session."
|
||||
}
|
||||
if let refreshProblem = await reloadFromSpool() {
|
||||
message += " \(refreshProblem)"
|
||||
}
|
||||
setStatus(message)
|
||||
}
|
||||
|
||||
/// Re-reads the open session and the past-session list from the store. Returns a
|
||||
/// problem description when either read failed (the caller decides how to surface
|
||||
/// it), nil when everything was refreshed — never silently substitutes stale state.
|
||||
func reloadFromSpool() async -> String? {
|
||||
var problems: [String] = []
|
||||
do {
|
||||
replaceSession(try await spool.currentSession())
|
||||
} catch {
|
||||
problems.append(
|
||||
"Could not reload the current session: \((error as? ShotdeckError)?.errorDescription ?? error.localizedDescription)")
|
||||
}
|
||||
do {
|
||||
setPastSessions(try await spool.archivedSessions())
|
||||
} catch {
|
||||
problems.append(
|
||||
"Could not load past sessions: \((error as? ShotdeckError)?.errorDescription ?? error.localizedDescription)")
|
||||
}
|
||||
return problems.isEmpty ? nil : problems.joined(separator: " ")
|
||||
}
|
||||
|
||||
/// Where a past session's sent PDF lives now (the outbox in AirDrop mode, the
|
||||
/// OneDrive folder in OneDrive mode), or nil when it was never sent / is gone.
|
||||
public func sentPDFURL(for session: CaptureSession) -> URL? {
|
||||
guard let name = session.pdfFileName else { return nil }
|
||||
let url = outboxURL.appendingPathComponent(name)
|
||||
return FileManager.default.fileExists(atPath: url.path) ? url : nil
|
||||
}
|
||||
|
||||
/// "PDF" action on a past-submission row: reveals the exact PDF that was sent.
|
||||
public func revealSentPDF(_ session: CaptureSession) {
|
||||
guard session.pdfFileName != nil else {
|
||||
setStatus("That session was never sent.")
|
||||
return
|
||||
}
|
||||
guard let url = sentPDFURL(for: session) else {
|
||||
setStatus("The PDF is no longer in \(outboxDisplayName).")
|
||||
return
|
||||
}
|
||||
NSWorkspace.shared.activateFileViewerSelecting([url])
|
||||
}
|
||||
|
||||
/// "Captures" action on a past-submission row: reveals that session's folder.
|
||||
public func revealSessionCaptures(_ session: CaptureSession) {
|
||||
let dir = paths.archiveDirectory(session.id)
|
||||
guard FileManager.default.fileExists(atPath: dir.path) else {
|
||||
setStatus("That past session is no longer on disk.")
|
||||
return
|
||||
}
|
||||
NSWorkspace.shared.activateFileViewerSelecting([dir])
|
||||
}
|
||||
|
||||
/// The single folder every retained session lives in.
|
||||
public func openSessionsFolder() {
|
||||
NSWorkspace.shared.open(paths.archive)
|
||||
}
|
||||
|
||||
public func copyCommentedLinks() async {
|
||||
do {
|
||||
let text = try await ledger.clipboardText()
|
||||
|
||||
Reference in New Issue
Block a user