mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-19 14:53:44 +00:00
feat(ui): add download percentage and ETA display (#1238)
This commit is contained in:
1 parent
a9eee26be7
commit
f86a379f93
2 files changed
+63
-2
No files matched your search
@@ -214,6 +214,43 @@ class BuildTaskListView extends GetView {
|
|||||||
(total > 0 ? " / ${Util.fmtByte(total)}" : "");
|
(total > 0 ? " / ${Util.fmtByte(total)}" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get percentage text, e.g. " (50.5%)"
|
||||||
|
String getPercentText() {
|
||||||
|
final total = task.meta.res?.size ?? 0;
|
||||||
|
if (total <= 0 || isDone()) return "";
|
||||||
|
double p = getProgress();
|
||||||
|
return "(${(p * 100).toStringAsFixed(1)}%)";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get ETA text, e.g. "00:05:30"
|
||||||
|
String getEtaText() {
|
||||||
|
if (isDone()) return "";
|
||||||
|
|
||||||
|
final total = task.meta.res?.size ?? 0;
|
||||||
|
final downloaded = task.progress.downloaded;
|
||||||
|
final speed = task.progress.speed;
|
||||||
|
|
||||||
|
// If speed is 0 or file is downloaded, don't show time
|
||||||
|
if (total <= 0 || speed <= 0 || downloaded >= total) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
final remainingBytes = total - downloaded;
|
||||||
|
final remainingSeconds = remainingBytes ~/ speed;
|
||||||
|
|
||||||
|
// If time is too long (e.g. > 1 day), return > 1d
|
||||||
|
if (remainingSeconds > 86400) return "> 1d";
|
||||||
|
|
||||||
|
Duration duration = Duration(seconds: remainingSeconds);
|
||||||
|
String twoDigits(int n) => n.toString().padLeft(2, "0");
|
||||||
|
|
||||||
|
if (duration.inHours > 0) {
|
||||||
|
return "${twoDigits(duration.inHours)}:${twoDigits(duration.inMinutes.remainder(60))}:${twoDigits(duration.inSeconds.remainder(60))}";
|
||||||
|
} else {
|
||||||
|
return "${twoDigits(duration.inMinutes.remainder(60))}:${twoDigits(duration.inSeconds.remainder(60))}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final taskController = Get.find<TaskController>();
|
final taskController = Get.find<TaskController>();
|
||||||
final taskListController = taskController.tabIndex.value == 0
|
final taskListController = taskController.tabIndex.value == 0
|
||||||
? Get.find<TaskDownloadingController>()
|
? Get.find<TaskDownloadingController>()
|
||||||
@@ -308,18 +345,41 @@ class BuildTaskListView extends GetView {
|
|||||||
)),
|
)),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
|
// Left side: Progress text + Percentage
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 1,
|
flex: 1,
|
||||||
child: Text(
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
getProgressText(),
|
getProgressText(),
|
||||||
style: Get.textTheme.bodyLarge
|
style: Get.textTheme.bodyLarge
|
||||||
?.copyWith(color: Get.theme.disabledColor),
|
?.copyWith(color: Get.theme.disabledColor),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
getPercentText(),
|
||||||
|
style: Get.textTheme.bodyLarge
|
||||||
|
?.copyWith(color: Get.theme.disabledColor),
|
||||||
|
),
|
||||||
|
],
|
||||||
).padding(left: 18)),
|
).padding(left: 18)),
|
||||||
|
// Right side: ETA + Speed + Actions
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 1,
|
flex: 1,
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
|
Text(
|
||||||
|
getEtaText(),
|
||||||
|
style: Get.textTheme.titleSmall,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
" | ",
|
||||||
|
style: Get.textTheme.titleSmall?.copyWith(
|
||||||
|
color: Get.theme.disabledColor,
|
||||||
|
fontWeight: FontWeight.w300,
|
||||||
|
),
|
||||||
|
).padding(horizontal: 4),
|
||||||
Text("${Util.fmtByte(task.progress.speed)} / s",
|
Text("${Util.fmtByte(task.progress.speed)} / s",
|
||||||
style: Get.textTheme.titleSmall),
|
style: Get.textTheme.titleSmall),
|
||||||
...buildActions()
|
...buildActions()
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ const frFR = {
|
|||||||
'useServerCtime':
|
'useServerCtime':
|
||||||
'Utiliser l\'heure du serveur pour la création de fichier',
|
'Utiliser l\'heure du serveur pour la création de fichier',
|
||||||
'maxRunning': 'Tâches en cours maximum',
|
'maxRunning': 'Tâches en cours maximum',
|
||||||
'autoStartTasks': 'Démarrer automatiquement les tâches incomplètes au lancement',
|
'autoStartTasks':
|
||||||
|
'Démarrer automatiquement les tâches incomplètes au lancement',
|
||||||
'items': '@count éléments',
|
'items': '@count éléments',
|
||||||
'subscribeTracker': 'S\'abonner au tracker',
|
'subscribeTracker': 'S\'abonner au tracker',
|
||||||
'subscribeFail':
|
'subscribeFail':
|
||||||
|
|||||||
Reference in new issue
Block a user