2024-07-26 17:39:20 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-07-30 18:00:03 +00:00
|
|
|
import 'package:flutter_animate/flutter_animate.dart';
|
2024-07-26 17:39:20 +00:00
|
|
|
import 'package:get/get.dart';
|
2024-07-31 17:21:27 +00:00
|
|
|
import 'package:provider/provider.dart';
|
2024-07-26 17:39:20 +00:00
|
|
|
import 'package:solian/exts.dart';
|
|
|
|
import 'package:solian/providers/auth.dart';
|
|
|
|
import 'package:solian/providers/content/channel.dart';
|
2024-08-01 07:21:43 +00:00
|
|
|
import 'package:solian/providers/content/realm.dart';
|
2024-07-26 17:39:20 +00:00
|
|
|
import 'package:solian/providers/relation.dart';
|
2024-07-31 17:21:27 +00:00
|
|
|
import 'package:solian/providers/theme_switcher.dart';
|
2024-07-26 17:39:20 +00:00
|
|
|
import 'package:solian/providers/websocket.dart';
|
|
|
|
import 'package:solian/services.dart';
|
2024-07-26 18:11:59 +00:00
|
|
|
import 'package:solian/widgets/sized_container.dart';
|
2024-07-26 17:39:20 +00:00
|
|
|
|
|
|
|
class BootstrapperShell extends StatefulWidget {
|
|
|
|
final Widget child;
|
|
|
|
|
|
|
|
const BootstrapperShell({super.key, required this.child});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<BootstrapperShell> createState() => _BootstrapperShellState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _BootstrapperShellState extends State<BootstrapperShell> {
|
|
|
|
bool _isBusy = true;
|
|
|
|
bool _isErrored = false;
|
|
|
|
String? _subtitle;
|
|
|
|
|
|
|
|
Color get _unFocusColor =>
|
|
|
|
Theme.of(context).colorScheme.onSurface.withOpacity(0.75);
|
|
|
|
|
|
|
|
int _periodCursor = 0;
|
|
|
|
|
|
|
|
late final List<({String label, Future<void> Function() action})> _periods = [
|
2024-07-31 17:21:27 +00:00
|
|
|
(
|
|
|
|
label: 'bsLoadingTheme',
|
|
|
|
action: () async {
|
|
|
|
await context.read<ThemeSwitcher>().restoreTheme();
|
|
|
|
},
|
|
|
|
),
|
2024-07-26 17:39:20 +00:00
|
|
|
(
|
|
|
|
label: 'bsCheckingServer',
|
|
|
|
action: () async {
|
|
|
|
final client = ServiceFinder.configureClient('dealer');
|
|
|
|
final resp = await client.get('/.well-known');
|
2024-07-27 06:16:49 +00:00
|
|
|
if (resp.statusCode != null && resp.statusCode != 200) {
|
|
|
|
setState(() {
|
|
|
|
_isErrored = true;
|
|
|
|
_subtitle = 'bsCheckingServerDown'.tr;
|
|
|
|
});
|
|
|
|
throw Exception('unable connect to server');
|
|
|
|
} else if (resp.statusCode == null) {
|
2024-07-26 17:39:20 +00:00
|
|
|
setState(() {
|
|
|
|
_isErrored = true;
|
|
|
|
_subtitle = 'bsCheckingServerFail'.tr;
|
|
|
|
});
|
2024-07-27 06:16:49 +00:00
|
|
|
throw Exception('unable connect to server');
|
2024-07-26 17:39:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
label: 'bsAuthorizing',
|
|
|
|
action: () async {
|
|
|
|
final AuthProvider auth = Get.find();
|
|
|
|
await auth.refreshAuthorizeStatus();
|
|
|
|
if (auth.isAuthorized.isTrue) {
|
|
|
|
await auth.refreshUserProfile();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
label: 'bsEstablishingConn',
|
|
|
|
action: () async {
|
|
|
|
final AuthProvider auth = Get.find();
|
|
|
|
if (auth.isAuthorized.isTrue) {
|
|
|
|
await Get.find<WebSocketProvider>().connect();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
label: 'bsPreparingData',
|
|
|
|
action: () async {
|
|
|
|
final AuthProvider auth = Get.find();
|
|
|
|
if (auth.isAuthorized.isTrue) {
|
|
|
|
await Future.wait([
|
2024-08-01 07:21:43 +00:00
|
|
|
Get.find<RealmProvider>().refreshAvailableRealms(),
|
2024-07-26 17:39:20 +00:00
|
|
|
Get.find<ChannelProvider>().refreshAvailableChannel(),
|
2024-08-02 15:15:28 +00:00
|
|
|
Get.find<RelationshipProvider>().refreshRelativeList(),
|
2024-07-26 17:39:20 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
label: 'bsRegisteringPushNotify',
|
|
|
|
action: () async {
|
|
|
|
final AuthProvider auth = Get.find();
|
|
|
|
if (auth.isAuthorized.isTrue) {
|
|
|
|
try {
|
|
|
|
Get.find<WebSocketProvider>().registerPushNotifications();
|
|
|
|
} catch (err) {
|
|
|
|
context.showSnackbar(
|
|
|
|
'pushNotifyRegisterFailed'.trParams({'reason': err.toString()}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
Future<void> _runPeriods() async {
|
2024-07-27 06:16:49 +00:00
|
|
|
try {
|
|
|
|
for (var idx = 0; idx < _periods.length; idx++) {
|
|
|
|
await _periods[idx].action();
|
|
|
|
if (_isErrored) break;
|
2024-07-30 18:00:03 +00:00
|
|
|
if (_periodCursor < _periods.length - 1) {
|
|
|
|
setState(() => _periodCursor++);
|
|
|
|
}
|
2024-07-27 06:16:49 +00:00
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
setState(() => _isBusy = false);
|
2024-07-26 17:39:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_runPeriods();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (_isBusy || _isErrored) {
|
|
|
|
return Material(
|
|
|
|
color: Theme.of(context).colorScheme.surface,
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 280,
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.bottomCenter,
|
2024-07-30 18:00:03 +00:00
|
|
|
child: Image.asset('assets/logo.png', width: 80, height: 80)
|
|
|
|
.animate(onPlay: (c) => c.repeat())
|
|
|
|
.rotate(duration: 850.ms, curve: Curves.easeInOut),
|
2024-07-26 17:39:20 +00:00
|
|
|
),
|
|
|
|
),
|
2024-07-27 06:16:49 +00:00
|
|
|
GestureDetector(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
if (_isErrored)
|
|
|
|
const Icon(Icons.cancel, size: 24)
|
|
|
|
else
|
|
|
|
const SizedBox(
|
|
|
|
width: 24,
|
|
|
|
height: 24,
|
|
|
|
child: CircularProgressIndicator(strokeWidth: 3),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
CenteredContainer(
|
|
|
|
maxWidth: 280,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
_subtitle ??
|
|
|
|
'${_periods[_periodCursor].label.tr} (${_periodCursor + 1}/${_periods.length})',
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 13,
|
|
|
|
color: _unFocusColor,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'2024 © Solsynth LLC',
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 11,
|
|
|
|
color: _unFocusColor,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2024-07-26 18:11:59 +00:00
|
|
|
),
|
2024-07-26 17:39:20 +00:00
|
|
|
),
|
2024-07-27 06:16:49 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
if (_isBusy) return;
|
|
|
|
setState(() {
|
|
|
|
_isBusy = true;
|
|
|
|
_isErrored = false;
|
|
|
|
_periodCursor = 0;
|
|
|
|
});
|
|
|
|
_runPeriods();
|
|
|
|
},
|
2024-07-26 17:39:20 +00:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return widget.child;
|
|
|
|
}
|
|
|
|
}
|