11import type { NavigationProp , ParamListBase } from '@react-navigation/native' ;
22import { useNavigation } from '@react-navigation/native' ;
3+ import packageJson from '@root/package.json' ;
34
45import type { FC } from 'react' ;
56import { useMemo , useCallback , useState } from 'react' ;
67import { useTranslation } from 'react-i18next' ;
78import { ScrollView } from 'react-native' ;
89import { Box } from 'react-native-flex-layout' ;
9- import { Badge , List , useTheme } from 'react-native-paper' ;
10+ import { Badge , List , Text , useTheme } from 'react-native-paper' ;
11+ import { useDispatch } from 'react-redux' ;
12+
13+ import { setDebugEnabled } from '@/slices/settings' ;
1014
1115import ChangeLanguageModal from '@/components/modals/ChangeLanguageModal' ;
1216import ChangeThemeModal from '@/components/modals/ChangeThemeModal' ;
1317
1418import useDtuState from '@/hooks/useDtuState' ;
1519import useHasNewAppVersion from '@/hooks/useHasNewAppVersion' ;
1620import useIsConnected from '@/hooks/useIsConnected' ;
21+ import useRequireMultiplePresses from '@/hooks/useRequireMultiplePresses' ;
22+ import useSettings from '@/hooks/useSettings' ;
1723
1824import { StyledSafeAreaView } from '@/style' ;
1925
2026const MainSettingsTab : FC = ( ) => {
2127 const navigation = useNavigation ( ) as NavigationProp < ParamListBase > ;
2228 const { t } = useTranslation ( ) ;
29+ const dispatch = useDispatch ( ) ;
2330
2431 const theme = useTheme ( ) ;
2532
@@ -40,6 +47,8 @@ const MainSettingsTab: FC = () => {
4047 usedForIndicatorOnly : true ,
4148 } ) ;
4249
50+ const showDebugScreen = useSettings ( state => state ?. debugEnabled ) ;
51+
4352 const hasSystemInformation = ! ! useDtuState ( state => ! ! state ?. systemStatus ) ;
4453 const hasNetworkInformation = ! ! useDtuState ( state => ! ! state ?. networkStatus ) ;
4554 const hasNtpInformation = ! ! useDtuState ( state => ! ! state ?. ntpStatus ) ;
@@ -86,6 +95,15 @@ const MainSettingsTab: FC = () => {
8695 navigation . navigate ( 'MqttInformationScreen' ) ;
8796 } , [ navigation ] ) ;
8897
98+ const handleDebugScreen = useCallback ( ( ) => {
99+ navigation . navigate ( 'DebugScreen' ) ;
100+ } , [ navigation ] ) ;
101+
102+ const enableDebugMode = useCallback ( ( ) => {
103+ dispatch ( setDebugEnabled ( { debugEnabled : true } ) ) ;
104+ } , [ dispatch ] ) ;
105+ const handleUnlockDebug = useRequireMultiplePresses ( enableDebugMode ) ;
106+
89107 return (
90108 < StyledSafeAreaView theme = { theme } >
91109 < Box style = { { width : '100%' , flex : 1 } } >
@@ -158,7 +176,17 @@ const MainSettingsTab: FC = () => {
158176 left = { props => < List . Icon { ...props } icon = "file-document" /> }
159177 onPress = { handleLicenses }
160178 />
179+ { showDebugScreen ? (
180+ < List . Item
181+ title = { t ( 'settings.debug' ) }
182+ left = { props => < List . Icon { ...props } icon = "bug" /> }
183+ onPress = { handleDebugScreen }
184+ />
185+ ) : null }
161186 </ List . Section >
187+ < Text style = { { textAlign : 'center' } } onPress = { handleUnlockDebug } >
188+ { t ( 'version' ) } { packageJson . version }
189+ </ Text >
162190 </ ScrollView >
163191 </ Box >
164192 < ChangeThemeModal
0 commit comments