mirror of
https://github.com/Auties00/Reboot-Launcher.git
synced 2026-01-14 03:32:23 +01:00
Added headless switch
Fixed UI
This commit is contained in:
@@ -1,24 +1,25 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
import 'package:reboot_launcher/src/controller/build_controller.dart';
|
||||
import 'package:reboot_launcher/src/controller/game_controller.dart';
|
||||
import 'package:reboot_launcher/src/util/os.dart';
|
||||
import 'package:reboot_launcher/src/widget/deployment_selector.dart';
|
||||
import 'package:reboot_launcher/src/widget/host_checkbox.dart';
|
||||
import 'package:reboot_launcher/src/widget/launch_button.dart';
|
||||
import 'package:reboot_launcher/src/widget/username_box.dart';
|
||||
import 'package:reboot_launcher/src/widget/version_selector.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../util/binary.dart';
|
||||
import '../util/reboot.dart';
|
||||
import '../widget/warning_info.dart';
|
||||
|
||||
class LauncherPage extends StatefulWidget {
|
||||
final bool ready;
|
||||
final Object? error;
|
||||
final StackTrace? stackTrace;
|
||||
|
||||
const LauncherPage(
|
||||
{Key? key, required this.ready, required this.error, this.stackTrace})
|
||||
{Key? key})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
@@ -26,68 +27,94 @@ class LauncherPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _LauncherPageState extends State<LauncherPage> {
|
||||
final GameController _gameController = Get.find<GameController>();
|
||||
final BuildController _buildController = Get.find<BuildController>();
|
||||
bool shouldWriteError = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_buildController.cancelledDownload
|
||||
.listen((value) => value ? _onCancelWarning() : {});
|
||||
if(_gameController.updater == null) {
|
||||
_gameController.updater = compute(downloadRebootDll, _updateTime)
|
||||
..then((value) => _updateTime = value)
|
||||
..onError(_saveError);
|
||||
_buildController.cancelledDownload
|
||||
.listen((value) => value ? _onCancelWarning() : {});
|
||||
}
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
int? get _updateTime {
|
||||
var storage = GetStorage("update");
|
||||
return storage.read("last_update");
|
||||
}
|
||||
|
||||
set _updateTime(int? updateTime) {
|
||||
var storage = GetStorage("update");
|
||||
storage.write("last_update", updateTime);
|
||||
}
|
||||
|
||||
Future<void> _saveError(Object? error, StackTrace stackTrace) async {
|
||||
var errorFile = await loadBinary("error.txt", true);
|
||||
errorFile.writeAsString(
|
||||
"Error: $error\nStacktrace: $stackTrace", mode: FileMode.write);
|
||||
}
|
||||
|
||||
void _onCancelWarning() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if(!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
showSnackbar(context,
|
||||
const Snackbar(content: Text("Download cancelled")));
|
||||
_buildController.cancelledDownload.value = false;
|
||||
_buildController.cancelledDownload(false);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!widget.ready && widget.error == null) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const [
|
||||
ProgressRing(),
|
||||
SizedBox(height: 16.0),
|
||||
Text("Updating Reboot DLL...")
|
||||
return FutureBuilder(
|
||||
future: _gameController.updater,
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData && !snapshot.hasError) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const [
|
||||
ProgressRing(),
|
||||
SizedBox(height: 16.0),
|
||||
Text("Updating Reboot DLL...")
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if(snapshot.hasError)
|
||||
_createUpdateError(snapshot),
|
||||
UsernameBox(),
|
||||
const VersionSelector(),
|
||||
const DeploymentSelector(),
|
||||
const LaunchButton()
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if(widget.error != null)
|
||||
WarningInfo(
|
||||
text: "Cannot update Reboot DLL",
|
||||
icon: FluentIcons.info,
|
||||
severity: InfoBarSeverity.warning,
|
||||
onPressed: () async {
|
||||
if (shouldWriteError) {
|
||||
await errorFile.writeAsString(
|
||||
"Error: ${widget.error}\nStacktrace: ${widget.stackTrace}",
|
||||
mode: FileMode.write
|
||||
);
|
||||
shouldWriteError = false;
|
||||
}
|
||||
|
||||
launchUrl(errorFile.uri);
|
||||
},
|
||||
),
|
||||
UsernameBox(),
|
||||
VersionSelector(),
|
||||
DeploymentSelector(enabled: true),
|
||||
const LaunchButton()
|
||||
],
|
||||
Widget _createUpdateError(AsyncSnapshot<Object?> snapshot) {
|
||||
return WarningInfo(
|
||||
text: "Cannot update Reboot DLL",
|
||||
icon: FluentIcons.info,
|
||||
severity: InfoBarSeverity.warning,
|
||||
onPressed: () => loadBinary("error.txt", true)
|
||||
.then((file) => launchUrl(file.uri))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user