mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-29 15:43:47 +01:00
fix(covers): keep temporary player covers out of Loved and recents
A song loved from the player without a Library record stored the item's artUri as its collection cover, and an album or artist opened from the player recorded its cover in recents. Older builds put loopback URLs there; a tag cover the store could not keep still shows from a temporary file on that play. Both writers now store only covers that outlast the run, through durableCoverReference.
This commit is contained in:
1 parent
cd66e168f9
commit
e33d2d7089
4 files changed
+76
-4
No files matched your search
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:mornye/services/app_state_database.dart';
|
||||
import 'package:mornye/services/cover_store.dart';
|
||||
import 'package:mornye/utils/logger.dart';
|
||||
|
||||
const _maxRecentItems = 20;
|
||||
@@ -195,7 +196,7 @@ class RecentAccessNotifier extends Notifier<RecentAccessState> {
|
||||
RecentAccessItem(
|
||||
id: id,
|
||||
name: name,
|
||||
imageUrl: imageUrl,
|
||||
imageUrl: durableCoverReference(imageUrl),
|
||||
type: RecentAccessType.artist,
|
||||
accessedAt: DateTime.now(),
|
||||
providerId: providerId,
|
||||
@@ -215,7 +216,7 @@ class RecentAccessNotifier extends Notifier<RecentAccessState> {
|
||||
id: id,
|
||||
name: name,
|
||||
subtitle: artistName,
|
||||
imageUrl: imageUrl,
|
||||
imageUrl: durableCoverReference(imageUrl),
|
||||
type: RecentAccessType.album,
|
||||
accessedAt: DateTime.now(),
|
||||
providerId: providerId,
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:audio_service/audio_service.dart' show MediaItem;
|
||||
import 'package:mornye/models/download_history.dart';
|
||||
import 'package:mornye/models/track.dart';
|
||||
import 'package:mornye/models/unified_library_item.dart';
|
||||
import 'package:mornye/services/cover_store.dart';
|
||||
import 'package:mornye/services/library_database.dart';
|
||||
|
||||
/// The download or Library record of the file a media item plays: by its
|
||||
@@ -36,7 +37,8 @@ Future<UnifiedLibraryItem?> libraryItemForMedia({
|
||||
}
|
||||
|
||||
/// The collection track that loves [item]: its Library record's identity
|
||||
/// when it has one ([match]), otherwise the media item's own fields.
|
||||
/// when it has one ([match]), otherwise the media item's own fields, with
|
||||
/// no cover when the item shows one that does not outlast this run.
|
||||
Track collectionTrackForMedia(MediaItem item, UnifiedLibraryItem? match) =>
|
||||
match?.toTrack() ??
|
||||
Track(
|
||||
@@ -44,7 +46,7 @@ Track collectionTrackForMedia(MediaItem item, UnifiedLibraryItem? match) =>
|
||||
name: item.title,
|
||||
artistName: item.artist ?? '',
|
||||
albumName: item.album ?? '',
|
||||
coverUrl: item.artUri?.toString(),
|
||||
coverUrl: durableCoverReference(item.artUri?.toString()),
|
||||
duration: item.duration?.inSeconds ?? 0,
|
||||
source: 'local',
|
||||
);
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:audio_service/audio_service.dart' show MediaItem;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mornye/services/library_media_identity.dart';
|
||||
|
||||
void main() {
|
||||
test('a loved song keeps only a cover that outlasts this run', () {
|
||||
String? cover(String artUri) => collectionTrackForMedia(
|
||||
MediaItem(
|
||||
id: 'network://nas/Album/song.flac',
|
||||
title: 'Song',
|
||||
artUri: Uri.parse(artUri),
|
||||
),
|
||||
null,
|
||||
).coverUrl;
|
||||
|
||||
for (final durable in [
|
||||
'file:///data/user/0/app/files/covers/a_b.image',
|
||||
'https://example.com/cover.jpg',
|
||||
]) {
|
||||
expect(cover(durable), durable);
|
||||
}
|
||||
for (final temporary in [
|
||||
'http://127.0.0.1:41234/7f3a',
|
||||
'file:///data/user/0/app/cache/network_metadata/a1.jpg',
|
||||
Uri.file('${Directory.systemTemp.path}/cover.jpg').toString(),
|
||||
]) {
|
||||
expect(cover(temporary), isNull, reason: temporary);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -255,6 +255,43 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'albums and artists opened from the player store no temporary cover',
|
||||
() async {
|
||||
final database = _Database();
|
||||
final container = _container(database);
|
||||
addTearDown(container.dispose);
|
||||
final notifier = container.read(recentAccessProvider.notifier);
|
||||
database.releaseRead.complete();
|
||||
await _waitUntilLoaded(container);
|
||||
const kept = 'https://example.com/album.jpg';
|
||||
for (final (id, cover) in [
|
||||
('temporary', '/data/user/0/app/cache/network_metadata/a1.jpg'),
|
||||
('loopback', 'http://127.0.0.1:41234/7f3a'),
|
||||
('kept', kept),
|
||||
]) {
|
||||
notifier
|
||||
..recordAlbumAccess(id: id, name: id, imageUrl: cover)
|
||||
..recordArtistAccess(id: id, name: id, imageUrl: cover);
|
||||
}
|
||||
await database.whenCompleted('record:artist:default:kept');
|
||||
expect(
|
||||
{
|
||||
for (final item in database.items.values)
|
||||
'${item.type.name}:${item.id}': item.imageUrl,
|
||||
},
|
||||
{
|
||||
'album:temporary': null,
|
||||
'artist:temporary': null,
|
||||
'album:loopback': null,
|
||||
'artist:loopback': null,
|
||||
'album:kept': kept,
|
||||
'artist:kept': kept,
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('failed load preserves early state and still owns its writes', () async {
|
||||
final database = _Database()..failRead = true;
|
||||
final container = _container(database);
|
||||
|
||||
Reference in new issue
Block a user