From fdf76824097d516feb67f65cfd33214c5f994c39 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 16 Jun 2026 23:23:43 +0000 Subject: [PATCH] feat: re-scan Health Connect when the app resumes The suggestion only scanned once when the Workouts screen first opened, so a workout that synced afterwards (e.g. a watch workout reaching Health Connect while Amethyst was backgrounded) never appeared until a cold restart. Replace the one-shot LaunchedEffect with a LifecycleResumeEffect so we scan on entry and again every time the app returns to the foreground. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_015qgqQKHSewRHVM8vSCLt9P --- .../workouts/suggestion/WorkoutSuggestionCard.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/workouts/suggestion/WorkoutSuggestionCard.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/workouts/suggestion/WorkoutSuggestionCard.kt index 5c17c3c576..1253003edf 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/workouts/suggestion/WorkoutSuggestionCard.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/workouts/suggestion/WorkoutSuggestionCard.kt @@ -43,7 +43,6 @@ import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -56,6 +55,7 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.health.connect.client.PermissionController +import androidx.lifecycle.compose.LifecycleResumeEffect import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.commons.icons.symbols.Icon @@ -112,7 +112,14 @@ fun WorkoutSuggestions( scope.launch { state.refresh() } } - LaunchedEffect(pubkeyHex) { state.refresh() } + // Scan on entry and every time the app returns to the foreground — a workout finished on + // a watch (Samsung Health → Health Connect) typically syncs while Amethyst is backgrounded, + // so coming back should pick it up. LifecycleResumeEffect runs on the initial RESUMED state + // too, so this also covers the first scan. + LifecycleResumeEffect(pubkeyHex) { + scope.launch { state.refresh() } + onPauseOrDispose {} + } val suggestions by state.suggestions.collectAsStateWithLifecycle() val hasPermission by state.hasPermission.collectAsStateWithLifecycle()