This commit is contained in:
Forrest 2026-08-04 16:08:51 -04:00
parent d558aba246
commit 3bd713d667
17 changed files with 1566 additions and 132 deletions

View file

@ -138,8 +138,6 @@ class DownloadController extends StateNotifier<DownloadState> {
headers: {'User-Agent': 'timbre'},
));
static const int _maxConcurrent = 3;
int _generation = 0;
String? _loadedKey;
final List<String> _queue = [];
@ -271,8 +269,17 @@ class DownloadController extends StateNotifier<DownloadState> {
}
}
/// Re-run the pump — used when the concurrency setting is raised so queued
/// tracks start immediately instead of waiting for the next enqueue/finish.
void onConcurrencyChanged() => _pump();
void _pump() {
while (_active < _maxConcurrent && _queue.isNotEmpty) {
// Re-read the concurrency cap each pump so a settings change takes effect
// mid-session: raising it starts more downloads immediately; lowering it
// stops launching new ones while in-flight downloads drain naturally.
final maxConcurrent =
AppSettings.clampConcurrentDownloads(_settingsGetter().maxConcurrentDownloads);
while (_active < maxConcurrent && _queue.isNotEmpty) {
final id = _queue.removeAt(0);
final info = state.byId[id];
if (info == null || info.status != DownloadStatus.queued) continue;