feat(downloads): support up to 3 concurrent downloads

The Dart queue loop was already built around an activeDownloads map and
per-item progress tracking but was gated to one download at a time. Add
a concurrentDownloads setting (1-3, default 1) exposed in Download
Settings > Performance, and let the scheduler keep up to that many
items in flight. The experimental Android native worker is still
strictly sequential, so it is skipped in favor of the Dart queue while
concurrency is enabled.
This commit is contained in:
zarzet
2026-07-10 05:58:25 +07:00
parent 19f69a6090
commit 1998a9300e
22 changed files with 376 additions and 5 deletions
+13 -5
View File
@@ -3742,6 +3742,12 @@ class DownloadQueueNotifier extends Notifier<DownloadQueueState> {
if (!Platform.isAndroid || !settings.nativeDownloadWorkerEnabled) {
return false;
}
if (settings.concurrentDownloads > 1) {
// The experimental native worker downloads strictly sequentially, so
// prefer the Dart queue when the user enabled concurrent downloads.
_log.i('Concurrent downloads enabled; skipping native worker');
return false;
}
if (!settings.useExtensionProviders) {
return false;
}
@@ -5470,7 +5476,7 @@ class DownloadQueueNotifier extends Notifier<DownloadQueueState> {
}
try {
await _processQueueSequential();
await _runQueueLoop();
} finally {
if (iosDownloadBookmarkActive) {
await PlatformBridge.stopAccessingIosBookmark();
@@ -5550,7 +5556,7 @@ class DownloadQueueNotifier extends Notifier<DownloadQueueState> {
}
}
Future<void> _processQueueSequential() async {
Future<void> _runQueueLoop() async {
final activeDownloads = <String, Future<void>>{};
_startMultiProgressPolling();
@@ -5582,9 +5588,11 @@ class DownloadQueueNotifier extends Notifier<DownloadQueueState> {
break;
}
// One download at a time: only start the next item once the current
// download has finished, to stay within the API's single-request limit.
if (activeDownloads.isEmpty &&
final maxConcurrent = ref
.read(settingsProvider)
.concurrentDownloads
.clamp(1, 3);
while (activeDownloads.length < maxConcurrent &&
queuedItems.isNotEmpty &&
!state.isPaused) {
final item = queuedItems.removeAt(0);
+5
View File
@@ -613,6 +613,11 @@ class SettingsNotifier extends Notifier<AppSettings> {
_saveSettings();
}
void setConcurrentDownloads(int count) {
state = state.copyWith(concurrentDownloads: count.clamp(1, 3));
_saveSettings();
}
void setNetworkCompatibilityMode(bool enabled) {
state = state.copyWith(networkCompatibilityMode: enabled);
_saveSettings();