Compare commits
No commits in common. "76643fcc624219bd48f31f81f73423ca67f838b2" and "0f16edd8cc4553550c185f87f21f8bcc36649e71" have entirely different histories.
76643fcc62
...
0f16edd8cc
@ -9,7 +9,6 @@
|
|||||||
"userInterfaceStyle": "automatic",
|
"userInterfaceStyle": "automatic",
|
||||||
"newArchEnabled": true,
|
"newArchEnabled": true,
|
||||||
"ios": {
|
"ios": {
|
||||||
"bundleIdentifier": "traintrapemoi",
|
|
||||||
"supportsTablet": true
|
"supportsTablet": true
|
||||||
},
|
},
|
||||||
"android": {
|
"android": {
|
||||||
@ -41,6 +40,7 @@
|
|||||||
"favicon": "./assets/images/favicon.png"
|
"favicon": "./assets/images/favicon.png"
|
||||||
},
|
},
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
"expo-background-fetch",
|
||||||
[
|
[
|
||||||
"expo-location",
|
"expo-location",
|
||||||
{
|
{
|
||||||
@ -52,7 +52,6 @@
|
|||||||
"expo-notifications",
|
"expo-notifications",
|
||||||
"expo-router",
|
"expo-router",
|
||||||
"expo-secure-store",
|
"expo-secure-store",
|
||||||
"expo-share-extension",
|
|
||||||
[
|
[
|
||||||
"expo-splash-screen",
|
"expo-splash-screen",
|
||||||
{
|
{
|
||||||
|
@ -11,6 +11,7 @@ import { useReactNavigationDevTools } from '@dev-plugins/react-navigation'
|
|||||||
import { useReactQueryDevTools } from '@dev-plugins/react-query'
|
import { useReactQueryDevTools } from '@dev-plugins/react-query'
|
||||||
import { useColorScheme } from '@/hooks/useColorScheme'
|
import { useColorScheme } from '@/hooks/useColorScheme'
|
||||||
import store from '@/utils/store'
|
import store from '@/utils/store'
|
||||||
|
import { useStartBackgroundFetchServiceEffect } from '@/utils/background'
|
||||||
import LoginProvider from '@/components/LoginProvider'
|
import LoginProvider from '@/components/LoginProvider'
|
||||||
import GeolocationProvider from '@/components/GeolocationProvider'
|
import GeolocationProvider from '@/components/GeolocationProvider'
|
||||||
import GameProvider from '@/components/GameProvider'
|
import GameProvider from '@/components/GameProvider'
|
||||||
@ -26,6 +27,7 @@ const queryClient = new QueryClient({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export default function RootLayout() {
|
export default function RootLayout() {
|
||||||
|
useStartBackgroundFetchServiceEffect()
|
||||||
const colorScheme = useColorScheme()
|
const colorScheme = useColorScheme()
|
||||||
|
|
||||||
const navigationRef = useNavigationContainerRef()
|
const navigationRef = useNavigationContainerRef()
|
||||||
|
@ -16,18 +16,19 @@ export default function GeolocationProvider({ children }: { children: ReactNode
|
|||||||
const setLastPlayerLocations = useSetLastPlayerLocations()
|
const setLastPlayerLocations = useSetLastPlayerLocations()
|
||||||
const geolocationMutation = useGeolocationMutation({
|
const geolocationMutation = useGeolocationMutation({
|
||||||
auth,
|
auth,
|
||||||
onPostSuccess: (data) => unqueueLocation(data),
|
onPostSuccess: (data) => {
|
||||||
|
unqueueLocation(data)
|
||||||
|
geolocationMutation.reset()
|
||||||
|
},
|
||||||
onError: ({ response, error }) => { console.error(response, error) }
|
onError: ({ response, error }) => { console.error(response, error) }
|
||||||
})
|
})
|
||||||
|
|
||||||
if (Platform.OS !== "web") {
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (geolocationsQueue.length === 0 || geolocationMutation.isPending || isAuthValid(auth))
|
if (geolocationsQueue.length === 0 || geolocationMutation.isPending || Platform.OS === "web")
|
||||||
return
|
return
|
||||||
const locToSend = geolocationsQueue[0]
|
const locToSend = geolocationsQueue[0]
|
||||||
geolocationMutation.mutate(locToSend)
|
geolocationMutation.mutate(locToSend)
|
||||||
}, [auth, geolocationMutation.status, geolocationsQueue])
|
}, [auth, geolocationsQueue])
|
||||||
}
|
|
||||||
|
|
||||||
const lastLocationsQuery = useQuery({
|
const lastLocationsQuery = useQuery({
|
||||||
queryKey: ['get-last-locations', auth.token],
|
queryKey: ['get-last-locations', auth.token],
|
||||||
|
1620
client/package-lock.json
generated
1620
client/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -4,8 +4,8 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "expo start",
|
"start": "expo start",
|
||||||
"android": "expo run:android",
|
"android": "expo start --android",
|
||||||
"ios": "expo run:ios",
|
"ios": "expo start --ios",
|
||||||
"web": "expo start --web",
|
"web": "expo start --web",
|
||||||
"test": "jest --watchAll",
|
"test": "jest --watchAll",
|
||||||
"lint": "expo lint"
|
"lint": "expo lint"
|
||||||
@ -17,7 +17,8 @@
|
|||||||
"@dev-plugins/react-navigation": "^0.1.0",
|
"@dev-plugins/react-navigation": "^0.1.0",
|
||||||
"@dev-plugins/react-query": "^0.1.0",
|
"@dev-plugins/react-query": "^0.1.0",
|
||||||
"@expo/vector-icons": "^14.0.2",
|
"@expo/vector-icons": "^14.0.2",
|
||||||
"@maplibre/maplibre-react-native": "^10.0.0-beta.8",
|
"@maplibre/maplibre-react-native": "^10.0.0-alpha.28",
|
||||||
|
"@pchmn/expo-material3-theme": "github:pchmn/expo-material3-theme",
|
||||||
"@react-native-async-storage/async-storage": "1.23.1",
|
"@react-native-async-storage/async-storage": "1.23.1",
|
||||||
"@react-navigation/bottom-tabs": "^7.0.0",
|
"@react-navigation/bottom-tabs": "^7.0.0",
|
||||||
"@react-navigation/native": "^7.0.0",
|
"@react-navigation/native": "^7.0.0",
|
||||||
@ -27,6 +28,7 @@
|
|||||||
"@tanstack/react-query-persist-client": "^5.62.7",
|
"@tanstack/react-query-persist-client": "^5.62.7",
|
||||||
"@turf/circle": "^7.1.0",
|
"@turf/circle": "^7.1.0",
|
||||||
"expo": "~52.0.11",
|
"expo": "~52.0.11",
|
||||||
|
"expo-background-fetch": "~13.0.3",
|
||||||
"expo-blur": "~14.0.1",
|
"expo-blur": "~14.0.1",
|
||||||
"expo-constants": "~17.0.3",
|
"expo-constants": "~17.0.3",
|
||||||
"expo-dev-client": "~5.0.4",
|
"expo-dev-client": "~5.0.4",
|
||||||
@ -37,7 +39,6 @@
|
|||||||
"expo-notifications": "~0.29.11",
|
"expo-notifications": "~0.29.11",
|
||||||
"expo-router": "~4.0.9",
|
"expo-router": "~4.0.9",
|
||||||
"expo-secure-store": "~14.0.0",
|
"expo-secure-store": "~14.0.0",
|
||||||
"expo-share-extension": "^2.0.1",
|
|
||||||
"expo-splash-screen": "~0.29.13",
|
"expo-splash-screen": "~0.29.13",
|
||||||
"expo-status-bar": "~2.0.0",
|
"expo-status-bar": "~2.0.0",
|
||||||
"expo-symbols": "~0.2.0",
|
"expo-symbols": "~0.2.0",
|
||||||
|
40
client/utils/background.ts
Normal file
40
client/utils/background.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import * as BackgroundFetch from 'expo-background-fetch'
|
||||||
|
import * as TaskManager from 'expo-task-manager'
|
||||||
|
import { Platform } from 'react-native'
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
|
||||||
|
const BACKGROUND_FETCH_TASK = "background-fetch"
|
||||||
|
const BACKGROUND_FETCH_INTERVAL = 60000
|
||||||
|
|
||||||
|
async function backgroundUpdate() {
|
||||||
|
const now = Date.now()
|
||||||
|
console.log(`Got background fetch call at date: ${new Date(now).toISOString()}`)
|
||||||
|
// Be sure to return the successful result type!
|
||||||
|
return BackgroundFetch.BackgroundFetchResult.NewData
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskManager.defineTask(BACKGROUND_FETCH_TASK, backgroundUpdate)
|
||||||
|
|
||||||
|
export async function startBackgroundFetchService(): Promise<void | (() => void)> {
|
||||||
|
if (Platform.OS === "web") {
|
||||||
|
const interval = setInterval(backgroundUpdate, BACKGROUND_FETCH_INTERVAL)
|
||||||
|
return () => clearInterval(interval)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (await TaskManager.isTaskRegisteredAsync(BACKGROUND_FETCH_TASK))
|
||||||
|
return async () => await BackgroundFetch.unregisterTaskAsync(BACKGROUND_FETCH_TASK)
|
||||||
|
|
||||||
|
await BackgroundFetch.registerTaskAsync(BACKGROUND_FETCH_TASK, {
|
||||||
|
minimumInterval: BACKGROUND_FETCH_INTERVAL,
|
||||||
|
stopOnTerminate: false,
|
||||||
|
startOnBoot: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
return async () => await BackgroundFetch.unregisterTaskAsync(BACKGROUND_FETCH_TASK)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useStartBackgroundFetchServiceEffect = () => useEffect(() => {
|
||||||
|
let cleanup: void | (() => void) = () => {}
|
||||||
|
startBackgroundFetchService().then(result => cleanup = result)
|
||||||
|
return cleanup
|
||||||
|
}, [])
|
Loading…
x
Reference in New Issue
Block a user