fix(ble): 修复首次搜索时 stopDiscovery 误报适配器未打开错误

stopDiscoverySilently 移入 initialized 判断块内,仅在适配器已初始化时才尝试停止扫描
This commit is contained in:
ozh 2026-04-30 16:52:48 +08:00
parent 2a6eeccbed
commit cc02eb5998
1 changed files with 2 additions and 4 deletions

View File

@ -384,7 +384,7 @@ export function createBluetoothDiscovery(options = {}) {
}
offStateChange = controller.ble.on('state:change', (state) => {
console.debug('state:change', state)
// console.debug('state:change', state)
onStageChange(state.stage)
if (state.profileId && state.profileId !== currentProfileId) {
@ -615,11 +615,9 @@ export function createBluetoothDiscovery(options = {}) {
clearDiscoveryPollTimer()
clearAutoStopTimer()
// 先停止上一次残留扫描
await stopDiscoverySilently()
// 重置 BLE 适配器:关闭并重开,确保每次搜索都是干净的初始状态
if (initialized) {
await stopDiscoverySilently()
unbindControllerEvents()
await controller.ble.closeAdapter()
await delay(RESTART_SCAN_DELAY_MS)