From a75e0fdcdd5b3d21037e5e08ae13bb210e427986 Mon Sep 17 00:00:00 2001 From: Aman Chaturvedi Date: Tue, 17 Oct 2023 16:54:48 +0530 Subject: [PATCH] TP-0 | fixes --- src/common/TrackingComponent.tsx | 4 +--- src/components/utlis/PermissionUtils.ts | 3 --- src/services/foregroundServices/foreground.service.ts | 8 ++++++++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/common/TrackingComponent.tsx b/src/common/TrackingComponent.tsx index bbca5509..288f11ef 100644 --- a/src/common/TrackingComponent.tsx +++ b/src/common/TrackingComponent.tsx @@ -404,9 +404,7 @@ const TrackingComponent: React.FC = ({ children }) => { useEffect(() => { let appStateSubscription: NativeEventSubscription; appStateSubscription = AppState.addEventListener('change', handleAppStateChange); - if (AppState.currentState === AppStates.ACTIVE) { - CosmosForegroundService.start(tasks); - } + CosmosForegroundService.start(tasks); return () => { appStateSubscription?.remove(); }; diff --git a/src/components/utlis/PermissionUtils.ts b/src/components/utlis/PermissionUtils.ts index 2e450ea7..c4ea066f 100644 --- a/src/components/utlis/PermissionUtils.ts +++ b/src/components/utlis/PermissionUtils.ts @@ -37,9 +37,6 @@ export const getPermissionsToRequest = async () => { if (!notificationStatus) { permissionsToRequest.push(permission); } else { - if (AppState.currentState !== AppStates.ACTIVE) { - continue; - } const isFGSRunning = await CosmosForegroundService.isRunning(); if (!isFGSRunning) { CosmosForegroundService.start(); diff --git a/src/services/foregroundServices/foreground.service.ts b/src/services/foregroundServices/foreground.service.ts index f40965ba..dca532c4 100644 --- a/src/services/foregroundServices/foreground.service.ts +++ b/src/services/foregroundServices/foreground.service.ts @@ -1,6 +1,8 @@ import ForegroundService from '@supersami/rn-foreground-service'; import { logError } from '../../components/utlis/errorUtils'; import { GLOBAL } from '../../constants/Global'; +import { AppState } from 'react-native'; +import { AppStates } from '@types/appStates'; export interface IForegroundTask { task: () => void; @@ -34,6 +36,9 @@ class CosmosForegroundService { private constructor() {} static async start(tasks?: IForegroundTask[]) { + if (AppState.currentState !== AppStates.ACTIVE) { + return; + } if (GLOBAL.IS_IMPERSONATED) { return; } @@ -60,6 +65,9 @@ class CosmosForegroundService { } static async update() { + if (AppState.currentState !== AppStates.ACTIVE) { + return; + } if (GLOBAL.IS_IMPERSONATED) { return; }