Browse Source

上传iOS改动和扫描底层优化

weicu
liwei1dao 12 months ago
parent
commit
c4d3ec2ad5
  1. 1
      lib/core/translations/language/en_us.dart
  2. 2
      lib/core/translations/language/zh_cn.dart
  3. 9
      lib/modules/pairing/controllers/pairing_controller.dart
  4. 27
      local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift
  5. 11
      local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift

1
lib/core/translations/language/en_us.dart

@ -540,6 +540,7 @@ const Map<String, String> enUS = {
"loadMoreMessages": "Load more messages...",
"loadFailedClickRetry": "Load failed, click to retry",
"swipeUpForMore": "Swipe up for more",
"callingTool": "I'm helping you, please wait!", // 正在帮您,请稍等!
// 预设提示词
"presetMusic": "Play some music", // Play some music

2
lib/core/translations/language/zh_cn.dart

@ -511,7 +511,7 @@ const Map<String, String> zhCN = {
"loadMoreMessages": "加载更多消息...",
"loadFailedClickRetry": "加载失败,点击重试",
"swipeUpForMore": "向上滑动查看更多",
"callingTool": "正在调用工具!",
"callingTool": "正在帮您,请稍等!",
// 预设提示词
"presetMusic": "来点音乐", // 来点音乐

9
lib/modules/pairing/controllers/pairing_controller.dart

@ -807,13 +807,13 @@ class PairingController extends GetxController with WidgetsBindingObserver {
}
} else {
//未绑定设备
_bleManager.clearPairedDevices();
Logger.i(_tag, '验证时BLE状态: $currentBleState');
if (currentBleState == 2) {
//已连接 清理
// BleConnectionState.connected
Logger.i(_tag, 'BLE已连接,断开并清理缓存');
_bleManager.clearPairedDevices();
_bleManager.disconnect();
}
}
@ -944,6 +944,11 @@ class PairingController extends GetxController with WidgetsBindingObserver {
}
}
}
final currentBleState = await _bleManager.getConnectionState();
if (currentBleState == 2) {
_bleManager.clearPairedDevices();
_bleManager.disconnect();
}
await Future.delayed(Duration(seconds: 1));
}
_bleManager.stopScan();

27
local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift

@ -27,6 +27,10 @@ class AgentServiceImpl: NSObject {
static let shared = AgentServiceImpl()
// UserDefaults 相关常量
private let PREF_NAME = "agent_service_prefs"
private let KEY_IS_INTERRUPT = "is_interrupt"
private var listeners = [AgentServiceListener]()
private let listenersLock = NSLock()
@ -252,6 +256,8 @@ class AgentServiceImpl: NSObject {
if isInitialized {
loadChatHistory()
// 从 UserDefaults 加载 isInterrupt 状态
loadIsInterruptFromCache()
}
LocationService.shared.getCurrentLocation() { location in
// self.locationInfo = location
@ -2238,4 +2244,25 @@ extension AgentServiceImpl: AzureAsrHelper.ContinuousRecognizeCallback {
stopRequestedDuringStart = false
stopIdleCheck()
}
// MARK: - isInterrupt 缓存方法
/**
* 从 UserDefaults 加载 isInterrupt 状态
*/
private func loadIsInterruptFromCache() {
let userDefaults = UserDefaults.standard
let cachedValue = userDefaults.bool(forKey: KEY_IS_INTERRUPT) // 默认值为 false
isInterrupt = cachedValue
os_log("从缓存加载 isInterrupt 状态: %{public}@", log: logger, type: .info, String(isInterrupt))
}
/**
* 保存 isInterrupt 状态到 UserDefaults
*/
func saveIsInterruptToCache(_ isInterrupt: Bool) {
let userDefaults = UserDefaults.standard
userDefaults.set(isInterrupt, forKey: KEY_IS_INTERRUPT)
os_log("保存 isInterrupt 状态到缓存: %{public}@", log: logger, type: .info, String(isInterrupt))
}
}

11
local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift

@ -79,8 +79,15 @@ public class AgentServicePlugin: NSObject, FlutterPlugin {
impl.startRecognition(mode: mode)
result(true)
case "isInterrupt":
impl.isInterrupt = !impl.isInterrupt
result(impl.isInterrupt)
if let args = call.arguments as? [String: Any],
let isInterrupt = args["isinterrupt"] as? Bool {
impl.isInterrupt = isInterrupt
// 保存到 UserDefaults
impl.saveIsInterruptToCache(isInterrupt)
result(impl.isInterrupt)
} else {
result(FlutterError(code: "INVALID_ARGUMENTS", message: "isinterrupt 参数缺失或类型错误", details: nil))
}
case "recognizeCallback":
impl.recognizeCallback()

Loading…
Cancel
Save