mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-30 13:19:44 +02:00
fix(library): index native completions and refresh background downloads
This commit is contained in:
1 parent
e3bec31b36
commit
b15bb2673c
6 files changed
+132
-35
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import 'package:spotiflac_android/utils/logger.dart';
|
||||
|
||||
/// A completed file and a persisted Library entry are separate guarantees.
|
||||
/// In particular, `already_exists` does not mean history was ever saved.
|
||||
Future<void> reconcileNativeDownloadHistory({
|
||||
required Map<String, dynamic> result,
|
||||
required Future<void> Function(Map<String, dynamic>) adopt,
|
||||
required Future<void> Function() reload,
|
||||
required Future<void> Function() persistFallback,
|
||||
}) async {
|
||||
final historyItem = result['history_item'];
|
||||
if (historyItem is Map) {
|
||||
try {
|
||||
await adopt(Map<String, dynamic>.from(historyItem));
|
||||
return;
|
||||
} catch (error) {
|
||||
AppLogger('DownloadHistory').w(
|
||||
'Failed to adopt native history item, retrying from download result: $error',
|
||||
);
|
||||
}
|
||||
} else if (result['history_written'] == true) {
|
||||
await reload();
|
||||
return;
|
||||
}
|
||||
await persistFallback();
|
||||
}
|
||||
Reference in new issue
Block a user