mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-07 13:38:13 -08:00
45 lines
1.3 KiB
Dart
45 lines
1.3 KiB
Dart
import 'package:background_downloader/background_downloader.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)
|
|
class BackgroundDownloader extends _$BackgroundDownloader {
|
|
@override
|
|
FileDownloader build() {
|
|
final maxDownloads = ref.read(clientSettingsProvider.select((value) => value.maxConcurrentDownloads));
|
|
return FileDownloader()
|
|
..configure(
|
|
globalConfig: globalConfig(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: globalConfig(value),
|
|
);
|
|
}
|
|
|
|
(String, dynamic) globalConfig(int value) => value == 0
|
|
? ("", "")
|
|
: (
|
|
Config.holdingQueue,
|
|
(
|
|
//maxConcurrent
|
|
value,
|
|
//maxConcurrentByHost
|
|
value,
|
|
//maxConcurrentByGroup
|
|
value,
|
|
),
|
|
);
|
|
}
|