2024-03-07 23:01:32 +08:00
|
|
|
import 'package:fluent_ui/fluent_ui.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
2024-03-09 20:22:44 +08:00
|
|
|
import 'package:go_router/go_router.dart';
|
2024-03-07 23:01:32 +08:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:starcitizen_doctor/api/analytics.dart';
|
|
|
|
import 'package:starcitizen_doctor/app.dart';
|
|
|
|
import 'package:starcitizen_doctor/common/conf/const_conf.dart';
|
|
|
|
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
|
|
|
import 'package:starcitizen_doctor/common/utils/log.dart';
|
2024-03-09 19:42:57 +08:00
|
|
|
import 'package:starcitizen_doctor/provider/aria2c.dart';
|
2024-03-07 23:01:32 +08:00
|
|
|
import 'package:starcitizen_doctor/widgets/widgets.dart';
|
2024-02-03 12:28:15 +08:00
|
|
|
|
2024-03-07 23:01:32 +08:00
|
|
|
class SplashUI extends HookConsumerWidget {
|
|
|
|
const SplashUI({super.key});
|
2024-02-03 12:28:15 +08:00
|
|
|
|
|
|
|
@override
|
2024-03-07 23:01:32 +08:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final stepState = useState(0);
|
|
|
|
final step = stepState.value;
|
|
|
|
|
|
|
|
useEffect(() {
|
|
|
|
final appModel = ref.read(appGlobalModelProvider.notifier);
|
2024-03-09 19:42:57 +08:00
|
|
|
_initApp(context, appModel, stepState, ref);
|
2024-03-07 23:01:32 +08:00
|
|
|
return null;
|
|
|
|
}, const []);
|
|
|
|
|
|
|
|
return makeDefaultPage(context,
|
2024-02-03 12:28:15 +08:00
|
|
|
content: Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Image.asset("assets/app_logo.png", width: 192, height: 192),
|
|
|
|
const SizedBox(height: 32),
|
|
|
|
const ProgressRing(),
|
|
|
|
const SizedBox(height: 32),
|
2024-03-07 23:01:32 +08:00
|
|
|
if (step == 0) const Text("正在检测可用性,这可能需要一点时间..."),
|
|
|
|
if (step == 1) const Text("正在检查更新..."),
|
|
|
|
if (step == 2) const Text("即将完成..."),
|
2024-02-03 12:28:15 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
titleRow: Align(
|
|
|
|
alignment: AlignmentDirectional.centerStart,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Image.asset(
|
|
|
|
"assets/app_logo_mini.png",
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
const Text(
|
2024-03-07 23:01:32 +08:00
|
|
|
"SC汉化盒子 V${ConstConf.appVersion} ${ConstConf.isMSE ? "" : " Dev"}")
|
2024-02-03 12:28:15 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2024-03-07 23:01:32 +08:00
|
|
|
void _initApp(BuildContext context, AppGlobalModel appModel,
|
2024-03-09 19:42:57 +08:00
|
|
|
ValueNotifier<int> stepState, WidgetRef ref) async {
|
2024-03-07 23:01:32 +08:00
|
|
|
await appModel.initApp();
|
|
|
|
AnalyticsApi.touch("launch");
|
|
|
|
try {
|
|
|
|
await URLConf.checkHost();
|
|
|
|
} catch (e) {
|
|
|
|
dPrint("checkHost Error:$e");
|
|
|
|
}
|
|
|
|
stepState.value = 1;
|
|
|
|
if (!context.mounted) return;
|
|
|
|
await appModel.checkUpdate(context);
|
|
|
|
stepState.value = 2;
|
2024-03-09 19:42:57 +08:00
|
|
|
ref.read(aria2cModelProvider);
|
2024-03-09 20:22:44 +08:00
|
|
|
if (!context.mounted) return;
|
|
|
|
context.go("/index");
|
2024-03-07 23:01:32 +08:00
|
|
|
}
|
2024-02-03 12:28:15 +08:00
|
|
|
}
|