Review #1885: one concurrency setting with a safe default and a numeric control

Replaces the MultiThreadEnabled checkbox and the ProcessorCount default
with a single MaxConcurrentDownloads value where 1 means serial - the
behaviour Libation had before parallel downloads existed.

The old pairing could not express 'off' at all: the bool was hardcoded
true in the view model constructor and the int setter clamped to a
minimum of 2, so there was no way back to one-at-a-time downloads.
Collapsing both into one value makes that state unreachable rather than
merely fixed, and removes the risk of the two settings disagreeing.

Bounds live in Configuration as named constants: minimum 1, default 3,
maximum 10. Audible throttles license requests, so the default is
deliberately conservative and the cap keeps users from choosing a number
that produces license denials instead of speed.

WinForms swaps the 'Parallel downloads' checkbox for an 'At once:'
spinner that reads its bounds from those constants.
This commit is contained in:
Allamagoosa
2026-08-14 11:12:41 -07:00
parent ad59032693
commit 2db63a8edd
4 changed files with 65 additions and 29 deletions

View File

@@ -43,17 +43,31 @@ public class ProcessQueueViewModel : ReactiveObject
SpeedLimit = Configuration.Instance.DownloadSpeedLimit / 1024m / 1024;
MaxConcurrentDownloads = Configuration.Instance.MaxConcurrentDownloads;
AutoScrollQueue = Configuration.Instance.AutoScrollQueue;
MultiThreadEnabled = true;
}
public int CompletedCount { get => field; private set { RaiseAndSetIfChanged(ref field, value); RaisePropertyChanged(nameof(AnyCompleted)); } }
public int QueuedCount { get => field; private set { this.RaiseAndSetIfChanged(ref field, value); RaisePropertyChanged(nameof(AnyQueued)); } }
public int ErrorCount { get => field; private set { RaiseAndSetIfChanged(ref field, value); RaisePropertyChanged(nameof(AnyErrors)); } }
public int MaxConcurrentDownloads { get => field; set { RaiseAndSetIfChanged(ref field, value); Configuration.Instance.MaxConcurrentDownloads = value; } }
/// <summary>
/// How many books download and decrypt at once. <see cref="Configuration.MinConcurrentDownloads"/>
/// means one at a time, which is how Libation behaved before parallel downloads existed - so this
/// single value is both the limit and the off switch, and the two can never disagree.
/// </summary>
public int MaxConcurrentDownloads
{
get => field;
set
{
var clamped = Math.Clamp(value, Configuration.MinConcurrentDownloads, Configuration.MaxAllowedConcurrentDownloads);
RaiseAndSetIfChanged(ref field, clamped);
Configuration.Instance.MaxConcurrentDownloads = clamped;
}
}
public bool AutoScrollQueue { get => field; set { RaiseAndSetIfChanged(ref field, value); Configuration.Instance.AutoScrollQueue = value; } }
public bool MultiThreadEnabled { get => field; set => RaiseAndSetIfChanged(ref field, value); }
private int EffectiveConcurrentDownloads => MultiThreadEnabled ? Math.Max(2, MaxConcurrentDownloads) : 1;
/// <summary>Exposed so UI controls can bind their spinner bounds rather than hardcoding them.</summary>
public static int MinConcurrentDownloads => Configuration.MinConcurrentDownloads;
public static int MaxAllowedConcurrentDownloads => Configuration.MaxAllowedConcurrentDownloads;
public string? RunningTime { get => field; set => RaiseAndSetIfChanged(ref field, value); }
public bool ProgressBarVisible { get => field; set => RaiseAndSetIfChanged(ref field, value); }
public bool AnyCompleted => CompletedCount > 0;
@@ -662,7 +676,7 @@ public class ProcessQueueViewModel : ReactiveObject
}
// If at capacity, wait for a slot to open before trying to dequeue more
if (activeTasks.Count >= EffectiveConcurrentDownloads)
if (activeTasks.Count >= MaxConcurrentDownloads)
{
await Task.WhenAny(activeTasks);
continue;