11import React , { useCallback , useEffect , useMemo , useState } from 'react' ;
2- import { StyleSheet , View , Switch , TextInput , ActivityIndicator , Platform , TouchableOpacity } from 'react-native' ;
2+ import { StyleSheet , View , Switch , TextInput , ActivityIndicator , Platform , TouchableOpacity , AppState } from 'react-native' ;
33import { BlueCard , BlueText } from '../../BlueComponents' ;
44import { useSettings } from '../../hooks/context/useSettings' ;
55import { useTheme } from '../../components/themes' ;
@@ -9,17 +9,16 @@ import { BlueSpacing20 } from '../../components/BlueSpacing';
99import TorManager , { type TorStatus } from '../../blue_modules/torManager' ;
1010import loc from '../../loc' ;
1111
12- const STATUS_LABELS : Record < TorStatus , string > = {
13- disabled : loc . settings . tor_status_disabled ,
14- checking : loc . settings . tor_status_checking ,
15- connected : loc . settings . tor_status_connected ,
16- unavailable : loc . settings . tor_status_unavailable ,
17- } ;
18-
1912const TorSettings : React . FC = ( ) => {
2013 const { colors } = useTheme ( ) ;
2114 const { isTorEnabled, setIsTorEnabled, isTorOnly, setIsTorOnly, torSocksPort, setTorSocksPort, torStatus, settingsInitialized } =
2215 useSettings ( ) ;
16+ const statusLabels : Record < TorStatus , string > = {
17+ disabled : loc . settings . tor_status_disabled ,
18+ checking : loc . settings . tor_status_checking ,
19+ connected : loc . settings . tor_status_connected ,
20+ unavailable : loc . settings . tor_status_unavailable ,
21+ } ;
2322 const [ portInput , setPortInput ] = useState ( String ( torSocksPort ) ) ;
2423 const [ orbotInstalled , setOrbotInstalled ] = useState < boolean | null > ( null ) ;
2524 const [ showAdvanced , setShowAdvanced ] = useState ( false ) ;
@@ -41,9 +40,16 @@ const TorSettings: React.FC = () => {
4140 ) ;
4241
4342 useEffect ( ( ) => {
44- TorManager . isOrbotInstalled ( )
45- . then ( setOrbotInstalled )
46- . catch ( ( ) => setOrbotInstalled ( null ) ) ;
43+ const check = ( ) => {
44+ TorManager . isOrbotInstalled ( )
45+ . then ( setOrbotInstalled )
46+ . catch ( ( ) => setOrbotInstalled ( null ) ) ;
47+ } ;
48+ check ( ) ;
49+ const sub = AppState . addEventListener ( 'change' , state => {
50+ if ( state === 'active' ) check ( ) ;
51+ } ) ;
52+ return ( ) => sub . remove ( ) ;
4753 } , [ ] ) ;
4854
4955 useEffect ( ( ) => {
@@ -146,7 +152,7 @@ const TorSettings: React.FC = () => {
146152
147153 < View style = { styles . statusRow } >
148154 < BlueText > { loc . settings . tor_status_label } </ BlueText >
149- < BlueText style = { [ styles . statusValue , { color : statusColors [ torStatus ] } ] } > { STATUS_LABELS [ torStatus ] } </ BlueText >
155+ < BlueText style = { [ styles . statusValue , { color : statusColors [ torStatus ] } ] } > { statusLabels [ torStatus ] } </ BlueText >
150156 { torStatus === 'checking' && < ActivityIndicator size = "small" style = { styles . spinner } /> }
151157 </ View >
152158
0 commit comments