|
|
@ -34,11 +34,13 @@ class Downloader: NSObject, ObservableObject {
|
|
|
|
urlSession = URLSession(configuration: config, delegate: self, delegateQueue: OperationQueue())
|
|
|
|
urlSession = URLSession(configuration: config, delegate: self, delegateQueue: OperationQueue())
|
|
|
|
downloadState.value = .downloading(0)
|
|
|
|
downloadState.value = .downloading(0)
|
|
|
|
urlSession?.getAllTasks { tasks in
|
|
|
|
urlSession?.getAllTasks { tasks in
|
|
|
|
// If there's an existing pending background task, let it proceed, otherwise start a new one.
|
|
|
|
// If there's an existing pending background task with the same URL, let it proceed.
|
|
|
|
// TODO: check URL when we support downloading more models.
|
|
|
|
guard tasks.filter({ $0.originalRequest?.url == url }).isEmpty else {
|
|
|
|
if tasks.first == nil {
|
|
|
|
print("Already downloading \(url)")
|
|
|
|
self.urlSession?.downloadTask(with: url).resume()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print("Starting download of \(url)")
|
|
|
|
|
|
|
|
self.urlSession?.downloadTask(with: url).resume()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|