react-native-rook-sdk 4.0.0 → 5.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +35 -3
- package/RNRookSdk.podspec +22 -0
- package/android/build.gradle +21 -40
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/rooksdk/RookSdkModule.kt +1709 -117
- package/android/src/main/java/com/rooksdk/RookSdkPackage.kt +26 -42
- package/android/src/main/java/com/rooksdk/broadcasts/AndroidPermissionsReceiverTransmitter.kt +34 -37
- package/android/src/main/java/com/rooksdk/broadcasts/HealthConnectPermissionsReceiverTransmitter.kt +8 -14
- package/android/src/main/java/com/rooksdk/broadcasts/SamsungHealthPermissionsReceiverTransmitter.kt +8 -16
- package/android/src/main/java/com/rooksdk/utils/{DatasourcesUtils.kt → DatasourceUtils.kt} +10 -9
- package/android/src/main/java/com/rooksdk/utils/{PermissionConversion.kt → PermissionConvertions.kt} +1 -1
- package/android/src/main/java/com/rooksdk/utils/ReadableToWritable.kt +0 -1
- package/android/src/main/java/com/rooksdk/utils/RookGsonBuilder.kt +3 -0
- package/android/src/main/java/com/rooksdk/utils/SamsungAvailability.kt +1 -0
- package/android/src/main/java/com/rooksdk/utils/serializers/InstantSerializer.kt +0 -1
- package/android/src/main/java/com/rooksdk/utils/serializers/ZoneDateTimeSerializer.kt +18 -0
- package/ios/DateHelper.swift +4 -4
- package/ios/Encodable.swift +25 -0
- package/ios/EncodableDataSource.swift +2 -3
- package/ios/EncodableDataSourceAuthorizer.swift +2 -3
- package/ios/EncodableSDKState.swift +3 -2
- package/ios/{EncodableHeartRate.swift → HearRateMapper.swift} +3 -3
- package/ios/NutritionMapper.swift +3 -3
- package/ios/RookBackground.swift +5 -8
- package/ios/RookConfiguration.swift +33 -30
- package/ios/{RookLocalData.swift → RookData.swift} +76 -69
- package/ios/RookEntry.swift +62 -0
- package/ios/RookPermissions.swift +36 -40
- package/ios/RookSdk-Bridging-Header.h +12 -0
- package/ios/RookSdk.h +3 -3
- package/ios/RookSdk.mm +390 -134
- package/ios/RookSources.swift +60 -54
- package/ios/RookSync.swift +48 -78
- package/ios/boost-boost_privacy-Bridging-Header.h +4 -0
- package/lib/{commonjs/types/AppleHealthPermissions.js → module/NativeRookSdk.js} +50 -6
- package/lib/module/NativeRookSdk.js.map +1 -0
- package/lib/module/context/RookSyncGateContext.js +2 -0
- package/lib/module/context/RookSyncGateContext.js.map +1 -1
- package/lib/module/context/RookSyncGateProvider.js +17 -18
- package/lib/module/context/RookSyncGateProvider.js.map +1 -1
- package/lib/module/context/RookSyncGateReducer.js +2 -0
- package/lib/module/context/RookSyncGateReducer.js.map +1 -1
- package/lib/module/context/RookSyncGateTypes.js +2 -0
- package/lib/module/hooks/useRookAPISources.js +10 -16
- package/lib/module/hooks/useRookAPISources.js.map +1 -1
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js +11 -12
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js.map +1 -1
- package/lib/module/hooks/useRookAppleHealth.js +9 -10
- package/lib/module/hooks/useRookAppleHealth.js.map +1 -1
- package/lib/module/hooks/useRookConfiguration.js +17 -22
- package/lib/module/hooks/useRookConfiguration.js.map +1 -1
- package/lib/module/hooks/useRookData.js +33 -38
- package/lib/module/hooks/useRookData.js.map +1 -1
- package/lib/module/hooks/useRookHealthConnect.js +9 -10
- package/lib/module/hooks/useRookHealthConnect.js.map +1 -1
- package/lib/module/hooks/useRookPermissions.js +34 -45
- package/lib/module/hooks/useRookPermissions.js.map +1 -1
- package/lib/module/hooks/useRookSamsungHealth.js +8 -20
- package/lib/module/hooks/useRookSamsungHealth.js.map +1 -1
- package/lib/module/hooks/useRookSync.js +23 -32
- package/lib/module/hooks/useRookSync.js.map +1 -1
- package/lib/module/hooks/useRookVariables.js +26 -29
- package/lib/module/hooks/useRookVariables.js.map +1 -1
- package/lib/module/index.js +18 -10
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/components/RookStateManager.js +31 -0
- package/lib/module/modules/components/RookStateManager.js.map +1 -0
- package/lib/module/modules/hook/useRookAutoSync.js +24 -36
- package/lib/module/modules/hook/useRookAutoSync.js.map +1 -1
- package/lib/module/modules/hook/useRookEmitter.js +61 -0
- package/lib/module/modules/hook/useRookEmitter.js.map +1 -0
- package/lib/module/modules/types/sendMessageBroadcast.js +1 -1
- package/lib/module/modules/utils/errors.js +2 -0
- package/lib/module/modules/utils/errors.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/module/types/ActivityEvent.js +2 -0
- package/lib/module/types/AppleHealthNutritionEvent.js +2 -0
- package/lib/module/types/AppleHealthNutritionEvent.js.map +1 -1
- package/lib/module/types/AppleHealthPermissions.js +2 -0
- package/lib/module/types/AppleHealthPermissions.js.map +1 -1
- package/lib/module/types/AuthorizedSources.js +2 -0
- package/lib/module/types/BodySummary.js +2 -0
- package/lib/module/types/DataSource.js +2 -0
- package/lib/module/types/DataSource.js.map +1 -1
- package/lib/module/types/HCMealData.js +3 -1
- package/lib/module/types/HCMealData.js.map +1 -1
- package/lib/module/types/HeartRateEvent.js +1 -1
- package/lib/module/types/PermissionsType.js +1 -1
- package/lib/module/types/PhysicalSummary.js +2 -0
- package/lib/module/types/Rook.js +2 -0
- package/lib/{commonjs/types/BodySummary.js.map → module/types/Rook.js.map} +1 -1
- package/lib/module/types/SDKSources.js +2 -0
- package/lib/module/types/SDKSources.js.map +1 -1
- package/lib/module/types/SamsungHealthPermissions.js +3 -0
- package/lib/module/types/SamsungHealthPermissions.js.map +1 -1
- package/lib/module/types/SleepSummary.js +2 -0
- package/lib/module/types/SummaryTypes.js +1 -1
- package/lib/module/types/SyncTypes.js +2 -0
- package/lib/module/types/SyncTypes.js.map +1 -1
- package/lib/module/types/WriteNutrition.js +2 -0
- package/lib/module/types/WriteNutrition.js.map +1 -1
- package/lib/module/utils/isModuleReady.js +2 -0
- package/lib/module/utils/isModuleReady.js.map +1 -1
- package/lib/module/utils/isRunningOnAndroid.js +2 -0
- package/lib/module/utils/isRunningOnAndroid.js.map +1 -1
- package/lib/module/utils/isRunningOniOS.js +2 -0
- package/lib/module/utils/isRunningOniOS.js.map +1 -1
- package/lib/module/utils/isValidDate.js +2 -0
- package/lib/module/utils/isValidDate.js.map +1 -1
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeRookSdk.d.ts +705 -0
- package/lib/typescript/src/NativeRookSdk.d.ts.map +1 -0
- package/lib/typescript/src/context/RookSyncGateContext.d.ts.map +1 -1
- package/lib/typescript/src/context/RookSyncGateProvider.d.ts.map +1 -1
- package/lib/typescript/src/context/RookSyncGateReducer.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookAPISources.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookAndroidBackgroundSteps.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookAppleHealth.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts +1 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookData.d.ts +1 -1
- package/lib/typescript/src/hooks/useRookData.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookHealthConnect.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookPermissions.d.ts +1 -1
- package/lib/typescript/src/hooks/useRookPermissions.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookSamsungHealth.d.ts +0 -6
- package/lib/typescript/src/hooks/useRookSamsungHealth.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookSync.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookVariables.d.ts +1 -1
- package/lib/typescript/src/hooks/useRookVariables.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +17 -8
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/modules/components/RookStateManager.d.ts +10 -0
- package/lib/typescript/src/modules/components/RookStateManager.d.ts.map +1 -0
- package/lib/typescript/src/modules/hook/useRookAutoSync.d.ts.map +1 -1
- package/lib/typescript/src/modules/hook/useRookEmitter.d.ts +4 -0
- package/lib/typescript/src/modules/hook/useRookEmitter.d.ts.map +1 -0
- package/lib/typescript/src/types/AppleHealthNutritionEvent.d.ts.map +1 -1
- package/lib/typescript/src/types/AuthorizedSources.d.ts +11 -0
- package/lib/typescript/src/types/AuthorizedSources.d.ts.map +1 -1
- package/lib/typescript/src/types/HCMealData.d.ts.map +1 -1
- package/lib/typescript/src/types/HeartRateEvent.d.ts +2 -2
- package/lib/typescript/src/types/HeartRateEvent.d.ts.map +1 -1
- package/lib/typescript/src/types/Rook.d.ts +9 -0
- package/lib/typescript/src/types/Rook.d.ts.map +1 -0
- package/lib/typescript/src/types/SamsungHealthPermissions.d.ts +1 -0
- package/lib/typescript/src/types/SamsungHealthPermissions.d.ts.map +1 -1
- package/lib/typescript/src/types/SyncTypes.d.ts +5 -1
- package/lib/typescript/src/types/SyncTypes.d.ts.map +1 -1
- package/lib/typescript/src/utils/isModuleReady.d.ts.map +1 -1
- package/lib/typescript/src/utils/isValidDate.d.ts.map +1 -1
- package/package.json +94 -98
- package/src/NativeRookSdk.ts +839 -0
- package/{lib/commonjs/context/RookSyncGateContext.js → src/context/RookSyncGateContext.ts} +10 -13
- package/src/context/RookSyncGateProvider.tsx +82 -0
- package/{lib/commonjs/context/RookSyncGateReducer.js → src/context/RookSyncGateReducer.ts} +14 -41
- package/src/context/RookSyncGateTypes.ts +40 -0
- package/{lib/commonjs/hooks/useRookAPISources.js → src/hooks/useRookAPISources.ts} +40 -36
- package/src/hooks/useRookAndroidBackgroundSteps.ts +81 -0
- package/src/hooks/useRookAppleHealth.ts +55 -0
- package/src/hooks/useRookConfiguration.ts +106 -0
- package/src/hooks/useRookData.ts +133 -0
- package/src/hooks/useRookHealthConnect.ts +59 -0
- package/src/hooks/useRookPermissions.ts +240 -0
- package/src/hooks/useRookSamsungHealth.ts +37 -0
- package/src/hooks/useRookSync.ts +157 -0
- package/src/hooks/useRookVariables.ts +98 -0
- package/src/index.tsx +28 -0
- package/src/modules/components/RookStateManager.tsx +41 -0
- package/{lib/commonjs/modules/hook/useRookAutoSync.js → src/modules/hook/useRookAutoSync.ts} +141 -95
- package/src/modules/hook/useRookEmitter.ts +94 -0
- package/src/modules/types/sendMessageBroadcast.ts +5 -0
- package/src/modules/utils/errors.ts +9 -0
- package/src/types/ActivityEvent.ts +159 -0
- package/src/types/AppleHealthNutritionEvent.ts +142 -0
- package/src/types/AppleHealthPermissions.ts +49 -0
- package/src/types/AuthorizedSources.ts +33 -0
- package/src/types/BodySummary.ts +116 -0
- package/src/types/DataSource.ts +16 -0
- package/{lib/commonjs/types/HCMealData.js → src/types/HCMealData.ts} +60 -11
- package/src/types/HeartRateEvent.ts +26 -0
- package/src/types/PermissionsType.ts +9 -0
- package/src/types/PhysicalSummary.ts +84 -0
- package/src/types/Rook.ts +8 -0
- package/src/types/SDKSources.ts +5 -0
- package/src/types/SamsungHealthPermissions.ts +16 -0
- package/src/types/SleepSummary.ts +66 -0
- package/src/types/SummaryTypes.ts +70 -0
- package/src/types/SyncTypes.ts +63 -0
- package/src/types/WriteNutrition.ts +66 -0
- package/{lib/commonjs/utils/isModuleReady.js → src/utils/isModuleReady.ts} +4 -10
- package/src/utils/isRunningOnAndroid.ts +10 -0
- package/src/utils/isRunningOniOS.ts +10 -0
- package/{lib/commonjs/utils/isValidDate.js → src/utils/isValidDate.ts} +12 -14
- package/android/src/main/AndroidManifestNew.xml +0 -36
- package/android/src/main/java/com/rooksdk/modules/RookBackgroundSyncModule.kt +0 -99
- package/android/src/main/java/com/rooksdk/modules/RookConfigurationModule.kt +0 -182
- package/android/src/main/java/com/rooksdk/modules/RookLocalData.kt +0 -301
- package/android/src/main/java/com/rooksdk/modules/RookPermissionsModule.kt +0 -359
- package/android/src/main/java/com/rooksdk/modules/RookSourcesModule.kt +0 -102
- package/android/src/main/java/com/rooksdk/modules/RookStepsModule.kt +0 -119
- package/android/src/main/java/com/rooksdk/modules/RookSyncModule.kt +0 -551
- package/android/src/main/res/drawable/ic_health_connect.xml +0 -19
- package/android/src/main/res/values/themes.xml +0 -3
- package/ios/EncodableRookDataSource.swift +0 -36
- package/ios/EncodableStatusDataSources.swift +0 -47
- package/ios/RookBackgroundModule.h +0 -5
- package/ios/RookBackgroundModule.mm +0 -15
- package/ios/RookConfigurationModule.h +0 -5
- package/ios/RookConfigurationModule.mm +0 -22
- package/ios/RookExternalModule.h +0 -5
- package/ios/RookExternalModule.m +0 -31
- package/ios/RookPermissionsModule.h +0 -5
- package/ios/RookPermissionsModule.mm +0 -20
- package/ios/RookSourcesModule.h +0 -5
- package/ios/RookSourcesModule.mm +0 -18
- package/ios/RookSync.h +0 -5
- package/ios/RookSync.m +0 -35
- package/ios/SwiftTest.swift +0 -18
- package/ios/react-native-rook-sdk-Bridging-Header.h +0 -12
- package/lib/commonjs/context/RookSyncGateContext.js.map +0 -1
- package/lib/commonjs/context/RookSyncGateProvider.js +0 -108
- package/lib/commonjs/context/RookSyncGateProvider.js.map +0 -1
- package/lib/commonjs/context/RookSyncGateReducer.js.map +0 -1
- package/lib/commonjs/context/RookSyncGateTypes.js +0 -6
- package/lib/commonjs/context/RookSyncGateTypes.js.map +0 -1
- package/lib/commonjs/context/index.js +0 -14
- package/lib/commonjs/context/index.js.map +0 -1
- package/lib/commonjs/hooks/index.js +0 -76
- package/lib/commonjs/hooks/index.js.map +0 -1
- package/lib/commonjs/hooks/useRookAPISources.js.map +0 -1
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js +0 -88
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js.map +0 -1
- package/lib/commonjs/hooks/useRookAppleHealth.js +0 -63
- package/lib/commonjs/hooks/useRookAppleHealth.js.map +0 -1
- package/lib/commonjs/hooks/useRookConfiguration.js +0 -113
- package/lib/commonjs/hooks/useRookConfiguration.js.map +0 -1
- package/lib/commonjs/hooks/useRookData.js +0 -116
- package/lib/commonjs/hooks/useRookData.js.map +0 -1
- package/lib/commonjs/hooks/useRookHealthConnect.js +0 -70
- package/lib/commonjs/hooks/useRookHealthConnect.js.map +0 -1
- package/lib/commonjs/hooks/useRookPermissions.js +0 -211
- package/lib/commonjs/hooks/useRookPermissions.js.map +0 -1
- package/lib/commonjs/hooks/useRookSamsungHealth.js +0 -54
- package/lib/commonjs/hooks/useRookSamsungHealth.js.map +0 -1
- package/lib/commonjs/hooks/useRookSync.js +0 -148
- package/lib/commonjs/hooks/useRookSync.js.map +0 -1
- package/lib/commonjs/hooks/useRookVariables.js +0 -93
- package/lib/commonjs/hooks/useRookVariables.js.map +0 -1
- package/lib/commonjs/index.js +0 -121
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/modules/hook/useRookAutoSync.js.map +0 -1
- package/lib/commonjs/modules/types/sendMessageBroadcast.js +0 -2
- package/lib/commonjs/modules/types/sendMessageBroadcast.js.map +0 -1
- package/lib/commonjs/modules/utils/errors.js +0 -12
- package/lib/commonjs/modules/utils/errors.js.map +0 -1
- package/lib/commonjs/types/ActivityEvent.js +0 -6
- package/lib/commonjs/types/ActivityEvent.js.map +0 -1
- package/lib/commonjs/types/AppleHealthNutritionEvent.js +0 -77
- package/lib/commonjs/types/AppleHealthNutritionEvent.js.map +0 -1
- package/lib/commonjs/types/AppleHealthPermissions.js.map +0 -1
- package/lib/commonjs/types/AuthorizedSources.js +0 -6
- package/lib/commonjs/types/AuthorizedSources.js.map +0 -1
- package/lib/commonjs/types/BodySummary.js +0 -6
- package/lib/commonjs/types/DataSource.js +0 -16
- package/lib/commonjs/types/DataSource.js.map +0 -1
- package/lib/commonjs/types/DiagnosticState.js +0 -2
- package/lib/commonjs/types/DiagnosticState.js.map +0 -1
- package/lib/commonjs/types/HCMealData.js.map +0 -1
- package/lib/commonjs/types/HeartRateEvent.js +0 -2
- package/lib/commonjs/types/HeartRateEvent.js.map +0 -1
- package/lib/commonjs/types/PermissionsType.js +0 -2
- package/lib/commonjs/types/PermissionsType.js.map +0 -1
- package/lib/commonjs/types/PhysicalSummary.js +0 -6
- package/lib/commonjs/types/PhysicalSummary.js.map +0 -1
- package/lib/commonjs/types/SDKSources.js +0 -13
- package/lib/commonjs/types/SDKSources.js.map +0 -1
- package/lib/commonjs/types/SamsungHealthPermissions.js +0 -23
- package/lib/commonjs/types/SamsungHealthPermissions.js.map +0 -1
- package/lib/commonjs/types/SleepSummary.js +0 -6
- package/lib/commonjs/types/SleepSummary.js.map +0 -1
- package/lib/commonjs/types/SummaryTypes.js +0 -2
- package/lib/commonjs/types/SummaryTypes.js.map +0 -1
- package/lib/commonjs/types/SyncTypes.js +0 -33
- package/lib/commonjs/types/SyncTypes.js.map +0 -1
- package/lib/commonjs/types/WriteNutrition.js +0 -18
- package/lib/commonjs/types/WriteNutrition.js.map +0 -1
- package/lib/commonjs/utils/getNativeModule.js +0 -29
- package/lib/commonjs/utils/getNativeModule.js.map +0 -1
- package/lib/commonjs/utils/getRookModule.js +0 -28
- package/lib/commonjs/utils/getRookModule.js.map +0 -1
- package/lib/commonjs/utils/isModuleReady.js.map +0 -1
- package/lib/commonjs/utils/isRunningOnAndroid.js +0 -15
- package/lib/commonjs/utils/isRunningOnAndroid.js.map +0 -1
- package/lib/commonjs/utils/isRunningOniOS.js +0 -15
- package/lib/commonjs/utils/isRunningOniOS.js.map +0 -1
- package/lib/commonjs/utils/isValidDate.js.map +0 -1
- package/lib/commonjs/utils/nativeModules.js +0 -29
- package/lib/commonjs/utils/nativeModules.js.map +0 -1
- package/lib/commonjs/utils/packageInfo.js +0 -13
- package/lib/commonjs/utils/packageInfo.js.map +0 -1
- package/lib/module/context/index.js +0 -2
- package/lib/module/context/index.js.map +0 -1
- package/lib/module/hooks/index.js +0 -11
- package/lib/module/hooks/index.js.map +0 -1
- package/lib/module/types/DiagnosticState.js +0 -2
- package/lib/module/types/DiagnosticState.js.map +0 -1
- package/lib/module/utils/getNativeModule.js +0 -23
- package/lib/module/utils/getNativeModule.js.map +0 -1
- package/lib/module/utils/getRookModule.js +0 -22
- package/lib/module/utils/getRookModule.js.map +0 -1
- package/lib/module/utils/nativeModules.js +0 -23
- package/lib/module/utils/nativeModules.js.map +0 -1
- package/lib/module/utils/packageInfo.js +0 -7
- package/lib/module/utils/packageInfo.js.map +0 -1
- package/lib/typescript/src/context/index.d.ts +0 -2
- package/lib/typescript/src/context/index.d.ts.map +0 -1
- package/lib/typescript/src/hooks/index.d.ts +0 -11
- package/lib/typescript/src/hooks/index.d.ts.map +0 -1
- package/lib/typescript/src/types/DiagnosticState.d.ts +0 -13
- package/lib/typescript/src/types/DiagnosticState.d.ts.map +0 -1
- package/lib/typescript/src/utils/getNativeModule.d.ts +0 -10
- package/lib/typescript/src/utils/getNativeModule.d.ts.map +0 -1
- package/lib/typescript/src/utils/getRookModule.d.ts +0 -9
- package/lib/typescript/src/utils/getRookModule.d.ts.map +0 -1
- package/lib/typescript/src/utils/nativeModules.d.ts +0 -24
- package/lib/typescript/src/utils/nativeModules.d.ts.map +0 -1
- package/lib/typescript/src/utils/packageInfo.d.ts +0 -6
- package/lib/typescript/src/utils/packageInfo.d.ts.map +0 -1
- package/react-native-rook-sdk.podspec +0 -45
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import RookSdk, { type HeartRateData } from '../NativeRookSdk';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
import { isModuleReady } from '../utils/isModuleReady';
|
|
4
|
+
import { useRookSyncGateContext } from '../context/RookSyncGateContext';
|
|
5
|
+
import { SDKDataSource } from '../types/SDKSources';
|
|
6
|
+
|
|
7
|
+
export type Calories = {
|
|
8
|
+
active: number;
|
|
9
|
+
basal: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The `useRookVariables` hook returns an object with a `ready` boolean and an
|
|
14
|
+
* asynchronous function `getTodaySteps` that retrieves the number of steps taken today.
|
|
15
|
+
* @returns The `useRookVariable` hook is returning an object with two properties:
|
|
16
|
+
* 1. `ready`: This property is coming from the `useRookSyncGateContext` hook and represents the state
|
|
17
|
+
* of readiness.
|
|
18
|
+
* 2. `getTodaySteps`: This property is a function that retrieves the number of steps taken today
|
|
19
|
+
* asynchronously and returns a Promise<string> representing the number of steps taken today.
|
|
20
|
+
* 3. `getTodayCalories`: This property is a function that retrieves the number of calories burned today
|
|
21
|
+
* asynchronously and returns a Promise<string> representing the number of calories burned today.
|
|
22
|
+
*/
|
|
23
|
+
export const useRookVariables = () => {
|
|
24
|
+
const {
|
|
25
|
+
state: { ready },
|
|
26
|
+
} = useRookSyncGateContext();
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The function `getTodaySteps` retrieves the number of steps taken today asynchronously.
|
|
30
|
+
* @returns The function `getTodaySteps` is returning a string representing the number of steps taken today.
|
|
31
|
+
*/
|
|
32
|
+
const getTodaySteps = async (source: SDKDataSource): Promise<string> => {
|
|
33
|
+
isModuleReady(ready);
|
|
34
|
+
|
|
35
|
+
if (Platform.OS === 'android' && source === SDKDataSource.HEALTH_CONNECT) {
|
|
36
|
+
return RookSdk.syncTodayHealthConnectStepsCount();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (Platform.OS === 'android' && source === SDKDataSource.SAMSUNG_HEALTH) {
|
|
40
|
+
return RookSdk.syncTodaySamsungHealthStepsCount();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (Platform.OS !== 'android' && source === SDKDataSource.APPLE_HEALTH) {
|
|
44
|
+
return RookSdk.getTodayAppleHealthSteps();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
throw new Error('Invalid SDK datasource');
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The function `syncTodayCaloriesCount` retrieves the number of calories burned today asynchronously as string
|
|
52
|
+
* @returns The function `syncTodayCaloriesCount` is returning the result of calling
|
|
53
|
+
*/
|
|
54
|
+
const getTodayCalories = async (source: SDKDataSource): Promise<Calories> => {
|
|
55
|
+
isModuleReady(ready);
|
|
56
|
+
|
|
57
|
+
if (Platform.OS === 'android' && source === SDKDataSource.HEALTH_CONNECT) {
|
|
58
|
+
return RookSdk.syncTodayCaloriesCount();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (Platform.OS === 'android' && source === SDKDataSource.SAMSUNG_HEALTH) {
|
|
62
|
+
return RookSdk.syncSHTodayCaloriesCount();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (Platform.OS !== 'android' && source === SDKDataSource.APPLE_HEALTH) {
|
|
66
|
+
return RookSdk.syncTodayCaloriesCount();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
throw new Error('Invalid SDK datasource');
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const getTodayHeartRate = async (
|
|
73
|
+
source: SDKDataSource
|
|
74
|
+
): Promise<HeartRateData> => {
|
|
75
|
+
if (Platform.OS === 'android' && source === SDKDataSource.HEALTH_CONNECT) {
|
|
76
|
+
const result = await RookSdk.getTodayHeartRate();
|
|
77
|
+
return JSON.parse(result as unknown as string);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (Platform.OS === 'android' && source === SDKDataSource.SAMSUNG_HEALTH) {
|
|
81
|
+
const result = await RookSdk.getSHTodayHeartRate();
|
|
82
|
+
return JSON.parse(result as unknown as string);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (Platform.OS !== 'android' && source === SDKDataSource.APPLE_HEALTH) {
|
|
86
|
+
return RookSdk.getTodayHeartRate();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
throw new Error('Please check the data source');
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
ready,
|
|
94
|
+
getTodaySteps,
|
|
95
|
+
getTodayCalories,
|
|
96
|
+
getTodayHeartRate,
|
|
97
|
+
};
|
|
98
|
+
};
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { default as RookSdk } from './NativeRookSdk';
|
|
2
|
+
|
|
3
|
+
export { default as RookSyncGate } from './context/RookSyncGateProvider';
|
|
4
|
+
|
|
5
|
+
export { useRookAPISources } from './hooks/useRookAPISources';
|
|
6
|
+
export { useRookAppleHealth } from './hooks/useRookAppleHealth';
|
|
7
|
+
export { useRookConfiguration } from './hooks/useRookConfiguration';
|
|
8
|
+
export { useRookPermissions } from './hooks/useRookPermissions';
|
|
9
|
+
export { useRookData } from './hooks/useRookData';
|
|
10
|
+
export { useRookAndroidBackgroundSteps } from './hooks/useRookAndroidBackgroundSteps';
|
|
11
|
+
export { useRookHealthConnect } from './hooks/useRookHealthConnect';
|
|
12
|
+
export { useRookSamsungHealth } from './hooks/useRookSamsungHealth';
|
|
13
|
+
export { useRookVariables } from './hooks/useRookVariables';
|
|
14
|
+
export { useRookSync } from './hooks/useRookSync';
|
|
15
|
+
|
|
16
|
+
export { APIDataSource } from './types/DataSource';
|
|
17
|
+
export { SDKDataSource } from './types/SDKSources';
|
|
18
|
+
export { AppleHealthPermission } from './types/AppleHealthPermissions';
|
|
19
|
+
export { type SamsungHealthPermission } from './types/SamsungHealthPermissions';
|
|
20
|
+
export { type PhysicalSummary } from './types/PhysicalSummary';
|
|
21
|
+
export { type BodySummary } from './types/BodySummary';
|
|
22
|
+
export { type SleepSummary } from './types/SleepSummary';
|
|
23
|
+
export {
|
|
24
|
+
SharedHealthEvents,
|
|
25
|
+
UniqueAppleHealthEvents,
|
|
26
|
+
UniqueSamsungHealthEvents,
|
|
27
|
+
UniqueHealthConnectEvents,
|
|
28
|
+
} from './types/SyncTypes';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
+
import { useEffect, useRef, type FC } from 'react';
|
|
3
|
+
import { AppState, type AppStateStatus } from 'react-native';
|
|
4
|
+
import type { RookSyncGateState } from '../../context/RookSyncGateTypes';
|
|
5
|
+
import { useRookPermissionEmitter } from '../hook/useRookEmitter';
|
|
6
|
+
import { useRookAutoSync } from '../hook/useRookAutoSync';
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
state: RookSyncGateState;
|
|
10
|
+
enableBackground: boolean;
|
|
11
|
+
enableLogs: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const RookStateManager: FC<Props> = (props) => {
|
|
15
|
+
const { checkAndroidPermissions } = useRookPermissionEmitter();
|
|
16
|
+
const { startBackgroundServices } = useRookAutoSync(props);
|
|
17
|
+
const appState = useRef(AppState.currentState);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const subscription = AppState.addEventListener(
|
|
21
|
+
'change',
|
|
22
|
+
(nextAppState: AppStateStatus) => {
|
|
23
|
+
if (
|
|
24
|
+
appState.current?.match(/inactive|background/) &&
|
|
25
|
+
nextAppState === 'active'
|
|
26
|
+
) {
|
|
27
|
+
checkAndroidPermissions();
|
|
28
|
+
startBackgroundServices();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
appState.current = nextAppState;
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
return () => {
|
|
36
|
+
subscription.remove();
|
|
37
|
+
};
|
|
38
|
+
}, [checkAndroidPermissions]);
|
|
39
|
+
|
|
40
|
+
return <></>;
|
|
41
|
+
};
|
package/{lib/commonjs/modules/hook/useRookAutoSync.js → src/modules/hook/useRookAutoSync.ts}
RENAMED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useRookAutoSync = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _reactNative = require("react-native");
|
|
9
|
-
var _errors = require("../utils/errors");
|
|
10
|
-
var _getNativeModule = _interopRequireDefault(require("../../utils/getNativeModule"));
|
|
11
|
-
var _nativeModules = _interopRequireDefault(require("../../utils/nativeModules"));
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
1
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
+
import RookSdk from '../../NativeRookSdk';
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { AppState, Platform } from 'react-native';
|
|
5
|
+
import type { RookSyncGateState } from '../../context/RookSyncGateTypes';
|
|
6
|
+
import { errors } from '../utils/errors';
|
|
7
|
+
import type { Message } from '../types/sendMessageBroadcast';
|
|
8
|
+
import { AppleHealthPermission } from '../../types/AppleHealthPermissions';
|
|
9
|
+
|
|
10
|
+
type StartBackgroundSync = {
|
|
11
|
+
state: RookSyncGateState;
|
|
12
|
+
enableBackground: boolean;
|
|
13
|
+
enableLogs: boolean;
|
|
14
|
+
};
|
|
14
15
|
|
|
15
16
|
const MESSAGE_TYPE = 'ROOK_BACKGROUND_ENABLED';
|
|
16
17
|
|
|
@@ -30,119 +31,149 @@ const MESSAGE_TYPE = 'ROOK_BACKGROUND_ENABLED';
|
|
|
30
31
|
* is ready, the permissions status, and the user ID associated with the state. This state is used to
|
|
31
32
|
* determine when to start the
|
|
32
33
|
*/
|
|
33
|
-
const useRookAutoSync = ({
|
|
34
|
+
export const useRookAutoSync = ({
|
|
34
35
|
enableBackground,
|
|
35
36
|
enableLogs,
|
|
36
|
-
state
|
|
37
|
-
}) => {
|
|
38
|
-
const appState =
|
|
39
|
-
const [changeAppState, setChangeState] =
|
|
40
|
-
|
|
37
|
+
state,
|
|
38
|
+
}: StartBackgroundSync) => {
|
|
39
|
+
const appState = useRef(AppState.currentState);
|
|
40
|
+
const [changeAppState, setChangeState] = useState(0);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
41
43
|
if (!enableBackground) return;
|
|
42
|
-
|
|
44
|
+
|
|
45
|
+
const subscription = AppState.addEventListener('change', (nextAppState) => {
|
|
43
46
|
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
// Check previous state to check if he app was inactive or in background
|
|
48
|
+
// and then pass to be active
|
|
49
|
+
appState.current?.match(/inactive|background/) &&
|
|
50
|
+
nextAppState === 'active'
|
|
51
|
+
) {
|
|
52
|
+
setChangeState((prev) => prev + 1);
|
|
48
53
|
}
|
|
54
|
+
|
|
49
55
|
appState.current = nextAppState;
|
|
50
56
|
});
|
|
57
|
+
|
|
51
58
|
return () => {
|
|
52
59
|
subscription.remove();
|
|
53
60
|
};
|
|
54
61
|
}, []);
|
|
55
|
-
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
56
64
|
if (!state.ready || !enableBackground) return;
|
|
65
|
+
|
|
57
66
|
startBackgroundServices();
|
|
58
67
|
}, [state, changeAppState]);
|
|
68
|
+
|
|
59
69
|
const startBackgroundServices = () => {
|
|
60
|
-
const {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} = state;
|
|
70
|
+
const { clientUUID, secret, ready } = state;
|
|
71
|
+
|
|
72
|
+
if (!enableBackground) return;
|
|
73
|
+
|
|
65
74
|
if (!ready || !clientUUID || !secret) {
|
|
66
75
|
return;
|
|
67
76
|
}
|
|
68
|
-
|
|
77
|
+
|
|
78
|
+
if (Platform.OS === 'android') {
|
|
69
79
|
startAndroidBackgroundSync();
|
|
70
80
|
return;
|
|
71
81
|
}
|
|
82
|
+
|
|
72
83
|
startIOSBackgroundSync();
|
|
73
84
|
};
|
|
74
|
-
|
|
85
|
+
|
|
86
|
+
const isValidUser = async (): Promise<boolean> => {
|
|
75
87
|
try {
|
|
76
|
-
const
|
|
77
|
-
|
|
88
|
+
const userID = await RookSdk.getUserID();
|
|
89
|
+
|
|
78
90
|
if (userID) return true;
|
|
79
|
-
|
|
80
|
-
|
|
91
|
+
|
|
92
|
+
if (enableLogs) console.error(errors.noUserIDAndroidBackground);
|
|
93
|
+
|
|
94
|
+
throw new Error(errors.noUserIDAndroidBackground);
|
|
81
95
|
} catch (error) {
|
|
82
96
|
sendMessageToBroadcast({
|
|
83
97
|
type: 'ROOK_BACKGROUND_ENABLED',
|
|
84
|
-
message: 'There is not a user id',
|
|
85
|
-
value: false
|
|
98
|
+
message: (error as any).message || 'There is not a user id',
|
|
99
|
+
value: false,
|
|
86
100
|
});
|
|
101
|
+
|
|
87
102
|
return false;
|
|
88
103
|
}
|
|
89
104
|
};
|
|
90
|
-
|
|
105
|
+
|
|
106
|
+
const tryToStartBackgroundSync = async (): Promise<boolean> => {
|
|
91
107
|
try {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
const backgroundStatus =
|
|
109
|
+
await RookSdk.checkHealthConnectBackgroundReadStatus();
|
|
110
|
+
|
|
111
|
+
if (backgroundStatus !== 'PERMISSION_GRANTED')
|
|
112
|
+
throw new Error('No permission granted or not available');
|
|
113
|
+
|
|
114
|
+
const result = await RookSdk.scheduleBackgroundSync(enableLogs);
|
|
115
|
+
|
|
97
116
|
return result;
|
|
98
117
|
} catch (error) {
|
|
99
|
-
console.log(error);
|
|
100
118
|
sendMessageToBroadcast({
|
|
101
119
|
type: 'ROOK_BACKGROUND_ENABLED',
|
|
102
|
-
message:
|
|
103
|
-
|
|
120
|
+
message:
|
|
121
|
+
(error as any).message ||
|
|
122
|
+
'Health Connect background is not available on the device or the user does not grants permission',
|
|
123
|
+
value: false,
|
|
104
124
|
});
|
|
125
|
+
|
|
105
126
|
return false;
|
|
106
127
|
}
|
|
107
128
|
};
|
|
108
|
-
|
|
129
|
+
|
|
130
|
+
const tryToStartForegroundSync = async (): Promise<boolean> => {
|
|
109
131
|
try {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
const hasAndroidPermissions =
|
|
132
|
+
const hasHCPermissions =
|
|
133
|
+
await RookSdk.healthConnectHasPartialPermissions();
|
|
134
|
+
const hasAndroidPermissions =
|
|
135
|
+
await RookSdk.androidHasBackgroundPermissions();
|
|
136
|
+
|
|
113
137
|
if (!hasHCPermissions || !hasAndroidPermissions) {
|
|
114
|
-
if (enableLogs) console.error(
|
|
115
|
-
|
|
138
|
+
if (enableLogs) console.error(errors.autoStartAndroidBackgroundSync);
|
|
139
|
+
|
|
140
|
+
throw new Error(errors.autoStartAndroidBackgroundSync);
|
|
116
141
|
}
|
|
117
|
-
|
|
118
|
-
if (
|
|
119
|
-
await
|
|
142
|
+
|
|
143
|
+
if (AppState.currentState === 'active' && appState.current === 'active') {
|
|
144
|
+
await RookSdk.enableBackgroundAndroidSteps();
|
|
145
|
+
|
|
120
146
|
return true;
|
|
121
147
|
}
|
|
148
|
+
|
|
122
149
|
return false;
|
|
123
150
|
} catch (error) {
|
|
124
151
|
sendMessageToBroadcast({
|
|
125
152
|
type: 'ROOK_BACKGROUND_ENABLED',
|
|
126
153
|
value: false,
|
|
127
|
-
message: error.message
|
|
154
|
+
message: (error as Error).message,
|
|
128
155
|
});
|
|
156
|
+
|
|
129
157
|
return false;
|
|
130
158
|
}
|
|
131
159
|
};
|
|
132
|
-
|
|
160
|
+
|
|
161
|
+
const tryToStartSamsungHealthSync = async (): Promise<boolean> => {
|
|
133
162
|
try {
|
|
134
|
-
const
|
|
135
|
-
|
|
163
|
+
const isAvailable = await RookSdk.checkSamsungAvailability();
|
|
164
|
+
|
|
136
165
|
if (isAvailable !== 'INSTALLED') return false;
|
|
137
|
-
|
|
138
|
-
await
|
|
166
|
+
|
|
167
|
+
await RookSdk.enableSamsungSync();
|
|
168
|
+
|
|
139
169
|
return true;
|
|
140
170
|
} catch (error) {
|
|
141
171
|
sendMessageToBroadcast({
|
|
142
172
|
type: 'ROOK_BACKGROUND_ENABLED',
|
|
143
173
|
value: false,
|
|
144
|
-
message: error.message
|
|
174
|
+
message: (error as Error).message,
|
|
145
175
|
});
|
|
176
|
+
|
|
146
177
|
return false;
|
|
147
178
|
}
|
|
148
179
|
};
|
|
@@ -155,37 +186,45 @@ const useRookAutoSync = ({
|
|
|
155
186
|
* broadcast with `value` set to `false` and an error message is logged.
|
|
156
187
|
*/
|
|
157
188
|
const startAndroidBackgroundSync = async () => {
|
|
158
|
-
const {
|
|
159
|
-
|
|
160
|
-
secret,
|
|
161
|
-
ready
|
|
162
|
-
} = state;
|
|
189
|
+
const { clientUUID, secret, ready } = state;
|
|
190
|
+
|
|
163
191
|
if (!ready || !clientUUID || !secret) {
|
|
164
192
|
return;
|
|
165
193
|
}
|
|
194
|
+
|
|
166
195
|
try {
|
|
167
196
|
const enabledSources = [];
|
|
197
|
+
|
|
168
198
|
const isValid = await isValidUser();
|
|
169
199
|
if (!isValid) return;
|
|
200
|
+
|
|
170
201
|
const isSamsungEnabled = await tryToStartSamsungHealthSync();
|
|
171
202
|
const isEnabled = await tryToStartBackgroundSync();
|
|
203
|
+
|
|
172
204
|
if (isSamsungEnabled) enabledSources.push('Samsung Health');
|
|
173
205
|
if (isEnabled) enabledSources.push('Health Connect');
|
|
206
|
+
|
|
174
207
|
if (!isEnabled) {
|
|
175
208
|
const isForegroundEnabled = await tryToStartForegroundSync();
|
|
176
|
-
|
|
209
|
+
|
|
210
|
+
if (!isForegroundEnabled && !isSamsungEnabled)
|
|
211
|
+
throw new Error("We couldn't start background sync");
|
|
212
|
+
|
|
177
213
|
if (isForegroundEnabled) enabledSources.push('Foreground Service');
|
|
178
214
|
}
|
|
215
|
+
|
|
179
216
|
sendMessageToBroadcast({
|
|
180
217
|
type: 'ROOK_BACKGROUND_ENABLED',
|
|
181
218
|
value: true,
|
|
182
|
-
message: `via: ${enabledSources.join(', ')}
|
|
219
|
+
message: `via: ${enabledSources.join(', ')}`,
|
|
183
220
|
});
|
|
221
|
+
|
|
184
222
|
if (enableLogs) console.log('ROOK - Background enabled successfully');
|
|
185
223
|
} catch (error) {
|
|
186
224
|
sendMessageToBroadcast({
|
|
187
225
|
type: 'ROOK_BACKGROUND_ENABLED',
|
|
188
|
-
|
|
226
|
+
message: (error as any).message,
|
|
227
|
+
value: false,
|
|
189
228
|
});
|
|
190
229
|
}
|
|
191
230
|
};
|
|
@@ -199,44 +238,56 @@ const useRookAutoSync = ({
|
|
|
199
238
|
*/
|
|
200
239
|
const startIOSBackgroundSync = async () => {
|
|
201
240
|
try {
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
const rookConfigModule = (0, _getNativeModule.default)(_nativeModules.default.ios.CONFIGURATION);
|
|
205
|
-
const rookSync = (0, _getNativeModule.default)(_nativeModules.default.ios.SYNC);
|
|
206
|
-
const userID = await rookConfigModule.getUserID();
|
|
241
|
+
const userID = await RookSdk.getUserID();
|
|
242
|
+
|
|
207
243
|
if (!userID) {
|
|
208
|
-
if (enableLogs) console.error(
|
|
244
|
+
if (enableLogs) console.error(errors.noUserIDAndroidBackground);
|
|
245
|
+
|
|
209
246
|
sendMessageToBroadcast({
|
|
210
247
|
type: MESSAGE_TYPE,
|
|
211
248
|
value: false,
|
|
212
|
-
message:
|
|
249
|
+
message: errors.noUserIDAndroidBackground,
|
|
213
250
|
});
|
|
251
|
+
|
|
214
252
|
return;
|
|
215
253
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
254
|
+
|
|
255
|
+
const status = await RookSdk.appleHealthHasPermissions(
|
|
256
|
+
AppleHealthPermission.STEP_COUNT
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
if (status === 'PERMISSION_NOT_REQUESTED')
|
|
260
|
+
throw new Error('Permissions required');
|
|
261
|
+
|
|
262
|
+
await RookSdk.enableBackGroundUpdates();
|
|
263
|
+
|
|
264
|
+
RookSdk.sync(() => {
|
|
220
265
|
sendMessageToBroadcast({
|
|
221
266
|
type: MESSAGE_TYPE,
|
|
222
267
|
value: true,
|
|
223
|
-
message: 'Some data has already uploaded'
|
|
268
|
+
message: 'Some data has already uploaded',
|
|
224
269
|
});
|
|
225
270
|
});
|
|
271
|
+
|
|
226
272
|
sendMessageToBroadcast({
|
|
227
273
|
type: MESSAGE_TYPE,
|
|
228
|
-
value: true
|
|
274
|
+
value: true,
|
|
229
275
|
});
|
|
276
|
+
|
|
230
277
|
if (enableLogs) console.log('ROOK - Background enabled successfully');
|
|
231
278
|
} catch (err) {
|
|
232
|
-
const error = err;
|
|
279
|
+
const error = err as any;
|
|
280
|
+
|
|
233
281
|
sendMessageToBroadcast({
|
|
234
282
|
type: MESSAGE_TYPE,
|
|
235
283
|
value: false,
|
|
236
|
-
message:
|
|
284
|
+
message: errors.autoStartIOSBackgroundSync,
|
|
237
285
|
});
|
|
286
|
+
|
|
238
287
|
if (enableLogs) {
|
|
239
|
-
if (error.message && error.message.includes('emptyUserId'))
|
|
288
|
+
if (error.message && (error.message as string).includes('emptyUserId'))
|
|
289
|
+
console.error(errors.noUserIDAndroidBackground);
|
|
290
|
+
else console.error(errors.autoStartIOSBackgroundSync);
|
|
240
291
|
}
|
|
241
292
|
}
|
|
242
293
|
};
|
|
@@ -246,16 +297,11 @@ const useRookAutoSync = ({
|
|
|
246
297
|
* @param {Message} message - The `message` parameter is of type `Message`, which is likely an object
|
|
247
298
|
* containing information to be sent as a broadcast message.
|
|
248
299
|
*/
|
|
249
|
-
const sendMessageToBroadcast = message => {
|
|
250
|
-
|
|
251
|
-
android: () => _nativeModules.default.android.MAIN,
|
|
252
|
-
default: () => _nativeModules.default.ios.MAIN
|
|
253
|
-
})());
|
|
254
|
-
rookSyncModule.sendMessageToBroadcast(message).then().catch();
|
|
300
|
+
const sendMessageToBroadcast = (message: Message): void => {
|
|
301
|
+
RookSdk.sendMessage(message);
|
|
255
302
|
};
|
|
303
|
+
|
|
256
304
|
return {
|
|
257
|
-
startBackgroundServices
|
|
305
|
+
startBackgroundServices,
|
|
258
306
|
};
|
|
259
307
|
};
|
|
260
|
-
exports.useRookAutoSync = useRookAutoSync;
|
|
261
|
-
//# sourceMappingURL=useRookAutoSync.js.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
+
import { useRef, useCallback } from 'react';
|
|
3
|
+
import RookSdk, { type BackgroundStatus } from '../../NativeRookSdk';
|
|
4
|
+
|
|
5
|
+
const PERM_KEYS = {
|
|
6
|
+
HC: 'ROOK_HEALTH_CONNECT_PERMISSIONS',
|
|
7
|
+
HC_PARTIAL: 'ROOK_HEALTH_CONNECT_PERMISSIONS_PARTIALLY_GRANTED',
|
|
8
|
+
HC_BG: 'ROOK_HEALTH_CONNECT_BACKGROUND_PERMISSIONS',
|
|
9
|
+
SAMSUNG: 'ROOK_SAMSUNG_HEALTH_PERMISSIONS',
|
|
10
|
+
SAMSUNG_PARTIAL: 'ROOK_SAMSUNG_HEALTH_PERMISSIONS_PARTIALLY_GRANTED',
|
|
11
|
+
ANDROID_BG: 'ROOK_BACKGROUND_ANDROID_PERMISSIONS',
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
export const useRookPermissionEmitter = () => {
|
|
15
|
+
const emittedRef = useRef<Record<string, boolean>>({});
|
|
16
|
+
|
|
17
|
+
const evaluateAndEmit = useCallback(
|
|
18
|
+
async (key: string, checkFn: () => Promise<boolean | BackgroundStatus>) => {
|
|
19
|
+
let previuos = emittedRef.current[key] || false;
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const result = await checkFn();
|
|
23
|
+
|
|
24
|
+
const isGranted =
|
|
25
|
+
typeof result === 'string' ? result === 'PERMISSION_GRANTED' : result;
|
|
26
|
+
|
|
27
|
+
if (previuos === isGranted) return;
|
|
28
|
+
|
|
29
|
+
const success = await RookSdk.sendMessage({
|
|
30
|
+
type: key,
|
|
31
|
+
value: isGranted,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (success) {
|
|
35
|
+
emittedRef.current[key] = true;
|
|
36
|
+
}
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error(`Error checking/emitting ${key}:`, error);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
[]
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const checkAndroidSystem = async () => {
|
|
45
|
+
await evaluateAndEmit(
|
|
46
|
+
PERM_KEYS.ANDROID_BG,
|
|
47
|
+
RookSdk.androidHasBackgroundPermissions
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const checkHealthConnect = async () => {
|
|
52
|
+
await Promise.all([
|
|
53
|
+
evaluateAndEmit(PERM_KEYS.HC, RookSdk.healthConnectHasPermissions),
|
|
54
|
+
evaluateAndEmit(
|
|
55
|
+
PERM_KEYS.HC_PARTIAL,
|
|
56
|
+
RookSdk.healthConnectHasPartialPermissions
|
|
57
|
+
),
|
|
58
|
+
evaluateAndEmit(
|
|
59
|
+
PERM_KEYS.HC_BG,
|
|
60
|
+
RookSdk.checkHealthConnectBackgroundReadStatus
|
|
61
|
+
),
|
|
62
|
+
]);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const checkSamsungHealth = async () => {
|
|
66
|
+
await Promise.all([
|
|
67
|
+
evaluateAndEmit(PERM_KEYS.SAMSUNG, RookSdk.samsungHealthHasPermissions),
|
|
68
|
+
evaluateAndEmit(
|
|
69
|
+
PERM_KEYS.SAMSUNG_PARTIAL,
|
|
70
|
+
RookSdk.samsungHealthHasPartialPermissions
|
|
71
|
+
),
|
|
72
|
+
]);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const checkAndroidPermissions = async () => {
|
|
76
|
+
try {
|
|
77
|
+
const samsungStatus = await RookSdk.checkSamsungAvailability();
|
|
78
|
+
const isSamsungAvailable = samsungStatus === 'INSTALLED';
|
|
79
|
+
|
|
80
|
+
checkAndroidSystem().then().catch(console.log);
|
|
81
|
+
checkHealthConnect().then().catch(console.log);
|
|
82
|
+
|
|
83
|
+
if (isSamsungAvailable) {
|
|
84
|
+
checkSamsungHealth().catch(console.log);
|
|
85
|
+
} else {
|
|
86
|
+
console.log(`Skipping Samsung Health checks. Status: ${samsungStatus}`);
|
|
87
|
+
}
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error('Global Permission Check Failed', error);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return { checkAndroidPermissions };
|
|
94
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const errors = {
|
|
2
|
+
autoStartAndroidBackgroundSync:
|
|
3
|
+
'ROOK - We try to start the health connect background sync but some permissions are missing, please grant permissions on health connect and android permissions, https://docs.tryrook.io/docs/rookconnect/sdk/reactnative/fundamentals/grantpermissons/#request-permissions',
|
|
4
|
+
|
|
5
|
+
autoStartIOSBackgroundSync:
|
|
6
|
+
'ROOK - We try to start the background sync but some error occurred please check the permissions are granted and data exists in the device, https://docs.tryrook.io/docs/rookconnect/sdk/reactnative/fundamentals/grantpermissons/#request-permissions',
|
|
7
|
+
noUserIDAndroidBackground:
|
|
8
|
+
"ROOK - We couldn't start the background sync cause there is no user registered, https://docs.tryrook.io/docs/rookconnect/sdk/reactnative/fundamentals/updateuserid/",
|
|
9
|
+
};
|