-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
107 lines (95 loc) · 3.11 KB
/
Copy pathApp.tsx
File metadata and controls
107 lines (95 loc) · 3.11 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
import { useEffect, useState, useRef } from 'react';
import { View, Text, StyleSheet, Alert, AppState } from 'react-native';
import { StatusBar } from 'expo-status-bar';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import AsyncStorage from '@react-native-async-storage/async-storage';
import * as Linking from 'expo-linking';
import { AppNavigator } from './src/navigation/AppNavigator';
import { initDB } from './src/lib/storage';
import { Theme } from './src/theme';
import { handleIngestionUrl } from './src/lib/ingestion';
export default function App() {
const [isReady, setIsReady] = useState(false);
const [initialRoute, setInitialRoute] = useState<'Onboarding' | 'MainTabs'>('Onboarding');
const url = Linking.useURL();
const processedUrlRef = useRef<string | null>(null);
useEffect(() => {
console.log('[App] App component mounted');
}, []);
useEffect(() => {
const processUrl = async (currentUrl: string | null) => {
console.log('[App] processUrl triggered with:', currentUrl);
if (!currentUrl) return;
if (processedUrlRef.current === currentUrl) {
console.log('[App] URL already processed in this session, skipping to prevent duplicate alerts.');
return;
}
processedUrlRef.current = currentUrl;
const result = await handleIngestionUrl(currentUrl);
console.log('[App] handleIngestionUrl returned:', result?.isFlagged);
if (result) {
if (result.isFlagged) {
Alert.alert(
"Sentinel Alert",
`Suspicious ${result.sourceType} detected and saved to Vault.\nReason: ${result.reasons[0] || 'Unknown'}`,
[{ text: "OK", style: "default" }]
);
} else {
Alert.alert(
"Sentinel Scan Complete",
`A safe ${result.sourceType} was scanned successfully.`,
[{ text: "OK", style: "default" }]
);
}
} else {
console.log('[App] No valid result returned from handleIngestionUrl.');
}
};
if (isReady && url) {
console.log('[App] isReady && useURL hook resolved:', url);
processUrl(url);
}
}, [url, isReady]);
useEffect(() => {
async function prepare() {
try {
await initDB();
const flag = await AsyncStorage.getItem('hasCompletedOnboarding');
if (flag === 'true') {
setInitialRoute('MainTabs');
}
} catch (e) {
console.warn('Init error:', e);
} finally {
setIsReady(true);
}
}
prepare();
}, []);
if (!isReady) {
return (
<View style={styles.loadingContainer}>
<Text style={styles.loadingText}>Starting Sentinel...</Text>
</View>
);
}
return (
<SafeAreaProvider>
<AppNavigator initialRouteName={initialRoute} />
<StatusBar style="dark" />
</SafeAreaProvider>
);
}
const styles = StyleSheet.create({
loadingContainer: {
flex: 1,
backgroundColor: Theme.colors.background,
justifyContent: 'center',
alignItems: 'center',
},
loadingText: {
fontSize: 16,
fontWeight: '600',
color: Theme.colors.primary,
}
});