You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
2.0 KiB
50 lines
2.0 KiB
import 'package:get/get.dart';
|
|
import '../../core/controllers/permission_controller.dart';
|
|
import '../../data/services/audio_service.dart';
|
|
import '../../data/services/notification_service.dart';
|
|
import '../../data/services/volcano_ai_service.dart';
|
|
import '../../data/services/volcano_voice_recognition_service.dart';
|
|
import '../../data/services/volcano_tts_service.dart';
|
|
import '../../core/utils/logger.dart';
|
|
|
|
/// 初始绑定,用于管理全局依赖
|
|
class InitialBinding extends Bindings {
|
|
@override
|
|
void dependencies() {
|
|
// 初始化所有服务
|
|
final notificationService = Get.put(NotificationService(), permanent: true);
|
|
final audioService = Get.put(AudioServiceManager(), permanent: true);
|
|
final volcanoAiService = Get.put(VolcanoAIService(), permanent: true);
|
|
final voiceRecognitionService = Get.put(VolcanoVoiceRecognitionService(), permanent: true);
|
|
final volcanoTtsService = Get.put(VolcanoTtsService(), permanent: true);
|
|
|
|
// 只注册全局控制器
|
|
Get.put(PermissionController(), permanent: true);
|
|
|
|
// 异步初始化各个服务,确保顺序执行
|
|
_initializeServices(notificationService, audioService);
|
|
}
|
|
|
|
// 单独提取初始化服务的方法,以便更好地处理错误
|
|
void _initializeServices(NotificationService notificationService, AudioServiceManager audioService) async {
|
|
try {
|
|
// 首先初始化通知服务
|
|
await notificationService.init().catchError((error) {
|
|
Logger.error('通知服务初始化失败', error);
|
|
return null;
|
|
});
|
|
|
|
// 等待一段时间,确保通知权限请求完成
|
|
await Future.delayed(Duration(seconds: 1));
|
|
|
|
// 然后初始化音频服务
|
|
await audioService.init().then((_) {
|
|
Logger.info('AudioServiceManager 初始化完成,可以接收蓝牙耳机按键事件');
|
|
});
|
|
} catch (e) {
|
|
Logger.error('服务初始化过程中发生错误', e);
|
|
}
|
|
|
|
// 其他服务初始化可以在这里添加
|
|
}
|
|
}
|