improve download

This commit is contained in:
nyne
2024-10-29 10:54:53 +08:00
parent ca15a641a4
commit 74d0538f18
2 changed files with 17 additions and 4 deletions

View File

@@ -508,6 +508,8 @@ class _ImageDownloadWrapper {
var completers = <Completer<_ImageDownloadWrapper>>[];
var retry = 3;
void start() async {
int lastBytes = 0;
try {
@@ -531,6 +533,11 @@ class _ImageDownloadWrapper {
}
} catch (e, s) {
Log.error("Download", e.toString(), s);
retry--;
if (retry > 0) {
start();
return;
}
error = e.toString();
for (var c in completers) {
if (!c.isCompleted) {
@@ -561,6 +568,9 @@ abstract mixin class _TransferSpeedMixin {
void onData(int length) {
if (timer == null) return;
if(length < 0) {
return;
}
_bytesSinceLastSecond += length;
}
@@ -573,6 +583,7 @@ abstract mixin class _TransferSpeedMixin {
if (timer != null) {
timer!.cancel();
}
_bytesSinceLastSecond = 0;
timer = Timer.periodic(const Duration(seconds: 1), onNextSecond);
}

View File

@@ -172,11 +172,13 @@ class _DownloadTaskTileState extends State<_DownloadTaskTile> {
children: [
Row(
children: [
Text(
widget.task.title,
style: Theme.of(context).textTheme.bodyMedium,
Expanded(
child: Text(
widget.task.title,
style: Theme.of(context).textTheme.bodyMedium,
maxLines: 2,
),
),
const Spacer(),
MenuButton(
entries: [
MenuEntry(