Shared/Capture/PassiveLog.swift (1262B)
1import Foundation
2
3
4
5
6struct PassiveLog: Sendable {
7 let store: ReportStore
8 var capture: @Sendable () async -> Context = { await ContextCapture().capture() }
9
10
11
12 @discardableResult
13 func log(
14 kind: ReportKind = .manual,
15 trigger: ReportTrigger,
16 date: Date = Date(),
17 timeZone: TimeZone = .current,
18 promptedAt: Date? = nil
19 ) async throws -> UUID {
20 let report = Report(
21 id: UUID(),
22 date: date,
23 timeZone: timeZone.identifier,
24 kind: kind,
25 trigger: trigger,
26 state: .passive,
27 promptedAt: promptedAt,
28 modifiedAt: date
29 )
30 try await store.insert(report)
31 let context = await capture()
32 if context != Context() {
33 try await store.setContext(context, for: report.id)
34 }
35 return report.id
36 }
37}