From 561c74042a3541653e5178f2b24d5315dca41092 Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Sun, 28 Jul 2024 08:21:17 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E6=83=85=E5=A0=B1?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=9D=A1=E4=BB=B6=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index b83c6819c..059fa1693 100644 --- a/index.js +++ b/index.js @@ -15,6 +15,8 @@ TaskManager.defineTask(locationTaskName, ({ data, error }) => { } const curLocation = useLocationStore.getState().location + const setLocation = useLocationStore.getState().setLocation + if ( curLocation?.coords.latitude === data.locations[0]?.coords.latitude && curLocation?.coords.longitude === data.locations[0]?.coords.longitude @@ -22,18 +24,16 @@ TaskManager.defineTask(locationTaskName, ({ data, error }) => { return BackgroundFetchResult.NoData } - const now = dayjs() + const receivedTimestamp = + data.locations[0] && dayjs(data.locations[0].timestamp) const stateTimestamp = curLocation && dayjs(curLocation.timestamp) const diffSeconds = - (stateTimestamp && now.diff(stateTimestamp, 'seconds')) ?? 0 + (stateTimestamp && receivedTimestamp.diff(stateTimestamp, 'seconds')) ?? 0 if (diffSeconds < 1) { return BackgroundFetchResult.NoData } - useLocationStore.setState((state) => ({ - ...state, - location: data.locations[0], - })) + setLocation(data.locations[0]) return BackgroundFetchResult.NewData }) From a58775ea25808ad0105c83b775be1c0e72fe6014 Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Sun, 28 Jul 2024 13:32:43 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E5=80=A4?= =?UTF-8?q?=E3=81=AF=E5=8F=96=E3=82=89=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 059fa1693..f2320d1a3 100644 --- a/index.js +++ b/index.js @@ -14,24 +14,24 @@ TaskManager.defineTask(locationTaskName, ({ data, error }) => { return BackgroundFetchResult.Failed } - const curLocation = useLocationStore.getState().location + const stateLat = useLocationStore.getState().location?.coords.latitude + const stateLon = useLocationStore.getState().location?.coords.longitude + const stateTimestamp = useLocationStore.getState().location?.timestamp const setLocation = useLocationStore.getState().setLocation if ( - curLocation?.coords.latitude === data.locations[0]?.coords.latitude && - curLocation?.coords.longitude === data.locations[0]?.coords.longitude + stateLat === data.locations[0]?.coords.latitude && + stateLon === data.locations[0]?.coords.longitude ) { return BackgroundFetchResult.NoData } const receivedTimestamp = data.locations[0] && dayjs(data.locations[0].timestamp) - const stateTimestamp = curLocation && dayjs(curLocation.timestamp) const diffSeconds = - (stateTimestamp && receivedTimestamp.diff(stateTimestamp, 'seconds')) ?? 0 - if (diffSeconds < 1) { - return BackgroundFetchResult.NoData - } + stateTimestamp && receivedTimestamp.diff(stateTimestamp, 'seconds') + if (!diffSeconds) return BackgroundFetchResult.NoData + if (diffSeconds < 1) return BackgroundFetchResult.NoData setLocation(data.locations[0]) From 0e09049496080fac3852b73de0871012136ebd19 Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Sun, 28 Jul 2024 13:33:01 +0900 Subject: [PATCH 3/5] =?UTF-8?q?activityType=E4=B8=8D=E8=A6=81=E8=AA=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useStartBackgroundLocationUpdates.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hooks/useStartBackgroundLocationUpdates.ts b/src/hooks/useStartBackgroundLocationUpdates.ts index bb3684aa3..6821c4f0b 100644 --- a/src/hooks/useStartBackgroundLocationUpdates.ts +++ b/src/hooks/useStartBackgroundLocationUpdates.ts @@ -22,7 +22,6 @@ export const useStartBackgroundLocationUpdates = () => { await Location.startLocationUpdatesAsync(locationTaskName, { accuracy: locationServiceAccuracy, - activityType: Location.LocationActivityType.OtherNavigation, foregroundService: { notificationTitle: translate('bgAlertTitle'), notificationBody: translate('bgAlertContent'), From 2ed7a52d0d79c9cc5bac0fdb147a9d8d69cd893e Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Sun, 28 Jul 2024 20:39:05 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=E9=9D=9E=E5=8A=B9=E7=8E=87=E3=81=AA?= =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=89=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useAnonymousUser.ts | 12 ++++++------ src/hooks/useTTS.ts | 26 ++++---------------------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/hooks/useAnonymousUser.ts b/src/hooks/useAnonymousUser.ts index 9d76c4db3..95ac51cc2 100644 --- a/src/hooks/useAnonymousUser.ts +++ b/src/hooks/useAnonymousUser.ts @@ -1,26 +1,26 @@ import type { FirebaseAuthTypes } from '@react-native-firebase/auth' import auth from '@react-native-firebase/auth' -import { useEffect, useState } from 'react' +import { useEffect, useRef } from 'react' /** * Recoilが使えない環境の時にもユーザーを持ちたい場合に使います。基本的に `useCachedAnonymousUser` を使ってください。 */ const useAnonymousUser = (): FirebaseAuthTypes.User | undefined => { - const [user, setUser] = useState() + const userRef = useRef() useEffect(() => { const unsubscribe = auth().onAuthStateChanged((authUser) => { if (authUser) { - setUser(authUser) + userRef.current = authUser } else { auth() .signInAnonymously() - .then((credential) => setUser(credential.user)) + .then((credential) => (userRef.current = credential.user)) } }) return unsubscribe - }, [setUser, user]) + }, []) - return user + return userRef.current } export default useAnonymousUser diff --git a/src/hooks/useTTS.ts b/src/hooks/useTTS.ts index ff300cfac..50df89f29 100644 --- a/src/hooks/useTTS.ts +++ b/src/hooks/useTTS.ts @@ -1,17 +1,11 @@ import { Audio, InterruptionModeAndroid, InterruptionModeIOS } from 'expo-av' import * as FileSystem from 'expo-file-system' import { useCallback, useEffect, useMemo, useRef } from 'react' -import DeviceInfo from 'react-native-device-info' -import { - DEV_TTS_API_URL, - LOCAL_TTS_API_URL, - PRODUCTION_TTS_API_URL, -} from 'react-native-dotenv' +import { DEV_TTS_API_URL, PRODUCTION_TTS_API_URL } from 'react-native-dotenv' import { useRecoilValue } from 'recoil' import speechState from '../store/atoms/speech' import { isDevApp } from '../utils/isDevApp' import useAnonymousUser from './useAnonymousUser' -import useConnectivity from './useConnectivity' import { usePrevious } from './usePrevious' import { useTTSCache } from './useTTSCache' import useTTSText from './useTTSText' @@ -26,7 +20,7 @@ export const useTTS = (): void => { const ttsText = useTTSText(firstSpeechRef.current) const [prevTextJa, prevTextEn] = usePrevious(ttsText) const [textJa, textEn] = ttsText - const isInternetAvailable = useConnectivity() + const user = useAnonymousUser() const soundJaRef = useRef(null) @@ -80,9 +74,6 @@ export const useTTS = (): void => { }, []) const ttsApiUrl = useMemo(() => { - if (__DEV__ && DeviceInfo.isEmulatorSync()) { - return LOCAL_TTS_API_URL - } return isDevApp ? DEV_TTS_API_URL : PRODUCTION_TTS_API_URL }, []) @@ -173,9 +164,8 @@ export const useTTS = (): void => { useEffect(() => { if ( - playingRef.current || !enabled || - !isInternetAvailable || + playingRef.current || prevTextJa === textJa || prevTextEn === textEn ) { @@ -186,15 +176,7 @@ export const useTTS = (): void => { textJa, textEn, }) - }, [ - enabled, - isInternetAvailable, - prevTextEn, - prevTextJa, - speech, - textEn, - textJa, - ]) + }, [enabled, prevTextEn, prevTextJa, speech, textEn, textJa]) useEffect(() => { return () => { From 579b2374a42eaf5894e3f8cdd3eb22acfdf581b0 Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Sun, 28 Jul 2024 20:44:53 +0900 Subject: [PATCH 5/5] =?UTF-8?q?OtherNavigation=E5=BE=A9=E6=B4=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useStartBackgroundLocationUpdates.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hooks/useStartBackgroundLocationUpdates.ts b/src/hooks/useStartBackgroundLocationUpdates.ts index 6821c4f0b..c802c290c 100644 --- a/src/hooks/useStartBackgroundLocationUpdates.ts +++ b/src/hooks/useStartBackgroundLocationUpdates.ts @@ -22,6 +22,7 @@ export const useStartBackgroundLocationUpdates = () => { await Location.startLocationUpdatesAsync(locationTaskName, { accuracy: locationServiceAccuracy, + activityType: Location.ActivityType.OtherNavigation, foregroundService: { notificationTitle: translate('bgAlertTitle'), notificationBody: translate('bgAlertContent'),