mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-22 23:58:36 +01:00
Remove code duplication in background fetch.
This commit is contained in:
parent
9c119ee81d
commit
a6370d2c79
@ -142,12 +142,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
|
||||
os_log("Woken to perform account refresh.", log: log, type: .info)
|
||||
|
||||
let startingUnreadCount = unreadCount
|
||||
let updateCompletionHandler = { [unowned self] in
|
||||
|
||||
let completeProcessing = { [unowned self] in
|
||||
|
||||
UIApplication.shared.endBackgroundTask(self.backgroundUpdateTask)
|
||||
self.backgroundUpdateTask = UIBackgroundTaskIdentifier.invalid
|
||||
|
||||
if startingUnreadCount != self.unreadCount {
|
||||
completionHandler(.newData)
|
||||
} else {
|
||||
completionHandler(.noData)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AccountManager.shared.refreshAll()
|
||||
@ -157,9 +163,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
|
||||
DispatchQueue.global(qos: .background).async { [unowned self] in
|
||||
|
||||
self.backgroundUpdateTask = UIApplication.shared.beginBackgroundTask {
|
||||
UIApplication.shared.endBackgroundTask(self.backgroundUpdateTask)
|
||||
self.backgroundUpdateTask = UIBackgroundTaskIdentifier.invalid
|
||||
updateCompletionHandler()
|
||||
completeProcessing()
|
||||
}
|
||||
|
||||
sleep(1)
|
||||
@ -168,12 +172,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
completeProcessing()
|
||||
os_log("Accounts completed refresh processing.", log: self.log, type: .info)
|
||||
|
||||
UIApplication.shared.endBackgroundTask(self.backgroundUpdateTask)
|
||||
self.backgroundUpdateTask = UIBackgroundTaskIdentifier.invalid
|
||||
updateCompletionHandler()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user