mirror of
https://github.com/ALEZ-DEV/Babylonia-terminal.git
synced 2025-12-16 17:38:51 +00:00
Merge pull request #24 from ALEZ-DEV/show-download-speed
Show download speed
This commit is contained in:
commit
dfba16f675
@ -22,20 +22,16 @@ class Game with ChangeNotifier {
|
|||||||
|
|
||||||
Int64 currentProgress = Int64(0);
|
Int64 currentProgress = Int64(0);
|
||||||
Int64 maxProgress = Int64(0);
|
Int64 maxProgress = Int64(0);
|
||||||
|
Int64 currentSpeed = Int64(0);
|
||||||
|
|
||||||
Future startInstallation(GameStateProvider gameState, bool isUpdating) async {
|
Future startInstallation(GameStateProvider gameState, bool isUpdating) async {
|
||||||
StartGameInstallation(isUpdating: isUpdating).sendSignalToRust();
|
StartGameInstallation(isUpdating: isUpdating).sendSignalToRust();
|
||||||
gameInstallationState = GameInstallationState.checkingFile;
|
gameInstallationState = GameInstallationState.checkingFile;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
//final downloadStream = NotifyGameStartDownloading.rustSignalStream;
|
|
||||||
//await for (final _ in downloadStream) {
|
|
||||||
// gameInstallationState = GameInstallationState.downloading;
|
|
||||||
// notifyListeners();
|
|
||||||
// break;
|
|
||||||
//}
|
|
||||||
|
|
||||||
final downloadProgresStream = GameInstallationProgress.rustSignalStream;
|
final downloadProgresStream = GameInstallationProgress.rustSignalStream;
|
||||||
|
DateTime waitUntil = DateTime.now().add(const Duration(seconds: 1));
|
||||||
|
Int64 lastProgress = Int64(0);
|
||||||
await for (final rustSignal in downloadProgresStream) {
|
await for (final rustSignal in downloadProgresStream) {
|
||||||
if (gameInstallationState == GameInstallationState.checkingFile) {
|
if (gameInstallationState == GameInstallationState.checkingFile) {
|
||||||
gameInstallationState = GameInstallationState.downloading;
|
gameInstallationState = GameInstallationState.downloading;
|
||||||
@ -43,7 +39,19 @@ class Game with ChangeNotifier {
|
|||||||
|
|
||||||
currentProgress = rustSignal.message.current;
|
currentProgress = rustSignal.message.current;
|
||||||
maxProgress = rustSignal.message.max;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
waitUntil = DateTime.now().add(const Duration(seconds: 1));
|
||||||
|
}
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
if (currentProgress >= maxProgress) {
|
if (currentProgress >= maxProgress) {
|
||||||
@ -51,7 +59,6 @@ class Game with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print("patching game...");
|
|
||||||
gameInstallationState = GameInstallationState.patching;
|
gameInstallationState = GameInstallationState.patching;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,6 @@
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
import 'package:xml/xml.dart';
|
|
||||||
import 'package:xml/xpath.dart';
|
|
||||||
|
|
||||||
class ReleaseNoticeInfo {
|
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<String> getInfo(String currentVersion) async {
|
static Future<String> getInfo(String currentVersion) async {
|
||||||
final content = await rootBundle.loadString("CHANGELOG.md");
|
final content = await rootBundle.loadString("CHANGELOG.md");
|
||||||
return parseChangelog(content, currentVersion);
|
return parseChangelog(content, currentVersion);
|
||||||
|
|||||||
@ -110,6 +110,7 @@ class _DownloadingGame extends StatelessWidget {
|
|||||||
//1024^3 = 1073741824
|
//1024^3 = 1073741824
|
||||||
final currentGb = provider.currentProgress.toInt() / 1073741824;
|
final currentGb = provider.currentProgress.toInt() / 1073741824;
|
||||||
final maxGb = provider.maxProgress.toInt() / 1073741824;
|
final maxGb = provider.maxProgress.toInt() / 1073741824;
|
||||||
|
final currentSpeed = provider.currentSpeed.toInt() / 1048576;
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 40.0),
|
padding: const EdgeInsets.only(bottom: 40.0),
|
||||||
@ -119,7 +120,7 @@ class _DownloadingGame extends StatelessWidget {
|
|||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 8.0),
|
padding: const EdgeInsets.only(bottom: 8.0),
|
||||||
child: Text(
|
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(
|
YaruLinearProgressIndicator(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user