nomadro/apps/miniprogram/h5/src/app.tsx
Eric 4389ebe6cb Ship WeChat audit release 2026-11-02: realtime config, audit vip-ebook shell, admin ops.
Document test9 tag 2026-11-02 for upload; POST config pull + WS, fixed dark home, no debug bar.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-02 16:12:57 +08:00

101 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Fragment, useEffect } from 'react'
import type { PropsWithChildren } from 'react'
import Taro, { useDidHide, useDidShow, useLaunch } from '@tarojs/taro'
import { flush, trackAppLaunch } from './utils/track'
import {
loadRemoteConfig,
softRefreshRemoteConfig,
startRemoteConfigLiveSync,
} from './services/remoteConfig'
import { startH5RemLock } from './utils/h5RemLock'
import { applyH5Theme } from './utils/h5Theme'
import { startPresenceHeartbeat } from './utils/presence'
import { startVipAccessLiveSync } from './utils/vipAccess'
import DebugFab from './components/DebugFab'
import './styles/theme'
import './styles/ebook.scss'
import './app.scss'
function App({ children }: PropsWithChildren) {
useLaunch(() => {
trackAppLaunch()
void loadRemoteConfig(true)
applyH5Theme('dark')
// 小程序 AI 接力:账号卡片进入页时同步 payload(仅 weapp + 基础库支持时)
if (process.env.TARO_ENV === 'weapp') {
try {
const wxApi = Taro as unknown as {
onAgentHandoff?: (
cb: (p: {
pageId: number
path: string
query: string
payload: unknown
}) => void,
) => void
}
if (typeof wxApi.onAgentHandoff === 'function') {
wxApi.onAgentHandoff(({ pageId, path, query, payload }) => {
const g = globalThis as unknown as {
__nomadroAgentHandoffs?: Record<
number,
{ path: string; query: string; payload: unknown }
>
}
g.__nomadroAgentHandoffs = g.__nomadroAgentHandoffs || {}
g.__nomadroAgentHandoffs[pageId] = { path, query, payload }
})
}
} catch {
/* AI 模式未开通时忽略 */
}
}
})
useDidShow(() => {
softRefreshRemoteConfig()
})
useDidHide(() => {
void flush()
})
useEffect(() => {
const stopRem = startH5RemLock()
const stopLive = startRemoteConfigLiveSync()
let stopPresence: (() => void) | undefined
let stopVip: (() => void) | undefined
let defer: ReturnType<typeof setTimeout> | undefined
const startSide = () => {
stopPresence = startPresenceHeartbeat()
stopVip = startVipAccessLiveSync()
}
// 微信提审:延后心跳 / VIP 探活,避免冷启动抢跑干扰小册首屏
if (process.env.TARO_ENV === 'weapp') {
defer = setTimeout(startSide, 2500)
} else {
startSide()
}
if (process.env.TARO_ENV === 'h5') {
applyH5Theme('dark')
}
return () => {
if (defer) clearTimeout(defer)
stopRem()
stopLive()
stopPresence?.()
stopVip?.()
}
}, [])
// DebugFab 内部按 envVersion/NODE_ENV 自判;正式版 release 不渲染
return (
<Fragment>
{children}
<DebugFab />
</Fragment>
)
}
export default App