fix: BLE connection leak on page unload and retry timer cleanup

- onUnload disconnects BLE if not in 'done' state (prevents connection leak)
- onUnload clears retry timer to prevent setData on dead page
- Store retry setTimeout ref for proper cleanup
这个提交包含在:
Guoguo
2026-05-12 06:28:36 -07:00
父节点 1fa6434451
当前提交 f69da211ab
+9 -2
查看文件
@@ -34,8 +34,15 @@ Page({
onUnload: function () {
clearTimeout(this._scanTimer)
clearTimeout(this._retryTimer)
ble.stopScan()
if (this._onBindResult) ble.off('bind_result', this._onBindResult)
if (this._onBindResult) {
ble.off('bind_result', this._onBindResult)
this._onBindResult = null
}
if (this.data.state !== 'done') {
ble.disconnect()
}
},
startBleConnect: function () {
@@ -98,7 +105,7 @@ Page({
self._onBindResult = null
}
ble.disconnect()
setTimeout(function () {
self._retryTimer = setTimeout(function () {
self.startBleConnect()
}, 1000)
},