Refactored GUI

This commit is contained in:
Alessandro Autiero
2025-08-10 20:13:18 +01:00
parent 4ea73d17c7
commit c9ed6a5af3
5 changed files with 92 additions and 20 deletions

View File

@@ -325,19 +325,34 @@ class _LaunchButtonState extends State<LaunchButton> {
handleGameOutput(
line: line,
host: host,
onShutdown: () => _onStop(reason: _StopReason.normal, host: host),
onTokenError: () => _onStop(reason: _StopReason.tokenError, host: host),
onShutdown: () {
log("[${host ? 'HOST' : 'GAME'}] Called shutdown");
_onStop(reason: _StopReason.normal, host: host);
},
onTokenError: () {
log("[${host ? 'HOST' : 'GAME'}] Called token error");
_onStop(reason: _StopReason.tokenError, host: host);
},
onBuildCorrupted: () {
if(instance == null) {
log("[${host ? 'HOST' : 'GAME'}] Called build corrupted: no instance");
return;
}else if(!instance.launched) {
log("[${host ? 'HOST' : 'GAME'}] Called build corrupted: not launched");
_onStop(reason: _StopReason.corruptedVersionError, host: host);
}else {
log("[${host ? 'HOST' : 'GAME'}] Called build corrupted: crash");
_onStop(reason: _StopReason.crash, host: host);
}
},
onLoggedIn: () =>_onLoggedIn(host),
onMatchEnd: () => _onMatchEnd(version)
onLoggedIn: () {
log("[${host ? 'HOST' : 'GAME'}] Called logged in");
_onLoggedIn(host);
},
onMatchEnd: () {
log("[${host ? 'HOST' : 'GAME'}] Called match end");
_onMatchEnd(version);
}
);
}
gameProcess.stdOutput.listen((line) => onGameOutput(line, false));

View File

@@ -4,14 +4,18 @@ import 'dart:io';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:path/path.dart' as path;
import 'package:path/path.dart';
import 'package:reboot_common/common.dart';
import 'package:reboot_launcher/main.dart';
import 'package:reboot_launcher/src/util/translations.dart';
import 'package:reboot_launcher/src/messenger/info_bar.dart';
import 'package:reboot_launcher/src/page/settings_page.dart';
import 'package:reboot_launcher/src/util/translations.dart';
import 'package:version/version.dart';
import 'package:path/path.dart' as path;
import 'package:reboot_launcher/src/controller/game_controller.dart';
import 'package:reboot_launcher/src/controller/hosting_controller.dart';
// TODO: Refactor me
class DllController extends GetxController {
static const String storageName = "v3_dll_storage";
@@ -26,6 +30,7 @@ class DllController extends GetxController {
late final RxBool customGameServer;
late final RxnInt timestamp;
late final Rx<UpdateStatus> status;
late final Map<GameDll, StreamSubscription?> _subscriptions;
DllController() {
_storage = appWithNoStorage ? null : GetStorage(storageName);
@@ -44,6 +49,7 @@ class DllController extends GetxController {
customGameServer.listen((value) => _storage?.write("custom_game_server", value));
timestamp = RxnInt(_storage?.read("ts"));
timestamp.listen((value) => _storage?.write("ts", value));
_subscriptions = {};
}
TextEditingController _createController(String key, GameDll dll) {
@@ -73,6 +79,7 @@ class DllController extends GetxController {
try {
if(customGameServer.value) {
status.value = UpdateStatus.success;
_listenToFileEvents(GameDll.gameServer);
return true;
}
@@ -82,6 +89,7 @@ class DllController extends GetxController {
);
if(!needsUpdate) {
status.value = UpdateStatus.success;
_listenToFileEvents(GameDll.gameServer);
return true;
}
@@ -121,6 +129,7 @@ class DllController extends GetxController {
duration: infoBarShortDuration
);
}
_listenToFileEvents(GameDll.gameServer);
return true;
}catch(message) {
infoBarEntry?.close();
@@ -215,6 +224,7 @@ class DllController extends GetxController {
if(!force && File(filePath).existsSync()) {
log("[DLL] $dll already exists");
_listenToFileEvents(dll);
return true;
}
@@ -252,6 +262,7 @@ class DllController extends GetxController {
}else {
log("[DLL] Not showing success dialog for $dll");
}
_listenToFileEvents(dll);
return true;
}catch(message) {
log("[DLL] An error occurred while downloading $dll: $message");
@@ -287,6 +298,63 @@ class DllController extends GetxController {
}
}
}
void _listenToFileEvents(GameDll injectable) {
final controller = getDllEditingController(injectable);
final defaultPath = getDefaultDllPath(injectable);
void onFileEvent(FileSystemEvent event, String filePath) {
if (!path.equals(event.path, filePath)) {
return;
}
if(path.equals(filePath, defaultPath)) {
Get.find<GameController>()
.instance
.value
?.kill();
Get.find<HostingController>()
.instance
.value
?.kill();
showRebootInfoBar(
translations.downloadDllAntivirus(antiVirusName ?? defaultAntiVirusName, injectable.name),
duration: infoBarLongDuration,
severity: InfoBarSeverity.error
);
}
_updateInput(injectable);
}
StreamSubscription subscribe(String filePath) => File(filePath)
.parent
.watch(events: FileSystemEvent.delete | FileSystemEvent.move)
.listen((event) => onFileEvent(event, filePath));
controller.addListener(() {
_subscriptions[injectable]?.cancel();
_subscriptions[injectable] = subscribe(controller.text);
});
_subscriptions[injectable] = subscribe(controller.text);
}
void _updateInput(GameDll injectable) {
switch(injectable) {
case GameDll.console:
settingsConsoleDllInputKey.currentState?.validate();
break;
case GameDll.auth:
settingsAuthDllInputKey.currentState?.validate();
break;
case GameDll.gameServer:
settingsGameServerDllInputKey.currentState?.validate();
break;
case GameDll.memoryLeak:
settingsMemoryDllInputKey.currentState?.validate();
break;
}
}
}
enum UpdateStatus {

View File

@@ -25,7 +25,6 @@ class HostingController extends GetxController {
late final RxBool headless;
late final RxBool autoRestart;
late final RxBool started;
late final RxBool published;
late final Rxn<GameInstance> instance;
late final TextEditingController customLaunchArgs;
@@ -51,7 +50,6 @@ class HostingController extends GetxController {
autoRestart = RxBool(_storage?.read("auto_restart") ?? true);
autoRestart.listen((value) => _storage?.write("auto_restart", value));
started = RxBool(false);
published = RxBool(false);
showPassword = RxBool(false);
instance = Rxn();
customLaunchArgs = TextEditingController(text: _storage?.read("custom_launch_args") ?? "");

View File

@@ -309,10 +309,6 @@ class _HostingPageState extends AbstractPageState<HostPage> {
);
Future<void> _updateServer() async {
if(!_hostingController.published()) {
return;
}
try {
final server = await _hostingController.createServerBrowserEntry();
_serverBrowserController.addServer(server);
@@ -321,7 +317,6 @@ class _HostingPageState extends AbstractPageState<HostPage> {
}
}
void _showCopiedLink() => showRebootInfoBar(
translations.hostShareLinkMessageSuccess,
severity: InfoBarSeverity.success