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.
41 lines
1.6 KiB
41 lines
1.6 KiB
import 'package:device_plugin_interface/device_plugin_interface.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import '../core/utils/logger.dart';
|
|
import 'bes/bes_device_auth.dart';
|
|
import 'bes/bes_device_plugin.dart';
|
|
import 'device_hub.dart';
|
|
import 'holder/holder_device_plugin.dart';
|
|
import 'eaicar/eaicar_device_plugin.dart';
|
|
|
|
/// 装配设备中枢:注册所有厂商插件并初始化。由 InitialBinding 调用一次。
|
|
///
|
|
/// 新接一种芯片 = 在这里多 `registerPlugin` 一行 + `lib/devices/<vendor>/` 一个目录,
|
|
/// 业务层零改动。
|
|
///
|
|
/// 两个插件的 `initialize` 都是轻量的:恒玄在 iOS 上必须无条件建 CBCentralManager
|
|
/// 才能被动接管系统层连接,Android 只在绑过设备时申请权限;支架只在记住过设备时
|
|
/// 注册后台扫连。所以这里不做「按绑定记录挑插件」,行为与改造前一致。
|
|
void installDeviceHub() {
|
|
if (Get.isRegistered<DeviceHub>()) return;
|
|
final hub = Get.put<DeviceHub>(DeviceHub(), permanent: true);
|
|
|
|
final bes = BesDevicePlugin();
|
|
bes.link.auth = BesDeviceAuth(bes.link);
|
|
_register(hub, bes);
|
|
|
|
_register(hub, HolderDevicePlugin());
|
|
|
|
// EaiCar 车载香薰。BLE 走 flutter_blue_plus(纯 Dart,无原生插件)。
|
|
// initialize 里不申请权限也不起扫描,冷启动零副作用。
|
|
_register(hub, EaiCarDevicePlugin());
|
|
}
|
|
|
|
void _register(DeviceHub hub, DevicePlugin p) {
|
|
try {
|
|
hub.registerPlugin(p);
|
|
p.initialize(const DevicePluginConfig());
|
|
} catch (e) {
|
|
Logger.e('DeviceBootstrap', '初始化厂商插件 ${p.vendorKey} 失败: $e');
|
|
}
|
|
}
|
|
|