// Cotton Meetings' wiring, in the Meetings app alone: the recorder // (`CottonUI`'s `MeetingsEngine`) reaches the core once the app has opened // it; the intents (`CottonMeetingsLive`) reach the recorder; and every change // of the recording is shown as its Live Activity, in the kit's words. #if COTTON_MEETINGS import AppIntents import CottonKit import CottonMeetingsLive import CottonUI /// Lets the app's target find the intents the package declares. struct CottonMeetingsIntents: AppIntentsPackage { static let includedPackages: [any AppIntentsPackage.Type] = [MeetingsLivePackage.self] } @MainActor enum MeetingsGlue { static func attach(_ core: @escaping @Sendable () async -> (any CottonCalling)?) { let engine = MeetingsEngine.shared engine.attach(core) // A process that ended mid-recording left its Activity standing; // nothing is recording at launch, so it goes. MeetingsLiveActivity.end() engine.onLive = { live in MeetingsLiveActivity.show(live.map(content)) } MeetingsIntentBridge.perform = { act in await perform(act, on: engine) } // Every take a killed process left is finished by the core. Task { await engine.recoverAtLaunch() } } static func perform(_ act: MeetingsLiveAct, on engine: MeetingsEngine) async -> MeetingsLiveAnswer { switch act { case .startMeeting, .startMemo: switch await engine.start(act == .startMemo ? .memo : .meeting) { case .recording: return .done case .blocked: return .needsApp case .failed(let why): return .refused(why) } case .pause: engine.pause() case .resume: engine.resume() case .mark: engine.mark() case .stop: engine.stop() } return .done } static func content(_ live: MeetingsLive) -> MeetingActivityAttributes.ContentState { MeetingActivityAttributes.ContentState( memo: live.kind == .memo, startedAt: live.startedAt, bankedMs: live.bankedMs, runningSince: live.runningSince, marks: live.marks, headline: live.headline, pause: live.words.pause, resume: live.words.resume, stop: live.words.stop, mark: live.words.mark) } } #endif