This commit is contained in:
Alessandro Autiero
2024-12-09 14:36:43 +01:00
parent 2046cb14f6
commit 0a59a32c1b
5 changed files with 56 additions and 25 deletions

View File

@@ -134,17 +134,13 @@ Future<void> downloadArchiveBuild(FortniteBuildDownloadOptions options) async {
} }
Future<void> _startAriaServer() async { Future<void> _startAriaServer() async {
final running = await _isAriaRunning(); await stopDownloadServer();
if(running) {
await killProcessByPort(_ariaPort);
}
final aria2c = File("${assetsDirectory.path}\\build\\aria2c.exe"); final aria2c = File("${assetsDirectory.path}\\build\\aria2c.exe");
if(!aria2c.existsSync()) { if(!aria2c.existsSync()) {
throw "Missing aria2c.exe"; throw "Missing aria2c.exe";
} }
await startProcess( final process = await startProcess(
executable: aria2c, executable: aria2c,
args: [ args: [
"--max-connection-per-server=${Platform.numberOfProcessors}", "--max-connection-per-server=${Platform.numberOfProcessors}",
@@ -153,10 +149,14 @@ Future<void> _startAriaServer() async {
"--rpc-listen-all=true", "--rpc-listen-all=true",
"--rpc-allow-origin-all", "--rpc-allow-origin-all",
"--rpc-secret=$_ariaSecret", "--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++) { for(var i = 0; i < _ariaMaxSpawnTime.inSeconds; i++) {
if(await _isAriaRunning()) { if(await _isAriaRunning()) {
return; return;
@@ -177,8 +177,8 @@ Future<bool> _isAriaRunning() async {
"token:${_ariaSecret}" "token:${_ariaSecret}"
] ]
}; };
await http.post(_ariaEndpoint, body: jsonEncode(statusRequest)); final response = await http.post(_ariaEndpoint, body: jsonEncode(statusRequest));
return true; return response.statusCode == 200;
}catch(_) { }catch(_) {
return false; return false;
} }
@@ -227,11 +227,16 @@ Future<void> _stopAriaDownload(String downloadId) async {
] ]
}; };
await http.post(_ariaEndpoint, body: jsonEncode(addDownloadRequest)); await http.post(_ariaEndpoint, body: jsonEncode(addDownloadRequest));
stopDownloadServer();
}catch(error) { }catch(error) {
throw "Stop failed (${error})"; throw "Stop failed (${error})";
} }
} }
Future<void> stopDownloadServer() async {
await killProcessByPort(_ariaPort);
}
Future<void> _extractArchive(Completer<dynamic> stopped, String extension, File tempFile, FortniteBuildDownloadOptions options) async { Future<void> _extractArchive(Completer<dynamic> stopped, String extension, File tempFile, FortniteBuildDownloadOptions options) async {
Process? process; Process? process;

View File

@@ -216,7 +216,6 @@
"downloadedVersion": "The download was completed successfully!", "downloadedVersion": "The download was completed successfully!",
"download": "Download", "download": "Download",
"downloading": "Downloading...", "downloading": "Downloading...",
"allocatingSpace": "Allocating disk space...",
"startingDownload": "Starting download...", "startingDownload": "Starting download...",
"extracting": "Extracting...", "extracting": "Extracting...",
"buildProgress": "{progress}%", "buildProgress": "{progress}%",

View File

@@ -244,12 +244,12 @@ class _AddVersionDialogState extends State<AddVersionDialog> {
), ),
), ),
if(_progress.value != null && !_isAllocatingDiskSpace) if(_progress.value != null)
const SizedBox( const SizedBox(
height: 8.0, height: 8.0,
), ),
if(_progress.value != null && !_isAllocatingDiskSpace) if(_progress.value != null)
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@@ -272,7 +272,7 @@ class _AddVersionDialogState extends State<AddVersionDialog> {
SizedBox( SizedBox(
width: double.infinity, width: double.infinity,
child: ProgressBar(value: _isAllocatingDiskSpace ? null : _progress.value?.toDouble()) child: ProgressBar(value: _progress.value?.toDouble())
), ),
const SizedBox( const SizedBox(
@@ -291,15 +291,9 @@ class _AddVersionDialogState extends State<AddVersionDialog> {
return translations.startingDownload; return translations.startingDownload;
} }
if (_speed.value == 0) {
return translations.allocatingSpace;
}
return translations.downloading; return translations.downloading;
} }
bool get _isAllocatingDiskSpace => _status.value == _DownloadStatus.downloading && _speed.value == 0;
Widget _buildFormBody(List<FortniteBuild> builds) { Widget _buildFormBody(List<FortniteBuild> builds) {
return Column( return Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,

View File

@@ -10,6 +10,7 @@ import 'package:get/get.dart';
import 'package:reboot_common/common.dart'; import 'package:reboot_common/common.dart';
import 'package:reboot_launcher/src/controller/backend_controller.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/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/hosting_controller.dart';
import 'package:reboot_launcher/src/controller/settings_controller.dart'; import 'package:reboot_launcher/src/controller/settings_controller.dart';
import 'package:reboot_launcher/src/messenger/abstract/dialog.dart'; import 'package:reboot_launcher/src/messenger/abstract/dialog.dart';
@@ -43,6 +44,7 @@ class HomePage extends StatefulWidget {
class _HomePageState extends State<HomePage> with WindowListener, AutomaticKeepAliveClientMixin { class _HomePageState extends State<HomePage> with WindowListener, AutomaticKeepAliveClientMixin {
final BackendController _backendController = Get.find<BackendController>(); final BackendController _backendController = Get.find<BackendController>();
final GameController _gameController = Get.find<GameController>();
final HostingController _hostingController = Get.find<HostingController>(); final HostingController _hostingController = Get.find<HostingController>();
final SettingsController _settingsController = Get.find<SettingsController>(); final SettingsController _settingsController = Get.find<SettingsController>();
final DllController _dllController = Get.find<DllController>(); final DllController _dllController = Get.find<DllController>();
@@ -160,14 +162,45 @@ class _HomePageState extends State<HomePage> with WindowListener, AutomaticKeepA
@override @override
void onWindowClose() async { void onWindowClose() async {
try {
await windowManager.hide();
}catch(error) {
log("[WINDOW] Cannot hide window: $error");
}
try { try {
await _hostingController.discardServer(); await _hostingController.discardServer();
}catch(error) { }catch(error) {
log("[HOSTING] Cannot discard server: $error"); log("[HOSTING] Cannot discard server on exit: $error");
}finally {
// Force closing because the backend might be running, but we want the process to exit
exit(0);
} }
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 @override

View File

@@ -1,6 +1,6 @@
name: reboot_launcher name: reboot_launcher
description: Graphical User Interface for Project Reboot description: Graphical User Interface for Project Reboot
version: "10.0.1" version: "10.0.2"
publish_to: 'none' publish_to: 'none'