From e34fb52d664910b5e070261a206eab4e1bb95ca3 Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Thu, 18 Sep 2025 18:52:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(ota):=20=E4=BF=AE=E5=A4=8D=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=90=8D=E7=A7=B0=E8=8E=B7=E5=8F=96=E5=92=8C=E4=BA=A7?= =?UTF-8?q?=E5=93=81=E4=BF=A1=E6=81=AF=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加蓝牙管理器引用以获取设备名称 - 实现动态获取设备名称的方法 - 修改产品信息查询逻辑以使用实际设备名称 - 添加默认设备图片显示逻辑 - 修复存储中设备图片键名错误 - 移除会议控制器中音频类型限制注释 --- .../controllers/meeting_home_controller.dart | 2 +- .../controllers/ota_core_contropller.dart | 52 +++++++++++++++++-- .../controllers/ota_upgrade_controller.dart | 2 +- .../ota_upgrade/views/ota_upgrade_view.dart | 10 ++++ 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/lib/modules/meeting/controllers/meeting_home_controller.dart b/lib/modules/meeting/controllers/meeting_home_controller.dart index 96388f369..522661d6f 100644 --- a/lib/modules/meeting/controllers/meeting_home_controller.dart +++ b/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) { diff --git a/lib/modules/ota_upgrade/controllers/ota_core_contropller.dart b/lib/modules/ota_upgrade/controllers/ota_core_contropller.dart index be75315b0..bef30cae9 100644 --- a/lib/modules/ota_upgrade/controllers/ota_core_contropller.dart +++ b/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(); + final BluetoothManager _bluetoothManager = + Get.find(); // 添加蓝牙管理器引用 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> 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 { diff --git a/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart b/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart index 4a4e9e896..dae6049dd 100644 --- a/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart +++ b/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'); } diff --git a/lib/modules/ota_upgrade/views/ota_upgrade_view.dart b/lib/modules/ota_upgrade/views/ota_upgrade_view.dart index 10f7180b8..0597a37b5 100644 --- a/lib/modules/ota_upgrade/views/ota_upgrade_view.dart +++ b/lib/modules/ota_upgrade/views/ota_upgrade_view.dart @@ -189,6 +189,16 @@ class OtaUpgradeView extends GetView { 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,