## 主要变更 1. 修复8个空壳服务UI集成:标签/文件夹/同步/AI摘要/协作/跨设备/小组件/剪贴板监控服务 2. 替换DailyTaskPage/TaskCard硬编码颜色为AppTheme设计令牌 3. 将ReadlaterReminderService从SharedPreferences迁移至AppKVStore 4. 为ChatMessageService新增updateExt方法,实现标签自动同步 5. 替换同步I/O为异步文件操作 6. 更新CHANGELOG与新增自动化验收测试脚本
200 lines
5.8 KiB
Dart
200 lines
5.8 KiB
Dart
// ============================================================
|
|
// 闲言APP — 应用入口
|
|
// 创建时间: 2026-04-20
|
|
// 更新时间: 2026-05-15
|
|
// 作用: main 函数,初始化存储 + 液态玻璃 + 异常捕获 + 启动 App
|
|
// 上次更新: v5.8 新增HomeWidgetService/ClipboardMonitorService初始化
|
|
// ============================================================
|
|
|
|
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/services/network/deep_link_service.dart';
|
|
import 'core/services/notification/local_notification_service.dart';
|
|
import 'core/services/device/screen_wake_service.dart';
|
|
import 'core/services/readlater/sharing_receiver_service.dart';
|
|
import 'core/services/sound_service.dart';
|
|
import 'core/services/device/battery_optimization_service.dart';
|
|
import 'core/services/notification/readlater_reminder_service.dart';
|
|
import 'core/services/data/home_widget_service.dart';
|
|
import 'core/services/clipboard_monitor_service.dart';
|
|
import 'core/storage/app_kv_store.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';
|
|
import 'features/inspiration/services/chat_migration_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);
|
|
}
|
|
|
|
try {
|
|
await AppKVStore.init();
|
|
Log.i('AppKVStore (Hive) 初始化完成');
|
|
} catch (e) {
|
|
Log.e('AppKVStore 初始化失败', e);
|
|
}
|
|
|
|
await LiquidGlassWidgets.initialize();
|
|
Log.i('LiquidGlassWidgets 初始化完成');
|
|
|
|
await Platform3DService.instance.detectDeviceCapability();
|
|
Log.i('3D平台设备检测完成 (lowEnd=${Platform3DService.instance.isLowEnd})');
|
|
|
|
_validatePageRegistry();
|
|
|
|
try {
|
|
await DeepLinkService.init();
|
|
Log.i('深度链接服务初始化完成');
|
|
} catch (e) {
|
|
Log.e('深度链接服务初始化失败', e);
|
|
}
|
|
|
|
try {
|
|
SharingReceiverService().init();
|
|
SharingReceiverService().setNavigatorKey(rootNavigatorKey);
|
|
Log.i('分享接收服务初始化完成');
|
|
} catch (e) {
|
|
Log.e('分享接收服务初始化失败', e);
|
|
}
|
|
|
|
try {
|
|
await LocalNotificationService.init();
|
|
Log.i('本地通知服务初始化完成');
|
|
} catch (e) {
|
|
Log.e('本地通知服务初始化失败', e);
|
|
}
|
|
|
|
try {
|
|
await ScreenWakeService.init();
|
|
Log.i('屏幕常亮服务初始化完成');
|
|
} catch (e) {
|
|
Log.e('屏幕常亮服务初始化失败', e);
|
|
}
|
|
|
|
try {
|
|
await SoundService.init();
|
|
Log.i('音效服务初始化完成');
|
|
} catch (e) {
|
|
Log.e('音效服务初始化失败', e);
|
|
}
|
|
|
|
try {
|
|
await BatteryOptimizationService.init();
|
|
Log.i('电池优化服务初始化完成');
|
|
} catch (e) {
|
|
Log.e('电池优化服务初始化失败', e);
|
|
}
|
|
|
|
try {
|
|
await ReadlaterReminderService.startMonitoring();
|
|
Log.i('稍后读提醒服务初始化完成');
|
|
} catch (e) {
|
|
Log.e('稍后读提醒服务初始化失败', e);
|
|
}
|
|
|
|
try {
|
|
await ChatMigrationService.migrateIfNeeded();
|
|
Log.i('聊天数据迁移检查完成');
|
|
} catch (e) {
|
|
Log.e('聊天数据迁移检查失败', e);
|
|
}
|
|
|
|
try {
|
|
await HomeWidgetService.instance.init();
|
|
Log.i('桌面小组件服务初始化完成');
|
|
} catch (e) {
|
|
Log.e('桌面小组件服务初始化失败', e);
|
|
}
|
|
|
|
try {
|
|
await ClipboardMonitorService.instance.initFromStore();
|
|
Log.i('剪贴板监控服务初始化完成');
|
|
} catch (e) {
|
|
Log.e('剪贴板监控服务初始化失败', e);
|
|
}
|
|
|
|
Catcher2(
|
|
runAppFunction: () {
|
|
runApp(
|
|
LiquidGlassWidgets.wrap(
|
|
child: 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 未注册!');
|
|
}
|
|
}
|