From f0c9e4707a35165f2e54866e919afa58334527eb Mon Sep 17 00:00:00 2001 From: ALEZ-DEV Date: Wed, 6 Nov 2024 19:50:21 +0100 Subject: [PATCH 1/4] can now see the download speed --- .../lib/models/game.dart | 28 +++++++++++++------ .../lib/widgets/steps/game_steps_widget.dart | 5 ++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/babylonia_terminal_launcher/lib/models/game.dart b/babylonia_terminal_launcher/lib/models/game.dart index ea74752..7af9d6b 100644 --- a/babylonia_terminal_launcher/lib/models/game.dart +++ b/babylonia_terminal_launcher/lib/models/game.dart @@ -22,20 +22,16 @@ class Game with ChangeNotifier { Int64 currentProgress = Int64(0); Int64 maxProgress = Int64(0); + Int64 currentSpeed = Int64(0); Future startInstallation(GameStateProvider gameState, bool isUpdating) async { StartGameInstallation(isUpdating: isUpdating).sendSignalToRust(); gameInstallationState = GameInstallationState.checkingFile; notifyListeners(); - //final downloadStream = NotifyGameStartDownloading.rustSignalStream; - //await for (final _ in downloadStream) { - // gameInstallationState = GameInstallationState.downloading; - // notifyListeners(); - // break; - //} - final downloadProgresStream = GameInstallationProgress.rustSignalStream; + DateTime waitUntil = DateTime.now().add(const Duration(seconds: 1)); + Int64 lastProgress = Int64(0); await for (final rustSignal in downloadProgresStream) { if (gameInstallationState == GameInstallationState.checkingFile) { gameInstallationState = GameInstallationState.downloading; @@ -43,7 +39,22 @@ class Game with ChangeNotifier { currentProgress = rustSignal.message.current; maxProgress = rustSignal.message.max; - print("progress current : $currentProgress / $maxProgress"); + + if (waitUntil.isBefore(DateTime.now())) { + if (currentSpeed == 0) { + currentSpeed = currentProgress; + lastProgress = currentProgress; + } else { + currentSpeed = currentProgress - lastProgress; + lastProgress = currentProgress; + print('currentProgress -> $currentProgress'); + print('lastProgress -> $lastProgress'); + print('currentSpeed -> ${currentSpeed.toInt() / 1048576} MiB/s'); + } + + waitUntil = DateTime.now().add(Duration(seconds: 1)); + } + notifyListeners(); if (currentProgress >= maxProgress) { @@ -51,7 +62,6 @@ class Game with ChangeNotifier { } } - print("patching game..."); gameInstallationState = GameInstallationState.patching; notifyListeners(); diff --git a/babylonia_terminal_launcher/lib/widgets/steps/game_steps_widget.dart b/babylonia_terminal_launcher/lib/widgets/steps/game_steps_widget.dart index 34f5d4b..5b572ac 100644 --- a/babylonia_terminal_launcher/lib/widgets/steps/game_steps_widget.dart +++ b/babylonia_terminal_launcher/lib/widgets/steps/game_steps_widget.dart @@ -107,9 +107,10 @@ class _DownloadingGame extends StatelessWidget { final provider = Provider.of(context); final pourcent = (provider.currentProgress.toInt() / provider.maxProgress.toInt()) * 100; - //1024^3 = 1073741824 + //1024^3 = 1073741824 final currentGb = provider.currentProgress.toInt() / 1073741824; final maxGb = provider.maxProgress.toInt() / 1073741824; + final currentSpeed = provider.currentSpeed.toInt() / 1048576; return Padding( padding: const EdgeInsets.only(bottom: 40.0), @@ -119,7 +120,7 @@ class _DownloadingGame extends StatelessWidget { Padding( padding: const EdgeInsets.only(bottom: 8.0), child: Text( - "${currentGb.toStringAsFixed(2)} / ${maxGb.toStringAsFixed(2)} GiB (${pourcent.toStringAsFixed(2)}%)", + "${currentGb.toStringAsFixed(2)} / ${maxGb.toStringAsFixed(2)} GiB (${pourcent.toStringAsFixed(2)}%) - ${currentSpeed.toStringAsFixed(2)}MiB/s", ), ), YaruLinearProgressIndicator( From 6ea0d7ac1245896057fb4c3a7f5f5b900d501ef8 Mon Sep 17 00:00:00 2001 From: ALEZ-DEV Date: Wed, 6 Nov 2024 19:51:18 +0100 Subject: [PATCH 2/4] some cleaning --- babylonia_terminal_launcher/lib/models/game.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/babylonia_terminal_launcher/lib/models/game.dart b/babylonia_terminal_launcher/lib/models/game.dart index 7af9d6b..ab34b61 100644 --- a/babylonia_terminal_launcher/lib/models/game.dart +++ b/babylonia_terminal_launcher/lib/models/game.dart @@ -47,12 +47,9 @@ class Game with ChangeNotifier { } else { currentSpeed = currentProgress - lastProgress; lastProgress = currentProgress; - print('currentProgress -> $currentProgress'); - print('lastProgress -> $lastProgress'); - print('currentSpeed -> ${currentSpeed.toInt() / 1048576} MiB/s'); } - waitUntil = DateTime.now().add(Duration(seconds: 1)); + waitUntil = DateTime.now().add(const Duration(seconds: 1)); } notifyListeners(); From 80ea7ec2cfbbff045e292948d85082136abae3cc Mon Sep 17 00:00:00 2001 From: ALEZ-DEV Date: Wed, 6 Nov 2024 19:54:10 +0100 Subject: [PATCH 3/4] more cleaning --- babylonia_terminal_launcher/lib/models/release_notice.dart | 6 ------ 1 file changed, 6 deletions(-) diff --git a/babylonia_terminal_launcher/lib/models/release_notice.dart b/babylonia_terminal_launcher/lib/models/release_notice.dart index 90b2e69..7a74e65 100644 --- a/babylonia_terminal_launcher/lib/models/release_notice.dart +++ b/babylonia_terminal_launcher/lib/models/release_notice.dart @@ -1,12 +1,6 @@ import 'package:flutter/services.dart'; -import 'package:http/http.dart' as http; -import 'package:xml/xml.dart'; -import 'package:xml/xpath.dart'; class ReleaseNoticeInfo { - static const _releaseInfoUrl = - "https://raw.githubusercontent.com/ALEZ-DEV/Babylonia-terminal-flatpak-builds/refs/heads/main/moe.celica.BabyloniaTerminal.metainfo.xml"; - static Future getInfo(String currentVersion) async { final content = await rootBundle.loadString("CHANGELOG.md"); return parseChangelog(content, currentVersion); From f66922d8134e123484f5280b07a97c8ee71991c9 Mon Sep 17 00:00:00 2001 From: ALEZ-DEV Date: Wed, 6 Nov 2024 19:55:18 +0100 Subject: [PATCH 4/4] big edit --- .../lib/widgets/steps/game_steps_widget.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/babylonia_terminal_launcher/lib/widgets/steps/game_steps_widget.dart b/babylonia_terminal_launcher/lib/widgets/steps/game_steps_widget.dart index 5b572ac..5894bfb 100644 --- a/babylonia_terminal_launcher/lib/widgets/steps/game_steps_widget.dart +++ b/babylonia_terminal_launcher/lib/widgets/steps/game_steps_widget.dart @@ -120,7 +120,7 @@ class _DownloadingGame extends StatelessWidget { Padding( padding: const EdgeInsets.only(bottom: 8.0), child: Text( - "${currentGb.toStringAsFixed(2)} / ${maxGb.toStringAsFixed(2)} GiB (${pourcent.toStringAsFixed(2)}%) - ${currentSpeed.toStringAsFixed(2)}MiB/s", + "${currentGb.toStringAsFixed(2)} / ${maxGb.toStringAsFixed(2)} GiB (${pourcent.toStringAsFixed(2)}%) - ${currentSpeed.toStringAsFixed(2)} MiB/s", ), ), YaruLinearProgressIndicator(