diff --git a/lib/main.dart b/lib/main.dart index 9fafc96..906e376 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,6 +2,7 @@ import 'package:bitsdojo_window/bitsdojo_window.dart'; import 'package:fluent_ui/fluent_ui.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/controller/server_controller.dart'; import 'package:reboot_launcher/src/controller/warning_controller.dart'; @@ -12,8 +13,10 @@ void main() async { WidgetsFlutterBinding.ensureInitialized(); await GetStorage.init("game"); await GetStorage.init("server"); + await GetStorage.init("update"); Get.put(GameController()); Get.put(ServerController()); + Get.put(BuildController()); Get.put(WarningController()); SystemTheme.accentColor.load(); doWhenWindowReady(() { diff --git a/lib/src/page/home_page.dart b/lib/src/page/home_page.dart index 2ee2906..bf4952f 100644 --- a/lib/src/page/home_page.dart +++ b/lib/src/page/home_page.dart @@ -4,6 +4,8 @@ import 'package:reboot_launcher/src/page/launcher_page.dart'; import 'package:reboot_launcher/src/page/server_page.dart'; import 'package:reboot_launcher/src/widget/window_buttons.dart'; +import '../util/reboot.dart'; + class HomePage extends StatefulWidget { const HomePage({Key? key}) : super(key: key); @@ -13,8 +15,15 @@ class HomePage extends StatefulWidget { class _HomePageState extends State { final List _children = [LauncherPage(), ServerPage(), const InfoPage()]; + late final Future _future; int _index = 0; + @override + void initState() { + _future = downloadRebootDll(); + super.initState(); + } + @override Widget build(BuildContext context) { return NavigationView( @@ -29,9 +38,25 @@ class _HomePageState extends State { _createPane("Info", FluentIcons.info), ], trailing: const WindowTitleBar()), - content: NavigationBody( - index: _index, - children: _children + content: FutureBuilder( + future: _future, + builder: (context, snapshot) { + if (snapshot.hasError) { + return Center( + child: Text( + "An error occurred while loading the launcher: ${snapshot.error}", + textAlign: TextAlign.center)); + } + + if (!snapshot.hasData) { + return const Center(child: ProgressRing()); + } + + return NavigationBody( + index: _index, + children: _children + ); + } ) ); } diff --git a/lib/src/util/reboot.dart b/lib/src/util/reboot.dart index daa0e2f..78fe96c 100644 --- a/lib/src/util/reboot.dart +++ b/lib/src/util/reboot.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:archive/archive_io.dart'; +import 'package:get_storage/get_storage.dart'; import 'package:reboot_launcher/src/util/binary.dart'; import 'package:http/http.dart' as http; import 'package:crypto/crypto.dart'; @@ -8,16 +9,17 @@ import 'package:shared_preferences/shared_preferences.dart'; const _rebootUrl = "https://nightly.link/UWUFN/Universal-Walking-Simulator/workflows/msbuild/master/Release.zip"; +final GetStorage _storage = GetStorage("update"); -Future _getLastUpdate(SharedPreferences preferences) async { - var timeInMillis = preferences.getInt("last_update"); +Future _getLastUpdate() async { + int? timeInMillis = _storage.read("last_update"); return timeInMillis != null ? DateTime.fromMillisecondsSinceEpoch(timeInMillis) : null; } -Future downloadRebootDll(SharedPreferences preferences) async { +Future downloadRebootDll() async { var now = DateTime.now(); var oldRebootDll = await loadBinary("reboot.dll", true); - var lastUpdate = await _getLastUpdate(preferences); + var lastUpdate = await _getLastUpdate(); var exists = await oldRebootDll.exists(); if(lastUpdate != null && now.difference(lastUpdate).inHours <= 24 && exists){ return oldRebootDll; @@ -34,7 +36,7 @@ Future downloadRebootDll(SharedPreferences preferences) async { throw Exception("Missing reboot dll"); } - preferences.setInt("last_update", now.millisecondsSinceEpoch); + _storage.write("last_update", now.millisecondsSinceEpoch); if (exists && sha1.convert(await oldRebootDll.readAsBytes()) == sha1.convert(await rebootDll.readAsBytes())) { rebootDll.delete(); return oldRebootDll;