1
0
forked from dyf/APP

优化100J双模体验

This commit is contained in:
微微一笑
2026-03-30 16:05:03 +08:00
parent 6839e9fd40
commit 56e85e5dba

View File

@ -1121,17 +1121,26 @@ function execWithBleFirst(bleExec, httpExec, logName, onWaiting, opts = {}) {
} catch (e) {}
};
// 协议层认为已连:仍可能被系统蓝牙关闭/底层已断而滞后,先校验适配器,避免先发蓝牙卡超时再回退
if (protocolInstance.isBleConnected && protocolInstance.bleDeviceId) {
console.log('[100J] 语音上传:协议层已连接,执行蓝牙传文件');
return doBle().catch(onBleSendFail);
return getBleAdapterAvailable().then((adapterOk) => {
if (!adapterOk) {
protocolInstance.setBleConnectionStatus(false, '');
return go4GOrReject('系统蓝牙已关闭走4G');
}
console.log('[100J] 语音上传:协议层未就绪,将等待重连或走 4G', { isBleConnected: protocolInstance.isBleConnected, hasBleDeviceId: !!protocolInstance.bleDeviceId });
// 无 bleDeviceId系统蓝牙关闭则立即 4G开启则短时等页面扫描连上不再白等 12s
console.log('[100J]', logName || '指令', '协议层已连接,走蓝牙');
return doBle().catch(onBleSendFail);
});
}
console.log('[100J]', logName || '指令', '协议层未就绪', { isBleConnected: protocolInstance.isBleConnected, hasBleDeviceId: !!protocolInstance.bleDeviceId });
// 无 bleDeviceId本地仅蓝牙场景仍弹「请稍候」并等扫描可走 4G 时不弹 loading、不白等 5s直接 4G
if (!protocolInstance.bleDeviceId) {
return getBleAdapterAvailable().then((adapterOk) => {
if (!adapterOk) {
protocolInstance.setBleConnectionStatus(false, '');
return go4GOrReject('系统蓝牙未开启走4G');
}
if (no4G) {
if (typeof onWaiting === 'function') onWaiting();
else showWaitUi('请稍候…');
return waitForBleConnection()
@ -1139,19 +1148,20 @@ function execWithBleFirst(bleExec, httpExec, logName, onWaiting, opts = {}) {
return connected ? doBle().catch(onBleSendFail) : go4GOrReject('蓝牙未连接');
})
.finally(hideWaitUi);
}
return waitForBleConnection(0, BLE_POLL_INTERVAL_MS).then((connected) =>
connected ? doBle().catch(onBleSendFail) : go4GOrReject('无蓝牙连接走4G')
);
});
}
// 有 bleDeviceId 但未连:系统蓝牙关则直接 4G否则短时重连
// 有 bleDeviceId 但未连:用户刚关蓝牙/超出范围时,不再弹「请稍候」等重连 ~2s双通道在线时直接 4G
return getBleAdapterAvailable().then((adapterOk) => {
if (!adapterOk) {
protocolInstance.setBleConnectionStatus(false, '');
return go4GOrReject('系统蓝牙未开启走4G');
}
if (typeof onWaiting !== 'function') showWaitUi('请稍候…');
return tryReconnectBle()
.then((reconnected) => {
return reconnected ? doBle().catch(onBleSendFail) : go4GOrReject('蓝牙未连接');
})
.finally(hideWaitUi);
console.log('[100J]', logName || '指令', '蓝牙已断开直接走4G不阻塞重连');
return go4GOrReject(null);
});
}