mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-27 05:43:58 +02:00
Report download progress to the UI
This commit is contained in:
@@ -28,6 +28,10 @@ struct DownloadItem: Realmable, Codable {
|
||||
static func indexedProperties() -> [String] {
|
||||
["libraryItemId"]
|
||||
}
|
||||
|
||||
private enum CodingKeys : String, CodingKey {
|
||||
case id, libraryItemId, episodeId, userMediaProgress, serverConnectionConfigId, serverAddress, serverUserId, mediaType, itemTitle, downloadItemParts
|
||||
}
|
||||
}
|
||||
|
||||
extension DownloadItem {
|
||||
@@ -58,17 +62,20 @@ struct DownloadItemPart: Realmable, Codable {
|
||||
var uri: String?
|
||||
var destinationUri: String?
|
||||
var finalDestinationUri: String?
|
||||
var downloadId: Int?
|
||||
var progress: Int = 0
|
||||
var progress: Double = 0
|
||||
var task: URLSessionDownloadTask!
|
||||
|
||||
private enum CodingKeys : String, CodingKey {
|
||||
case id, progress
|
||||
static func primaryKey() -> String? {
|
||||
return "id"
|
||||
}
|
||||
|
||||
static func ignoredProperties() -> [String] {
|
||||
["task"]
|
||||
}
|
||||
|
||||
private enum CodingKeys : String, CodingKey {
|
||||
case id, filename, completed, moved, failed, progress
|
||||
}
|
||||
}
|
||||
|
||||
extension DownloadItemPart {
|
||||
|
||||
@@ -169,6 +169,20 @@ class Database {
|
||||
}
|
||||
}
|
||||
|
||||
public func updateDownloadItemPartPercent(downloadItemPartId: String, percent: Double) {
|
||||
Database.realmQueue.sync {
|
||||
try! instance.write {
|
||||
let part = instance.object(ofType: DownloadItemPart.self, forPrimaryKey: downloadItemPartId)
|
||||
guard var part = part else {
|
||||
NSLog("downloadItemPartId not found (\(downloadItemPartId)")
|
||||
return
|
||||
}
|
||||
part.progress = percent
|
||||
instance.add(part, update: .modified)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func getDeviceSettings() -> DeviceSettings {
|
||||
return Database.realmQueue.sync {
|
||||
return instance.objects(DeviceSettings.self).first ?? getDefaultDeviceSettings()
|
||||
|
||||
Reference in New Issue
Block a user