feat: 确保缓存连接时也重新写入请求头,并等待连接后的初始化回调,并加强 Android 等待 window.app 注入的逻辑
This commit is contained in:
parent
168ee5c475
commit
16c9bb70c0
@ -150,13 +150,22 @@ function handleAndroidPlatform(renderFun) {
|
||||
if (window.app) {
|
||||
debugLog('检测到window.app,开始连接')
|
||||
waitForFlutterInterface()
|
||||
} else if (checkCount < 50) {
|
||||
} else if (checkCount < 150) {
|
||||
if (
|
||||
(checkCount === 1 || checkCount % 20 === 0) &&
|
||||
window.FlutterPageControl &&
|
||||
window.FlutterPageControl.postMessage
|
||||
) {
|
||||
window.FlutterPageControl.postMessage('requestAccessOrigin')
|
||||
}
|
||||
setTimeout(checkApp, 100)
|
||||
} else {
|
||||
errorLog('等待window.app超时')
|
||||
// 手动通知Flutter注入接口
|
||||
if (window.FlutterApp && window.FlutterApp.postMessage) {
|
||||
window.FlutterApp.postMessage('requestAccessOrigin')
|
||||
} else if (window.FlutterPageControl && window.FlutterPageControl.postMessage) {
|
||||
window.FlutterPageControl.postMessage('requestAccessOrigin')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ export const connectToApp = async (onConnected, onFailed = defaultOnFailed) => {
|
||||
console.groupEnd()
|
||||
|
||||
await fetchUserInfoAfterConnection() //获取用户信息
|
||||
if (onConnected) onConnected() // 触发连接成功回调
|
||||
if (onConnected) await onConnected() // 触发连接成功回调
|
||||
|
||||
return { success: true, environment: 'browser' } // 浏览器环境
|
||||
}
|
||||
@ -80,12 +80,13 @@ export const connectToApp = async (onConnected, onFailed = defaultOnFailed) => {
|
||||
const cachedHeaderInfo = getAppHeaderInfo()
|
||||
if (cachedHeaderInfo) {
|
||||
console.debug('🔧 Using cached HTTP headers')
|
||||
await setHttpHeaders(cachedHeaderInfo)
|
||||
}
|
||||
|
||||
console.groupEnd()
|
||||
|
||||
await fetchUserInfoAfterConnection() //获取用户信息
|
||||
if (onConnected) onConnected() // 触发连接成功回调
|
||||
if (onConnected) await onConnected() // 触发连接成功回调
|
||||
|
||||
return { success: true, environment: 'app', fromCache: true } // APP环境
|
||||
}
|
||||
@ -98,7 +99,7 @@ export const connectToApp = async (onConnected, onFailed = defaultOnFailed) => {
|
||||
console.groupEnd()
|
||||
|
||||
await fetchUserInfoAfterConnection() //获取用户信息
|
||||
if (onConnected) onConnected() // 触发连接成功回调
|
||||
if (onConnected) await onConnected() // 触发连接成功回调
|
||||
|
||||
return { success: true, environment: 'app', fromCache: true } // APP环境
|
||||
}
|
||||
@ -148,7 +149,7 @@ export const connectToApp = async (onConnected, onFailed = defaultOnFailed) => {
|
||||
console.groupEnd()
|
||||
|
||||
await fetchUserInfoAfterConnection() //获取用户信息
|
||||
if (onConnected) onConnected() // 触发连接成功回调
|
||||
if (onConnected) await onConnected() // 触发连接成功回调
|
||||
|
||||
return connectionResult
|
||||
} catch (error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user