From 7d23beec5ef07c4d649185a69e7a2b9697dc6953 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sat, 10 Jun 2023 15:31:48 +0600 Subject: [PATCH] fix: disable background_downloader due to android build failures --- lib/components/library/user_downloads.dart | 3 +- lib/provider/download_manager_provider.dart | 181 ++++++++++---------- pubspec.lock | 8 - pubspec.yaml | 1 - 4 files changed, 93 insertions(+), 100 deletions(-) diff --git a/lib/components/library/user_downloads.dart b/lib/components/library/user_downloads.dart index 1c217d9cd..b0c9541c1 100644 --- a/lib/components/library/user_downloads.dart +++ b/lib/components/library/user_downloads.dart @@ -65,7 +65,8 @@ class UserDownloads extends HookConsumerWidget { .where((element) => element.taskId == track.id), ); final taskItSelf = useFuture( - FileDownloader().database.recordForId(track.id!), + Future.value(null), + // FileDownloader().database.recordForId(track.id!), ); final hasFailed = failedTaskStream.hasData || diff --git a/lib/provider/download_manager_provider.dart b/lib/provider/download_manager_provider.dart index 4ad2ed948..2ad95ba32 100644 --- a/lib/provider/download_manager_provider.dart +++ b/lib/provider/download_manager_provider.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'dart:io'; -import 'package:background_downloader/background_downloader.dart'; +// import 'package:background_downloader/background_downloader.dart'; import 'package:collection/collection.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:http/http.dart'; @@ -19,8 +19,8 @@ import 'package:spotube/utils/type_conversion_utils.dart'; class DownloadManagerProvider extends StateNotifier> { final Ref ref; - final StreamController activeDownloadProgress; - final StreamController failedDownloads; + final StreamController /* */ activeDownloadProgress; + final StreamController /* */ failedDownloads; Track? _activeItem; FutureOr Function(Track)? onFileExists; @@ -29,78 +29,78 @@ class DownloadManagerProvider extends StateNotifier> { : activeDownloadProgress = StreamController.broadcast(), failedDownloads = StreamController.broadcast(), super([]) { - FileDownloader().registerCallbacks( - group: FileDownloader.defaultGroup, - taskNotificationTapCallback: (task, notificationType) { - router.go("/library"); - }, - taskStatusCallback: (update) async { - if (update.status == TaskStatus.running) { - _activeItem = - state.firstWhereOrNull((track) => track.id == update.task.taskId); - state = state.toList(); - } - - if (update.status == TaskStatus.failed || - update.status == TaskStatus.notFound) { - failedDownloads.add(update.task); - } - - if (update.status == TaskStatus.complete) { - final track = - state.firstWhere((element) => element.id == update.task.taskId); - - // resetting the replace downloaded file state on queue completion - if (state.last == track) { - ref.read(replaceDownloadedFileState.notifier).state = null; - } - - state = state - .where((element) => element.id != update.task.taskId) - .toList(); - - final imageUri = TypeConversionUtils.image_X_UrlString( - track.album?.images ?? [], - placeholder: ImagePlaceholder.online, - ); - final response = await get(Uri.parse(imageUri)); - - final tempFile = File(await update.task.filePath()); - - final file = tempFile.copySync(_getPathForTrack(track)); - - await tempFile.delete(); - - await MetadataGod.writeMetadata( - file: file.path, - metadata: Metadata( - title: track.name, - artist: track.artists?.map((a) => a.name).join(", "), - album: track.album?.name, - albumArtist: track.artists?.map((a) => a.name).join(", "), - year: track.album?.releaseDate != null - ? int.tryParse(track.album!.releaseDate!) - : null, - trackNumber: track.trackNumber, - discNumber: track.discNumber, - durationMs: track.durationMs?.toDouble(), - fileSize: file.lengthSync(), - trackTotal: track.album?.tracks?.length, - picture: response.headers['content-type'] != null - ? Picture( - data: response.bodyBytes, - mimeType: response.headers['content-type']!, - ) - : null, - ), - ); - } - }, - taskProgressCallback: (update) { - activeDownloadProgress.add(update); - }, - ); - FileDownloader().trackTasks(markDownloadedComplete: true); + // FileDownloader().registerCallbacks( + // group: FileDownloader.defaultGroup, + // taskNotificationTapCallback: (task, notificationType) { + // router.go("/library"); + // }, + // taskStatusCallback: (update) async { + // if (update.status == TaskStatus.running) { + // _activeItem = + // state.firstWhereOrNull((track) => track.id == update.task.taskId); + // state = state.toList(); + // } + + // if (update.status == TaskStatus.failed || + // update.status == TaskStatus.notFound) { + // failedDownloads.add(update.task); + // } + + // if (update.status == TaskStatus.complete) { + // final track = + // state.firstWhere((element) => element.id == update.task.taskId); + + // // resetting the replace downloaded file state on queue completion + // if (state.last == track) { + // ref.read(replaceDownloadedFileState.notifier).state = null; + // } + + // state = state + // .where((element) => element.id != update.task.taskId) + // .toList(); + + // final imageUri = TypeConversionUtils.image_X_UrlString( + // track.album?.images ?? [], + // placeholder: ImagePlaceholder.online, + // ); + // final response = await get(Uri.parse(imageUri)); + + // final tempFile = File(await update.task.filePath()); + + // final file = tempFile.copySync(_getPathForTrack(track)); + + // await tempFile.delete(); + + // await MetadataGod.writeMetadata( + // file: file.path, + // metadata: Metadata( + // title: track.name, + // artist: track.artists?.map((a) => a.name).join(", "), + // album: track.album?.name, + // albumArtist: track.artists?.map((a) => a.name).join(", "), + // year: track.album?.releaseDate != null + // ? int.tryParse(track.album!.releaseDate!) + // : null, + // trackNumber: track.trackNumber, + // discNumber: track.discNumber, + // durationMs: track.durationMs?.toDouble(), + // fileSize: file.lengthSync(), + // trackTotal: track.album?.tracks?.length, + // picture: response.headers['content-type'] != null + // ? Picture( + // data: response.bodyBytes, + // mimeType: response.headers['content-type']!, + // ) + // : null, + // ), + // ); + // } + // }, + // taskProgressCallback: (update) { + // activeDownloadProgress.add(update); + // }, + // ); + // FileDownloader().trackTasks(markDownloadedComplete: true); } UserPreferences get preferences => ref.read(userPreferencesProvider); @@ -115,9 +115,9 @@ class DownloadManagerProvider extends StateNotifier> { "${track.name} - ${track.artists?.map((a) => a.name).join(", ")}.m4a", ); - Future _ensureSpotubeTrack(Track track) async { + Future /* */ _ensureSpotubeTrack(Track track) async { if (state.any((element) => element.id == track.id)) { - final task = await FileDownloader().taskForId(track.id!); + final task = null /* await FileDownloader().taskForId(track.id!) */; if (task != null) { return task; } @@ -133,16 +133,17 @@ class DownloadManagerProvider extends StateNotifier> { pipedClient, ); state = [...state, spotubeTrack]; - final task = DownloadTask( - url: spotubeTrack.ytUri, - baseDirectory: BaseDirectory.applicationSupport, - taskId: spotubeTrack.id!, - updates: Updates.statusAndProgress, - ); - return task; + // final task = DownloadTask( + // url: spotubeTrack.ytUri, + // baseDirectory: BaseDirectory.applicationSupport, + // taskId: spotubeTrack.id!, + // updates: Updates.statusAndProgress, + // ); + // return task; + return null; } - Future enqueue(Track track) async { + Future /* */ enqueue(Track track) async { final replaceFileGlobal = ref.read(replaceDownloadedFileState); final file = File(_getPathForTrack(track)); if (file.existsSync() && @@ -155,11 +156,11 @@ class DownloadManagerProvider extends StateNotifier> { final task = await _ensureSpotubeTrack(track); - await FileDownloader().enqueue(task); + // await FileDownloader().enqueue(task); return task; } - Future> enqueueAll(List tracks) async { + Future */ > enqueueAll(List tracks) async { final tasks = await Future.wait(tracks.mapIndexed((i, e) { if (i != 0) { /// One second delay between each download to avoid @@ -173,16 +174,16 @@ class DownloadManagerProvider extends StateNotifier> { ref.read(replaceDownloadedFileState.notifier).state = null; } - return tasks.whereType().toList(); + return tasks. /* whereType(). */ toList(); } Future cancel(Track track) async { - await FileDownloader().cancelTaskWithId(track.id!); + // await FileDownloader().cancelTaskWithId(track.id!); state = state.where((element) => element.id != track.id).toList(); } Future cancelAll() async { - (await FileDownloader().reset()); + // (await FileDownloader().reset()); state = []; } } diff --git a/pubspec.lock b/pubspec.lock index 3f680e731..a913095db 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -153,14 +153,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0" - background_downloader: - dependency: "direct main" - description: - name: background_downloader - sha256: "58318c7141ac30c559004a58ab2fdbdb5433e37227a926196b88525085af3d8e" - url: "https://pub.dev" - source: hosted - version: "7.3.1" badges: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 03d10b5fa..07db73fde 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -103,7 +103,6 @@ dependencies: media_kit_native_event_loop: ^1.0.4 dbus: ^0.7.8 motion_toast: ^2.6.8 - background_downloader: ^7.3.1 dev_dependencies: build_runner: ^2.3.2