@@ -199,12 +199,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
199199 task. setTaskCompleted ( success: true )
200200 }
201201
202- guard let tblAccount = await NCManageDatabase . shared. getActiveTableAccountAsync ( ) else {
203- nkLog ( tag: self . global. logTagTask, emoji: . info, message: " No active account or background task already running " )
204- return
205- }
206-
207- await backgroundSync ( tblAccount: tblAccount, task: task)
202+ await backgroundSync ( task: task)
208203 }
209204 }
210205
@@ -224,25 +219,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
224219 task. setTaskCompleted ( success: true )
225220 }
226221
227- guard let tblAccount = await NCManageDatabase . shared. getActiveTableAccountAsync ( ) else {
228- nkLog ( tag: self . global. logTagTask, emoji: . info, message: " No active account or background task already running " )
229- return
230- }
231-
232- await backgroundSync ( tblAccount: tblAccount, task: task)
222+ await backgroundSync ( task: task)
233223 }
234224 }
235225
236- func backgroundSync( tblAccount : tableAccount , task: BGTask ? = nil ) async {
226+ func backgroundSync( task: BGTask ? = nil ) async {
237227 // BGTask expiration flag
238228 var expired = false
239229 task? . expirationHandler = {
240230 expired = true
241231 }
242232
243233 // Discover new items for Auto Upload
244- let numAutoUpload = await NCAutoUpload . shared. initAutoUpload ( tblAccount : tblAccount )
245- nkLog ( tag: self . global. logTagBgSync, emoji: . start, message: " Auto upload found \( numAutoUpload) new items for \( tblAccount . account ) " )
234+ let numAutoUpload = await NCAutoUpload . shared. initAutoUpload ( )
235+ nkLog ( tag: self . global. logTagBgSync, emoji: . start, message: " Auto upload found \( numAutoUpload) new items " )
246236 guard !expired else {
247237 return
248238 }
@@ -252,8 +242,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
252242 predicate: NSPredicate ( format: " status != %d " , self . global. metadataStatusNormal) ,
253243 withSort: [ RealmSwift . SortDescriptor ( keyPath: " sessionDate " , ascending: true ) ] ,
254244 withLimit: NCBrandOptions . shared. numMaximumProcess) ,
255- !allMetadatas. isEmpty,
256- !expired else {
245+ !allMetadatas. isEmpty,
246+ !expired else {
257247 return
258248 }
259249
@@ -263,17 +253,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
263253 $0. sessionSelector == self . global. selectorUploadAutoUpload
264254 }
265255
266- for meta in pendingCreateFolders {
256+ for metadata in pendingCreateFolders {
267257 guard !expired else {
268258 return
269259 }
270260 let err = await NCNetworking . shared. createFolderForAutoUpload (
271- serverUrlFileName: meta . serverUrlFileName,
272- account: meta . account
261+ serverUrlFileName: metadata . serverUrlFileName,
262+ account: metadata . account
273263 )
274264 // Fail-fast: abort the whole sync on first failure
275265 if err != . success {
276- nkLog ( tag: self . global. logTagBgSync, emoji: . error, message: " Create folder ' \( meta . serverUrlFileName) ' failed: \( err. errorCode) – aborting sync " )
266+ nkLog ( tag: self . global. logTagBgSync, emoji: . error, message: " Create folder ' \( metadata . serverUrlFileName) ' failed: \( err. errorCode) – aborting sync " )
277267 return
278268 }
279269 }
@@ -283,7 +273,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
283273 let uploading = allMetadatas. lazy. filter { $0. status == self . global. metadataStatusUploading } . count
284274 let used = downloading + uploading
285275 let maximum = NCBrandOptions . shared. numMaximumProcess
286- let available = Swift . max ( 0 , maximum - used)
276+ let available = max ( 0 , maximum - used)
287277
288278 // Only inject more work if overall utilization <= 20%
289279 let utilization = Double ( used) / Double( maximum)
@@ -294,7 +284,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
294284 }
295285
296286 // Start Auto Uploads (cap by available slots)
297- let seedsToUpload = Array (
287+ let metadatasToUpload = Array (
298288 allMetadatas. lazy. filter {
299289 $0. status == self . global. metadataStatusWaitUpload &&
300290 $0. sessionSelector == self . global. selectorUploadAutoUpload &&
@@ -304,12 +294,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
304294 )
305295
306296 let cameraRoll = NCCameraRoll ( )
307- for seed in seedsToUpload {
297+ for metadata in metadatasToUpload {
308298 guard !expired else {
309299 return
310300 }
311301 // Expand seed into concrete metadatas (e.g., Live Photo pair)
312- let extracted = await cameraRoll. extractCameraRoll ( from: seed )
302+ let extracted = await cameraRoll. extractCameraRoll ( from: metadata )
313303
314304 for metadata in extracted {
315305 // Sequential await keeps ordering and simplifies backpressure
@@ -328,10 +318,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
328318 func application( _ application: UIApplication , handleEventsForBackgroundURLSession identifier: String , completionHandler: @escaping ( ) -> Void ) {
329319 nkLog ( debug: " Handle events For background URLSession: \( identifier) " )
330320
331- if NCManageDatabase . shared. openRealmBackground ( ) {
332- WidgetCenter . shared. reloadAllTimelines ( )
333- }
334-
335321 backgroundSessionCompletionHandler = completionHandler
336322 }
337323
0 commit comments