// Cotton Meetings on the lock screen, in the Dynamic Island, on the Action// Button and in Control Centre (voice plan, 17 Nov 2026). Only the Meetings// targets and their widget extension link this: no other Cotton app offers// "record a meeting" to Siri, Shortcuts or the lock screen.//// The widget extension draws; it never records. Every intent here runs in// the APP's process (`AudioRecordingIntent` and `LiveActivityIntent` do), and// reaches the app's recorder through `MeetingsIntentBridge`, which the app// fills at launch. So this module carries no core, no line set and no// recorder: the words the Activity shows come in its content, resolved by// the app from the kit's lines.importActivityKitimportAppIntentsimportFoundation/// The Live Activity's shape.publicstructMeetingActivityAttributes: ActivityAttributes {publicstructContentState: Codable, Hashable, Sendable {publicvar memo: Boolpublicvar startedAt: Date/// Whole spans that are over, in milliseconds.publicvar bankedMs: Double/// When the running span began; nil while paused.publicvar runningSince: Date?publicvar marks: Intpublicvar headline: Stringpublicvar pause: Stringpublicvar resume: Stringpublicvar stop: Stringpublicvar mark: Stringpublicinit( memo: Bool, startedAt: Date, bankedMs: Double, runningSince: Date?, marks: Int, headline: String, pause: String, resume: String, stop: String, mark: String ) {self.memo = memoself.startedAt = startedAtself.bankedMs = bankedMsself.runningSince = runningSinceself.marks = marksself.headline = headlineself.pause = pauseself.resume = resumeself.stop = stopself.mark = mark }publicvar paused: Bool { runningSince == nil }/// The moment the clock would read zero if it had never paused: what/// a running timer text counts from.publicvar clockZero: Date { (runningSince ?? Date()).addingTimeInterval(-bankedMs / 1000) }/// The banked length as a clock, for a paused Activity.publicvar bankedClock: String {let total = max(0, Int(bankedMs / 1000))let hours = total / 3600, minutes = (total % 3600) / 60, seconds = total % 60return hours > 0 ? String(format: "%d:%02d:%02d", hours, minutes, seconds) : String(format: "%d:%02d", minutes, seconds) } }publicinit() {}}/// What an intent asks the app's recorder.publicenumMeetingsLiveAct: Sendable, Equatable {case startMeetingcase startMemocase pausecase resumecase markcase stop}/// What the recorder answered an intent.publicenumMeetingsLiveAnswer: Sendable, Equatable {case done/// The microphone has not been allowed: the app must be opened once.case needsAppcase refused(String)}/// The app's recorder, as the intents reach it. Filled by the app at launch.@MainActorpublicenumMeetingsIntentBridge {publicstaticvar perform: (@MainActor (MeetingsLiveAct) async -> MeetingsLiveAnswer)?staticfunc run(_ act: MeetingsLiveAct) asyncthrows {guardlet perform else { throwMeetingsIntentError.notReady }switchawait perform(act) {case .done: returncase .needsApp: throwMeetingsIntentError.needsAppcase .refused(let why): throwMeetingsIntentError.refused(why) } }}enumMeetingsIntentError: Error, CustomLocalizedStringResourceConvertible {case notReadycase needsAppcase refused(String)var localizedStringResource: LocalizedStringResource {switchself {case .notReady, .needsApp: returnLocalizedStringResource("intent.needs_app", table: "Meetings")case .refused(let why): returnLocalizedStringResource(stringLiteral: why) } }}/// The Live Activity, driven by the app's recorder.@MainActorpublicenumMeetingsLiveActivity {privatestaticvar currentId: String?/// Show, change or end the Activity. `nil` ends it.publicstaticfunc show(_ state: MeetingActivityAttributes.ContentState?) {guardlet state else { end()return }let standing = Activity<MeetingActivityAttributes>.activities.first { ($0.id == currentId || currentId == nil) && ($0.activityState == .active || $0.activityState == .stale) }iflet standing { currentId = standing.idlet id = standing.idTask { await update(id, state) }return }guardActivityAuthorizationInfo().areActivitiesEnabled else { return }let made = try? Activity.request( attributes: MeetingActivityAttributes(), content: ActivityContent(state: state, staleDate: nil), pushType: nil) currentId = made?.id }/// End every Activity this app left standing, a killed process's too.publicstaticfunc end() { currentId = nilTask { await endAll() } }private nonisolated staticfunc update(_ id: String, _ state: MeetingActivityAttributes.ContentState) async {let found = Activity<MeetingActivityAttributes>.activities.first { $0.id == id }await found?.update(ActivityContent(state: state, staleDate: nil)) }private nonisolated staticfunc endAll() async {for one inActivity<MeetingActivityAttributes>.activities {await one.end(nil, dismissalPolicy: .immediate) } }}