From 0a59a32c1ba699f4a24c68c3df5a982b0645a3db Mon Sep 17 00:00:00 2001 From: Alessandro Autiero Date: Mon, 9 Dec 2024 14:36:43 +0100 Subject: [PATCH] 10.0.2 --- common/lib/src/util/build.dart | 25 ++++++----- gui/lib/l10n/reboot_en.arb | 1 - .../src/messenger/implementation/version.dart | 12 ++---- .../src/page/implementation/home_page.dart | 41 +++++++++++++++++-- gui/pubspec.yaml | 2 +- 5 files changed, 56 insertions(+), 25 deletions(-) diff --git a/common/lib/src/util/build.dart b/common/lib/src/util/build.dart index f3afc33..544cf12 100644 --- a/common/lib/src/util/build.dart +++ b/common/lib/src/util/build.dart @@ -134,17 +134,13 @@ Future downloadArchiveBuild(FortniteBuildDownloadOptions options) async { } Future _startAriaServer() async { - final running = await _isAriaRunning(); - if(running) { - await killProcessByPort(_ariaPort); - } - + await stopDownloadServer(); final aria2c = File("${assetsDirectory.path}\\build\\aria2c.exe"); if(!aria2c.existsSync()) { throw "Missing aria2c.exe"; } - await startProcess( + final process = await startProcess( executable: aria2c, args: [ "--max-connection-per-server=${Platform.numberOfProcessors}", @@ -153,10 +149,14 @@ Future _startAriaServer() async { "--rpc-listen-all=true", "--rpc-allow-origin-all", "--rpc-secret=$_ariaSecret", - "--rpc-listen-port=$_ariaPort" + "--rpc-listen-port=$_ariaPort", + "--file-allocation=none" ], - window: false + window: false ); + process.stdOutput.listen((message) => log("[ARIA] Message: $message")); + process.stdError.listen((error) => log("[ARIA] Error: $error")); + process.exitCode.then((exitCode) => log("[ARIA] Exit code: $exitCode")); for(var i = 0; i < _ariaMaxSpawnTime.inSeconds; i++) { if(await _isAriaRunning()) { return; @@ -177,8 +177,8 @@ Future _isAriaRunning() async { "token:${_ariaSecret}" ] }; - await http.post(_ariaEndpoint, body: jsonEncode(statusRequest)); - return true; + final response = await http.post(_ariaEndpoint, body: jsonEncode(statusRequest)); + return response.statusCode == 200; }catch(_) { return false; } @@ -227,11 +227,16 @@ Future _stopAriaDownload(String downloadId) async { ] }; await http.post(_ariaEndpoint, body: jsonEncode(addDownloadRequest)); + stopDownloadServer(); }catch(error) { throw "Stop failed (${error})"; } } +Future stopDownloadServer() async { + await killProcessByPort(_ariaPort); +} + Future _extractArchive(Completer stopped, String extension, File tempFile, FortniteBuildDownloadOptions options) async { Process? process; diff --git a/gui/lib/l10n/reboot_en.arb b/gui/lib/l10n/reboot_en.arb index cf0360f..b844465 100644 --- a/gui/lib/l10n/reboot_en.arb +++ b/gui/lib/l10n/reboot_en.arb @@ -216,7 +216,6 @@ "downloadedVersion": "The download was completed successfully!", "download": "Download", "downloading": "Downloading...", - "allocatingSpace": "Allocating disk space...", "startingDownload": "Starting download...", "extracting": "Extracting...", "buildProgress": "{progress}%", diff --git a/gui/lib/src/messenger/implementation/version.dart b/gui/lib/src/messenger/implementation/version.dart index 0deb5e2..043fb87 100644 --- a/gui/lib/src/messenger/implementation/version.dart +++ b/gui/lib/src/messenger/implementation/version.dart @@ -244,12 +244,12 @@ class _AddVersionDialogState extends State { ), ), - if(_progress.value != null && !_isAllocatingDiskSpace) + if(_progress.value != null) const SizedBox( height: 8.0, ), - if(_progress.value != null && !_isAllocatingDiskSpace) + if(_progress.value != null) Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -272,7 +272,7 @@ class _AddVersionDialogState extends State { SizedBox( width: double.infinity, - child: ProgressBar(value: _isAllocatingDiskSpace ? null : _progress.value?.toDouble()) + child: ProgressBar(value: _progress.value?.toDouble()) ), const SizedBox( @@ -291,15 +291,9 @@ class _AddVersionDialogState extends State { return translations.startingDownload; } - if (_speed.value == 0) { - return translations.allocatingSpace; - } - return translations.downloading; } - bool get _isAllocatingDiskSpace => _status.value == _DownloadStatus.downloading && _speed.value == 0; - Widget _buildFormBody(List builds) { return Column( mainAxisSize: MainAxisSize.min, diff --git a/gui/lib/src/page/implementation/home_page.dart b/gui/lib/src/page/implementation/home_page.dart index cc0a512..4c03c4e 100644 --- a/gui/lib/src/page/implementation/home_page.dart +++ b/gui/lib/src/page/implementation/home_page.dart @@ -10,6 +10,7 @@ import 'package:get/get.dart'; import 'package:reboot_common/common.dart'; import 'package:reboot_launcher/src/controller/backend_controller.dart'; import 'package:reboot_launcher/src/controller/dll_controller.dart'; +import 'package:reboot_launcher/src/controller/game_controller.dart'; import 'package:reboot_launcher/src/controller/hosting_controller.dart'; import 'package:reboot_launcher/src/controller/settings_controller.dart'; import 'package:reboot_launcher/src/messenger/abstract/dialog.dart'; @@ -43,6 +44,7 @@ class HomePage extends StatefulWidget { class _HomePageState extends State with WindowListener, AutomaticKeepAliveClientMixin { final BackendController _backendController = Get.find(); + final GameController _gameController = Get.find(); final HostingController _hostingController = Get.find(); final SettingsController _settingsController = Get.find(); final DllController _dllController = Get.find(); @@ -160,14 +162,45 @@ class _HomePageState extends State with WindowListener, AutomaticKeepA @override void onWindowClose() async { + try { + await windowManager.hide(); + }catch(error) { + log("[WINDOW] Cannot hide window: $error"); + } + try { await _hostingController.discardServer(); }catch(error) { - log("[HOSTING] Cannot discard server: $error"); - }finally { - // Force closing because the backend might be running, but we want the process to exit - exit(0); + log("[HOSTING] Cannot discard server on exit: $error"); } + + try { + if(_backendController.started.value) { + await _backendController.toggleInteractive(); + } + }catch(error) { + log("[BACKEND] Cannot stop backend on exit: $error"); + } + + try { + _gameController.instance.value?.kill(); + }catch(error) { + log("[GAME] Cannot stop game on exit: $error"); + } + + try { + _hostingController.instance.value?.kill(); + }catch(error) { + log("[HOST] Cannot stop host on exit: $error"); + } + + try { + await stopDownloadServer(); + }catch(error) { + log("[ARIA] Cannot stop aria server on exit: $error"); + } + + exit(0); } @override diff --git a/gui/pubspec.yaml b/gui/pubspec.yaml index fd5aca1..0766d59 100644 --- a/gui/pubspec.yaml +++ b/gui/pubspec.yaml @@ -1,6 +1,6 @@ name: reboot_launcher description: Graphical User Interface for Project Reboot -version: "10.0.1" +version: "10.0.2" publish_to: 'none'