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);
}
+7 -8
View File
@@ -21,16 +21,15 @@ class FileClipboard extends ChangeNotifier {
List<CacheableFile> get files => List.unmodifiable(_files);
bool get isEmpty => _files.isEmpty;
void cut(List<CacheableFile> files) {
if (files.isEmpty) return;
_operation = FileClipboardOperation.cut;
_files = List.of(files);
notifyListeners();
}
void cut(List<CacheableFile> files) =>
_set(FileClipboardOperation.cut, files);
void copy(List<CacheableFile> files) {
void copy(List<CacheableFile> files) =>
_set(FileClipboardOperation.copy, files);
void _set(FileClipboardOperation operation, List<CacheableFile> files) {
if (files.isEmpty) return;
_operation = FileClipboardOperation.copy;
_operation = operation;
_files = List.of(files);
notifyListeners();
}
-9
View File
@@ -8,12 +8,3 @@ String randomHexId({int bytes = 16}) {
(_) => random.nextInt(256),
).map((b) => b.toRadixString(16).padLeft(2, '0')).join();
}
/// Random RFC 4122 version-4 UUID, for ids a server expects in UUID form.
String randomUuidV4() {
final hex = randomHexId();
final variant = (int.parse(hex[16], radix: 16) & 0x3 | 0x8).toRadixString(16);
return '${hex.substring(0, 8)}-${hex.substring(8, 12)}-'
'4${hex.substring(13, 16)}-$variant${hex.substring(17, 20)}-'
'${hex.substring(20)}';
}