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

View File

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