@@ -18,8 +18,8 @@ class Download: Identifiable, @unchecked Sendable {
1818
1919 var overallProgress : Double {
2020 onlyArchiving
21- ? unpackageProgress
22- : ( 0.3 * unpackageProgress) + ( 0.7 * progress)
21+ ? unpackageProgress
22+ : ( 0.3 * unpackageProgress) + ( 0.7 * progress)
2323 }
2424
2525 var task : URLSessionDownloadTask ?
@@ -29,7 +29,7 @@ class Download: Identifiable, @unchecked Sendable {
2929 let url : URL
3030 let fileName : String
3131 let onlyArchiving : Bool
32-
32+
3333 init (
3434 id: String ,
3535 url: URL ,
@@ -52,7 +52,8 @@ class DownloadManager: NSObject, ObservableObject {
5252 }
5353
5454 private var _session : URLSession !
55-
55+
56+ #if !targetEnvironment(macCatalyst)
5657 private func _updateBackgroundAudioState( ) {
5758 if #unavailable( iOS 26 . 0 ) {
5859 if !downloads. isEmpty {
@@ -62,13 +63,14 @@ class DownloadManager: NSObject, ObservableObject {
6263 }
6364 }
6465 }
65-
66+ #endif
67+
6668 override init ( ) {
6769 super. init ( )
6870 let configuration = URLSessionConfiguration . default
6971 _session = URLSession ( configuration: configuration, delegate: self , delegateQueue: nil )
7072 }
71-
73+
7274 func startDownload(
7375 from url: URL ,
7476 id: String = UUID ( ) . uuidString
@@ -77,19 +79,23 @@ class DownloadManager: NSObject, ObservableObject {
7779 resumeDownload ( existingDownload)
7880 return existingDownload
7981 }
80-
82+
8183 let download = Download ( id: id, url: url)
82-
84+
8385 let task = _session. downloadTask ( with: url)
8486 download. task = task
8587 task. resume ( )
86-
88+
8789 downloads. append ( download)
90+
91+ #if !targetEnvironment(macCatalyst)
8892 if #available( iOS 26 . 0 , * ) {
8993 BackgroundTaskManager . shared. startTask ( for: id, filename: url. lastPathComponent)
9094 } else {
9195 _updateBackgroundAudioState ( )
9296 }
97+ #endif
98+
9399 return download
94100 }
95101
@@ -99,36 +105,50 @@ class DownloadManager: NSObject, ObservableObject {
99105 ) -> Download {
100106 let download = Download ( id: id, url: url, onlyArchiving: true )
101107 downloads. append ( download)
108+
109+ #if !targetEnvironment(macCatalyst)
102110 _updateBackgroundAudioState ( )
111+ #endif
112+
103113 return download
104114 }
105-
115+
106116 func resumeDownload( _ download: Download ) {
107117 if let resumeData = download. resumeData {
108118 let task = _session. downloadTask ( withResumeData: resumeData)
109119 download. task = task
110120 task. resume ( )
121+
122+ #if !targetEnvironment(macCatalyst)
111123 _updateBackgroundAudioState ( )
124+ #endif
112125 } else if let url = download. task? . originalRequest? . url {
113126 let task = _session. downloadTask ( with: url)
114127 download. task = task
115128 task. resume ( )
129+
130+ #if !targetEnvironment(macCatalyst)
116131 _updateBackgroundAudioState ( )
132+ #endif
117133 }
118134 }
119-
135+
120136 func cancelDownload( _ download: Download ) {
121137 download. task? . cancel ( )
122-
138+
123139 if let index = downloads. firstIndex ( where: { $0. id == download. id } ) {
124140 downloads. remove ( at: index)
141+
142+ #if !targetEnvironment(macCatalyst)
125143 _updateBackgroundAudioState ( )
144+
126145 if #available( iOS 26 . 0 , * ) {
127146 BackgroundTaskManager . shared. stopTask ( for: download. id, success: false )
128147 }
148+ #endif
129149 }
130150 }
131-
151+
132152 func isManualDownload( _ string: String ) -> Bool {
133153 return string. contains ( " FeatherManualDownload " )
134154 }
@@ -158,10 +178,14 @@ extension DownloadManager: URLSessionDownloadDelegate {
158178 DispatchQueue . main. async {
159179 if let index = DownloadManager . shared. getDownloadIndex ( by: dl. id) {
160180 DownloadManager . shared. downloads. remove ( at: index)
181+
182+ #if !targetEnvironment(macCatalyst)
161183 if #available( iOS 26 . 0 , * ) {
162184 BackgroundTaskManager . shared. updateProgress ( for: dl. id, progress: 1.0 )
163185 }
186+
164187 self . _updateBackgroundAudioState ( )
188+ #endif
165189 }
166190 }
167191 }
@@ -188,22 +212,25 @@ extension DownloadManager: URLSessionDownloadDelegate {
188212 print ( " Error handling downloaded file: \( error. localizedDescription) " )
189213 }
190214 }
191-
215+
192216 func urlSession( _ session: URLSession , downloadTask: URLSessionDownloadTask , didWriteData bytesWritten: Int64 , totalBytesWritten: Int64 , totalBytesExpectedToWrite: Int64 ) {
193217 guard let download = getDownloadTask ( by: downloadTask) else { return }
194-
218+
195219 DispatchQueue . main. async {
196220 download. progress = totalBytesExpectedToWrite > 0
197- ? Double ( totalBytesWritten) / Double( totalBytesExpectedToWrite)
198- : 0
221+ ? Double ( totalBytesWritten) / Double( totalBytesExpectedToWrite)
222+ : 0
199223 download. bytesDownloaded = totalBytesWritten
200224 download. totalBytes = totalBytesExpectedToWrite
225+
226+ #if !targetEnvironment(macCatalyst)
201227 if #available( iOS 26 . 0 , * ) {
202228 BackgroundTaskManager . shared. updateProgress ( for: download. id, progress: download. overallProgress)
203229 }
230+ #endif
204231 }
205232 }
206-
233+
207234 func urlSession( _ session: URLSession , task: URLSessionTask , didCompleteWithError error: Error ? ) {
208235 guard
209236 let _ = error,
0 commit comments