diff --git a/app/auth.tsx b/app/auth.tsx index a2c8d22..7955413 100644 --- a/app/auth.tsx +++ b/app/auth.tsx @@ -1,11 +1,12 @@ import { Ionicons } from '@expo/vector-icons' import { Block, Input, Text, Toast } from '@share/components' import { router } from 'expo-router' +import * as Updates from 'expo-updates' import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { TextInput } from 'react-native' import { KeyboardAwareScrollView } from 'react-native-keyboard-controller' -import { APP_VERSION } from '@/app.config' +import { APP_VERSION, VERSION } from '@/app.config' import BannerSection from '@/components/BannerSection' import { getSession, phoneNumber, setAuthToken, signIn } from '@/lib/auth' import { isValidPhone } from '@/utils' @@ -29,8 +30,55 @@ export default function Auth() { const [loading, setLoading] = useState(false) const [countdown, setCountdown] = useState(0) const [agreed, setAgreed] = useState(false) + const [currentBranch, setCurrentBranch] = useState('unknown') const countdownTimerRef = useRef | null>(null) + // 获取当前分支信息 + useEffect(() => { + const getBranchInfo = async () => { + try { + if (!Updates.isEnabled) { + setCurrentBranch('development') + return + } + + // 方法1: 使用 Updates.manifest (同步) + const manifest = Updates.manifest + + // 方法2: 或者尝试从更新中获取 + let branch = 'production' // 默认值 + + if (manifest?.extra?.eas?.branch) { + branch = manifest.extra.eas.branch + } else if (manifest?.metadata?.branchName) { + branch = manifest.metadata.branchName + } else if (Updates.channel) { + branch = Updates.channel + } + + // 方法3: 尝试获取当前运行的更新信息 + try { + const currentlyRunning = await Updates.fetchUpdateAsync() + if (currentlyRunning.manifest?.extra?.eas?.branch) { + branch = currentlyRunning.manifest.extra.eas.branch + } + } catch (e) { + console.log('Failed to fetch current update:', e) + } + + setCurrentBranch(branch) + console.log('Current branch:', branch) + console.log('Updates.channel:', Updates.channel) + console.log('Manifest:', manifest) + } catch (error) { + console.warn('Failed to get branch info:', error) + setCurrentBranch('unknown') + } + } + + getBranchInfo() + }, []) + const canSendCode = useMemo(() => { return isValidPhone(phone) && countdown === 0 }, [phone, countdown]) @@ -451,7 +499,9 @@ export default function Auth() { © 2025 LOOMART. All rights reserved. - 当前版本号: {APP_VERSION} + + 版本号: {VERSION} - {APP_VERSION} - {currentBranch} +