@@ -24,8 +24,6 @@ import QRCode from 'react-native-qrcode-svg';
2424import { useDevConnectionConfig } from '@/hooks/useDevConnectionConfig' ;
2525import { createConfigApiClient , type CoreConfig , type ApiProvider } from '@/services/api/config' ;
2626import { useColorScheme } from '@/hooks/use-color-scheme' ;
27- import { changeLanguage , SUPPORTED_LANGUAGES } from '@/i18n' ;
28-
2927// Icons as text
3028const Icons = {
3129 back : '←' ,
@@ -86,9 +84,10 @@ const DARK = {
8684
8785export default function SettingsScreen ( ) {
8886 const router = useRouter ( ) ;
89- const { config } = useDevConnectionConfig ( ) ;
87+ const { config, isLoaded } = useDevConnectionConfig ( ) ;
9088 const apiBase = `http://${ config . host } :${ config . port } ` ;
91- const { t, i18n } = useTranslation ( ) ;
89+ const p2pToken = config . p2p ?. token ;
90+ const { t } = useTranslation ( ) ;
9291
9392 const colorScheme = useColorScheme ( ) ;
9493 const isDark = colorScheme === 'dark' ;
@@ -124,7 +123,7 @@ export default function SettingsScreen() {
124123 setLoading ( true ) ;
125124 setError ( null ) ;
126125
127- const client = createConfigApiClient ( apiBase ) ;
126+ const client = createConfigApiClient ( apiBase , p2pToken ) ;
128127 const [ configData , providersData ] = await Promise . all ( [
129128 client . getCoreConfig ( ) ,
130129 client . getApiProviders ( ) ,
@@ -142,9 +141,10 @@ export default function SettingsScreen() {
142141 } , [ apiBase ] ) ;
143142
144143 useEffect ( ( ) => {
144+ if ( ! isLoaded ) return ;
145145 loadConfig ( ) ;
146146 loadP2PConfig ( ) ;
147- } , [ loadConfig , loadP2PConfig ] ) ;
147+ } , [ isLoaded , loadConfig , loadP2PConfig ] ) ;
148148
149149 // Save config
150150 const handleSave = useCallback ( async ( ) => {
@@ -153,7 +153,7 @@ export default function SettingsScreen() {
153153 setError ( null ) ;
154154 setSuccess ( null ) ;
155155
156- const client = createConfigApiClient ( apiBase ) ;
156+ const client = createConfigApiClient ( apiBase , p2pToken ) ;
157157 const result = await client . updateCoreConfig ( coreConfig ) ;
158158
159159 if ( result . success ) {
@@ -221,45 +221,6 @@ export default function SettingsScreen() {
221221 style = { styles . content }
222222 refreshControl = { < RefreshControl refreshing = { loading } onRefresh = { loadConfig } /> }
223223 >
224- { /* Language Section */ }
225- < View style = { styles . section } >
226- < View style = { styles . sectionHeader } >
227- < Text style = { styles . sectionIcon } > 🌐</ Text >
228- < Text style = { [ styles . sectionTitle , { color : theme . sectionTitle } ] } > { t ( 'settings.sections.language' ) } </ Text >
229- </ View >
230- < View style = { [ styles . card , { backgroundColor : theme . card } ] } >
231- < View style = { styles . field } >
232- < Text style = { [ styles . label , { color : theme . textLabel } ] } > { t ( 'settings.language.select' ) } </ Text >
233- < View style = { styles . pickerContainer } >
234- { SUPPORTED_LANGUAGES . map ( ( lang ) => (
235- < TouchableOpacity
236- key = { lang . code }
237- style = { [
238- styles . pickerOption ,
239- { backgroundColor : theme . pickerOptionBg , borderColor : theme . pickerOptionBorder } ,
240- i18n . language === lang . code && { backgroundColor : theme . accent , borderColor : theme . accent } ,
241- ] }
242- onPress = { ( ) => changeLanguage ( lang . code ) }
243- >
244- < Text
245- style = { [
246- styles . pickerOptionText ,
247- { color : theme . textPrimary } ,
248- i18n . language === lang . code && { color : theme . accentText , fontWeight : 'bold' } ,
249- ] }
250- >
251- { t ( `settings.language.languages.${ lang . code } ` ) }
252- </ Text >
253- { i18n . language === lang . code && (
254- < Text style = { styles . checkmark } > { Icons . check } </ Text >
255- ) }
256- </ TouchableOpacity >
257- ) ) }
258- </ View >
259- </ View >
260- </ View >
261- </ View >
262-
263224 { /* Core API Section */ }
264225 < View style = { styles . section } >
265226 < View style = { styles . sectionHeader } >
@@ -428,7 +389,27 @@ export default function SettingsScreen() {
428389 < Text style = { styles . sectionIcon } > 📱</ Text >
429390 < Text style = { [ styles . sectionTitle , { color : theme . sectionTitle } ] } > { t ( 'settings.sections.p2p' ) } </ Text >
430391 </ View >
431- < View style = { [ styles . card , { backgroundColor : theme . card , alignItems : 'center' } ] } >
392+ < View style = { [ styles . card , { backgroundColor : theme . card } ] } >
393+ { /* 说明文字 */ }
394+ < Text style = { [ styles . qrDesc , { color : theme . textLabel } ] } >
395+ { t ( 'settings.p2p.desc' ) }
396+ </ Text >
397+
398+ { /* 步骤 */ }
399+ < View style = { [ styles . qrSteps , { borderColor : theme . inputBorder } ] } >
400+ { ( [ 'step1' , 'step2' , 'step3' ] as const ) . map ( ( key , i ) => (
401+ < View key = { key } style = { styles . qrStepRow } >
402+ < View style = { [ styles . qrStepNum , { backgroundColor : theme . accent } ] } >
403+ < Text style = { styles . qrStepNumText } > { i + 1 } </ Text >
404+ </ View >
405+ < Text style = { [ styles . qrStepText , { color : theme . textLabel } ] } >
406+ { t ( `settings.p2p.${ key } ` ) }
407+ </ Text >
408+ </ View >
409+ ) ) }
410+ </ View >
411+
412+ { /* 二维码 */ }
432413 < View style = { styles . qrContainer } >
433414 < QRCode
434415 value = { JSON . stringify ( p2pConfig ) }
@@ -437,13 +418,19 @@ export default function SettingsScreen() {
437418 backgroundColor = { isDark ? '#1a1a2e' : '#f0f8ff' }
438419 />
439420 </ View >
440- < Text style = { [ styles . qrHint , { color : theme . textMuted } ] } >
441- Scan with N.E.K.O. RN App to connect
442- </ Text >
443- < View style = { styles . p2pInfo } >
444- < Text style = { [ styles . p2pInfoText , { color : theme . textMuted } ] } >
445- UDP: { p2pConfig . port } | TCP: { p2pConfig . tcp_port }
446- </ Text >
421+
422+ { /* 连接参数 */ }
423+ < View style = { [ styles . qrInfoBlock , { borderColor : theme . inputBorder } ] } >
424+ { [
425+ { label : t ( 'settings.p2p.lanIp' ) , value : p2pConfig . lan_ip || '--' } ,
426+ { label : t ( 'settings.p2p.port' ) , value : String ( p2pConfig . port || '--' ) } ,
427+ { label : t ( 'settings.p2p.token' ) , value : t ( 'settings.p2p.tokenHidden' ) } ,
428+ ] . map ( ( { label, value } ) => (
429+ < View key = { label } style = { [ styles . qrInfoRow , { borderBottomColor : theme . inputBorder } ] } >
430+ < Text style = { [ styles . qrInfoLabel , { color : theme . textMuted } ] } > { label } </ Text >
431+ < Text style = { [ styles . qrInfoValue , { color : theme . textLabel } ] } > { value } </ Text >
432+ </ View >
433+ ) ) }
447434 </ View >
448435 </ View >
449436 </ View >
0 commit comments