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,7 +1,5 @@
|
||||
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
import 'package:reboot_launcher/src/page/info_page.dart';
|
||||
import 'package:reboot_launcher/src/page/launcher_page.dart';
|
||||
import 'package:reboot_launcher/src/page/server_page.dart';
|
||||
@@ -10,8 +8,6 @@ import 'package:reboot_launcher/src/widget/window_border.dart';
|
||||
import 'package:reboot_launcher/src/widget/window_buttons.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import '../util/reboot.dart';
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({Key? key}) : super(key: key);
|
||||
|
||||
@@ -20,17 +16,12 @@ class HomePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _HomePageState extends State<HomePage> with WindowListener {
|
||||
late final Future _future;
|
||||
bool _focused = true;
|
||||
int _index = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
windowManager.addListener(this);
|
||||
var storage = GetStorage("update");
|
||||
int? lastUpdateMs = storage.read("last_update");
|
||||
_future = compute(downloadRebootDll, lastUpdateMs);
|
||||
_future.then((value) => storage.write("last_update", value));
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -47,7 +38,7 @@ class _HomePageState extends State<HomePage> with WindowListener {
|
||||
|
||||
@override
|
||||
void onWindowBlur() {
|
||||
setState(() => _focused = false);
|
||||
setState(() => _focused = !_focused);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -66,12 +57,13 @@ class _HomePageState extends State<HomePage> with WindowListener {
|
||||
_createPane("Info", FluentIcons.info),
|
||||
],
|
||||
trailing: WindowTitleBar(focused: _focused)),
|
||||
content: FutureBuilder(
|
||||
future: _future,
|
||||
builder: (context, snapshot) => NavigationBody(
|
||||
index: _index,
|
||||
children: _createPages(snapshot)
|
||||
)
|
||||
content: NavigationBody(
|
||||
index: _index,
|
||||
children: [
|
||||
const LauncherPage(),
|
||||
ServerPage(),
|
||||
const InfoPage()
|
||||
]
|
||||
)
|
||||
),
|
||||
|
||||
@@ -81,19 +73,6 @@ class _HomePageState extends State<HomePage> with WindowListener {
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _createPages(AsyncSnapshot snapshot) {
|
||||
|
||||
return [
|
||||
LauncherPage(
|
||||
ready: snapshot.hasData,
|
||||
error: snapshot.error,
|
||||
stackTrace: snapshot.stackTrace
|
||||
),
|
||||
ServerPage(),
|
||||
const InfoPage()
|
||||
];
|
||||
}
|
||||
|
||||
PaneItem _createPane(String label, IconData icon) {
|
||||
return PaneItem(icon: Icon(icon), title: Text(label));
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class InfoPage extends StatelessWidget {
|
||||
),
|
||||
const Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.bottomLeft, child: Text("Version 3.8${kDebugMode ? '-DEBUG' : ''}")))
|
||||
alignment: Alignment.bottomLeft, child: Text("Version 3.10${kDebugMode ? '-DEBUG' : ''}")))
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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