Skip to content

Commit

Permalink
Merge pull request #3617 from TrainLCD/fix/perf
Browse files Browse the repository at this point in the history
帰ってきた暴走対策
  • Loading branch information
TinyKitten authored Jul 26, 2024
2 parents 30767e2 + f50038a commit 6746bdc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
47 changes: 28 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
import 'fast-text-encoding'

import dayjs from 'dayjs'
import { registerRootComponent } from 'expo'
import * as Location from 'expo-location'
import * as TaskManager from 'expo-task-manager'
import App from './src'
import { useLocationStore } from './src/hooks/useLocationStore'
import { locationTaskName } from './src/utils/locationTaskName'
;(async () => {
await TaskManager.unregisterAllTasksAsync()

TaskManager.defineTask(locationTaskName, ({ data, error }) => {
if (error) {
console.error(error)
return
}
TaskManager.defineTask(locationTaskName, ({ data, error }) => {
if (error) {
console.error(error)
return
}

const curLocation = useLocationStore.getState().location
if (
curLocation?.coords.latitude === data.locations[0]?.coords.latitude &&
curLocation?.coords.longitude === data.locations[0]?.coords.longitude
) {
return
}

const curLocation = useLocationStore.getState().location
if (
curLocation?.coords.latitude === data.locations[0]?.coords.latitude &&
curLocation?.coords.longitude === data.locations[0]?.coords.longitude
) {
return
}
const now = dayjs()
const stateTimestamp = curLocation && dayjs(curLocation.timestamp)
if (stateTimestamp && now.diff(stateTimestamp, 'seconds') < 1) {
return
}

useLocationStore.setState((state) => ({
...state,
location: data.locations[0],
}))
})
useLocationStore.setState((state) => ({
...state,
location: data.locations[0],
}))
})
;(async () => {
await TaskManager.unregisterAllTasksAsync()
await Location.stopLocationUpdatesAsync(locationTaskName)
})()

// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
Expand Down
7 changes: 4 additions & 3 deletions src/constants/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const LOCATION_TASK_NAME_CANARY =
'trainlcd-canary-background-location-task'
// デフォルトの端末上の駅直線距離計算誤差(meter)
// 位置情報の処理間隔(meter)
export const DISTANCE_FILTER_LOW = 100
export const DISTANCE_FILTER_BALANCED = 10
export const DISTANCE_FILTER_HIGH = 1

export const DISTANCE_FILTER_LOW = 300
export const DISTANCE_FILTER_BALANCED = 150
export const DISTANCE_FILTER_HIGH = 100
1 change: 0 additions & 1 deletion src/hooks/useStartBackgroundLocationUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const useStartBackgroundLocationUpdates = () => {
accuracy: locationServiceAccuracy,
activityType: Location.LocationActivityType.OtherNavigation,
deferredUpdatesDistance: locationServiceDistanceFilter,
distanceInterval: 1,
foregroundService: {
notificationTitle: translate('bgAlertTitle'),
notificationBody: translate('bgAlertContent'),
Expand Down

0 comments on commit 6746bdc

Please sign in to comment.