fix: upload progress stuck at 0%

setProgressAsync (fire-and-forget) was dropping/coalescing updates before
they were persisted. Switch to awaited suspend setProgress() in both
UploadWorker and DownloadWorker so each progress write lands and the
LiveData observer actually sees pct advance.
This commit is contained in:
Mathieu Moran
2026-08-12 18:15:42 -04:00
parent 30b919bc03
commit 6f112ab622
2 changed files with 5 additions and 5 deletions
@@ -139,7 +139,7 @@ class DownloadWorker(
lastProgressMs = now
val pct = if (total > 0) ((downloaded * 100) / total).toInt() else 0
setForeground(createForegroundInfo(filename, pct, downloaded, total))
setProgressAsync(workDataOf("pct" to pct))
setProgress(workDataOf("pct" to pct))
}
}
}
@@ -55,14 +55,14 @@ class UploadWorker(
try {
// Promote to foreground immediately so large files aren't killed during hashing
setForeground(DownloadWorker.createForegroundNotification(applicationContext, "Preparing $filename", 0))
setProgressAsync(workDataOf("pct" to 0, "status" to "Hashing…"))
setProgress(workDataOf("pct" to 0, "status" to "Hashing…"))
// Compute SHA256
val sha256 = computeSha256(file)
val relativePath = filename // Using filename as relative_path since flat dir
// Check status
setProgressAsync(workDataOf("pct" to 0, "status" to "Checking server…"))
setProgress(workDataOf("pct" to 0, "status" to "Checking server…"))
val statusUrl = "$serverUrl/api/v1/dashcam/upload/status?relative_path=$relativePath&sha256=$sha256"
val statusReq = Request.Builder().url(statusUrl)
.addHeader("X-Device-Name", deviceName)
@@ -82,7 +82,7 @@ class UploadWorker(
val totalChunks = ((file.length() + CHUNK_SIZE - 1) / CHUNK_SIZE).toInt()
setForeground(DownloadWorker.createForegroundNotification(applicationContext, "Uploading $filename", 0))
setProgressAsync(workDataOf("pct" to 0, "status" to "Uploading…"))
setProgress(workDataOf("pct" to 0, "status" to "Uploading…"))
// Upload missing chunks
for (i in 0 until totalChunks) {
@@ -120,7 +120,7 @@ class UploadWorker(
val pct = ((i + 1) * 100) / totalChunks
setForeground(DownloadWorker.createForegroundNotification(applicationContext, "Uploading $filename", pct))
setProgressAsync(workDataOf("pct" to pct, "status" to "Uploading…"))
setProgress(workDataOf("pct" to pct, "status" to "Uploading…"))
}
return@withContext Result.success(workDataOf("filename" to filename))