feat: Add max concurrent downloads to settings (#347)

Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
PartyDonut 2025-05-18 10:14:23 +02:00 committed by GitHub
parent 947da2390f
commit 8acd880329
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 110 additions and 20 deletions

View file

@ -1,17 +1,55 @@
import 'package:background_downloader/background_downloader.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:fladder/providers/settings/client_settings_provider.dart';
part 'background_download_provider.g.dart';
@Riverpod(keepAlive: true)
FileDownloader backgroundDownloader(Ref ref) {
return FileDownloader()
..trackTasks()
..configureNotification(
running: const TaskNotification('Downloading', 'file: {filename}'),
complete: const TaskNotification('Download finished', 'file: {filename}'),
paused: const TaskNotification('Download paused', 'file: {filename}'),
progressBar: true,
class BackgroundDownloader extends _$BackgroundDownloader {
@override
FileDownloader build() {
final maxDownloads = ref.read(clientSettingsProvider.select((value) => value.maxConcurrentDownloads));
return FileDownloader()
..configure(
globalConfig: maxDownloads == 0
? ("", "")
: (
Config.holdingQueue,
(
//maxConcurrent
maxDownloads,
//maxConcurrentByHost
maxDownloads,
//maxConcurrentByGroup
maxDownloads,
),
),
)
..trackTasks()
..configureNotification(
running: const TaskNotification('Downloading', 'file: {filename}'),
complete: const TaskNotification('Download finished', 'file: {filename}'),
paused: const TaskNotification('Download paused', 'file: {filename}'),
progressBar: true,
);
}
void setMaxConcurrent(int value) {
state.configure(
globalConfig: value == 0
? ("", "")
: (
Config.holdingQueue,
(
//maxConcurrent
value,
//maxConcurrentByHost
value,
//maxConcurrentByGroup
value,
),
),
);
}
}

View file

@ -7,12 +7,13 @@ part of 'background_download_provider.dart';
// **************************************************************************
String _$backgroundDownloaderHash() =>
r'997d9f4ba79dd0d9d30d5f283b36d5280d10dfaa';
r'df72b6338a8e80178935985ba17c43bf720f4522';
/// See also [backgroundDownloader].
@ProviderFor(backgroundDownloader)
final backgroundDownloaderProvider = Provider<FileDownloader>.internal(
backgroundDownloader,
/// See also [BackgroundDownloader].
@ProviderFor(BackgroundDownloader)
final backgroundDownloaderProvider =
NotifierProvider<BackgroundDownloader, FileDownloader>.internal(
BackgroundDownloader.new,
name: r'backgroundDownloaderProvider',
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
? null
@ -21,8 +22,6 @@ final backgroundDownloaderProvider = Provider<FileDownloader>.internal(
allTransitiveDependencies: null,
);
@Deprecated('Will be removed in 3.0. Use Ref instead')
// ignore: unused_element
typedef BackgroundDownloaderRef = ProviderRef<FileDownloader>;
typedef _$BackgroundDownloader = Notifier<FileDownloader>;
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package