Merge pull request 'Redline: past submissions list + start-new-session with 10-session retention (MMDB-2925)' (#29) from feat/redline-sessions-history-20261011 into main
This commit was merged in pull request #29.
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,10 +32,17 @@ 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 updateStatus: String?
|
||||
public private(set) var isCapturing: Bool = false
|
||||
public private(set) var isSending: Bool = false
|
||||
/// True while "Start new session" is between its guard and its store call — the
|
||||
/// synchronous flag both this action and send() check BEFORE their first await, so
|
||||
/// the two can never interleave a session close with an in-flight compose (a
|
||||
/// SwiftUI `.disabled` render-time guard alone does not stop a queued Task).
|
||||
public private(set) var isStartingNewSession: Bool = false
|
||||
public private(set) var outboxDisplayName: String
|
||||
public private(set) var watchFolderDisplayName: String
|
||||
/// Live transport choice; WP-onedrive reads this to pick the send path and to drive
|
||||
@@ -126,6 +138,9 @@ public final class AppModel {
|
||||
func setStatus(_ text: String?) { statusLine = text }
|
||||
func setUpdateStatus(_ text: String?) { updateStatus = text }
|
||||
func setSending(_ value: Bool) { isSending = value }
|
||||
/// Fixture seam (same family as setSending): lets tests/PanelSnapshot stage the
|
||||
/// in-flight-start state that production only ever reaches inside startNewSession().
|
||||
func setStartingNewSession(_ value: Bool) { isStartingNewSession = value }
|
||||
func setCapturing(_ value: Bool) { isCapturing = value }
|
||||
func replaceSession(_ new: CaptureSession) { session = new }
|
||||
func replaceRegion(_ new: CaptureRegion?) { region = new }
|
||||
@@ -133,6 +148,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
|
||||
@@ -226,6 +242,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
|
||||
@@ -388,6 +410,100 @@ public final class AppModel {
|
||||
}
|
||||
}
|
||||
|
||||
/// True when "Start new session" applies: there is something to keep and neither a
|
||||
/// send nor another session start is in flight.
|
||||
public var canStartNewSession: Bool {
|
||||
!session.isEmpty && !isSending && !isStartingNewSession
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
// Re-checked here on the main actor, synchronously, before the first await:
|
||||
// the menu's `.disabled` state cannot stop a Task that was queued just before
|
||||
// a send started.
|
||||
guard !isSending, !isStartingNewSession else {
|
||||
setStatus(isSending ? "Finish the current send first." : "A new session is already being started.")
|
||||
return
|
||||
}
|
||||
isStartingNewSession = true
|
||||
defer { isStartingNewSession = false }
|
||||
|
||||
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