-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
114 lines (101 loc) · 3.56 KB
/
Copy pathApp.js
File metadata and controls
114 lines (101 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { useEffect, useState } from 'react';
import { Alert, PermissionsAndroid, Platform } from 'react-native';
import { Provider as PaperProvider } from 'react-native-paper';
import { SafeAreaProvider } from 'react-native-safe-area-context';
// Import screens
import AdvancedScanScreen from './src/screens/AdvancedScanScreen';
import ManualEntryScreen from './src/screens/ManualEntryScreen';
import ServerDetectionScreen from './src/screens/ServerDetectionScreen';
import SettingsScreen from './src/screens/SettingsScreen';
import SplashScreen from './src/screens/SplashScreen';
import WrapperScreen from './src/screens/WrapperScreen';
// Import storage utils
import { getActiveServer, hasConfigured } from './src/utils/storage';
const Stack = createNativeStackNavigator();
// Material Design 3 Theme
const theme = {
colors: {
primary: '#6200ee',
accent: '#03dac6',
background: '#ffffff',
surface: '#ffffff',
error: '#b00020',
text: '#000000',
onSurface: '#000000',
disabled: '#00000061',
placeholder: '#00000061',
backdrop: '#00000050',
},
};
export default function App() {
const [isConfigured, setIsConfigured] = useState(false);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
requestPermissions();
checkConfiguration();
}, []);
const requestPermissions = async () => {
try {
if (Platform.OS === 'android') {
const granted = await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
// For Android 12+
PermissionsAndroid.PERMISSIONS.NEARBY_WIFI_DEVICES,
]);
const allGranted = Object.values(granted).every(
status => status === PermissionsAndroid.RESULTS.GRANTED
);
if (!allGranted) {
Alert.alert(
'Permissions Required',
'Wi-Fi scanning and local server access need location permissions!'
);
}
}
} catch (err) {
console.warn('Error requesting permissions:', err);
}
};
const checkConfiguration = async () => {
try {
const configured = await hasConfigured();
const activeServer = await getActiveServer();
setIsConfigured(configured && activeServer !== null);
setIsLoading(false);
} catch (error) {
console.error('Error checking configuration:', error);
setIsLoading(false);
}
};
if (isLoading) {
return (
<PaperProvider theme={theme}>
<SafeAreaProvider>
<SplashScreen />
</SafeAreaProvider>
</PaperProvider>
);
}
return (
<PaperProvider theme={theme}>
<SafeAreaProvider>
<NavigationContainer>
<Stack.Navigator
screenOptions={{ headerShown: false }}
initialRouteName={isConfigured ? 'Wrapper' : 'Splash'}
>
<Stack.Screen name="Splash" component={SplashScreen} />
<Stack.Screen name="ServerDetection" component={ServerDetectionScreen} />
<Stack.Screen name="AdvancedScan" component={AdvancedScanScreen} />
<Stack.Screen name="ManualEntry" component={ManualEntryScreen} />
<Stack.Screen name="Wrapper" component={WrapperScreen} />
<Stack.Screen name="Settings" component={SettingsScreen} />
</Stack.Navigator>
</NavigationContainer>
</SafeAreaProvider>
</PaperProvider>
);
}