tangled
alpha
login
or
join now
coreyja.com
/
backup-blue
1
fork
atom
this repo has no description
1
fork
atom
overview
issues
pulls
pipelines
And so is the progress bar!
Corey Alexander
6 months ago
8bd2b279
9d6912e7
+64
-16
3 changed files
expand all
collapse all
unified
split
AtProtoBackup
BlobDownloader.swift
DownloadManager.swift
DownloadSection.swift
+3
-1
AtProtoBackup/BlobDownloader.swift
···
59
59
pdsURL: String,
60
60
cids: [String],
61
61
saveLocationBookmark: Data? = nil,
62
62
-
maxConcurrentDownloads: Int = 1
62
62
+
maxConcurrentDownloads: Int = 1,
63
63
+
progressHandler: ((Int, Int) -> Void)? = nil
63
64
) async throws -> [URL] {
64
65
self.maxConcurrentDownloads = maxConcurrentDownloads
65
66
// Cancel any existing download task
···
134
135
print("Download cancelled early")
135
136
}
136
137
print("Downloaded \(totalProcessed) of \(totalCIDs) blobs")
138
138
+
progressHandler?(totalProcessed, totalCIDs)
137
139
}
138
140
139
141
return urls
+16
-1
AtProtoBackup/DownloadManager.swift
···
30
30
let accountDid = account.did
31
31
if downloads[account.did] == nil {
32
32
downloads[account.did] = DownloadInfo(accountID: account.did)
33
33
+
} else {
34
34
+
// Reset progress for resume
35
35
+
downloads[account.did]?.progress = downloads[account.did]?.progress ?? 0
33
36
}
34
37
35
38
···
80
83
let totalCount: Int = allBlobCids.count
81
84
await MainActor.run {
82
85
downloads[accountDid]?.totalBlobs = totalCount
86
86
+
downloads[accountDid]?.progress = 0 // Reset progress for blob downloads
83
87
}
84
88
85
89
// guard let saveUrl = saveLocation.fileURL else {
···
105
109
}
106
110
}
107
111
108
108
-
let _ = try await blobDownloader.downloadBlobs(repo: account.did, pdsURL: account.pds, cids: allBlobCids, saveLocationBookmark: bookmarkData)
112
112
+
let _ = try await blobDownloader.downloadBlobs(repo: account.did, pdsURL: account.pds, cids: allBlobCids, saveLocationBookmark: bookmarkData) { [weak self] downloaded, total in
113
113
+
Task { @MainActor in
114
114
+
if let totalBlobs = self?.downloads[accountDid]?.totalBlobs {
115
115
+
self?.downloads[accountDid]?.progress = Double(downloaded) / Double(totalBlobs)
116
116
+
}
117
117
+
}
118
118
+
}
119
119
+
120
120
+
await MainActor.run {
121
121
+
downloads[accountDid]?.progress = 1.0
122
122
+
downloads[accountDid]?.isDownloading = false
123
123
+
}
109
124
110
125
} catch {
111
126
print("Download error: \(error)")
+45
-14
AtProtoBackup/DownloadSection.swift
···
43
43
var body: some View {
44
44
VStack(spacing: 8) {
45
45
if download.isDownloading {
46
46
-
ProgressView(value: download.progress) {
47
47
-
Text("Downloading... \(Int(download.progress * 100))%")
48
48
-
.font(.caption)
46
46
+
VStack(spacing: 4) {
47
47
+
if let totalBlobs = download.totalBlobs {
48
48
+
ProgressView(value: download.progress) {
49
49
+
Text("Downloading... \(Int(download.progress * 100))%")
50
50
+
.font(.caption)
51
51
+
}
52
52
+
.progressViewStyle(LinearProgressViewStyle())
53
53
+
54
54
+
Text("\(Int(download.progress * Double(totalBlobs))) of \(totalBlobs) blobs")
55
55
+
.font(.caption2)
56
56
+
.foregroundColor(.secondary)
57
57
+
} else {
58
58
+
HStack {
59
59
+
ProgressView()
60
60
+
.scaleEffect(0.8)
61
61
+
Text("Fetching repository data...")
62
62
+
.font(.caption)
63
63
+
.foregroundColor(.secondary)
64
64
+
}
65
65
+
}
49
66
}
50
50
-
.progressViewStyle(LinearProgressViewStyle())
51
67
} else if download.progress > 0 && download.progress < 1.0 {
52
52
-
HStack {
53
53
-
Text("Download paused at \(Int(download.progress * 100))%")
54
54
-
.font(.caption)
55
55
-
.foregroundColor(.secondary)
68
68
+
VStack(spacing: 6) {
69
69
+
HStack {
70
70
+
Text("Download paused at \(Int(download.progress * 100))%")
71
71
+
.font(.caption)
72
72
+
.foregroundColor(.secondary)
56
73
57
57
-
Button("Resume") {
58
58
-
downloadManager.startDownload(for: account)
74
74
+
Button("Resume") {
75
75
+
downloadManager.startDownload(for: account)
76
76
+
}
77
77
+
.buttonStyle(BorderedButtonStyle())
78
78
+
}
79
79
+
80
80
+
if let totalBlobs = download.totalBlobs {
81
81
+
Text("\(Int(download.progress * Double(totalBlobs))) of \(totalBlobs) blobs")
82
82
+
.font(.caption2)
83
83
+
.foregroundColor(.secondary)
59
84
}
60
60
-
.buttonStyle(BorderedButtonStyle())
61
85
}
62
86
} else if download.progress >= 1.0 {
63
87
HStack {
64
88
Image(systemName: "checkmark.circle.fill")
65
89
.foregroundColor(.green)
66
66
-
Text("Download complete")
67
67
-
.font(.caption)
68
68
-
.foregroundColor(.secondary)
90
90
+
VStack(alignment: .leading, spacing: 2) {
91
91
+
Text("Download complete")
92
92
+
.font(.caption)
93
93
+
.foregroundColor(.secondary)
94
94
+
if let totalBlobs = download.totalBlobs {
95
95
+
Text("\(totalBlobs) blobs downloaded")
96
96
+
.font(.caption2)
97
97
+
.foregroundColor(.secondary)
98
98
+
}
99
99
+
}
69
100
}
70
101
}
71
102
}