simplified code across the app and consolidated duplicated helpers

This commit is contained in:
2026-09-27 17:29:54 +02:00
parent 3e856d0b1c
commit ee1240f71a
155 changed files with 1772 additions and 2546 deletions
+2 -9
View File
@@ -35,11 +35,7 @@ class DownloadFailed extends DownloadStatus {
/// the same job. Kept engine-agnostic on purpose — the native
/// `background_downloader` task lives entirely inside [DownloadManager].
class DownloadJob {
DownloadJob({
required this.remotePath,
required this.name,
this.remoteFile,
});
DownloadJob({required this.remotePath, required this.name, this.remoteFile});
final String remotePath;
final String name;
@@ -59,10 +55,7 @@ class DownloadJob {
const DownloadInProgress(0),
);
bool get isFinished =>
status.value is DownloadDone ||
status.value is DownloadFailed ||
status.value is DownloadCancelled;
bool get isFinished => status.value is! DownloadInProgress;
bool get isDone => status.value is DownloadDone;
bool get isFailed => status.value is DownloadFailed;
+6 -4
View File
@@ -237,9 +237,7 @@ class DownloadManager {
// instead of freezing at the last percent.
job.status.value = const DownloadCancelled();
}
_jobs.remove(job.remotePath);
if (taskId != null) _byTaskId.remove(taskId);
scheduleMicrotask(job.dispose);
_forget(job);
}
_refreshVisible();
}
@@ -330,10 +328,14 @@ class DownloadManager {
// --- bookkeeping -----------------------------------------------------------
void _remove(DownloadJob job) {
_forget(job);
_refreshVisible();
}
void _forget(DownloadJob job) {
_jobs.remove(job.remotePath);
final taskId = job.taskId;
if (taskId != null) _byTaskId.remove(taskId);
_refreshVisible();
scheduleMicrotask(job.dispose);
}