react-native-asleep 1.0.6 → 1.0.8
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/AGENTS.md +107 -0
- package/CHANGELOG.md +17 -0
- package/android/src/main/java/ai/asleep/reactnative/AsleepModule.kt +168 -2
- package/build/Asleep.types.d.ts +9 -0
- package/build/Asleep.types.d.ts.map +1 -1
- package/build/Asleep.types.js.map +1 -1
- package/build/AsleepStore.d.ts +16 -2
- package/build/AsleepStore.d.ts.map +1 -1
- package/build/AsleepStore.js +134 -8
- package/build/AsleepStore.js.map +1 -1
- package/build/index.d.ts +35 -5
- package/build/index.d.ts.map +1 -1
- package/build/index.js +27 -6
- package/build/index.js.map +1 -1
- package/ios/AsleepModule.swift +42 -1
- package/package.json +1 -1
- package/src/Asleep.types.ts +10 -0
- package/src/AsleepStore.ts +181 -15
- package/src/index.ts +47 -5
package/AGENTS.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
React Native SDK for Asleep's AI-powered sleep tracking technology. This SDK provides non-invasive sleep tracking through audio analysis without requiring wearable devices.
|
|
8
|
+
|
|
9
|
+
## Development Commands
|
|
10
|
+
|
|
11
|
+
### Building and Testing
|
|
12
|
+
```bash
|
|
13
|
+
# Build the SDK
|
|
14
|
+
yarn build
|
|
15
|
+
|
|
16
|
+
# Clean build artifacts
|
|
17
|
+
yarn clean
|
|
18
|
+
|
|
19
|
+
# Run linting
|
|
20
|
+
yarn lint
|
|
21
|
+
|
|
22
|
+
# Run tests
|
|
23
|
+
yarn test
|
|
24
|
+
|
|
25
|
+
# Prepare the module
|
|
26
|
+
yarn prepare
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Example App Commands
|
|
30
|
+
```bash
|
|
31
|
+
# In the example directory
|
|
32
|
+
yarn start # Start Expo development server
|
|
33
|
+
yarn android # Run on Android
|
|
34
|
+
yarn ios # Run on iOS
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Publishing and Release
|
|
38
|
+
```bash
|
|
39
|
+
# Manual release via GitHub Actions
|
|
40
|
+
# Go to Actions > Release > Run workflow
|
|
41
|
+
|
|
42
|
+
# Automatic semantic release
|
|
43
|
+
yarn semantic-release
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Architecture
|
|
47
|
+
|
|
48
|
+
### Core Components
|
|
49
|
+
|
|
50
|
+
1. **Native Modules** (`ios/AsleepModule.swift`, `android/.../AsleepModule.kt`)
|
|
51
|
+
- Platform-specific implementations wrapping native Asleep SDKs
|
|
52
|
+
- Handle audio recording, permission management, and sleep tracking
|
|
53
|
+
- iOS SDK version: 3.1.5, Android SDK version: 3.1.4
|
|
54
|
+
|
|
55
|
+
2. **State Management** (`src/AsleepStore.ts`)
|
|
56
|
+
- Zustand store with singleton pattern for consistent state across app
|
|
57
|
+
- Handles all SDK state including tracking status, session management, and error handling
|
|
58
|
+
- Provides event listener initialization and cleanup
|
|
59
|
+
|
|
60
|
+
3. **API Surface** (`src/index.ts`)
|
|
61
|
+
- `useAsleep` hook for React components
|
|
62
|
+
- `AsleepSDK` singleton for non-React contexts
|
|
63
|
+
- Event-driven architecture with automatic state updates
|
|
64
|
+
|
|
65
|
+
4. **Type Definitions** (`src/Asleep.types.ts`)
|
|
66
|
+
- TypeScript interfaces for all API responses and configurations
|
|
67
|
+
- Comprehensive sleep report and session structures
|
|
68
|
+
|
|
69
|
+
### Key Features
|
|
70
|
+
|
|
71
|
+
- **Setup Methods**: Two initialization approaches - `setup()` for ODA (On-Device Analysis) and `initAsleepConfig()` for standard mode
|
|
72
|
+
- **Real-time Tracking**: Start/stop tracking with automatic microphone permission handling
|
|
73
|
+
- **Report Generation**: Fetch detailed sleep analysis reports with comprehensive metrics
|
|
74
|
+
- **Event System**: Automatic event handling through EventEmitter with state synchronization
|
|
75
|
+
- **Platform Differences**:
|
|
76
|
+
- Android: Returns analysis results immediately from `requestAnalysis()`
|
|
77
|
+
- iOS: Returns acknowledgment only, results come via `onAnalysisResult` event
|
|
78
|
+
|
|
79
|
+
### Native Integration Points
|
|
80
|
+
|
|
81
|
+
- **iOS**: Swift module using Expo modules, requires audio background mode
|
|
82
|
+
- **Android**: Kotlin module with foreground service for long-running tracking
|
|
83
|
+
- **Permissions**: Microphone access required on both platforms, battery optimization exemption recommended on Android
|
|
84
|
+
|
|
85
|
+
## Development Guidelines
|
|
86
|
+
|
|
87
|
+
### State Management Pattern
|
|
88
|
+
- Always use store actions for state updates
|
|
89
|
+
- Check `isSetupInProgress` and `isTracking` flags to prevent duplicate operations
|
|
90
|
+
- Handle platform differences in analysis result handling
|
|
91
|
+
|
|
92
|
+
### Error Handling
|
|
93
|
+
- All async operations should be wrapped in try-catch blocks
|
|
94
|
+
- Errors are automatically stored in the state and accessible via the `error` property
|
|
95
|
+
- Use the `addLog` function for debug logging when `enableLog(true)` is set
|
|
96
|
+
|
|
97
|
+
### Testing Changes
|
|
98
|
+
- Test on both iOS and Android platforms
|
|
99
|
+
- Verify permission handling flows
|
|
100
|
+
- Test background tracking scenarios
|
|
101
|
+
- Ensure state consistency across tracking lifecycle
|
|
102
|
+
|
|
103
|
+
### Release Process
|
|
104
|
+
- Uses semantic-release with custom configuration
|
|
105
|
+
- All commits trigger patch releases
|
|
106
|
+
- Changelog automatically generated
|
|
107
|
+
- NPM publishing handled by GitHub Actions
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
## [1.0.8](https://github.com/asleep-ai/asleep-sdk-react-native/compare/v1.0.7...v1.0.8) (2025-09-12)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### fix
|
|
5
|
+
|
|
6
|
+
* Add battery optimization API with backward-compatible permission handling ([](https://github.com/asleep-ai/asleep-sdk-react-native/commit/6f7d5565230c57caa9bc5213e51a1291bd71d4f9))
|
|
7
|
+
|
|
8
|
+
## [1.0.7](https://github.com/asleep-ai/asleep-sdk-react-native/compare/v1.0.6...v1.0.7) (2025-09-11)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### fix
|
|
12
|
+
|
|
13
|
+
* Add AGENTS.md for SDK documentation and create CLAUDE.md symlink ([](https://github.com/asleep-ai/asleep-sdk-react-native/commit/1e147c574c8ee6475491fd97e620ced8c7f7b702))
|
|
14
|
+
* Add Android service recovery and lifecycle management ([](https://github.com/asleep-ai/asleep-sdk-react-native/commit/a48d01bd15e4c65e7ed6919b37657042bb941f88))
|
|
15
|
+
* Add tracking recovery check on app startup with store cleanup ([](https://github.com/asleep-ai/asleep-sdk-react-native/commit/13440c50e29dd7c182830a55f9370b832711b7ce))
|
|
16
|
+
* feat: Add customizable Android foreground service notifications for sleep tracking ([](https://github.com/asleep-ai/asleep-sdk-react-native/commit/1899506b01b4142d2cea0487e78365c3ae1c7815))
|
|
17
|
+
|
|
1
18
|
## [1.0.6](https://github.com/asleep-ai/asleep-sdk-react-native/compare/v1.0.5...v1.0.6) (2025-08-18)
|
|
2
19
|
|
|
3
20
|
|
|
@@ -39,6 +39,9 @@ import kotlin.coroutines.resume
|
|
|
39
39
|
import kotlin.coroutines.resumeWithException
|
|
40
40
|
import android.os.DeadObjectException
|
|
41
41
|
import android.util.Log
|
|
42
|
+
import android.os.PowerManager
|
|
43
|
+
import android.provider.Settings
|
|
44
|
+
import android.net.Uri
|
|
42
45
|
|
|
43
46
|
class AsleepModule : Module() {
|
|
44
47
|
private val gson = Gson()
|
|
@@ -175,7 +178,64 @@ class AsleepModule : Module() {
|
|
|
175
178
|
}
|
|
176
179
|
}
|
|
177
180
|
|
|
178
|
-
AsyncFunction("
|
|
181
|
+
AsyncFunction("isSleepTrackingAlive") { promise: Promise ->
|
|
182
|
+
try {
|
|
183
|
+
val context = appContext.reactContext!!.applicationContext
|
|
184
|
+
val isAlive = Asleep.isSleepTrackingAlive(context)
|
|
185
|
+
|
|
186
|
+
sendEvent("onDebugLog", mapOf("message" to "isSleepTrackingAlive: $isAlive"))
|
|
187
|
+
promise.resolve(isAlive)
|
|
188
|
+
} catch (e: Exception) {
|
|
189
|
+
sendEvent("onDebugLog", mapOf("message" to "Error checking tracking status: ${e.message}"))
|
|
190
|
+
promise.reject("STATUS_CHECK_ERROR", "Failed to check tracking status: ${e.message}", e)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
AsyncFunction("connectSleepTracking") { promise: Promise ->
|
|
195
|
+
try {
|
|
196
|
+
// This function assumes the caller has already verified the service is alive
|
|
197
|
+
// The TypeScript layer checks isSleepTrackingAlive before calling this
|
|
198
|
+
sendEvent("onDebugLog", mapOf("message" to "Restoring connection to sleep tracking service..."))
|
|
199
|
+
|
|
200
|
+
// Mark tracking as active
|
|
201
|
+
isTracking = true
|
|
202
|
+
|
|
203
|
+
// Re-establish the tracking listener to receive events from the existing service
|
|
204
|
+
// This ensures we continue to receive tracking events even after app restart
|
|
205
|
+
Asleep.connectSleepTracking(object : Asleep.AsleepTrackingListener {
|
|
206
|
+
override fun onFail(errorCode: Int, detail: String) {
|
|
207
|
+
sendEvent("onDebugLog", mapOf("message" to "Sleep tracking failed: $errorCode - $detail"))
|
|
208
|
+
sendEvent("onTrackingFailed", mapOf("errorCode" to errorCode, "detail" to detail))
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
override fun onFinish(sessionId: String?) {
|
|
212
|
+
isTracking = false
|
|
213
|
+
sendEvent("onTrackingClosed", mapOf("sessionId" to (sessionId ?: "")))
|
|
214
|
+
sendEvent("onDebugLog", mapOf("message" to "Sleep tracking finished: $sessionId"))
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
override fun onPerform(sequence: Int) {
|
|
218
|
+
sendEvent("onTrackingUploaded", mapOf("sequence" to sequence))
|
|
219
|
+
sendEvent("onDebugLog", mapOf("message" to "Sleep tracking performing: $sequence"))
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
override fun onStart(sessionId: String) {
|
|
223
|
+
// This shouldn't be called for reconnection, but handle it just in case
|
|
224
|
+
isTracking = true
|
|
225
|
+
sendEvent("onTrackingCreated", mapOf("sessionId" to sessionId))
|
|
226
|
+
sendEvent("onDebugLog", mapOf("message" to "Sleep tracking started: $sessionId"))
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
sendEvent("onDebugLog", mapOf("message" to "Successfully restored connection to existing sleep tracking service"))
|
|
231
|
+
promise.resolve(true)
|
|
232
|
+
} catch (e: Exception) {
|
|
233
|
+
sendEvent("onDebugLog", mapOf("message" to "Error connecting to tracking service: ${e.message}"))
|
|
234
|
+
promise.reject("CONNECTION_ERROR", "Failed to connect to tracking service: ${e.message}", e)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
AsyncFunction("startTracking") { config: Map<String, Any>?, promise: Promise ->
|
|
179
239
|
try {
|
|
180
240
|
val audioPermission = ContextCompat.checkSelfPermission(appContext.reactContext!!, Manifest.permission.RECORD_AUDIO)
|
|
181
241
|
val fgsPermission = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
@@ -201,7 +261,6 @@ class AsleepModule : Module() {
|
|
|
201
261
|
|
|
202
262
|
|
|
203
263
|
|
|
204
|
-
val context = appContext.reactContext!!.applicationContext as Application
|
|
205
264
|
sendEvent("onDebugLog", mapOf("message" to "Starting tracking"))
|
|
206
265
|
if (_asleepConfig == null) {
|
|
207
266
|
sendEvent("onDebugLog", mapOf("message" to "AsleepConfig is not initialized"))
|
|
@@ -213,8 +272,26 @@ class AsleepModule : Module() {
|
|
|
213
272
|
|
|
214
273
|
sendEvent("onDebugLog", mapOf("message" to "Starting tracking!"))
|
|
215
274
|
|
|
275
|
+
// Extract Android notification settings from config
|
|
276
|
+
val notification = (config?.get("android") as? Map<*, *>)
|
|
277
|
+
?.get("notification") as? Map<*, *>
|
|
278
|
+
|
|
279
|
+
val context = appContext.reactContext!!
|
|
280
|
+
val notificationTitle = notification?.get("title") as? String ?: "Sleep Tracking"
|
|
281
|
+
val notificationText = notification?.get("text") as? String ?: "Monitoring your sleep"
|
|
282
|
+
val notificationIcon = notification?.get("icon")?.let { iconName ->
|
|
283
|
+
context.resources.getIdentifier(iconName as String, "drawable", context.packageName)
|
|
284
|
+
} ?: context.applicationInfo.icon
|
|
285
|
+
|
|
286
|
+
val processAlive = Asleep.isSleepTrackingAlive(context)
|
|
287
|
+
sendEvent("onDebugLog", mapOf("message" to "$processAlive"))
|
|
288
|
+
|
|
216
289
|
Asleep.beginSleepTracking(
|
|
217
290
|
asleepConfig = _asleepConfig!!,
|
|
291
|
+
notificationClass = appContext.currentActivity?.javaClass,
|
|
292
|
+
notificationTitle = notificationTitle,
|
|
293
|
+
notificationText = notificationText,
|
|
294
|
+
notificationIcon = notificationIcon,
|
|
218
295
|
asleepTrackingListener = object : Asleep.AsleepTrackingListener {
|
|
219
296
|
override fun onFail(errorCode: Int, detail: String) {
|
|
220
297
|
sendEvent("onDebugLog", mapOf("message" to "Sleep tracking failed: $errorCode - $detail"))
|
|
@@ -338,7 +415,42 @@ class AsleepModule : Module() {
|
|
|
338
415
|
}
|
|
339
416
|
}
|
|
340
417
|
|
|
418
|
+
// Deprecated method for backward compatibility
|
|
341
419
|
AsyncFunction("requestMicrophonePermission") { promise: Promise ->
|
|
420
|
+
// Delegate to the new method
|
|
421
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
422
|
+
try {
|
|
423
|
+
val permissions = mutableListOf(android.Manifest.permission.RECORD_AUDIO)
|
|
424
|
+
|
|
425
|
+
// Add notification permission for Android 13+
|
|
426
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
427
|
+
permissions.add(android.Manifest.permission.POST_NOTIFICATIONS)
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// Request permissions
|
|
431
|
+
val permissionsArray = permissions.toTypedArray()
|
|
432
|
+
if (appContext.currentActivity != null) {
|
|
433
|
+
ActivityCompat.requestPermissions(
|
|
434
|
+
appContext.currentActivity!!,
|
|
435
|
+
permissionsArray,
|
|
436
|
+
100
|
|
437
|
+
)
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// Check granted status
|
|
441
|
+
val allGranted = permissions.all { permission ->
|
|
442
|
+
ContextCompat.checkSelfPermission(appContext.reactContext!!, permission) ==
|
|
443
|
+
PackageManager.PERMISSION_GRANTED
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
promise.resolve(allGranted)
|
|
447
|
+
} catch (e: Exception) {
|
|
448
|
+
promise.reject("PERMISSION_ERROR", e.message, e)
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
AsyncFunction("requestRequiredPermissions") { promise: Promise ->
|
|
342
454
|
CoroutineScope(Dispatchers.Main).launch {
|
|
343
455
|
try {
|
|
344
456
|
val audioPermission = ContextCompat.checkSelfPermission(appContext.reactContext!!, Manifest.permission.RECORD_AUDIO)
|
|
@@ -427,6 +539,60 @@ class AsleepModule : Module() {
|
|
|
427
539
|
}
|
|
428
540
|
}
|
|
429
541
|
}
|
|
542
|
+
|
|
543
|
+
// Battery optimization check function - minimal implementation
|
|
544
|
+
AsyncFunction("isBatteryOptimizationExempted") { promise: Promise ->
|
|
545
|
+
try {
|
|
546
|
+
// API 23+ required for battery optimization checks
|
|
547
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
548
|
+
val context = appContext.reactContext!!
|
|
549
|
+
val pm = context.getSystemService(Context.POWER_SERVICE) as PowerManager
|
|
550
|
+
val packageName = context.packageName
|
|
551
|
+
val isExempted = pm.isIgnoringBatteryOptimizations(packageName)
|
|
552
|
+
promise.resolve(isExempted)
|
|
553
|
+
} else {
|
|
554
|
+
// For older Android versions, return true (no battery optimization restrictions)
|
|
555
|
+
sendEvent("onDebugLog", mapOf("message" to "Battery optimization not applicable for API < 23"))
|
|
556
|
+
promise.resolve(true)
|
|
557
|
+
}
|
|
558
|
+
} catch (e: Exception) {
|
|
559
|
+
sendEvent("onDebugLog", mapOf("message" to "Error checking battery optimization: ${e.message}"))
|
|
560
|
+
promise.resolve(false)
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
AsyncFunction("requestBatteryOptimizationExemption") { promise: Promise ->
|
|
565
|
+
try {
|
|
566
|
+
// API 23+ required for battery optimization
|
|
567
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
568
|
+
val context = appContext.reactContext!!
|
|
569
|
+
val pm = context.getSystemService(Context.POWER_SERVICE) as PowerManager
|
|
570
|
+
val packageName = context.packageName
|
|
571
|
+
|
|
572
|
+
// Check if already exempted
|
|
573
|
+
if (pm.isIgnoringBatteryOptimizations(packageName)) {
|
|
574
|
+
sendEvent("onDebugLog", mapOf("message" to "Battery optimization already exempted"))
|
|
575
|
+
promise.resolve(true)
|
|
576
|
+
return@AsyncFunction
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// Open battery optimization settings
|
|
580
|
+
val intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
|
|
581
|
+
intent.data = Uri.parse("package:$packageName")
|
|
582
|
+
appContext.currentActivity?.startActivity(intent)
|
|
583
|
+
|
|
584
|
+
sendEvent("onDebugLog", mapOf("message" to "Opened battery optimization settings"))
|
|
585
|
+
promise.resolve(false) // Settings opened, not exempted yet
|
|
586
|
+
} else {
|
|
587
|
+
// For older Android versions, return true (no battery optimization restrictions)
|
|
588
|
+
sendEvent("onDebugLog", mapOf("message" to "Battery optimization not applicable for API < 23"))
|
|
589
|
+
promise.resolve(true)
|
|
590
|
+
}
|
|
591
|
+
} catch (e: Exception) {
|
|
592
|
+
sendEvent("onDebugLog", mapOf("message" to "Error opening battery settings: ${e.message}"))
|
|
593
|
+
promise.reject("SETTINGS_ERROR", "Cannot open battery optimization settings", e)
|
|
594
|
+
}
|
|
595
|
+
}
|
|
430
596
|
}
|
|
431
597
|
|
|
432
598
|
private fun <T> T.serializeToMap(): Map<String, Any> {
|
package/build/Asleep.types.d.ts
CHANGED
|
@@ -84,6 +84,15 @@ export type AsleepAnalysisResult = {
|
|
|
84
84
|
breathStages?: number[];
|
|
85
85
|
snoringStages?: number[];
|
|
86
86
|
};
|
|
87
|
+
export type TrackingConfig = {
|
|
88
|
+
android?: {
|
|
89
|
+
notification?: {
|
|
90
|
+
title?: string;
|
|
91
|
+
text?: string;
|
|
92
|
+
icon?: string;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
};
|
|
87
96
|
export type AsleepEventType = {
|
|
88
97
|
onTrackingCreated: {
|
|
89
98
|
sessionId?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Asleep.types.d.ts","sourceRoot":"","sources":["../src/Asleep.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE;QACP,EAAE,EAAE,MAAM,CAAC;QACX,eAAe,EAAE,MAAM,CAAC;QACxB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B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CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,iBAAiB,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1C,kBAAkB,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,gBAAgB,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IACxC,gBAAgB,EAAE,SAAS,CAAC;IAC5B,qBAAqB,EAAE,SAAS,CAAC;IACjC,iBAAiB,EAAE,SAAS,CAAC;IAC7B,qBAAqB,EAAE,SAAS,CAAC;IACjC,YAAY,EAAE,SAAS,CAAC;IACxB,gBAAgB,EAAE,SAAS,CAAC;IAC5B,aAAa,EAAE,SAAS,CAAC;IACzB,UAAU,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAChC,kBAAkB,EAAE,SAAS,CAAC;IAC9B,cAAc,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAClC,iBAAiB,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACxC,gBAAgB,EAAE,oBAAoB,CAAC;CACxC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Asleep.types.js","sourceRoot":"","sources":["../src/Asleep.types.ts"],"names":[],"mappings":"","sourcesContent":["export type AsleepConfig = {\n apiKey: string;\n userId?: string;\n baseUrl?: string;\n callbackUrl?: string;\n};\n\nexport type AsleepSetupConfig = {\n apiKey: string;\n baseUrl?: string;\n callbackUrl?: string;\n service?: string;\n enableODA?: boolean;\n};\n\nexport type AsleepReport = {\n timezone: string;\n session: {\n id: string;\n createdTimezone: string;\n startTime: string;\n endTime?: string;\n unexpectedEndTime?: string;\n state: string;\n sleepStages?: number[];\n breathStages?: number[];\n snoringStages?: number[];\n };\n missingDataRatio: number;\n peculiarities: string[];\n stat?: AsleepStat;\n};\n\nexport type AsleepStat = {\n sleepCycleTime?: number[];\n timeInStableBreath?: number;\n timeInBed?: number;\n unstableBreathRatio?: number;\n sleepCycle?: number;\n timeInSleep?: number;\n breathingIndex?: number;\n deepLatency?: number;\n remLatency?: number;\n timeInSnoring?: number;\n wakeTime?: string;\n longestWaso?: number;\n lightRatio?: number;\n noSnoringRatio?: number;\n snoringCount?: number;\n unstableBreathCount?: number;\n timeInDeep?: number;\n sleepTime?: string;\n sleepCycleCount?: number;\n wakeupLatency?: number;\n breathingPattern?: string;\n timeInRem?: number;\n snoringRatio?: number;\n stableBreathRatio?: number;\n timeInSleepPeriod?: number;\n lightLatency?: number;\n remRatio?: number;\n sleepEfficiency?: number;\n timeInNoSnoring?: number;\n sleepLatency?: number;\n timeInLight?: number;\n sleepIndex?: number;\n sleepRatio?: number;\n timeInUnstableBreath?: number;\n wasoCount?: number;\n wakeRatio?: number;\n deepRatio?: number;\n timeInWake?: number;\n};\n\nexport type AsleepSession = {\n sessionId: string;\n state: string;\n sessionStartTime: string;\n sessionEndTime?: string;\n timeInBed?: number;\n};\n\nexport type AsleepAnalysisResult = {\n id?: string;\n state?: string;\n startTime?: string;\n endTime?: string;\n sleepStages?: number[];\n breathStages?: number[];\n snoringStages?: number[];\n};\n\nexport type AsleepEventType = {\n onTrackingCreated: { sessionId?: string };\n onTrackingUploaded: { sequence: number };\n onTrackingClosed: { sessionId: string };\n onTrackingFailed: undefined;\n onTrackingInterrupted: undefined;\n onTrackingResumed: undefined;\n onMicPermissionDenied: undefined;\n onUserJoined: undefined;\n onUserJoinFailed: undefined;\n onUserDeleted: undefined;\n onDebugLog: { message: string };\n onSetupDidComplete: undefined;\n onSetupDidFail: { error: string };\n onSetupInProgress: { progress: number };\n onAnalysisResult: AsleepAnalysisResult;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"Asleep.types.js","sourceRoot":"","sources":["../src/Asleep.types.ts"],"names":[],"mappings":"","sourcesContent":["export type AsleepConfig = {\n apiKey: string;\n userId?: string;\n baseUrl?: string;\n callbackUrl?: string;\n};\n\nexport type AsleepSetupConfig = {\n apiKey: string;\n baseUrl?: string;\n callbackUrl?: string;\n service?: string;\n enableODA?: boolean;\n};\n\nexport type AsleepReport = {\n timezone: string;\n session: {\n id: string;\n createdTimezone: string;\n startTime: string;\n endTime?: string;\n unexpectedEndTime?: string;\n state: string;\n sleepStages?: number[];\n breathStages?: number[];\n snoringStages?: number[];\n };\n missingDataRatio: number;\n peculiarities: string[];\n stat?: AsleepStat;\n};\n\nexport type AsleepStat = {\n sleepCycleTime?: number[];\n timeInStableBreath?: number;\n timeInBed?: number;\n unstableBreathRatio?: number;\n sleepCycle?: number;\n timeInSleep?: number;\n breathingIndex?: number;\n deepLatency?: number;\n remLatency?: number;\n timeInSnoring?: number;\n wakeTime?: string;\n longestWaso?: number;\n lightRatio?: number;\n noSnoringRatio?: number;\n snoringCount?: number;\n unstableBreathCount?: number;\n timeInDeep?: number;\n sleepTime?: string;\n sleepCycleCount?: number;\n wakeupLatency?: number;\n breathingPattern?: string;\n timeInRem?: number;\n snoringRatio?: number;\n stableBreathRatio?: number;\n timeInSleepPeriod?: number;\n lightLatency?: number;\n remRatio?: number;\n sleepEfficiency?: number;\n timeInNoSnoring?: number;\n sleepLatency?: number;\n timeInLight?: number;\n sleepIndex?: number;\n sleepRatio?: number;\n timeInUnstableBreath?: number;\n wasoCount?: number;\n wakeRatio?: number;\n deepRatio?: number;\n timeInWake?: number;\n};\n\nexport type AsleepSession = {\n sessionId: string;\n state: string;\n sessionStartTime: string;\n sessionEndTime?: string;\n timeInBed?: number;\n};\n\nexport type AsleepAnalysisResult = {\n id?: string;\n state?: string;\n startTime?: string;\n endTime?: string;\n sleepStages?: number[];\n breathStages?: number[];\n snoringStages?: number[];\n};\n\nexport type TrackingConfig = {\n android?: {\n notification?: {\n title?: string;\n text?: string;\n icon?: string;\n };\n };\n};\n\nexport type AsleepEventType = {\n onTrackingCreated: { sessionId?: string };\n onTrackingUploaded: { sequence: number };\n onTrackingClosed: { sessionId: string };\n onTrackingFailed: undefined;\n onTrackingInterrupted: undefined;\n onTrackingResumed: undefined;\n onMicPermissionDenied: undefined;\n onUserJoined: undefined;\n onUserJoinFailed: undefined;\n onUserDeleted: undefined;\n onDebugLog: { message: string };\n onSetupDidComplete: undefined;\n onSetupDidFail: { error: string };\n onSetupInProgress: { progress: number };\n onAnalysisResult: AsleepAnalysisResult;\n};\n"]}
|
package/build/AsleepStore.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AsleepConfig, AsleepSetupConfig, AsleepEventType, AsleepReport, AsleepSession, AsleepAnalysisResult } from "./Asleep.types";
|
|
1
|
+
import { AsleepConfig, AsleepSetupConfig, AsleepEventType, AsleepReport, AsleepSession, AsleepAnalysisResult, TrackingConfig } from "./Asleep.types";
|
|
2
2
|
export interface AsleepState {
|
|
3
3
|
didClose: boolean;
|
|
4
4
|
isTracking: boolean;
|
|
@@ -15,14 +15,26 @@ export interface AsleepState {
|
|
|
15
15
|
isInitialized: boolean;
|
|
16
16
|
isSetupInProgress: boolean;
|
|
17
17
|
isSetupComplete: boolean;
|
|
18
|
+
hasCheckedStatus: boolean;
|
|
19
|
+
hasCheckedBatteryOptimization: boolean;
|
|
18
20
|
setup: (config: AsleepSetupConfig) => Promise<void>;
|
|
19
21
|
initAsleepConfig: (config: AsleepConfig) => Promise<void>;
|
|
20
|
-
|
|
22
|
+
checkAndRestoreTracking: () => Promise<{
|
|
23
|
+
hasActiveSession: boolean;
|
|
24
|
+
}>;
|
|
25
|
+
checkBatteryOptimization: () => Promise<{
|
|
26
|
+
exempted: boolean;
|
|
27
|
+
platform: string;
|
|
28
|
+
message?: string;
|
|
29
|
+
}>;
|
|
30
|
+
requestBatteryOptimizationExemption: () => Promise<boolean>;
|
|
31
|
+
startTracking: (config?: TrackingConfig) => Promise<void>;
|
|
21
32
|
stopTracking: () => Promise<void>;
|
|
22
33
|
getReport: (sessionId: string) => Promise<AsleepReport | null>;
|
|
23
34
|
getReportList: (fromDate: string, toDate: string) => Promise<AsleepSession[]>;
|
|
24
35
|
deleteSession: (sessionId: string) => Promise<void>;
|
|
25
36
|
requestMicrophonePermission: () => Promise<boolean>;
|
|
37
|
+
requestRequiredPermissions: () => Promise<boolean>;
|
|
26
38
|
setCustomNotification: (title: string, text: string) => Promise<void>;
|
|
27
39
|
enableLog: (print: boolean) => void;
|
|
28
40
|
requestAnalysis: () => Promise<AsleepAnalysisResult | null>;
|
|
@@ -40,6 +52,8 @@ export interface AsleepState {
|
|
|
40
52
|
setIsInitialized: (initialized: boolean) => void;
|
|
41
53
|
setIsSetupInProgress: (inProgress: boolean) => void;
|
|
42
54
|
setIsSetupComplete: (complete: boolean) => void;
|
|
55
|
+
setHasCheckedStatus: (checked: boolean) => void;
|
|
56
|
+
setHasCheckedBatteryOptimization: (checked: boolean) => void;
|
|
43
57
|
addLog: (log: string) => void;
|
|
44
58
|
}
|
|
45
59
|
export declare const useAsleepStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<AsleepState>, "subscribe"> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsleepStore.d.ts","sourceRoot":"","sources":["../src/AsleepStore.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,oBAAoB,
|
|
1
|
+
{"version":3,"file":"AsleepStore.d.ts","sourceRoot":"","sources":["../src/AsleepStore.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,cAAc,EACf,MAAM,gBAAgB,CAAC;AAKxB,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,E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C;IAClD,gBAAgB,EAAE,CAAC,WAAW,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,oBAAoB,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IACpD,kBAAkB,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IAChD,mBAAmB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAChD,gCAAgC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7D,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/B;AAeD,eAAO,MAAM,cAAc;;;;;;;;EA6e1B,CAAC;AAOF,eAAO,MAAM,yBAAyB,cAHV,IAqI3B,CAAC"}
|
package/build/AsleepStore.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { create } from "zustand";
|
|
2
2
|
import { subscribeWithSelector } from "zustand/middleware";
|
|
3
3
|
import { EventEmitter } from "expo-modules-core";
|
|
4
|
-
import {
|
|
4
|
+
import { Platform, PermissionsAndroid } from "react-native";
|
|
5
5
|
import AsleepModule from "./AsleepModule";
|
|
6
6
|
const emitter = new EventEmitter(AsleepModule);
|
|
7
7
|
const convertKeysToCamelCase = (obj) => {
|
|
@@ -34,6 +34,10 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
34
34
|
isInitialized: false,
|
|
35
35
|
isSetupInProgress: false,
|
|
36
36
|
isSetupComplete: false,
|
|
37
|
+
// Service status state
|
|
38
|
+
hasCheckedStatus: false,
|
|
39
|
+
// Battery optimization state
|
|
40
|
+
hasCheckedBatteryOptimization: false,
|
|
37
41
|
// actions
|
|
38
42
|
setup: async (config) => {
|
|
39
43
|
try {
|
|
@@ -81,9 +85,82 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
81
85
|
throw error;
|
|
82
86
|
}
|
|
83
87
|
},
|
|
84
|
-
|
|
88
|
+
checkAndRestoreTracking: async () => {
|
|
85
89
|
try {
|
|
86
|
-
const {
|
|
90
|
+
const { addLog } = get();
|
|
91
|
+
addLog("[checkAndRestoreTracking] Start");
|
|
92
|
+
// Check if sleep tracking service is alive
|
|
93
|
+
const isAlive = await AsleepModule.isSleepTrackingAlive();
|
|
94
|
+
set({
|
|
95
|
+
hasCheckedStatus: true
|
|
96
|
+
});
|
|
97
|
+
// If service is alive on Android, restore connection to it
|
|
98
|
+
if (isAlive && Platform.OS === "android") {
|
|
99
|
+
addLog("[checkAndRestoreTracking] Service is alive, restoring connection...");
|
|
100
|
+
const isConnected = await AsleepModule.connectSleepTracking();
|
|
101
|
+
if (isConnected) {
|
|
102
|
+
set({ isTracking: true });
|
|
103
|
+
addLog("[checkAndRestoreTracking] Successfully restored connection to existing service");
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
addLog("[checkAndRestoreTracking] Failed to restore connection to existing service");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
addLog(`[checkAndRestoreTracking] Complete - hasActiveSession: ${isAlive}`);
|
|
110
|
+
return {
|
|
111
|
+
hasActiveSession: isAlive
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.error("checkAndRestoreTracking error:", error);
|
|
116
|
+
set({ error: error.message });
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
checkBatteryOptimization: async () => {
|
|
121
|
+
const { addLog } = get();
|
|
122
|
+
addLog("[checkBatteryOptimization] Checking battery optimization status...");
|
|
123
|
+
// Mark that check was performed (required for startTracking)
|
|
124
|
+
set({ hasCheckedBatteryOptimization: true });
|
|
125
|
+
if (Platform.OS === 'ios') {
|
|
126
|
+
addLog("[checkBatteryOptimization] iOS - not applicable");
|
|
127
|
+
return { exempted: true, platform: 'ios' };
|
|
128
|
+
}
|
|
129
|
+
// Android: Check current status
|
|
130
|
+
const exempted = await AsleepModule.isBatteryOptimizationExempted();
|
|
131
|
+
addLog(`[checkBatteryOptimization] Exempted: ${exempted}`);
|
|
132
|
+
return {
|
|
133
|
+
exempted,
|
|
134
|
+
platform: 'android',
|
|
135
|
+
message: exempted ?
|
|
136
|
+
"Battery optimization disabled - ready for tracking" :
|
|
137
|
+
"Battery optimization must be disabled for reliable tracking"
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
requestBatteryOptimizationExemption: async () => {
|
|
141
|
+
const { addLog } = get();
|
|
142
|
+
if (Platform.OS === 'ios') {
|
|
143
|
+
addLog("[requestBatteryOptimizationExemption] iOS - not applicable");
|
|
144
|
+
return true; // Not applicable on iOS
|
|
145
|
+
}
|
|
146
|
+
addLog("[requestBatteryOptimizationExemption] Opening battery settings...");
|
|
147
|
+
// This just opens settings, doesn't wait
|
|
148
|
+
// Returns true if already exempted, false if settings opened
|
|
149
|
+
return await AsleepModule.requestBatteryOptimizationExemption();
|
|
150
|
+
},
|
|
151
|
+
startTracking: async (config) => {
|
|
152
|
+
try {
|
|
153
|
+
const { requestRequiredPermissions, addLog, isODAEnabled, isSetupInProgress, hasCheckedStatus, } = get();
|
|
154
|
+
// Enforce that checkAndRestoreTracking must be called first
|
|
155
|
+
if (!hasCheckedStatus) {
|
|
156
|
+
addLog("[startTracking] Must call checkAndRestoreTracking() at app startup");
|
|
157
|
+
throw new Error("Must call checkAndRestoreTracking() at app startup before starting tracking");
|
|
158
|
+
}
|
|
159
|
+
// Enforce battery optimization was checked (developer awareness)
|
|
160
|
+
if (Platform.OS === 'android' && !get().hasCheckedBatteryOptimization) {
|
|
161
|
+
addLog("[startTracking] ERROR: Must check battery optimization first");
|
|
162
|
+
throw new Error("Must call checkBatteryOptimization() before starting tracking on Android");
|
|
163
|
+
}
|
|
87
164
|
// Block startTracking execution if setup is in progress
|
|
88
165
|
if (isSetupInProgress) {
|
|
89
166
|
addLog("[startTracking] Cannot start tracking while setup is in progress.");
|
|
@@ -95,10 +172,25 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
95
172
|
throw new Error("Tracking is already in progress.");
|
|
96
173
|
}
|
|
97
174
|
addLog("[startTracking] Start");
|
|
98
|
-
const permission = await
|
|
175
|
+
const permission = await requestRequiredPermissions();
|
|
99
176
|
if (!permission) {
|
|
100
|
-
|
|
101
|
-
|
|
177
|
+
// SDK shouldn't show UI directly - throw specific error message
|
|
178
|
+
if (Platform.OS === 'android' && Platform.Version >= 33) {
|
|
179
|
+
throw new Error("Microphone and notification permissions are required for sleep tracking");
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
throw new Error("Microphone permission is required for sleep tracking");
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// Always verify CURRENT exemption status
|
|
186
|
+
if (Platform.OS === 'android') {
|
|
187
|
+
const batteryExempted = await AsleepModule.isBatteryOptimizationExempted();
|
|
188
|
+
if (!batteryExempted) {
|
|
189
|
+
addLog("[startTracking] ERROR: Battery optimization not disabled");
|
|
190
|
+
throw new Error("Battery optimization must be disabled for reliable sleep tracking. " +
|
|
191
|
+
"Call requestBatteryOptimizationExemption() to guide user to settings.");
|
|
192
|
+
}
|
|
193
|
+
addLog("[startTracking] Battery optimization exempted - OK");
|
|
102
194
|
}
|
|
103
195
|
set({
|
|
104
196
|
didClose: false,
|
|
@@ -106,7 +198,7 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
106
198
|
isAnalyzing: false,
|
|
107
199
|
trackingStartTime: new Date(),
|
|
108
200
|
});
|
|
109
|
-
await AsleepModule.startTracking();
|
|
201
|
+
await AsleepModule.startTracking(config);
|
|
110
202
|
if (isODAEnabled) {
|
|
111
203
|
addLog("[startTracking] ODA enabled - real-time analysis will start automatically");
|
|
112
204
|
}
|
|
@@ -212,8 +304,40 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
212
304
|
throw error;
|
|
213
305
|
}
|
|
214
306
|
},
|
|
307
|
+
/**
|
|
308
|
+
* @deprecated Use requestRequiredPermissions instead. This method will be removed in a future version.
|
|
309
|
+
*/
|
|
215
310
|
requestMicrophonePermission: async () => {
|
|
216
|
-
|
|
311
|
+
console.warn('[AsleepSDK] requestMicrophonePermission is deprecated. Please use requestRequiredPermissions instead.');
|
|
312
|
+
return get().requestRequiredPermissions();
|
|
313
|
+
},
|
|
314
|
+
requestRequiredPermissions: async () => {
|
|
315
|
+
if (Platform.OS === 'android') {
|
|
316
|
+
try {
|
|
317
|
+
// Prepare permissions array with RECORD_AUDIO
|
|
318
|
+
const permissions = [PermissionsAndroid.PERMISSIONS.RECORD_AUDIO];
|
|
319
|
+
// Add POST_NOTIFICATIONS for Android 13+ (API level 33)
|
|
320
|
+
if (Platform.Version >= 33) {
|
|
321
|
+
permissions.push(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);
|
|
322
|
+
}
|
|
323
|
+
// Request all permissions together for better UX (single dialog)
|
|
324
|
+
const results = await PermissionsAndroid.requestMultiple(permissions);
|
|
325
|
+
// Check if all required permissions are granted
|
|
326
|
+
const audioGranted = results[PermissionsAndroid.PERMISSIONS.RECORD_AUDIO] ===
|
|
327
|
+
PermissionsAndroid.RESULTS.GRANTED;
|
|
328
|
+
const notificationGranted = Platform.Version >= 33 ?
|
|
329
|
+
results[PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS] ===
|
|
330
|
+
PermissionsAndroid.RESULTS.GRANTED : true;
|
|
331
|
+
// Both must be granted for tracking to work properly
|
|
332
|
+
return audioGranted && notificationGranted;
|
|
333
|
+
}
|
|
334
|
+
catch (err) {
|
|
335
|
+
console.warn('Permission request error:', err);
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
// iOS uses native implementation
|
|
340
|
+
return AsleepModule.requestRequiredPermissions();
|
|
217
341
|
},
|
|
218
342
|
setCustomNotification: async (title, text) => {
|
|
219
343
|
if (Platform.OS === "android") {
|
|
@@ -273,6 +397,8 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
273
397
|
setIsInitialized: (initialized) => set({ isInitialized: initialized }),
|
|
274
398
|
setIsSetupInProgress: (inProgress) => set({ isSetupInProgress: inProgress }),
|
|
275
399
|
setIsSetupComplete: (complete) => set({ isSetupComplete: complete }),
|
|
400
|
+
setHasCheckedStatus: (checked) => set({ hasCheckedStatus: checked }),
|
|
401
|
+
setHasCheckedBatteryOptimization: (checked) => set({ hasCheckedBatteryOptimization: checked }),
|
|
276
402
|
addLog: (log) => {
|
|
277
403
|
const { showDebugLog } = get();
|
|
278
404
|
const now = new Date();
|