()
| 52 | } |
| 53 | |
| 54 | function AppContent() { |
| 55 | const safeAreaInsets = useSafeAreaInsets(); |
| 56 | const isDarkMode = useColorScheme() === 'dark'; |
| 57 | const [trackingEnabled, setTrackingEnabled] = useState(false); |
| 58 | const [isMoving, setIsMoving] = useState(false); |
| 59 | const [currentActivity, setCurrentActivity] = useState('unknown'); |
| 60 | const [lastLocation, setLastLocation] = useState<Location | null>(null); |
| 61 | const [providerEnabled, setProviderEnabled] = useState(false); |
| 62 | const [menuVisible, setMenuVisible] = useState(false); |
| 63 | const [registrationVisible, setRegistrationVisible] = useState(false); |
| 64 | const [odometer, setOdometer] = useState(0); |
| 65 | const [odometerError, setOdometerError] = useState<number | null>(null); |
| 66 | const [isInitialized, setIsInitialized] = useState(false); |
| 67 | const [emailDialogVisible, setEmailDialogVisible] = useState(false); |
| 68 | const [emailInput, setEmailInput] = useState(''); |
| 69 | |
| 70 | // Check registration status on mount |
| 71 | useEffect(() => { |
| 72 | checkRegistrationAndInitialize(); |
| 73 | }, []); |
| 74 | |
| 75 | const checkRegistrationAndInitialize = async () => { |
| 76 | try { |
| 77 | // Check if user has registered before |
| 78 | const registered = await AsyncStorage.getItem('@transistor_registered'); |
| 79 | |
| 80 | if (!registered) { |
| 81 | // First launch - show registration modal |
| 82 | setRegistrationVisible(true); |
| 83 | } else { |
| 84 | // Already registered - initialize BackgroundGeolocation |
| 85 | const org = await AsyncStorage.getItem('@transistor_org'); |
| 86 | const username = await AsyncStorage.getItem('@transistor_username'); |
| 87 | |
| 88 | if (org && username) { |
| 89 | await initializeBackgroundGeolocation(org, username); |
| 90 | } else { |
| 91 | // Corrupted storage - re-register |
| 92 | setRegistrationVisible(true); |
| 93 | } |
| 94 | } |
| 95 | } catch (error) { |
| 96 | console.error('Error checking registration:', error); |
| 97 | setRegistrationVisible(true); |
| 98 | } |
| 99 | }; |
| 100 | |
| 101 | const initializeBackgroundGeolocation = async (org: string, username: string) => { |
| 102 | if (isInitialized) return; // Prevent double initialization |
| 103 | |
| 104 | // Poke a custom log message into SDK logs. |
| 105 | BackgroundGeolocation.logger.debug("INITIALIZING BACKGROUND GEOLOCATION"); |
| 106 | |
| 107 | try { |
| 108 | // Get or create demo server (tracker.transistorsoft.com) token with the registered credentials |
| 109 | const token = await BackgroundGeolocation.findOrCreateTransistorAuthorizationToken(org, username); |
| 110 | |
| 111 | const state = await BackgroundGeolocation.ready({ |
nothing calls this directly
no test coverage detected