From 45d51cfc4729226c6a013202c66e6ff9c9f580d9 Mon Sep 17 00:00:00 2001 From: Chaphasilor Date: Sun, 3 Nov 2024 23:53:06 +0100 Subject: [PATCH] download playlist metadata only after logging in - also reworded the download item name for it --- lib/l10n/app_en.arb | 2 +- lib/models/finamp_models.dart | 9 +++++++-- lib/screens/music_screen.dart | 12 ++++++++++++ lib/services/downloads_service.dart | 21 +++++++++++++-------- lib/services/finamp_settings_helper.dart | 7 +++++++ 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 7638511f..ee603f30 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -1357,7 +1357,7 @@ }, "description": "Tooltip for downloadbutton on incidental downloads, which show a lock icon. It says one of the requiring downloads." }, - "finampCollectionNames": "{itemType, select, favorites{Favorites} allPlaylists{All Playlists} fiveLatestAlbums{5 Latest Albums} allPlaylistsMetadata{Info for All Playlists} other{{itemType}} }", + "finampCollectionNames": "{itemType, select, favorites{Favorites} allPlaylists{All Playlists} fiveLatestAlbums{5 Latest Albums} allPlaylistsMetadata{Playlist Metadata} other{{itemType}} }", "@finampCollectionNames": { "placeholders": { "itemType": { diff --git a/lib/models/finamp_models.dart b/lib/models/finamp_models.dart index 41d13e3f..43c5a0cc 100644 --- a/lib/models/finamp_models.dart +++ b/lib/models/finamp_models.dart @@ -113,6 +113,7 @@ const _showStopButtonOnMediaNotificationDefault = false; const _showSeekControlsOnMediaNotificationDefault = true; const _keepScreenOnOption = KeepScreenOnOption.whileLyrics; const _keepScreenOnWhilePluggedIn = true; +const _hasDownloadedPlaylistInfoDefault = false; @HiveType(typeId: 28) class FinampSettings { @@ -157,7 +158,7 @@ class FinampSettings { this.autoloadLastQueueOnStartup = _autoLoadLastQueueOnStartup, this.hasCompletedBlurhashImageMigration = true, this.hasCompletedBlurhashImageMigrationIdFix = true, - this.hasCompleteddownloadsServiceMigration = true, + this.hasCompleteddownloadsServiceMigration = false, this.requireWifiForDownloads = false, this.onlyShowFullyDownloaded = false, this.showDownloadsWithUnknownLibrary = true, @@ -196,7 +197,8 @@ class FinampSettings { this.showSeekControlsOnMediaNotification = _showSeekControlsOnMediaNotificationDefault, this.keepScreenOnOption = _keepScreenOnOption, - this.keepScreenOnWhilePluggedIn = _keepScreenOnWhilePluggedIn}); + this.keepScreenOnWhilePluggedIn = _keepScreenOnWhilePluggedIn, + this.hasDownloadedPlaylistInfo = false}); @HiveField(0, defaultValue: _isOfflineDefault) bool isOffline; @@ -433,6 +435,9 @@ class FinampSettings { @HiveField(73, defaultValue: _keepScreenOnWhilePluggedIn) bool keepScreenOnWhilePluggedIn; + @HiveField(74, defaultValue: _hasDownloadedPlaylistInfoDefault) + bool hasDownloadedPlaylistInfo; + static Future create() async { final downloadLocation = await DownloadLocation.create( name: "Internal Storage", diff --git a/lib/screens/music_screen.dart b/lib/screens/music_screen.dart index b97bb6e2..57986fe3 100644 --- a/lib/screens/music_screen.dart +++ b/lib/screens/music_screen.dart @@ -9,6 +9,7 @@ import 'package:get_it/get_it.dart'; import 'package:hive/hive.dart'; import 'package:logging/logging.dart'; +import 'package:finamp/services/downloads_service.dart'; import '../components/MusicScreen/music_screen_drawer.dart'; import '../components/MusicScreen/music_screen_tab_view.dart'; import '../components/MusicScreen/sort_by_menu_button.dart'; @@ -21,6 +22,16 @@ import '../services/finamp_settings_helper.dart'; import '../services/finamp_user_helper.dart'; import '../services/jellyfin_api_helper.dart'; +void postLaunchHook() async { + final downloadsService = GetIt.instance(); + + // make sure playlist info is downloaded for users upgrading from older versions and new installations AFTER logging in and selecting their libraries/views + if (!FinampSettingsHelper.finampSettings.hasDownloadedPlaylistInfo) { + await downloadsService.addDefaultPlaylistInfoDownload(); + FinampSettingsHelper.setHasDownloadedPlaylistInfo(true); + } +} + class MusicScreen extends ConsumerStatefulWidget { const MusicScreen({super.key}); @@ -92,6 +103,7 @@ class _MusicScreenState extends ConsumerState @override void initState() { super.initState(); + postLaunchHook(); } @override diff --git a/lib/services/downloads_service.dart b/lib/services/downloads_service.dart index 91de1216..aa36c136 100644 --- a/lib/services/downloads_service.dart +++ b/lib/services/downloads_service.dart @@ -1012,7 +1012,6 @@ class DownloadsService { /// always be re-run later by the user. Note that the existing hive metadata is /// not deleted by this migration, we just stop using it. Future migrateFromHive() async { - final finampUserHelper = GetIt.instance(); if (FinampSettingsHelper.finampSettings.downloadLocationsMap.values .where((element) => element.baseDirectory == DownloadLocationType.internalSupport) @@ -1038,13 +1037,6 @@ class DownloadsService { content: Text(AppLocalizations.of(scaffold)!.runRepairWarning), duration: const Duration(seconds: 20))); })); - - // Automatically download playlist metadata (to enhance the playlist actions dialog and offline mode) - unawaited(addDownload( - stub: DownloadStub.fromFinampCollection(FinampCollection(type: FinampCollectionType.allPlaylistsMetadata)), - viewId: finampUserHelper.currentUser!.currentViewId!, - transcodeProfile: DownloadProfile(transcodeCodec: FinampTranscodingCodec.original), - )); } /// Substep 1 of [migrateFromHive]. @@ -1232,6 +1224,19 @@ class DownloadsService { } } + Future addDefaultPlaylistInfoDownload() async { + final finampUserHelper = GetIt.instance(); + + // Automatically download playlist metadata (to enhance the playlist actions dialog and offline mode) + await addDownload( + stub: DownloadStub.fromFinampCollection( + FinampCollection(type: FinampCollectionType.allPlaylistsMetadata)), + viewId: finampUserHelper.currentUser!.currentViewId!, + transcodeProfile: + DownloadProfile(transcodeCodec: FinampTranscodingCodec.original), + ); + } + /// Get all user-downloaded items. Used to show items on downloads screen. List getUserDownloaded() => getVisibleChildren(_anchor); diff --git a/lib/services/finamp_settings_helper.dart b/lib/services/finamp_settings_helper.dart index 4d1d6e44..b6b6b06d 100644 --- a/lib/services/finamp_settings_helper.dart +++ b/lib/services/finamp_settings_helper.dart @@ -305,6 +305,13 @@ class FinampSettingsHelper { .put("FinampSettings", finampSettingsTemp); } + static void setHasDownloadedPlaylistInfo(bool hasDownloadedPlaylistInfo) { + FinampSettings finampSettingsTemp = finampSettings; + finampSettingsTemp.hasDownloadedPlaylistInfo = hasDownloadedPlaylistInfo; + Hive.box("FinampSettings") + .put("FinampSettings", finampSettingsTemp); + } + static void setTabOrder(List newTabOrder) { FinampSettings finampSettingsTemp = finampSettings; finampSettingsTemp.tabOrder = newTabOrder;