107 lines
3.3 KiB
Dart
107 lines
3.3 KiB
Dart
// ============================================================
|
||
// 闲言APP — 应用入口
|
||
// 创建时间: 2026-04-20
|
||
// 更新时间: 2026-04-23
|
||
// 作用: main 函数,初始化存储 + 液态玻璃 + 异常捕获 + 启动 App
|
||
// 上次更新: 修复release打包后状态栏模糊+底栏颜色不一致问题,强制黑色系统UI
|
||
// ============================================================
|
||
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||
import 'package:catcher_2/catcher_2.dart';
|
||
import 'package:catcher_2/model/platform_type.dart';
|
||
import 'package:liquid_glass_widgets/liquid_glass_widgets.dart';
|
||
import 'package:flutter/services.dart';
|
||
|
||
import 'app/app.dart';
|
||
import 'core/storage/kv_storage.dart';
|
||
import 'core/utils/logger.dart';
|
||
import 'core/registry/page_registry.dart';
|
||
import 'core/router/app_router.dart';
|
||
import 'editor/services/3d/platform_3d_service.dart';
|
||
|
||
bool kvStorageReady = false;
|
||
|
||
void main() async {
|
||
WidgetsFlutterBinding.ensureInitialized();
|
||
|
||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||
SystemChrome.setSystemUIOverlayStyle(
|
||
const SystemUiOverlayStyle(
|
||
statusBarColor: Colors.black,
|
||
statusBarIconBrightness: Brightness.light,
|
||
statusBarBrightness: Brightness.dark,
|
||
systemNavigationBarColor: Colors.black,
|
||
systemNavigationBarIconBrightness: Brightness.light,
|
||
systemNavigationBarDividerColor: Colors.black,
|
||
),
|
||
);
|
||
|
||
try {
|
||
await KvStorage.init();
|
||
kvStorageReady = true;
|
||
Log.i('KV 存储初始化完成');
|
||
} catch (e) {
|
||
Log.e('KV 存储初始化失败', e);
|
||
}
|
||
|
||
await LiquidGlassWidgets.initialize();
|
||
Log.i('LiquidGlassWidgets 初始化完成');
|
||
|
||
await Platform3DService.instance.detectDeviceCapability();
|
||
Log.i('3D平台设备检测完成 (lowEnd=${Platform3DService.instance.isLowEnd})');
|
||
|
||
_validatePageRegistry();
|
||
|
||
Catcher2(
|
||
runAppFunction: () {
|
||
runApp(LiquidGlassWidgets.wrap(const ProviderScope(child: XianyanApp())));
|
||
},
|
||
debugConfig: Catcher2Options(
|
||
SilentReportMode(),
|
||
[_RateLimitedHandler()],
|
||
localizationOptions: [LocalizationOptions.buildDefaultChineseOptions()],
|
||
),
|
||
releaseConfig: Catcher2Options(SilentReportMode(), []),
|
||
profileConfig: Catcher2Options(SilentReportMode(), []),
|
||
);
|
||
}
|
||
|
||
class _RateLimitedHandler extends ReportHandler {
|
||
DateTime? _lastLog;
|
||
static const _cooldown = Duration(seconds: 5);
|
||
|
||
@override
|
||
Future<bool> handle(Report report, BuildContext? context) async {
|
||
final now = DateTime.now();
|
||
if (_lastLog == null || now.difference(_lastLog!) > _cooldown) {
|
||
_lastLog = now;
|
||
Log.e('Catcher2: ${report.error}');
|
||
}
|
||
return true;
|
||
}
|
||
|
||
@override
|
||
List<PlatformType> getSupportedPlatforms() => PlatformType.values.toList();
|
||
|
||
@override
|
||
bool isContextRequired() => false;
|
||
}
|
||
|
||
/// 页面注册表强制验证
|
||
void _validatePageRegistry() {
|
||
final errors = PageRegistry.validateAll();
|
||
if (errors.isNotEmpty) {
|
||
for (final e in errors) {
|
||
Log.e('页面注册表验证失败: $e');
|
||
}
|
||
} else {
|
||
Log.i('页面注册表验证通过,共 ${PageRegistry.pageCount} 个页面已注册');
|
||
}
|
||
|
||
const route = AppRoutes.home;
|
||
if (!PageRegistry.isRouteRegistered(route)) {
|
||
Log.e('页面注册表验证: 首页路由 $route 未注册!');
|
||
}
|
||
}
|