Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ local.properties
.claude/
/data/schemas/
references/

# Gradle wrapper JAR (binary - generate with `gradle wrapper`)
gradle/wrapper/gradle-wrapper.jar
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -256,13 +257,17 @@ class WhoopRecordingService : Service() {
pendingLiveRestartAfterStop = false
startupMode = null
val wasHistoricalSync = currentMode == WhoopSessionMode.HISTORICAL_SYNC
recordCollectorJob?.cancel()
recordCollectorJob = null
unknownCollectorJob?.cancel()
unknownCollectorJob = null
runCatching { gattManager.disableActiveStreams() }
.onFailure { Timber.w(it, "Failed to disable WHOOP streams before disconnect") }
gattManager.disconnect()
// Give the collectors a moment to drain any records already buffered
// from the GATT callback before we cancel them, so the last batch of
// historical/live data isn't dropped on the floor at shutdown.
delay(500L)
recordCollectorJob?.cancelAndJoin()
recordCollectorJob = null
unknownCollectorJob?.cancelAndJoin()
unknownCollectorJob = null
if (currentSessionId >= 0) {
val sessionId = currentSessionId
recordingRepo.endSession(sessionId)
Expand Down Expand Up @@ -716,8 +721,8 @@ class WhoopRecordingService : Service() {
val sessionId = currentSessionId
if (sessionId < 0L) return
runBlocking {
recordCollectorJob?.cancel()
unknownCollectorJob?.cancel()
recordCollectorJob?.cancelAndJoin()
unknownCollectorJob?.cancelAndJoin()
runCatching { gattManager.disableActiveStreams() }
.onFailure { Timber.w(it, "Failed to disable WHOOP streams during $reason") }
recordingRepo.endSession(sessionId)
Expand Down
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
251 changes: 251 additions & 0 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,6 @@ class WhoopGattManager @Inject constructor(
}

record?.let { _records.tryEmit(it) }
if (
sessionMode == WhoopSessionMode.HISTORICAL_SYNC &&
!historicalSyncDeferred.isCompleted &&
(packetType == 0x28 || packetType == 0x2B)
) {
traceInternal("metadata", "Historical sync implicitly complete after realtime frame")
historicalSyncDeferred.complete(Unit)
_state.value = ConnectionState.READY
}
if (packetType == 0x30) {
if (record == null) {
val eventType = eventType(frame)
Expand Down
Loading