Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 阻断屏核对器补种挂载时的 AppState,回前台首次即核对
guyong556519817e73
diff --git a/apps/mobile/src/update/forcedUpdateRecheck.test.ts b/apps/mobile/src/update/forcedUpdateRecheck.test.tsindex c0cdadc4a6..5979f31fc7 100644--- a/apps/mobile/src/update/forcedUpdateRecheck.test.ts+++ b/apps/mobile/src/update/forcedUpdateRecheck.test.ts@@ -55,6 +55,40 @@ describe('createForcedUpdateRechecker 触发条件', () => {expect(deps.fetchLatest).not.toHaveBeenCalled();});+ it('挂载时已在后台(阻断态被迟到的 /latest 置位)→ 回前台第一次就核对', async () => {+ // 没有这条 seeding,本实例见不到 'background' 事件,回前台首次会被 wasBackground+ // 门挡掉,用户得再走一个完整的切后台→回前台周期才自愈。+ const deps = makeDeps({ getAppState: () => 'background' });+ const rechecker = createForcedUpdateRechecker(deps, { minIntervalMs: 0 });+ deps.advance(1);+ const result = rechecker.handleAppStateChange('active');+ expect(result).not.toBeNull();+ await result;+ expect(deps.fetchLatest).toHaveBeenCalledOnce();+ });++ it('挂载时处于 inactive(iOS 抖动 / 系统弹框)→ 同样按已离开前台处理', async () => {+ const deps = makeDeps({ getAppState: () => 'inactive' });+ const rechecker = createForcedUpdateRechecker(deps, { minIntervalMs: 0 });+ deps.advance(1);+ expect(rechecker.handleAppStateChange('active')).not.toBeNull();+ });++ it('挂载时在前台 → 维持原行为(首次 active 不检查)', () => {+ const deps = makeDeps({ getAppState: () => 'active' });+ const rechecker = createForcedUpdateRechecker(deps, { minIntervalMs: 0 });+ deps.advance(1);+ expect(rechecker.handleAppStateChange('active')).toBeNull();+ expect(deps.fetchLatest).not.toHaveBeenCalled();+ });++ it('挂载时已在后台但用户很快回来 → 节流仍然生效(刚查过,重查冗余)', () => {+ const deps = makeDeps({ getAppState: () => 'background' });+ const rechecker = createForcedUpdateRechecker(deps, { minIntervalMs: 30_000 });+ deps.advance(1000); // 远小于节流间隔+ expect(rechecker.handleAppStateChange('active')).toBeNull();+ });+it('间隔不足的连续回前台 → 只检查一次(节流)', async () => {const deps = makeDeps();const rechecker = createForcedUpdateRechecker(deps, { minIntervalMs: 1000 });diff --git a/apps/mobile/src/update/forcedUpdateRecheck.ts b/apps/mobile/src/update/forcedUpdateRecheck.tsindex dc26809545..ee92b1b094 100644--- a/apps/mobile/src/update/forcedUpdateRecheck.ts+++ b/apps/mobile/src/update/forcedUpdateRecheck.ts@@ -40,6 +40,14 @@ export interface ForcedUpdateRecheckDeps {now: () => number;/** 阻断屏卸载后使迟到结果失效。 */isCurrent?: () => boolean;+ /**+ * 创建时读一次当前 AppState(实参为 () => AppState.currentState)。+ * 必要性:阻断态可能在 App **已经切到后台之后**才被置位(启动 / resume 检查的+ * /latest 迟到返回),此时本实例从未见过 'background' 事件,回前台的第一次+ * 'active' 会被 wasBackground 门挡掉 —— 运维撤回门槛正好发生在用户离开期间时,+ * 用户回来还要再切一次后台才自愈。省略则按 'active' 处理(维持旧行为)。+ */+ getAppState?: () => string;}export interface ForcedUpdateRecheckOptions {@@ -68,9 +76,12 @@ export function createForcedUpdateRechecker(latestTimeoutMs = DEFAULT_LATEST_TIMEOUT_MS,}: ForcedUpdateRecheckOptions = {},): ForcedUpdateRechecker {- // 与 resume 通道不同:阻断屏刚挂载时那次检查刚跑完,所以创建时刻同样视为"刚查过"。+ // 与 resume 通道不同:阻断屏刚挂载时那次检查刚跑完,所以创建时刻同样视为"刚查过"+ // (节流仍然生效:用户离开不足 minIntervalMs 就回来时,重查是冗余的)。let lastRunAt = deps.now();- let wasBackground = false;+ // 挂载时若 App 已不在前台,视同"已经进过后台":下一次回前台就该核对,+ // 不必等用户再走一个完整的切后台→回前台周期。+ let wasBackground = deps.getAppState ? deps.getAppState() !== 'active' : false;let inFlight = false;async function run(): Promise<ForcedUpdateRecheckOutcome> {diff --git a/apps/mobile/src/update/useForcedUpdateRecheck.ts b/apps/mobile/src/update/useForcedUpdateRecheck.tsindex 53b8c7b6e2..b3079662c7 100644--- a/apps/mobile/src/update/useForcedUpdateRecheck.ts+++ b/apps/mobile/src/update/useForcedUpdateRecheck.ts@@ -30,6 +30,9 @@ export function useForcedUpdateRecheck(isCanary = isCanaryChannel()): void {onStillForced: enterForcedUpdate,now: () => Date.now(),isCurrent: () => current,+ // 阻断态可能在 App 已切后台后才被置位(检查的 /latest 迟到返回),+ // 那时本实例见不到 'background' 事件;这里补种当前状态。+ getAppState: () => AppState.currentState,});const subscription = AppState.addEventListener('change', (next) => {