mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-08-27 13:22:49 +02:00
fix(download): recover queue after worker timeout (#524)
This commit is contained in:
@@ -75,6 +75,17 @@ bool canStartForegroundDownloadForLifecycle(AppLifecycleState? lifecycleState) {
|
||||
return lifecycleState == AppLifecycleState.resumed;
|
||||
}
|
||||
|
||||
String nativeWorkerStatusAfterSnapshotStop({
|
||||
required bool workerRunning,
|
||||
required String status,
|
||||
}) {
|
||||
if (workerRunning) return status;
|
||||
return switch (status) {
|
||||
'preparing' || 'downloading' || 'finalizing' => 'queued',
|
||||
_ => status,
|
||||
};
|
||||
}
|
||||
|
||||
/// Keeps a download in its finalizing state until its durable Library record
|
||||
/// has been written. If persistence fails, completion is deliberately not
|
||||
/// published so the queue can surface the error instead of losing the file
|
||||
|
||||
@@ -863,6 +863,7 @@ extension _DownloadQueueNativeWorker on DownloadQueueNotifier {
|
||||
if (itemSnapshots.isEmpty) {
|
||||
return;
|
||||
}
|
||||
final workerRunning = snapshot['is_running'] == true;
|
||||
|
||||
for (final itemSnapshot in itemSnapshots) {
|
||||
final itemId = itemSnapshot['item_id']?.toString() ?? '';
|
||||
@@ -872,7 +873,10 @@ extension _DownloadQueueNativeWorker on DownloadQueueNotifier {
|
||||
final context = contexts[itemId];
|
||||
if (context == null) continue;
|
||||
|
||||
final status = itemSnapshot['status']?.toString() ?? 'queued';
|
||||
final status = nativeWorkerStatusAfterSnapshotStop(
|
||||
workerRunning: workerRunning,
|
||||
status: itemSnapshot['status']?.toString() ?? 'queued',
|
||||
);
|
||||
final progress = ((itemSnapshot['progress'] as num?)?.toDouble() ?? 0.0)
|
||||
.clamp(0.0, 1.0)
|
||||
.toDouble();
|
||||
|
||||
Reference in New Issue
Block a user