feat: 添加获取当前分支信息的功能,并在界面上显示版本号和分支信息

This commit is contained in:
康猛 2026-02-04 15:35:57 +08:00
parent f6f46f518f
commit 43857594d2
1 changed files with 52 additions and 2 deletions

View File

@ -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<string>('unknown')
const countdownTimerRef = useRef<ReturnType<typeof setInterval> | 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() {
<Block className="mt-[24px] items-center">
<Text className="font-700 text-[12px] text-gray-400">© 2025 LOOMART. All rights reserved.</Text>
<Text className="font-700 text-[12px] text-gray-400">: {APP_VERSION}</Text>
<Text className="font-700 text-[12px] text-gray-400">
: {VERSION} - {APP_VERSION} - {currentBranch}
</Text>
</Block>
</Block>
</Block>