|
|
@ -1,5 +1,6 @@ |
|
|
import 'package:get/get.dart'; |
|
|
import 'package:get/get.dart'; |
|
|
import 'dart:async'; |
|
|
import 'dart:async'; |
|
|
|
|
|
import '../../../data/services/novice_guide_service.dart'; |
|
|
import '../../../routes/app_routes.dart'; |
|
|
import '../../../routes/app_routes.dart'; |
|
|
import '../../../core/utils/logger.dart'; |
|
|
import '../../../core/utils/logger.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
@ -24,7 +25,7 @@ class HomeController extends GetxController { |
|
|
|
|
|
|
|
|
final _isFullyConnected = false.obs; |
|
|
final _isFullyConnected = false.obs; |
|
|
String? _lastConnectedDeviceName; |
|
|
String? _lastConnectedDeviceName; |
|
|
|
|
|
|
|
|
bool get isFullyConnected => _isFullyConnected.value; |
|
|
bool get isFullyConnected => _isFullyConnected.value; |
|
|
RxBool get isFullyConnectedRx => _isFullyConnected; |
|
|
RxBool get isFullyConnectedRx => _isFullyConnected; |
|
|
BluetoothDevice? get currentDevice => _bluetoothManager.currentDevice; |
|
|
BluetoothDevice? get currentDevice => _bluetoothManager.currentDevice; |
|
|
@ -55,12 +56,15 @@ class HomeController extends GetxController { |
|
|
final _bleManager = Get.find<BleManager>(); |
|
|
final _bleManager = Get.find<BleManager>(); |
|
|
final _storage = GetStorage(); |
|
|
final _storage = GetStorage(); |
|
|
|
|
|
|
|
|
|
|
|
final noviceGuideService = Get.find<NoviceGuideService>(); |
|
|
|
|
|
|
|
|
// 会话级别的版本检查标记(静态变量,整个应用会话期间保持) |
|
|
// 会话级别的版本检查标记(静态变量,整个应用会话期间保持) |
|
|
static bool _hasCheckedVersionInSession = false; |
|
|
static bool _hasCheckedVersionInSession = false; |
|
|
|
|
|
|
|
|
// 版本检查相关常量 |
|
|
// 版本检查相关常量 |
|
|
static const String _lastVersionCheckKey = 'last_version_check_timestamp'; |
|
|
static const String _lastVersionCheckKey = 'last_version_check_timestamp'; |
|
|
static const int _versionCheckIntervalHours = 24; // 24小时间隔 |
|
|
static const int _versionCheckIntervalHours = 24; // 24小时间隔 |
|
|
|
|
|
|
|
|
@override |
|
|
@override |
|
|
void onInit() { |
|
|
void onInit() { |
|
|
super.onInit(); |
|
|
super.onInit(); |
|
|
@ -94,13 +98,14 @@ class HomeController extends GetxController { |
|
|
update(); |
|
|
update(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
_classicBluetoothWorker = ever(_bluetoothManager.currentDeviceRx, (BluetoothDevice? device) { |
|
|
_classicBluetoothWorker = |
|
|
|
|
|
ever(_bluetoothManager.currentDeviceRx, (BluetoothDevice? device) { |
|
|
if (device != null) { |
|
|
if (device != null) { |
|
|
_lastConnectedDeviceName = device.name; |
|
|
_lastConnectedDeviceName = device.name; |
|
|
} |
|
|
} |
|
|
_checkConnectionStatus(); |
|
|
_checkConnectionStatus(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
_bleConnectionWorker = ever(_bleManager.connectionStateRx, (int state) { |
|
|
_bleConnectionWorker = ever(_bleManager.connectionStateRx, (int state) { |
|
|
_checkConnectionStatus(); |
|
|
_checkConnectionStatus(); |
|
|
}); |
|
|
}); |
|
|
@ -121,30 +126,30 @@ class HomeController extends GetxController { |
|
|
void exploreAIFeatures() { |
|
|
void exploreAIFeatures() { |
|
|
Get.toNamed(Routes.agent); |
|
|
Get.toNamed(Routes.agent); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Future<void> _checkConnectionStatus() async { |
|
|
Future<void> _checkConnectionStatus() async { |
|
|
try { |
|
|
try { |
|
|
final currentBleState = await _bleManager.getConnectionState(); |
|
|
final currentBleState = await _bleManager.getConnectionState(); |
|
|
|
|
|
|
|
|
bool hasClassicBluetooth = currentDevice != null; |
|
|
bool hasClassicBluetooth = currentDevice != null; |
|
|
bool hasBleConnection = currentBleState == 2; |
|
|
bool hasBleConnection = currentBleState == 2; |
|
|
bool wasConnected = _isFullyConnected.value; |
|
|
bool wasConnected = _isFullyConnected.value; |
|
|
bool isNowConnected = hasClassicBluetooth && hasBleConnection; |
|
|
bool isNowConnected = hasClassicBluetooth && hasBleConnection; |
|
|
|
|
|
|
|
|
if (isNowConnected && currentDevice == null) { |
|
|
if (isNowConnected && currentDevice == null) { |
|
|
isNowConnected = false; |
|
|
isNowConnected = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (_isFullyConnected.value != isNowConnected) { |
|
|
if (_isFullyConnected.value != isNowConnected) { |
|
|
_isFullyConnected.value = isNowConnected; |
|
|
_isFullyConnected.value = isNowConnected; |
|
|
_isFullyConnected.refresh(); |
|
|
_isFullyConnected.refresh(); |
|
|
update(); |
|
|
update(); |
|
|
|
|
|
|
|
|
if (!wasConnected && isNowConnected) { |
|
|
if (!wasConnected && isNowConnected) { |
|
|
await _bleManager.fetchDeviceInfo(); |
|
|
await _bleManager.fetchDeviceInfo(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
update(); |
|
|
update(); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
Logger.e(_tag, '${'checkConnectionStatusFailed'.tr}: $e'); |
|
|
Logger.e(_tag, '${'checkConnectionStatusFailed'.tr}: $e'); |
|
|
@ -165,26 +170,28 @@ class HomeController extends GetxController { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool get shouldShowDeviceInfo => currentDevice != null; |
|
|
bool get shouldShowDeviceInfo => currentDevice != null; |
|
|
|
|
|
|
|
|
String getDeviceName() { |
|
|
String getDeviceName() { |
|
|
if (_isFullyConnected.value && currentDevice == null) { |
|
|
if (_isFullyConnected.value && currentDevice == null) { |
|
|
_checkConnectionStatus(); |
|
|
_checkConnectionStatus(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
final deviceName = currentDevice?.name; |
|
|
final deviceName = currentDevice?.name; |
|
|
if (deviceName != null && deviceName.isNotEmpty) { |
|
|
if (deviceName != null && deviceName.isNotEmpty) { |
|
|
return deviceName; |
|
|
return deviceName; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
final bleDeviceName = deviceInfo.value?.name; |
|
|
final bleDeviceName = deviceInfo.value?.name; |
|
|
if (bleDeviceName != null && bleDeviceName.isNotEmpty) { |
|
|
if (bleDeviceName != null && bleDeviceName.isNotEmpty) { |
|
|
return bleDeviceName; |
|
|
return bleDeviceName; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!_isFullyConnected.value && _lastConnectedDeviceName != null && _lastConnectedDeviceName!.isNotEmpty) { |
|
|
if (!_isFullyConnected.value && |
|
|
|
|
|
_lastConnectedDeviceName != null && |
|
|
|
|
|
_lastConnectedDeviceName!.isNotEmpty) { |
|
|
return _lastConnectedDeviceName!; |
|
|
return _lastConnectedDeviceName!; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return 'unknownEquipment'.tr; |
|
|
return 'unknownEquipment'.tr; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -288,7 +295,8 @@ class HomeController extends GetxController { |
|
|
} |
|
|
} |
|
|
// 条件2:距离上次检查超过24小时 |
|
|
// 条件2:距离上次检查超过24小时 |
|
|
else if (lastCheckTimestamp != null) { |
|
|
else if (lastCheckTimestamp != null) { |
|
|
final lastCheckTime = DateTime.fromMillisecondsSinceEpoch(lastCheckTimestamp); |
|
|
final lastCheckTime = |
|
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(lastCheckTimestamp); |
|
|
final timeDifference = now.difference(lastCheckTime); |
|
|
final timeDifference = now.difference(lastCheckTime); |
|
|
|
|
|
|
|
|
if (timeDifference.inHours >= _versionCheckIntervalHours) { |
|
|
if (timeDifference.inHours >= _versionCheckIntervalHours) { |
|
|
|