Skip to content

Commit

Permalink
code: refactor _saveLatestQueueToStorage()
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Nov 26, 2024
1 parent de391a9 commit 0cddbc1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions lib/controller/queue_controller.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:collection';
import 'dart:convert';
import 'dart:io';

import 'package:namida/class/queue.dart';
Expand Down Expand Up @@ -261,13 +262,21 @@ class QueueController {
}

Future<void> _saveLatestQueueToStorage(List<Playable> items) async {
final queueObjects = <Object>[];
final queueObjects = items
.map((e) => {
'p': e.toJson(),
't': _LatestQueueSaver._typesMapLookup[e.runtimeType],
})
.toList();

items.loop((e) => queueObjects.add({
'p': e.toJson(),
't': _LatestQueueSaver._typesMapLookup[e.runtimeType],
}));
await File(AppPaths.LATEST_QUEUE).writeAsJson(queueObjects);
try {
final file = File(AppPaths.LATEST_QUEUE);
file.createSync(recursive: true);
const encoder = JsonEncoder();
await file.writeAsString(encoder.convert(queueObjects));
} catch (e) {
printy(e, isError: true);
}
}

Future<void> _deleteQueueFromStorage(Queue queue) async {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 4.7.26-beta+241126183
version: 4.7.27-beta+241126185

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down

0 comments on commit 0cddbc1

Please sign in to comment.