[AI Generated]: fix(lefu): 修复蓝牙断连后 isConnected 误报及重连无效问题,新增 equipmentMember 页 onShow 兜底注释

This commit is contained in:
17792275749
2026-05-18 09:30:36 +08:00
parent ce586bf6ae
commit 49b356335e
4 changed files with 19 additions and 6 deletions
+10 -3
View File
@@ -83,6 +83,7 @@ class LeFuService {
private readonly _maxReconnect = 3
private _reconnectTimer: number | null = null
private _keepAliveTimer: number | null = null
private _lastRawDevice: RawDevice | null = null
private _onDevicesListCb: ((devices: ScannedDevice[]) => void) | null = null
private _onConnectStateCb: ((state: string) => void) | null = null
@@ -181,6 +182,7 @@ class LeFuService {
plugin.bus.subscribe('deviceWillDisconnect', () => {
console.warn(TAG, 'bus[deviceWillDisconnect]intentionalConnect:', this._intentionalConnect)
this._activeProtocol = null
this._stopKeepAlive()
this._onDisconnectedCb?.()
if (!this._intentionalConnect) {
@@ -191,6 +193,7 @@ class LeFuService {
connect(rawDevice: RawDevice): void {
console.log(TAG, 'connect():', rawDevice.name)
this._lastRawDevice = rawDevice
this._intentionalConnect = true
this._stopKeepAlive()
this._stopReconnectTimer()
@@ -331,15 +334,19 @@ class LeFuService {
private _doReconnect(): void {
if (this._reconnectCount >= this._maxReconnect) {
console.warn(TAG, '重连次数已达上限')
this._onDisconnectedCb?.()
return
}
if (!this._lastRawDevice) {
console.warn(TAG, '无缓存设备,放弃重连')
return
}
this._reconnectCount++
console.log(TAG, `_doReconnect 第 ${this._reconnectCount}`)
this._stopReconnectTimer()
this._reconnectTimer = setTimeout(() => {
plugin.Blue.disconnect((res: any) => {
if (res?.errCode === 0) plugin.Blue.startBluetoothDevicesDiscovery()
})
plugin.Blue.clearProtocol()
plugin.Blue.createBLEConnection(this._lastRawDevice!)
}, 2000)
}