From 74d0538f184046a088b2544407a57f9602a60415 Mon Sep 17 00:00:00 2001 From: nyne Date: Tue, 29 Oct 2024 10:54:53 +0800 Subject: [PATCH] improve download --- lib/network/download.dart | 11 +++++++++++ lib/pages/downloading_page.dart | 10 ++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/network/download.dart b/lib/network/download.dart index 052526d..c6d60a8 100644 --- a/lib/network/download.dart +++ b/lib/network/download.dart @@ -508,6 +508,8 @@ class _ImageDownloadWrapper { var completers = >[]; + 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); } diff --git a/lib/pages/downloading_page.dart b/lib/pages/downloading_page.dart index ce21d1b..011127f 100644 --- a/lib/pages/downloading_page.dart +++ b/lib/pages/downloading_page.dart @@ -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(