@@ -60,6 +60,7 @@ extension RecordingEngine {
6060 do {
6161 try await ensurePermissions ( )
6262
63+ let resolvedFilter = await augmentedFilterIfNeeded ( from: filter)
6364 let directory = try await directoryProvider. recordingsDirectory ( )
6465 let outputURL = makeOutputURL ( in: directory)
6566 currentOutputURL = outputURL
@@ -79,7 +80,7 @@ extension RecordingEngine {
7980 )
8081
8182 try await captureService. startRecording (
82- filter: filter ,
83+ filter: resolvedFilter ,
8384 configuration: config,
8485 outputURL: outputURL,
8586 options: options,
@@ -93,6 +94,33 @@ extension RecordingEngine {
9394 }
9495 }
9596
97+ private func augmentedFilterIfNeeded( from filter: SCContentFilter ) async -> SCContentFilter {
98+ guard captureSource == . application else { return filter }
99+ guard let bundleIdentifier = Bundle . main. bundleIdentifier else { return filter }
100+
101+ let currentApplications = filter. includedApplications
102+ if currentApplications. contains ( where: { $0. bundleIdentifier == bundleIdentifier } ) {
103+ return filter
104+ }
105+
106+ do {
107+ let content = try await SCShareableContent . current
108+ guard let captureApp = content. applications. first ( where: { $0. bundleIdentifier == bundleIdentifier } ) else {
109+ return filter
110+ }
111+
112+ guard let display = filter. includedDisplays. first ?? content. displays. first else {
113+ return filter
114+ }
115+
116+ var updatedApplications = currentApplications
117+ updatedApplications. append ( captureApp)
118+ return SCContentFilter ( display: display, including: updatedApplications, exceptingWindows: [ ] )
119+ } catch {
120+ return filter
121+ }
122+ }
123+
96124 func stopRecording( discard: Bool ) async {
97125 guard state. isRecording || state == . stopping else { return }
98126 setState ( . stopping)
0 commit comments