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.
35 lines
1.1 KiB
35 lines
1.1 KiB
import 'package:get/get.dart';
|
|
|
|
import '../models/device_category.dart';
|
|
import 'agent_module_service.dart';
|
|
|
|
/// 设备品类首次连接时,把该品类的默认功能铺到 AI 页。
|
|
///
|
|
/// AgentModuleService 是 MainTabBinding 里 put 的,蓝牙服务可能比它先跑,
|
|
/// 没注册就先建出来(permanent,和 MainTabBinding 里的守卫互不冲突)。
|
|
void applyAgentDefaultsFor(String categoryId) {
|
|
try {
|
|
final service = Get.isRegistered<AgentModuleService>()
|
|
? AgentModuleService.to
|
|
: Get.put<AgentModuleService>(AgentModuleService(), permanent: true);
|
|
service.applyDeviceDefaults(categoryId);
|
|
} catch (_) {
|
|
// 铺默认功能失败不能影响连接本身
|
|
}
|
|
}
|
|
|
|
/// 便捷别名,避免各处再去 import device_category
|
|
class AgentDefaults {
|
|
AgentDefaults._();
|
|
|
|
static void onHolderConnected() =>
|
|
applyAgentDefaultsFor(DeviceCategories.phoneHolder);
|
|
|
|
static void onEarphoneConnected() =>
|
|
applyAgentDefaultsFor(DeviceCategories.earphone);
|
|
|
|
static void onJieliConnected(String? categoryId) {
|
|
if (categoryId == null || categoryId.isEmpty) return;
|
|
applyAgentDefaultsFor(categoryId);
|
|
}
|
|
}
|
|
|