mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-10 08:27:04 +00:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015qgqQKHSewRHVM8vSCLt9P
This commit is contained in:
+9
-2
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user