Browse Source

fix(ota): 修复设备名称获取和产品信息查询逻辑

- 添加蓝牙管理器引用以获取设备名称
- 实现动态获取设备名称的方法
- 修改产品信息查询逻辑以使用实际设备名称
- 添加默认设备图片显示逻辑
- 修复存储中设备图片键名错误
- 移除会议控制器中音频类型限制注释
newdev_shunjiawei
lxm 1 year ago
parent
commit
e34fb52d66
  1. 2
      lib/modules/meeting/controllers/meeting_home_controller.dart
  2. 52
      lib/modules/ota_upgrade/controllers/ota_core_contropller.dart
  3. 2
      lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart
  4. 10
      lib/modules/ota_upgrade/views/ota_upgrade_view.dart

2
lib/modules/meeting/controllers/meeting_home_controller.dart

@ -341,7 +341,7 @@ class MeetingHomeController extends GetxController {
} else {
FilePickerResult? result = await FilePicker.platform.pickFiles(
withData: false,
type: FileType.audio,
//type: FileType.audio,
allowMultiple: false,
);
if (result != null) {

52
lib/modules/ota_upgrade/controllers/ota_core_contropller.dart

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:logger/web.dart';
import '../../../data/services/ble_manager.dart';
import '../../../data/services/bluetooth_manager.dart'; // 添加蓝牙管理器导入
import '../../../data/models/appconfig.dart';
import '../../../data/models/appconfig_model.dart';
@ -9,6 +10,8 @@ import '../../../data/models/appconfig_model.dart';
/// 整合设备检查、版本管理和状态管理功能
class OtaCoreService {
final BleManager _bleManager = Get.find<BleManager>();
final BluetoothManager _bluetoothManager =
Get.find<BluetoothManager>(); // 添加蓝牙管理器引用
final int maxRetryAttempts = 3;
int currentRetryCount = 0;
@ -261,6 +264,35 @@ class OtaCoreService {
// ==================== 版本管理功能 ====================
/// 动态获取当前连接的设备名称
/// 参考home_controller中的getDeviceName方法实现
String getDeviceName() {
try {
// 优先从经典蓝牙获取设备名称
final currentDevice = _bluetoothManager.currentDevice;
if (currentDevice?.name != null && currentDevice!.name.isNotEmpty) {
return currentDevice.name;
}
// 其次从BLE设备信息获取
final deviceInfo = _bleManager.deviceInfo.value;
if (deviceInfo?.name != null && deviceInfo!.name.isNotEmpty) {
return deviceInfo.name;
}
// 最后从BLE管理器的最后连接设备名称获取
// if (_bleManager.currentDeviceName.isNotEmpty) {
// return _bleManager.currentDeviceName;
// }
// 如果都获取不到,返回默认值
return "unknownEquipment";
} catch (e) {
Logger().e("获取设备名称失败: $e");
return "unknownEquipment";
}
}
/// 获取当前设备版本信息
/// 返回包含当前版本、产品ID和设备信息的Map
/// 抛出异常如果获取失败
@ -288,10 +320,16 @@ class OtaCoreService {
throw "获取设备信息失败,请检查连接";
}
String deviceName = getDeviceName();
// 获取产品信息以确定设备类型
DBProduct? product = AppConfig.getproduct("DeapSound");
DBProduct? product = AppConfig.getproduct(deviceName);
if (product == null) {
throw "无法获取产品信息";
// 如果根据设备名称找不到产品,尝试使用默认产品名称
product = AppConfig.getproduct("DeapSound");
if (product == null) {
throw "无法获取产品信息,设备名称: $deviceName";
}
}
// 根据设备类型进行不同的版本校验
@ -342,10 +380,16 @@ class OtaCoreService {
/// 返回包含最新版本、更新描述和更新包地址的Map
/// 抛出异常如果获取失败
Future<Map<String, dynamic>> getLatestVersionInfo() async {
DBProduct? product = AppConfig.getproduct("DeapSound");
// 动态获取当前连接的设备名称
String deviceName = getDeviceName();
DBProduct? product = AppConfig.getproduct(deviceName);
if (product == null) {
throw "无法获取产品信息";
// 如果根据设备名称找不到产品,尝试使用默认产品名称
product = AppConfig.getproduct("DeapSound");
if (product == null) {
throw "无法获取产品信息,设备名称: $deviceName";
}
}
return {

2
lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart

@ -60,7 +60,7 @@ class OtaUpgradeController extends GetxController {
/// 从本地存储加载上一次连接设备的图片链接
void _loadLastConnectedDeviceImage() {
_lastConnectedDeviceImage = _storage.read('last_connected_device_name');
_lastConnectedDeviceImage = _storage.read('last_connected_device_image');
Logger.d(
'OtaUpgradeController', '加载上一次连接设备的图片: $_lastConnectedDeviceImage');
}

10
lib/modules/ota_upgrade/views/ota_upgrade_view.dart

@ -189,6 +189,16 @@ class OtaUpgradeView extends GetView<OtaUpgradeController> {
builder: (controller) {
final imagePath = controller.lastConnectedDeviceImage;
if (imagePath == null || imagePath.isEmpty) {
return Image.asset(
isDarkMode
? 'assets/images/headphone_new3.png'
: 'assets/images/headphone_new4.png',
height: 100.h,
fit: BoxFit.contain,
);
}
// 网络图片
return Image.network(
imagePath,

Loading…
Cancel
Save