mirror of
https://github.com/Auties00/Reboot-Launcher.git
synced 2026-01-13 03:02:22 +01:00
Refactored GUI
This commit is contained in:
@@ -325,19 +325,34 @@ class _LaunchButtonState extends State<LaunchButton> {
|
|||||||
handleGameOutput(
|
handleGameOutput(
|
||||||
line: line,
|
line: line,
|
||||||
host: host,
|
host: host,
|
||||||
onShutdown: () => _onStop(reason: _StopReason.normal, host: host),
|
onShutdown: () {
|
||||||
onTokenError: () => _onStop(reason: _StopReason.tokenError, host: host),
|
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: () {
|
onBuildCorrupted: () {
|
||||||
if(instance == null) {
|
if(instance == null) {
|
||||||
|
log("[${host ? 'HOST' : 'GAME'}] Called build corrupted: no instance");
|
||||||
return;
|
return;
|
||||||
}else if(!instance.launched) {
|
}else if(!instance.launched) {
|
||||||
|
log("[${host ? 'HOST' : 'GAME'}] Called build corrupted: not launched");
|
||||||
_onStop(reason: _StopReason.corruptedVersionError, host: host);
|
_onStop(reason: _StopReason.corruptedVersionError, host: host);
|
||||||
}else {
|
}else {
|
||||||
|
log("[${host ? 'HOST' : 'GAME'}] Called build corrupted: crash");
|
||||||
_onStop(reason: _StopReason.crash, host: host);
|
_onStop(reason: _StopReason.crash, host: host);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoggedIn: () =>_onLoggedIn(host),
|
onLoggedIn: () {
|
||||||
onMatchEnd: () => _onMatchEnd(version)
|
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));
|
gameProcess.stdOutput.listen((line) => onGameOutput(line, false));
|
||||||
|
|||||||
@@ -4,14 +4,18 @@ import 'dart:io';
|
|||||||
import 'package:fluent_ui/fluent_ui.dart';
|
import 'package:fluent_ui/fluent_ui.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:get_storage/get_storage.dart';
|
import 'package:get_storage/get_storage.dart';
|
||||||
import 'package:path/path.dart' as path;
|
|
||||||
import 'package:path/path.dart';
|
import 'package:path/path.dart';
|
||||||
import 'package:reboot_common/common.dart';
|
import 'package:reboot_common/common.dart';
|
||||||
import 'package:reboot_launcher/main.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/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: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 {
|
class DllController extends GetxController {
|
||||||
static const String storageName = "v3_dll_storage";
|
static const String storageName = "v3_dll_storage";
|
||||||
|
|
||||||
@@ -26,6 +30,7 @@ class DllController extends GetxController {
|
|||||||
late final RxBool customGameServer;
|
late final RxBool customGameServer;
|
||||||
late final RxnInt timestamp;
|
late final RxnInt timestamp;
|
||||||
late final Rx<UpdateStatus> status;
|
late final Rx<UpdateStatus> status;
|
||||||
|
late final Map<GameDll, StreamSubscription?> _subscriptions;
|
||||||
|
|
||||||
DllController() {
|
DllController() {
|
||||||
_storage = appWithNoStorage ? null : GetStorage(storageName);
|
_storage = appWithNoStorage ? null : GetStorage(storageName);
|
||||||
@@ -44,6 +49,7 @@ class DllController extends GetxController {
|
|||||||
customGameServer.listen((value) => _storage?.write("custom_game_server", value));
|
customGameServer.listen((value) => _storage?.write("custom_game_server", value));
|
||||||
timestamp = RxnInt(_storage?.read("ts"));
|
timestamp = RxnInt(_storage?.read("ts"));
|
||||||
timestamp.listen((value) => _storage?.write("ts", value));
|
timestamp.listen((value) => _storage?.write("ts", value));
|
||||||
|
_subscriptions = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditingController _createController(String key, GameDll dll) {
|
TextEditingController _createController(String key, GameDll dll) {
|
||||||
@@ -73,6 +79,7 @@ class DllController extends GetxController {
|
|||||||
try {
|
try {
|
||||||
if(customGameServer.value) {
|
if(customGameServer.value) {
|
||||||
status.value = UpdateStatus.success;
|
status.value = UpdateStatus.success;
|
||||||
|
_listenToFileEvents(GameDll.gameServer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +89,7 @@ class DllController extends GetxController {
|
|||||||
);
|
);
|
||||||
if(!needsUpdate) {
|
if(!needsUpdate) {
|
||||||
status.value = UpdateStatus.success;
|
status.value = UpdateStatus.success;
|
||||||
|
_listenToFileEvents(GameDll.gameServer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,6 +129,7 @@ class DllController extends GetxController {
|
|||||||
duration: infoBarShortDuration
|
duration: infoBarShortDuration
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
_listenToFileEvents(GameDll.gameServer);
|
||||||
return true;
|
return true;
|
||||||
}catch(message) {
|
}catch(message) {
|
||||||
infoBarEntry?.close();
|
infoBarEntry?.close();
|
||||||
@@ -215,6 +224,7 @@ class DllController extends GetxController {
|
|||||||
|
|
||||||
if(!force && File(filePath).existsSync()) {
|
if(!force && File(filePath).existsSync()) {
|
||||||
log("[DLL] $dll already exists");
|
log("[DLL] $dll already exists");
|
||||||
|
_listenToFileEvents(dll);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,6 +262,7 @@ class DllController extends GetxController {
|
|||||||
}else {
|
}else {
|
||||||
log("[DLL] Not showing success dialog for $dll");
|
log("[DLL] Not showing success dialog for $dll");
|
||||||
}
|
}
|
||||||
|
_listenToFileEvents(dll);
|
||||||
return true;
|
return true;
|
||||||
}catch(message) {
|
}catch(message) {
|
||||||
log("[DLL] An error occurred while downloading $dll: $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 {
|
enum UpdateStatus {
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ class HostingController extends GetxController {
|
|||||||
late final RxBool headless;
|
late final RxBool headless;
|
||||||
late final RxBool autoRestart;
|
late final RxBool autoRestart;
|
||||||
late final RxBool started;
|
late final RxBool started;
|
||||||
late final RxBool published;
|
|
||||||
late final Rxn<GameInstance> instance;
|
late final Rxn<GameInstance> instance;
|
||||||
late final TextEditingController customLaunchArgs;
|
late final TextEditingController customLaunchArgs;
|
||||||
|
|
||||||
@@ -51,7 +50,6 @@ class HostingController extends GetxController {
|
|||||||
autoRestart = RxBool(_storage?.read("auto_restart") ?? true);
|
autoRestart = RxBool(_storage?.read("auto_restart") ?? true);
|
||||||
autoRestart.listen((value) => _storage?.write("auto_restart", value));
|
autoRestart.listen((value) => _storage?.write("auto_restart", value));
|
||||||
started = RxBool(false);
|
started = RxBool(false);
|
||||||
published = RxBool(false);
|
|
||||||
showPassword = RxBool(false);
|
showPassword = RxBool(false);
|
||||||
instance = Rxn();
|
instance = Rxn();
|
||||||
customLaunchArgs = TextEditingController(text: _storage?.read("custom_launch_args") ?? "");
|
customLaunchArgs = TextEditingController(text: _storage?.read("custom_launch_args") ?? "");
|
||||||
|
|||||||
@@ -309,10 +309,6 @@ class _HostingPageState extends AbstractPageState<HostPage> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
Future<void> _updateServer() async {
|
Future<void> _updateServer() async {
|
||||||
if(!_hostingController.published()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final server = await _hostingController.createServerBrowserEntry();
|
final server = await _hostingController.createServerBrowserEntry();
|
||||||
_serverBrowserController.addServer(server);
|
_serverBrowserController.addServer(server);
|
||||||
@@ -321,7 +317,6 @@ class _HostingPageState extends AbstractPageState<HostPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void _showCopiedLink() => showRebootInfoBar(
|
void _showCopiedLink() => showRebootInfoBar(
|
||||||
translations.hostShareLinkMessageSuccess,
|
translations.hostShareLinkMessageSuccess,
|
||||||
severity: InfoBarSeverity.success
|
severity: InfoBarSeverity.success
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ class ServerBrowserEntry {
|
|||||||
final DateTime timestamp;
|
final DateTime timestamp;
|
||||||
final String ip;
|
final String ip;
|
||||||
final String author;
|
final String author;
|
||||||
final bool discoverable;
|
|
||||||
|
|
||||||
ServerBrowserEntry({
|
ServerBrowserEntry({
|
||||||
required this.id,
|
required this.id,
|
||||||
@@ -17,8 +16,7 @@ class ServerBrowserEntry {
|
|||||||
required this.password,
|
required this.password,
|
||||||
required this.timestamp,
|
required this.timestamp,
|
||||||
required this.ip,
|
required this.ip,
|
||||||
required this.author,
|
required this.author
|
||||||
required this.discoverable,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
@@ -30,8 +28,7 @@ class ServerBrowserEntry {
|
|||||||
'password': password,
|
'password': password,
|
||||||
'timestamp': timestamp.toIso8601String(),
|
'timestamp': timestamp.toIso8601String(),
|
||||||
'ip': ip,
|
'ip': ip,
|
||||||
'author': author,
|
'author': author
|
||||||
'discoverable': discoverable,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,8 +41,7 @@ class ServerBrowserEntry {
|
|||||||
password: json['password'],
|
password: json['password'],
|
||||||
timestamp: DateTime.parse(json['timestamp']),
|
timestamp: DateTime.parse(json['timestamp']),
|
||||||
ip: json['ip'],
|
ip: json['ip'],
|
||||||
author: json['author'],
|
author: json['author']
|
||||||
discoverable: json['discoverable'],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user