From ad925926a454f7162f745f75774959d861e86b36 Mon Sep 17 00:00:00 2001 From: MSOB7YY Date: Sun, 19 Jan 2025 00:22:18 +0200 Subject: [PATCH] fix: notification artwork not falling back to folder cover --- lib/base/audio_handler.dart | 6 ++++-- lib/controller/indexer_controller.dart | 11 +++++++++++ lib/ui/widgets/artwork.dart | 9 +-------- pubspec.yaml | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/base/audio_handler.dart b/lib/base/audio_handler.dart index da71af9d..3c9aa38e 100644 --- a/lib/base/audio_handler.dart +++ b/lib/base/audio_handler.dart @@ -2001,7 +2001,9 @@ extension TrackToAudioSourceMediaItem on Selectable { MediaItem toMediaItem(int currentIndex, int queueLength, Duration? duration) { final tr = track.toTrackExt(); final artist = tr.originalArtist == '' ? UnknownTags.ARTIST : tr.originalArtist; - final imagePage = tr.pathToImage; + final imagePath = tr.pathToImage; + String? imagePathToUse = File(imagePath).existsSync() ? imagePath : null; + imagePathToUse ??= Indexer.inst.getFallbackFolderArtworkPath(folderPath: tr.folderPath); return MediaItem( id: tr.path, title: tr.title, @@ -2012,7 +2014,7 @@ extension TrackToAudioSourceMediaItem on Selectable { album: tr.hasUnknownAlbum ? '' : tr.album, genre: tr.originalGenre, duration: duration ?? Duration(milliseconds: tr.durationMS), - artUri: Uri.file(File(imagePage).existsSync() ? imagePage : AppPaths.NAMIDA_LOGO_MONET), + artUri: Uri.file(imagePathToUse ?? AppPaths.NAMIDA_LOGO_MONET), ); } } diff --git a/lib/controller/indexer_controller.dart b/lib/controller/indexer_controller.dart index 5d3c3470..f45df193 100644 --- a/lib/controller/indexer_controller.dart +++ b/lib/controller/indexer_controller.dart @@ -105,6 +105,17 @@ class Indexer { bool imageObtainedBefore(String imagePath) => _artworksMap[imagePath] != null || _artworksMapFullRes[imagePath] != null; + String? getFallbackFolderArtworkPath({required String folderPath}) { + String? cover = this.allFolderCovers[folderPath]; + if (cover == null && folderPath.endsWith(Platform.pathSeparator)) { + try { + folderPath = folderPath.substring(0, folderPath.length - 1); + cover = this.allFolderCovers[folderPath]; + } catch (_) {} + } + return cover; + } + /// {imagePath: (TrackExtended, id)}; final _backupMediaStoreIDS = {}; final artworksMap = {}; diff --git a/lib/ui/widgets/artwork.dart b/lib/ui/widgets/artwork.dart index 23bba81e..01e69720 100644 --- a/lib/ui/widgets/artwork.dart +++ b/lib/ui/widgets/artwork.dart @@ -153,14 +153,7 @@ class _ArtworkWidgetState extends State with LoadingItemsDelayMix } if (_imagePath == null && widget.track != null && widget.fallbackToFolderCover) { - String folderPath = widget.track!.folderPath; - String? cover = Indexer.inst.allFolderCovers[folderPath]; - if (cover == null && folderPath.endsWith(Platform.pathSeparator)) { - try { - folderPath = folderPath.substring(0, folderPath.length - 1); - cover = Indexer.inst.allFolderCovers[folderPath]; - } catch (_) {} - } + final cover = Indexer.inst.getFallbackFolderArtworkPath(folderPath: widget.track!.folderPath); if (cover != null && mounted) setState(() => _imagePath = cover); } } diff --git a/pubspec.yaml b/pubspec.yaml index f73e2f9f..7512ec70 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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.9.2-beta+250118221 +version: 4.9.2-beta+250118223 environment: sdk: ">=3.6.0 <4.0.0"