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.
70 lines
2.6 KiB
Swift
70 lines
2.6 KiB
Swift
import Foundation
|
|
|
|
/// How long Redline keeps a past session's captured screenshots.
|
|
///
|
|
/// The default is `.never`: every session is saved and nothing is deleted unless the
|
|
/// user picks an age limit in Settings. Session folders are the only thing an age
|
|
/// policy ever removes — a PDF that was already sent stays in the folder it went to.
|
|
public enum SessionRetention: Sendable, Equatable, Hashable {
|
|
case never
|
|
case days(Int)
|
|
|
|
/// The one list Settings offers, in display order. `nil` day counts never expire.
|
|
public static let presets: [SessionRetention] = [
|
|
.never, .days(7), .days(14), .days(30), .days(90), .days(180), .days(365),
|
|
]
|
|
|
|
public var dayCount: Int? {
|
|
switch self {
|
|
case .never: return nil
|
|
case .days(let count): return count
|
|
}
|
|
}
|
|
|
|
/// "Never (default)", "7 days", "30 days", "1 year".
|
|
public var displayName: String {
|
|
switch self {
|
|
case .never: return "Never (default)"
|
|
case .days(365): return "1 year"
|
|
case .days(let count): return "\(count) days"
|
|
}
|
|
}
|
|
|
|
/// Caption for the Settings row and the panel footer: what actually happens.
|
|
public var policyDescription: String {
|
|
switch self {
|
|
case .never: return "All sessions kept."
|
|
case .days(365): return "Sessions older than 1 year are deleted."
|
|
case .days(let count): return "Sessions older than \(count) days are deleted."
|
|
}
|
|
}
|
|
|
|
/// Sessions created before this instant are expired; nil means nothing expires.
|
|
public func cutoff(now: Date = Date()) -> Date? {
|
|
guard let dayCount else { return nil }
|
|
return Calendar(identifier: .gregorian).date(byAdding: .day, value: -dayCount, to: now)
|
|
}
|
|
}
|
|
|
|
/// Persistence for the age limit, backed by UserDefaults.
|
|
///
|
|
/// Stored as a day count; 0 (or no stored value at all) means `never`. A stored value
|
|
/// is only ever written by `save`, so an absent key is the honest "user never chose"
|
|
/// state, not a hidden default.
|
|
public enum RetentionSettings {
|
|
public static let defaultsKey = "ai.flowmaster.shotdeck.sessionRetentionDays"
|
|
|
|
public static func load(defaults: UserDefaults = .standard) -> SessionRetention {
|
|
guard let stored = defaults.object(forKey: defaultsKey) as? Int else { return .never }
|
|
return stored > 0 ? .days(stored) : .never
|
|
}
|
|
|
|
public static func save(_ value: SessionRetention, defaults: UserDefaults = .standard) {
|
|
guard let dayCount = value.dayCount else {
|
|
defaults.removeObject(forKey: defaultsKey)
|
|
return
|
|
}
|
|
defaults.set(dayCount, forKey: defaultsKey)
|
|
}
|
|
}
|