From 287af2874bd462d1c51652e3c26321655403c33b Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Wed, 14 Aug 2024 00:34:28 +0900 Subject: [PATCH 01/10] =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E6=83=85=E5=A0=B1?= =?UTF-8?q?=E5=8F=96=E5=BE=97=E9=96=8B=E5=A7=8B=E5=89=8D=E3=81=AB=E7=A2=BA?= =?UTF-8?q?=E8=AA=8D=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../useStartBackgroundLocationUpdates.ts | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/hooks/useStartBackgroundLocationUpdates.ts b/src/hooks/useStartBackgroundLocationUpdates.ts index 18a83012c..ba4afd1ce 100644 --- a/src/hooks/useStartBackgroundLocationUpdates.ts +++ b/src/hooks/useStartBackgroundLocationUpdates.ts @@ -10,15 +10,22 @@ export const useStartBackgroundLocationUpdates = () => { if (autoModeEnabled) { return } - Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, { - accuracy: Location.Accuracy.High, - distanceInterval: 100, - foregroundService: { - notificationTitle: translate('bgAlertTitle'), - notificationBody: translate('bgAlertContent'), - killServiceOnDestroy: true, - }, - }) + // eslint-disable-next-line @typescript-eslint/no-extra-semi + ;(async () => { + if ( + !(await Location.hasStartedLocationUpdatesAsync(LOCATION_TASK_NAME)) + ) { + Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, { + accuracy: Location.Accuracy.High, + distanceInterval: 100, + foregroundService: { + notificationTitle: translate('bgAlertTitle'), + notificationBody: translate('bgAlertContent'), + killServiceOnDestroy: true, + }, + }) + } + })() return () => { Location.stopLocationUpdatesAsync(LOCATION_TASK_NAME).catch(console.debug) From 4b48330c251f14d4ccd96804547d6d9c5a998b43 Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Wed, 14 Aug 2024 19:10:38 +0900 Subject: [PATCH 02/10] =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=A0=E3=82=B9?= =?UTF-8?q?=E3=82=BF=E3=83=B3=E3=83=97=E3=81=8C=E6=96=B0=E3=81=97=E3=81=8F?= =?UTF-8?q?=E3=81=AA=E3=81=84=E5=A0=B4=E5=90=88React=E3=81=AB=E3=82=82?= =?UTF-8?q?=E6=B8=A1=E3=81=95=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index b482847e8..527669bf3 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,9 @@ import * as TaskManager from 'expo-task-manager' +TaskManager.unregisterAllTasksAsync().catch(console.error) + +let lastTimestamp = 0 + if (!TaskManager.isTaskDefined(LOCATION_TASK_NAME)) { TaskManager.defineTask(LOCATION_TASK_NAME, ({ data, error }) => { if (error) { @@ -7,7 +11,11 @@ if (!TaskManager.isTaskDefined(LOCATION_TASK_NAME)) { return } - setLocation(data.locations[0]) + const latestTimestamp = data.locations[0]?.timestamp ?? 0 + if (lastTimestamp < latestTimestamp) { + setLocation(data.locations[0]) + lastTimestamp = latestTimestamp + } }) } @@ -18,8 +26,6 @@ import App from './src' import { LOCATION_TASK_NAME } from './src/constants' import { setLocation } from './src/hooks/useLocationStore' -TaskManager.unregisterAllTasksAsync().catch(console.error) - // registerRootComponent calls AppRegistry.registerComponent('main', () => App); // It also ensures that whether you load the app in the Expo client or in a native build, // the environment is set up appropriately From da651f77dd9945cb0c89fe2e2d7945ddfc61121b Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Wed, 14 Aug 2024 19:10:47 +0900 Subject: [PATCH 03/10] distanceInterval: 250 --- src/hooks/useStartBackgroundLocationUpdates.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/useStartBackgroundLocationUpdates.ts b/src/hooks/useStartBackgroundLocationUpdates.ts index ba4afd1ce..28cddc2f2 100644 --- a/src/hooks/useStartBackgroundLocationUpdates.ts +++ b/src/hooks/useStartBackgroundLocationUpdates.ts @@ -17,7 +17,7 @@ export const useStartBackgroundLocationUpdates = () => { ) { Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, { accuracy: Location.Accuracy.High, - distanceInterval: 100, + distanceInterval: 250, foregroundService: { notificationTitle: translate('bgAlertTitle'), notificationBody: translate('bgAlertContent'), From 42239c60b85402c88fe9cadd6e323b2736eb5a87 Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Fri, 16 Aug 2024 07:51:12 +0900 Subject: [PATCH 04/10] =?UTF-8?q?JRW=E3=83=86=E3=83=BC=E3=83=9E=E3=81=A7?= =?UTF-8?q?=E7=9F=A2=E5=8D=B0=E3=81=8C=E5=87=BA=E3=81=AA=E3=81=84=E6=99=82?= =?UTF-8?q?=E3=81=8C=E3=81=82=E3=82=8B=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/LineBoardWest.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/LineBoardWest.tsx b/src/components/LineBoardWest.tsx index 1ffe1f55c..906b23616 100644 --- a/src/components/LineBoardWest.tsx +++ b/src/components/LineBoardWest.tsx @@ -434,6 +434,8 @@ const StationNameCell: React.FC = ({ const LineBoardWest: React.FC = ({ stations, lineColors }: Props) => { const { selectedLine } = useRecoilValue(lineState) + const { arrived } = useRecoilValue(stationState) + const isPassing = useIsPassing() const currentLine = useCurrentLine() @@ -448,11 +450,11 @@ const LineBoardWest: React.FC = ({ stations, lineColors }: Props) => { key={s.groupId} station={s} stations={stations} - arrived={!isPassing} + arrived={!isPassing && arrived} index={i} /> ), - [isPassing, stations] + [arrived, isPassing, stations] ) const emptyArray = useMemo( From 4172248b284afdb66cb1e72f29636733c3ca456d Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Fri, 16 Aug 2024 08:20:44 +0900 Subject: [PATCH 05/10] bump v7.7.2 --- android/app/build.gradle | 4 ++-- android/wearable/build.gradle.kts | 4 ++-- ios/TrainLCD.xcodeproj/project.pbxproj | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 332a458a3..7b01f9b7f 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -127,8 +127,8 @@ android { } prod { dimension "environment" - versionCode 70701000 - versionName "7.7.1" + versionCode 70702000 + versionName "7.7.2" } } }// Apply static values from `gradle.properties` to the `android.packagingOptions` diff --git a/android/wearable/build.gradle.kts b/android/wearable/build.gradle.kts index 104d5b2e3..56ab86491 100644 --- a/android/wearable/build.gradle.kts +++ b/android/wearable/build.gradle.kts @@ -39,8 +39,8 @@ android { } create("prod") { dimension = "environment" - versionCode = 70701001 - versionName = "7.7.1" + versionCode = 70702001 + versionName = "7.7.2" } } diff --git a/ios/TrainLCD.xcodeproj/project.pbxproj b/ios/TrainLCD.xcodeproj/project.pbxproj index 7a9c93c63..71f90b7fd 100644 --- a/ios/TrainLCD.xcodeproj/project.pbxproj +++ b/ios/TrainLCD.xcodeproj/project.pbxproj @@ -1451,7 +1451,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 7.7.1; + MARKETING_VERSION = 7.7.2; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -1489,7 +1489,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 7.7.1; + MARKETING_VERSION = 7.7.2; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -2131,7 +2131,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 7.7.1; + MARKETING_VERSION = 7.7.2; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_DEBUG"; @@ -2175,7 +2175,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 7.7.1; + MARKETING_VERSION = 7.7.2; MTL_FAST_MATH = YES; OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_RELEASE -D EXPO_CONFIGURATION_DEBUG"; PRODUCT_BUNDLE_IDENTIFIER = me.tinykitten.trainlcd.watchkitapp.watchkitextension; @@ -2213,7 +2213,7 @@ GCC_C_LANGUAGE_STANDARD = gnu11; IBSC_MODULE = WatchApp_Extension; INFOPLIST_FILE = WatchApp/Schemes/Prod/Info.plist; - MARKETING_VERSION = 7.7.1; + MARKETING_VERSION = 7.7.2; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_DEBUG"; @@ -2253,7 +2253,7 @@ GCC_C_LANGUAGE_STANDARD = gnu11; IBSC_MODULE = WatchApp_Extension; INFOPLIST_FILE = WatchApp/Schemes/Prod/Info.plist; - MARKETING_VERSION = 7.7.1; + MARKETING_VERSION = 7.7.2; MTL_FAST_MATH = YES; OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_RELEASE -D EXPO_CONFIGURATION_DEBUG"; PRODUCT_BUNDLE_IDENTIFIER = me.tinykitten.trainlcd.watchkitapp; From cc1b552302e4d5386cfc1be2afc68fc9747a8ee0 Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Fri, 16 Aug 2024 09:37:10 +0900 Subject: [PATCH 06/10] =?UTF-8?q?JRW=E3=83=86=E3=83=BC=E3=83=9E=E3=81=A7?= =?UTF-8?q?=E3=80=8C=E3=81=BE=E3=82=82=E3=81=AA=E3=81=8F=E3=80=8D=E3=81=AE?= =?UTF-8?q?=E6=99=82=E3=81=AB=E7=9F=A2=E5=8D=B0=E3=81=8C=E5=87=BA=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/LineBoardWest.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/LineBoardWest.tsx b/src/components/LineBoardWest.tsx index 906b23616..faee8764a 100644 --- a/src/components/LineBoardWest.tsx +++ b/src/components/LineBoardWest.tsx @@ -434,7 +434,7 @@ const StationNameCell: React.FC = ({ const LineBoardWest: React.FC = ({ stations, lineColors }: Props) => { const { selectedLine } = useRecoilValue(lineState) - const { arrived } = useRecoilValue(stationState) + const { arrived, approaching } = useRecoilValue(stationState) const isPassing = useIsPassing() const currentLine = useCurrentLine() @@ -450,11 +450,11 @@ const LineBoardWest: React.FC = ({ stations, lineColors }: Props) => { key={s.groupId} station={s} stations={stations} - arrived={!isPassing && arrived} + arrived={!isPassing && !approaching && arrived} index={i} /> ), - [arrived, isPassing, stations] + [approaching, arrived, isPassing, stations] ) const emptyArray = useMemo( From 4ffa391a51ce324d38582d86d83fb0885354c6bb Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Fri, 16 Aug 2024 09:55:34 +0900 Subject: [PATCH 07/10] =?UTF-8?q?=E3=83=AB=E3=83=BC=E3=83=88=E3=83=93?= =?UTF-8?q?=E3=83=AB=E3=83=80=E3=83=BC=E3=82=92=E4=BD=BF=E3=81=88=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useSavedRoutes.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hooks/useSavedRoutes.ts b/src/hooks/useSavedRoutes.ts index a109daac9..3cacd2bec 100644 --- a/src/hooks/useSavedRoutes.ts +++ b/src/hooks/useSavedRoutes.ts @@ -32,9 +32,10 @@ export const useSavedRoutes = () => { req.ids = route.stations.map((sta) => sta.id) const res = await grpcClient.getStationByIdList(req, {}) const stations = res?.stations ?? [] - return stations.map((sta, idx) => ({ + return stations.map((sta) => ({ ...sta, - stopCondition: route.stations[idx].stopCondition, + stopCondition: route.stations.find((rs) => rs.id === sta.id) + ?.stopCondition, trainType: route.trainType, })) }, []) From 332652c82690c94c65124a249e661fbf64a3eef1 Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Fri, 16 Aug 2024 10:22:35 +0900 Subject: [PATCH 08/10] =?UTF-8?q?=E3=83=AB=E3=83=BC=E3=83=88=E3=83=93?= =?UTF-8?q?=E3=83=AB=E3=83=80=E3=83=BC=E3=83=87=E3=83=BC=E3=82=BF=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E3=81=AEswr=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useSavedRoutes.ts | 73 +++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/src/hooks/useSavedRoutes.ts b/src/hooks/useSavedRoutes.ts index 3cacd2bec..526a0c9c3 100644 --- a/src/hooks/useSavedRoutes.ts +++ b/src/hooks/useSavedRoutes.ts @@ -1,5 +1,6 @@ import firestore from '@react-native-firebase/firestore' -import { useCallback, useEffect, useState } from 'react' +import useSWR from 'swr' +import useSWRMutation from 'swr/dist/mutation' import { GetStationByIdListRequest } from '../../gen/proto/stationapi_pb' import { grpcClient } from '../lib/grpc' import { SavedRoute } from '../models/SavedRoute' @@ -7,38 +8,48 @@ import useCachedInitAnonymousUser from './useCachedAnonymousUser' export const useSavedRoutes = () => { useCachedInitAnonymousUser() - const [routes, setRoutes] = useState([]) - const [loading, setLoading] = useState(false) - useEffect(() => { - const fetchRoutesAsync = async () => { - setLoading(true) - const routesSnapshot = await firestore() - .collection('uploadedCommunityRoutes') - .orderBy('createdAt', 'desc') - .get() - const routes = routesSnapshot.docs.map((doc) => ({ - id: doc.id, - ...doc.data(), + const { + data: routes, + isLoading: isRoutesLoading, + error: fetchRoutesError, + } = useSWR('/firestore/uploadedCommunityRoutes', async () => { + const routesSnapshot = await firestore() + .collection('uploadedCommunityRoutes') + .orderBy('createdAt', 'desc') + .get() + + return routesSnapshot.docs.map((doc) => ({ + id: doc.id, + ...doc.data(), + })) as SavedRoute[] + }) + + const { + isMutating: isStationsLoading, + error: fetchStationsError, + trigger: fetchStationsByRoute, + } = useSWRMutation( + '/app.trainlcd.grpc/GetStationByIdListRequest', + async (_, { arg: route }: { arg: SavedRoute }) => { + const req = new GetStationByIdListRequest() + req.ids = route.stations.map((sta) => sta.id) + const res = await grpcClient.getStationByIdList(req, {}) + const stations = res?.stations ?? [] + + return stations.map((sta) => ({ + ...sta, + stopCondition: route.stations.find((rs) => rs.id === sta.id) + ?.stopCondition, + trainType: route.trainType, })) - setRoutes(routes as SavedRoute[]) - setLoading(false) } - fetchRoutesAsync() - }, []) - - const fetchStationsByRoute = useCallback(async (route: SavedRoute) => { - const req = new GetStationByIdListRequest() - req.ids = route.stations.map((sta) => sta.id) - const res = await grpcClient.getStationByIdList(req, {}) - const stations = res?.stations ?? [] - return stations.map((sta) => ({ - ...sta, - stopCondition: route.stations.find((rs) => rs.id === sta.id) - ?.stopCondition, - trainType: route.trainType, - })) - }, []) + ) - return { routes, loading, fetchStationsByRoute } + return { + routes, + loading: isRoutesLoading || isStationsLoading, + error: fetchRoutesError || fetchStationsError, + fetchStationsByRoute, + } } From 6584212dec1976c1b6ac3a99d01202a86bc6045b Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Fri, 16 Aug 2024 23:25:23 +0900 Subject: [PATCH 09/10] =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E6=83=85=E5=A0=B1?= =?UTF-8?q?=E5=8F=96=E5=BE=97=E7=B2=BE=E5=BA=A6=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useStartBackgroundLocationUpdates.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/hooks/useStartBackgroundLocationUpdates.ts b/src/hooks/useStartBackgroundLocationUpdates.ts index 28cddc2f2..3aa926593 100644 --- a/src/hooks/useStartBackgroundLocationUpdates.ts +++ b/src/hooks/useStartBackgroundLocationUpdates.ts @@ -16,7 +16,11 @@ export const useStartBackgroundLocationUpdates = () => { !(await Location.hasStartedLocationUpdatesAsync(LOCATION_TASK_NAME)) ) { Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, { - accuracy: Location.Accuracy.High, + // NOTE: BestForNavigationにしたら暴走時のCPU使用率が50%ほど低下した + accuracy: Location.Accuracy.BestForNavigation, + // NOTE: マップマッチが勝手に行われると電車での経路と大きく異なることがあるはずなので + // OtherNavigationは必須 + activityType: Location.ActivityType.OtherNavigation, distanceInterval: 250, foregroundService: { notificationTitle: translate('bgAlertTitle'), From 0eab70be9063d36cc6c1aff76fa56a67ce8173ae Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Fri, 16 Aug 2024 23:29:21 +0900 Subject: [PATCH 10/10] =?UTF-8?q?distanceInterval:=20100=E3=81=AB=E6=88=BB?= =?UTF-8?q?=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useStartBackgroundLocationUpdates.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/useStartBackgroundLocationUpdates.ts b/src/hooks/useStartBackgroundLocationUpdates.ts index 3aa926593..6738f7364 100644 --- a/src/hooks/useStartBackgroundLocationUpdates.ts +++ b/src/hooks/useStartBackgroundLocationUpdates.ts @@ -21,7 +21,7 @@ export const useStartBackgroundLocationUpdates = () => { // NOTE: マップマッチが勝手に行われると電車での経路と大きく異なることがあるはずなので // OtherNavigationは必須 activityType: Location.ActivityType.OtherNavigation, - distanceInterval: 250, + distanceInterval: 100, foregroundService: { notificationTitle: translate('bgAlertTitle'), notificationBody: translate('bgAlertContent'),