fix(lefu): 搜索时 UNAVAILABLE 抖动不再清空协议,修复返回后设备误判断开
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
97bf4674c0
commit
507915f2c4
@@ -187,10 +187,17 @@ class LeFuService {
|
||||
this._doReconnect()
|
||||
return
|
||||
}
|
||||
// 蓝牙不可用:做完整清理
|
||||
// 蓝牙不可用:蓝牙真关了才清空协议;扫描/连接期间的 UNAVAILABLE 抖动(蓝牙还开着)保留协议
|
||||
if (res === plugin.BLUE_STATE.UNAVAILABLE) {
|
||||
let bluetoothOff = false
|
||||
try { bluetoothOff = wx.getSystemSetting().bluetoothEnabled === false } catch (e) { bluetoothOff = false }
|
||||
console.log(TAG, 'UNAVAILABLE 排查', { intentionalConnect: this._intentionalConnect, hasProtocol: !!this._activeProtocol, bluetoothOff })
|
||||
this._stopKeepAlive()
|
||||
this._stopReconnectTimer()
|
||||
// 蓝牙还开着:只是抖动,保留协议,避免 isConnected 误判为 false
|
||||
if (!bluetoothOff) {
|
||||
return
|
||||
}
|
||||
if (this._activeProtocol) {
|
||||
this._activeProtocol = null
|
||||
this._onDisconnectedCbs.forEach(cb => cb())
|
||||
@@ -220,7 +227,9 @@ class LeFuService {
|
||||
|
||||
// 即将断开:清理协议实例,若非主动断开则触发重连
|
||||
plugin.bus.subscribe('deviceWillDisconnect', () => {
|
||||
console.warn(TAG, 'bus[deviceWillDisconnect],intentionalConnect:', this._intentionalConnect)
|
||||
let bluetoothEnabled = ''
|
||||
try { bluetoothEnabled = String(wx.getSystemSetting().bluetoothEnabled) } catch (e) { bluetoothEnabled = 'unknown' }
|
||||
console.warn(TAG, 'deviceWillDisconnect 排查', { intentionalConnect: this._intentionalConnect, hasProtocol: !!this._activeProtocol, bluetoothEnabled })
|
||||
this._stopKeepAlive()
|
||||
if (this._activeProtocol) {
|
||||
this._activeProtocol = null
|
||||
|
||||
Reference in New Issue
Block a user