feat(downloads): WiFi-only network-type-aware download gating

Add a metered/cellular network detector so downloads honour a "WiFi
only" preference. Android reports network type via NetworkTypeMonitor;
Rust exposes it through download/network.rs and holds the queue pump when
on a metered connection, emitting a queue-wide waitingForNetwork event.
The frontend surfaces this via the networkType service and a
waitingForNetwork store flag.

TRACES: UR-053 | DR-074
This commit is contained in:
2026-07-23 20:02:07 +02:00
parent 8f8433eebe
commit e083b53ee8
13 changed files with 944 additions and 3 deletions
+30 -1
View File
@@ -40,7 +40,16 @@ export interface DownloadInfo {
}
export interface DownloadEvent {
type: 'queued' | 'started' | 'progress' | 'completed' | 'failed' | 'paused' | 'cancelled';
type:
| 'queued'
| 'started'
| 'progress'
| 'completed'
| 'failed'
| 'paused'
| 'cancelled'
| 'waitingForNetwork';
/** Absent on 'waitingForNetwork', which is queue-wide rather than per-download. */
downloadId: number;
itemId: string;
bytesDownloaded?: number;
@@ -64,6 +73,15 @@ interface DownloadsState {
stats: DownloadStats;
}
/**
* True when the download queue is held because "WiFi Only" is enabled and the
* device is on a metered/cellular network. Pending rows stay pending; the queue
* resumes automatically when an acceptable network appears.
*
* TRACES: UR-053 | DR-074
*/
export const waitingForNetwork = writable(false);
function createDownloadsStore() {
const { subscribe, update, set } = writable<DownloadsState>({
downloads: {},
@@ -607,6 +625,17 @@ function handleDownloadEvent(payload: DownloadEvent): void {
case 'cancelled':
removeDownloadFromStore(payload.downloadId);
break;
case 'waitingForNetwork':
// Queue-wide, not tied to one download: the pump refused to start
// anything because WiFi-only is on and we're on a metered network.
waitingForNetwork.set(true);
break;
}
// Any per-download progress proves the gate isn't holding us any more.
if (payload.type === 'started' || payload.type === 'progress') {
waitingForNetwork.set(false);
}
}