fix: fiabilité de la soumission du score en fin de partie

This commit is contained in:
herel committed 2026-08-29 09:05:38 +02:00
1 parent 2f73d2cd15
commit 639a34de5b
1 file changed
+10 -4
@@ -20,7 +20,9 @@ import com.livrets.ui.HistoryScreen
import com.livrets.ui.HomeScreen import com.livrets.ui.HomeScreen
import com.livrets.ui.ResultsScreen import com.livrets.ui.ResultsScreen
import com.livrets.ui.SwipeBack import com.livrets.ui.SwipeBack
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okio.Path.Companion.toPath import okio.Path.Companion.toPath
sealed interface Screen { sealed interface Screen {
@@ -63,11 +65,15 @@ fun App(
config = current.config, config = current.config,
onFinish = { result -> onFinish = { result ->
screen = Screen.Results(result) screen = Screen.Results(result)
scope.launch { history.save(result) }
scope.launch { scope.launch {
val score = result.leaderboardScore() withContext(NonCancellable) { history.save(result) }
if (score > 0 && gamesServices.isSignedIn()) { }
gamesServices.submitScore(result.config.leaderboardId(), score) scope.launch {
withContext(NonCancellable) {
val score = result.leaderboardScore()
if (score > 0 && (gamesServices.isSignedIn() || gamesServices.signIn())) {
gamesServices.submitScore(result.config.leaderboardId(), score)
}
} }
} }
}, },