Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 恢复中国大陆版 iOS 微信登录并修正身份选择行 (#5161)
boboa21072bbbdbf
diff --git a/apps/mobile/src/auth/__tests__/mobileSocialLoginMode.test.ts b/apps/mobile/src/auth/__tests__/mobileSocialLoginMode.test.tsindex c8ad6a1ee6..f3bc1cfbf2 100644--- a/apps/mobile/src/auth/__tests__/mobileSocialLoginMode.test.ts+++ b/apps/mobile/src/auth/__tests__/mobileSocialLoginMode.test.ts@@ -3,9 +3,8 @@ import { describe, expect, it } from 'vitest';import { resolveMobileSocialLoginMode } from '@/auth/mobileSocialLoginMode';describe('resolveMobileSocialLoginMode', () => {- it.each(['ios', 'android'])(- 'temporarily hides WeChat on %s even when configured',- (platform) => {+ it('uses native WeChat only on configured Mainland China iOS builds', () => {+ for (const platform of ['ios', 'android']) {for (const region of ['cn', 'global'] as const) {for (const nativeSupported of [true, false]) {expect(@@ -15,14 +14,14 @@ describe('resolveMobileSocialLoginMode', () => {platform,nativeSupported,}),- ).toBeNull();+ ).toBe(platform === 'ios' && region === 'cn' && nativeSupported ? 'native' : null);}}- },- );+ }+ });it.each(['ios', 'android'])(- 'restores the configured CN WeChat path on %s when re-enabled',+ 'hides WeChat on %s when explicitly disabled',(platform) => {expect(resolveMobileSocialLoginMode({@@ -30,25 +29,7 @@ describe('resolveMobileSocialLoginMode', () => {region: 'cn',platform,nativeSupported: true,- wechatLoginEnabled: true,- }),- ).toBe('native');- expect(- resolveMobileSocialLoginMode({- provider: 'wechat',- region: 'cn',- platform,- nativeSupported: false,- wechatLoginEnabled: true,- }),- ).toBeNull();- expect(- resolveMobileSocialLoginMode({- provider: 'wechat',- region: 'global',- platform,- nativeSupported: true,- wechatLoginEnabled: true,+ wechatLoginEnabled: false,}),).toBeNull();},diff --git a/apps/mobile/src/auth/__tests__/useMobileSocialProviderModes.test.tsx b/apps/mobile/src/auth/__tests__/useMobileSocialProviderModes.test.tsxindex 8c0a2f7872..95a914e4b7 100644--- a/apps/mobile/src/auth/__tests__/useMobileSocialProviderModes.test.tsx+++ b/apps/mobile/src/auth/__tests__/useMobileSocialProviderModes.test.tsx@@ -37,10 +37,16 @@ import { useMobileSocialProviderModes } from '../useMobileSocialProviderModes';const providers: SocialProvider[] = ['wechat'];-function Probe({ wechatLoginEnabled }: { wechatLoginEnabled?: boolean }) {+function Probe({+ wechatLoginEnabled,+ region = 'cn',+}: {+ wechatLoginEnabled?: boolean;+ region?: 'cn' | 'global';+}) {const modes = useMobileSocialProviderModes({providers,- region: 'cn',+ region,wechatLoginEnabled,});return (@@ -55,9 +61,12 @@ function Probe({ wechatLoginEnabled }: { wechatLoginEnabled?: boolean }) {let host: HTMLDivElement;let root: Root;-async function renderProbe(wechatLoginEnabled?: boolean) {+async function renderProbe(+ wechatLoginEnabled?: boolean,+ region: 'cn' | 'global' = 'cn',+) {await act(async () => {- root.render(<Probe wechatLoginEnabled={wechatLoginEnabled} />);+ root.render(<Probe wechatLoginEnabled={wechatLoginEnabled} region={region} />);await Promise.resolve();});}@@ -82,36 +91,36 @@ describe('mobile social provider visibility', () => {expect(native.listeners.size).toBe(0);});- it('hides WeChat on iOS without probing the SDK', async () => {+ it('shows WeChat on iOS after the first successful installation probe', async () => {native.available.mockResolvedValue(true);await renderProbe();- expect(wechatButton()).toBeNull();- expect(native.available).not.toHaveBeenCalled();- expect(native.listeners.size).toBe(0);+ expect(wechatButton()).not.toBeNull();+ expect(native.available).toHaveBeenCalledWith('wechat');});- it('hides WeChat on Android without probing installation', async () => {+ it('hides WeChat on Android even when configured and installed', async () => {native.platform = 'android';+ native.available.mockResolvedValue(true);await renderProbe();expect(wechatButton()).toBeNull();expect(native.available).not.toHaveBeenCalled();});- it('shows WeChat on iOS after the first successful installation probe when re-enabled', async () => {+ it('hides WeChat on Global iOS without probing installation', async () => {native.available.mockResolvedValue(true);- await renderProbe(true);- expect(wechatButton()).not.toBeNull();- expect(native.available).toHaveBeenCalledWith('wechat');+ await renderProbe(undefined, 'global');+ expect(wechatButton()).toBeNull();+ expect(native.available).not.toHaveBeenCalled();});- it('keeps WeChat hidden on iOS when the installation probe fails after re-enabling', async () => {- await renderProbe(true);+ it('keeps WeChat hidden on iOS when the installation probe fails', async () => {+ await renderProbe();expect(wechatButton()).toBeNull();});- it('refreshes iOS WeChat visibility on foreground when re-enabled', async () => {+ it('refreshes iOS WeChat visibility on foreground', async () => {native.available.mockResolvedValueOnce(false).mockResolvedValueOnce(true);- await renderProbe(true);+ await renderProbe();expect(wechatButton()).toBeNull();await act(async () => {@@ -123,10 +132,46 @@ describe('mobile social provider visibility', () => {expect(native.available).toHaveBeenCalledTimes(2);});- it('shows configured WeChat on Android without probing installation when re-enabled', async () => {- native.platform = 'android';- await renderProbe(true);+ it('hides iOS WeChat after it is uninstalled while Cindy is in the background', async () => {+ native.available.mockResolvedValueOnce(true).mockResolvedValueOnce(false);+ await renderProbe();expect(wechatButton()).not.toBeNull();++ await act(async () => {+ for (const listener of native.listeners) listener('active');+ await Promise.resolve();+ });++ expect(wechatButton()).toBeNull();+ });++ it('ignores an older installation probe that completes after a foreground refresh', async () => {+ let finishFirstProbe!: (installed: boolean) => void;+ native.available+ .mockImplementationOnce(() => new Promise<boolean>((resolve) => {+ finishFirstProbe = resolve;+ }))+ .mockResolvedValueOnce(false);+ await renderProbe();++ await act(async () => {+ for (const listener of native.listeners) listener('active');+ await Promise.resolve();+ });+ await act(async () => {+ finishFirstProbe(true);+ await Promise.resolve();+ });++ expect(wechatButton()).toBeNull();+ expect(native.available).toHaveBeenCalledTimes(2);+ });++ it('does not probe or show WeChat when explicitly disabled', async () => {+ native.available.mockResolvedValue(true);+ await renderProbe(false);+ expect(wechatButton()).toBeNull();expect(native.available).not.toHaveBeenCalled();+ expect(native.listeners.size).toBe(0);});});diff --git a/apps/mobile/src/auth/mobileSocialLoginMode.ts b/apps/mobile/src/auth/mobileSocialLoginMode.tsindex 918a5ff8f7..e12fe309c7 100644--- a/apps/mobile/src/auth/mobileSocialLoginMode.ts+++ b/apps/mobile/src/auth/mobileSocialLoginMode.ts@@ -2,9 +2,7 @@ import type { AuthRegion, SocialProvider } from '@cindy/auth-client';export type MobileSocialLoginMode = 'native' | 'browser';-// The mobile app's WeChat Open Platform configuration is being corrected.-// Keep native integration intact so the entry can return after both platforms pass verification.-export const MOBILE_WECHAT_LOGIN_ENABLED = false;+export const MOBILE_WECHAT_LOGIN_ENABLED = true;/*** Chooses the credential path for a provider advertised by auth-server.@@ -21,7 +19,8 @@ export function resolveMobileSocialLoginMode(input: {if (input.provider === 'wechat' &&(!(input.wechatLoginEnabled ?? MOBILE_WECHAT_LOGIN_ENABLED) ||- input.region !== 'cn')+ input.region !== 'cn' ||+ input.platform !== 'ios')) {return null;}diff --git a/apps/mobile/src/auth/nativeSocial.ts b/apps/mobile/src/auth/nativeSocial.tsindex 69b68d0c2f..5e047cb1fa 100644--- a/apps/mobile/src/auth/nativeSocial.ts+++ b/apps/mobile/src/auth/nativeSocial.ts@@ -49,10 +49,9 @@ export function isNativeSocialProviderSupported(/*** Resolves whether a configured native provider should be offered on this- * device. WeChat's iOS flow requires the companion app, so App Review builds- * hide that entry when the SDK cannot find WeChat. Android keeps the entry and- * reports an unavailable provider after a tap, matching the platform's normal- * install flow.+ * device. The current login UI offers WeChat only on Mainland China iOS after+ * the SDK confirms that WeChat is installed. Android credential acquisition+ * remains available to callers, but the login UI does not advertise it.*/export async function isNativeSocialProviderAvailable(provider: SocialProvider,diff --git a/apps/mobile/src/auth/useMobileSocialProviderModes.ts b/apps/mobile/src/auth/useMobileSocialProviderModes.tsindex 1a597bd325..eefd125249 100644--- a/apps/mobile/src/auth/useMobileSocialProviderModes.ts+++ b/apps/mobile/src/auth/useMobileSocialProviderModes.ts@@ -23,13 +23,26 @@ export function useMobileSocialProviderModes({wechatLoginEnabled?: boolean;}): ReadonlyMap<SocialProvider, MobileSocialLoginMode> {const [iosWechatAvailable, setIosWechatAvailable] = useState(false);+ const hasWechatProvider = providers.includes('wechat');useEffect(() => {- if (!wechatLoginEnabled || Platform.OS !== 'ios') return;+ if (+ !wechatLoginEnabled ||+ region !== 'cn' ||+ !hasWechatProvider ||+ Platform.OS !== 'ios'+ ) {+ setIosWechatAvailable(false);+ return;+ }let cancelled = false;+ let latestRequest = 0;const refresh = async () => {+ const request = ++latestRequest;+ setIosWechatAvailable(false);const available = await isNativeSocialProviderAvailable('wechat');- if (!cancelled) setIosWechatAvailable(available);+ if (!cancelled && request === latestRequest)+ setIosWechatAvailable(available);};void refresh();const subscription = AppState.addEventListener('change', (state) => {@@ -39,7 +52,7 @@ export function useMobileSocialProviderModes({cancelled = true;subscription.remove();};- }, [wechatLoginEnabled]);+ }, [wechatLoginEnabled, region, hasWechatProvider]);return useMemo(() => {const modes = new Map<SocialProvider, MobileSocialLoginMode>();diff --git a/apps/mobile/src/components/LoginNativeButton.ios.tsx b/apps/mobile/src/components/LoginNativeButton.ios.tsxindex d15c332dff..f34c2b71b6 100644--- a/apps/mobile/src/components/LoginNativeButton.ios.tsx+++ b/apps/mobile/src/components/LoginNativeButton.ios.tsx@@ -12,10 +12,10 @@ import type { LoginNativeButtonProps } from './LoginNativeButton';export const hasNativeLoginButtons = true;/** Login's scaled layout owns the frame; SwiftUI owns activation and feedback.- * RNHostView is reserved for existing brand artwork, never an inner Pressable. */+ * RNHostView renders existing artwork and the fixed method-row layout, never an inner Pressable. */export function LoginNativeButton({ label, onPress, disabled, busy, testID,width, height, fontSize, style, variant = 'secondary', subtitle, children, trailingArtwork,- artworkSize = fontSize, showLabel = !children, accessibilityLabel: spokenLabel, selected,+ artworkSize = fontSize, showLabel = !children, accessibilityLabel: spokenLabel, selected, content,}: LoginNativeButtonProps) {const { colors, mode } = useTheme();const prominent = variant === 'primary' || variant === 'circle';@@ -35,7 +35,9 @@ export function LoginNativeButton({ label, onPress, disabled, busy, testID,foregroundStyle(foreground), accessibilityLabel(spokenLabel ?? label), disabledModifier(inert),...(selected ? [accessibilityAddTraits(['isSelected'])] : []),]}>- <HStack spacing={fontSize / 2}>+ {content ? <VStack modifiers={[frame({ width, height })]}>+ <RNHostView><View pointerEvents="none" style={{ width, height }}>{content}</View></RNHostView>+ </VStack> : <HStack spacing={fontSize / 2}>{children ? <VStack modifiers={[frame({ width: artworkSize, height: artworkSize })]}><RNHostView><View pointerEvents="none" style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>{children}</View></RNHostView></VStack> : null}@@ -48,7 +50,7 @@ export function LoginNativeButton({ label, onPress, disabled, busy, testID,<RNHostView><View pointerEvents="none" style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>{trailingArtwork}</View></RNHostView></VStack> : null}{selected ? <Image systemName="checkmark" size={fontSize} /> : null}- </HStack>+ </HStack>}</Button></Host>;}diff --git a/apps/mobile/src/components/LoginNativeButton.tsx b/apps/mobile/src/components/LoginNativeButton.tsxindex 9526abf0de..209bc8f274 100644--- a/apps/mobile/src/components/LoginNativeButton.tsx+++ b/apps/mobile/src/components/LoginNativeButton.tsx@@ -16,6 +16,8 @@ export interface LoginNativeButtonProps {subtitle?: string;children?: ReactNode;trailingArtwork?: ReactNode;+ /** Fixed-size React Native contents for rows with positioned icons and text. */+ content?: ReactNode;showLabel?: boolean;selected?: boolean;artworkSize?: number;diff --git a/apps/mobile/src/components/LoginSkinControls.tsx b/apps/mobile/src/components/LoginSkinControls.tsxindex 7f579bd4f9..076a0798fa 100644--- a/apps/mobile/src/components/LoginSkinControls.tsx+++ b/apps/mobile/src/components/LoginSkinControls.tsx@@ -1057,14 +1057,29 @@ export function LoginMethodRow({accessibilityLabel?: string;}) {const styles = useThemedStyles(makeStyles);- if (hasNativeLoginButtons) return <LoginNativeButton label={title} subtitle={subtitle}- accessibilityLabel={accessibilityLabel} showLabel artworkSize={LOGIN_METHOD_ROW.leftIcon.size}- trailingArtwork={<ShareIcon />}+ const rowContent = <View+ pointerEvents="none"+ style={[StyleSheet.absoluteFill, disabled && styles.disabledText]}+ >+ <View style={icon === 'person' ? styles.methodRowPersonIcon : styles.methodRowLeftIcon}>+ {icon === 'person' ? <PersonIcon /> : <EnterpriseIcon />}+ </View>+ <View style={styles.methodRowTextBox}>+ <Text+ numberOfLines={1}+ style={[styles.methodRowTitle, disabled && styles.methodRowDisabledTitle]}+ >+ {title}+ </Text>+ {subtitle != null ? <Text numberOfLines={1} style={styles.methodRowSubtitle}>{subtitle}</Text> : null}+ </View>+ <View style={styles.methodRowRightIcon}><ShareIcon /></View>+ </View>;+ if (hasNativeLoginButtons) return <LoginNativeButton label={title}+ accessibilityLabel={accessibilityLabel} content={rowContent}onPress={onPress} disabled={disabled} testID={testID}width={LOGIN_METHOD_ROW.width} height={LOGIN_METHOD_ROW.height} fontSize={LOGIN_METHOD_ROW.titleFont}- style={{ position: 'absolute', left: LOGIN_METHOD_ROW.x, top }}>- {icon === 'person' ? <PersonIcon /> : <EnterpriseIcon />}- </LoginNativeButton>;+ style={{ position: 'absolute', left: LOGIN_METHOD_ROW.x, top }} />;return (<PressableaccessibilityLabel={accessibilityLabel ?? title}@@ -1077,28 +1092,7 @@ export function LoginMethodRow({>{({ pressed }) => (<>- <View- style={- icon === 'person'- ? styles.methodRowPersonIcon- : styles.methodRowLeftIcon- }- >- {icon === 'person' ? <PersonIcon /> : <EnterpriseIcon />}- </View>- <View style={styles.methodRowTextBox}>- <Text numberOfLines={1} style={styles.methodRowTitle}>- {title}- </Text>- {subtitle != null ? (- <Text numberOfLines={1} style={styles.methodRowSubtitle}>- {subtitle}- </Text>- ) : null}- </View>- <View style={styles.methodRowRightIcon}>- <ShareIcon />- </View>+ {rowContent}<StateOverlaycornerRadius={LOGIN_METHOD_ROW.radius}pressed={pressed && !disabled}@@ -1659,6 +1653,9 @@ const makeStyles = (colors: ThemeColors) =>fontSize: LOGIN_METHOD_ROW.titleFont,fontWeight: fontWeight.bold,},+ methodRowDisabledTitle: {+ color: colors.login.secondaryText,+ },methodRowSubtitle: {color: colors.login.secondaryText,fontSize: LOGIN_METHOD_ROW.subtitleFont,diff --git a/docs/dev-rules/mobile-development.md b/docs/dev-rules/mobile-development.mdindex 6046ccbb68..da5861f184 100644--- a/docs/dev-rules/mobile-development.md+++ b/docs/dev-rules/mobile-development.md@@ -106,11 +106,13 @@ pnpm --filter mobile test:smoke### 中国大陆版微信个人登录-- 微信开放平台的移动应用配置修正并完成双平台真机验收前,iOS / Android 登录页暂时隐藏- 微信入口;开关位于 `src/auth/mobileSocialLoginMode.ts`,不移除原生 SDK 或构建配置,- 以便配置修正后恢复。此处仅改 JS 行为,不额外触发原生冷更。-- 复用 `xdt-wechat-login`:iOS/Android 拉起微信取临时 code,再由 auth-server 交换。- PC 使用同一服务端的网站应用扫码入口。登录结果统一进入手机号补绑或身份选择流程。+- 仅 iOS 中国大陆版登录页恢复微信入口;开关位于+ `src/auth/mobileSocialLoginMode.ts`。入口要求构建包含微信 AppID 与 Universal Link,+ 并由 OpenSDK 确认已安装微信;Global 与 Android 均不显示。开关只影响 JS 行为,+ 不额外触发原生冷更。+- iOS 复用 `xdt-wechat-login` 拉起微信取临时 code,再由 auth-server 交换;Android+ 原生能力保留,但本轮不显示入口。PC 使用同一服务端的网站应用扫码入口。登录结果+ 统一进入手机号补绑或身份选择流程。- 在 Mobile `.env`(本地)或打包机环境中成对填写`EXPO_PUBLIC_CINDY_WECHAT_APP_ID` 与 `EXPO_PUBLIC_CINDY_WECHAT_UNIVERSAL_LINK`,说明与空值占位见 `apps/mobile/.env.example`。AppID 必须匹配服务端@@ -122,11 +124,10 @@ pnpm --filter mobile test:smoke- iOS config plugin 按[微信官方接入说明](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html)生成 `weixin`、`weixinULAPI`、`weixinURLParamsAPI` 三项查询白名单,并保留 AppID URL Scheme与 Universal Link 的 Associated Domains。遗漏白名单需重建原生包,不能通过 JS 热更补齐。-- 恢复入口前真机验证 iOS Universal Link/AASA、Android 包名/签名与 WXEntryActivity,覆盖+- 真机验收需验证 iOS Universal Link/AASA,覆盖同意授权、取消、未安装微信、回到前台超时后重试。iOS Simulator 不支持微信授权。- 入口恢复后,iOS 登录页仅在 OpenSDK 确认已安装微信后显示微信入口;Android 保持入口- 可见,点击时再由原生桥确认微信是否可用。凭据获取前仍须二次检查安装状态,不能只依赖页面显隐。- 未绑手机号须短信验证,已绑用户免短信;用同一微信在 PC 和两种手机上确认账号一致。+ iOS 登录页在回到前台时重新检查安装状态;凭据获取前仍须二次检查,不能只依赖页面显隐。+ 未绑手机号须短信验证,已绑用户免短信;用同一微信在 PC 和 iPhone 上确认账号一致。- 微信 OpenSDK 的 `oauth` / `refreshToken` 回调会同时到达原生 delegate 与 Expo Router;Universal Link 校验还会回跳配置路径下的 `<AppID>/?_wechat_sdk_biz_data=…`,Router 可能