Orbit Arcade Stage C: review fixes and verification
- Back on an Arcade page returns to Play Games; on Play Games it goes back to Orbit. - A game opening while How to Play is still closing isn't paused at once; only going out of sight pauses. - Lint: remember no longer returns Unit; the repo singleton's application context is marked as intended. - docs/arcade-stage-c.md and docs/VERIFICATION-arcade-stage-c.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -88,7 +88,7 @@ internal fun OrbitArcade(modifier: Modifier, onPlaying: (Boolean) -> Unit, onExi
|
||||
val context = LocalContext.current
|
||||
val profile = Profiles.current ?: return
|
||||
val repo = remember { ArcadeRepo.get(context) }
|
||||
remember { ArcadeLook.load(OrbitSettings(context)) }
|
||||
remember { OrbitSettings(context).also(ArcadeLook::load) }
|
||||
var data by remember(profile.id) { mutableStateOf(repo.store.load(profile.id)) }
|
||||
val latestData by rememberUpdatedState(data)
|
||||
val household = remember { repo.household }
|
||||
@@ -140,6 +140,8 @@ internal fun OrbitArcade(modifier: Modifier, onPlaying: (Boolean) -> Unit, onExi
|
||||
}
|
||||
}
|
||||
|
||||
// Back on one of the Arcade's pages goes to Play Games; on Play Games it goes back to Orbit TV (MainActivity).
|
||||
androidx.activity.compose.BackHandler(page != ArcadePage.Play) { page = ArcadePage.Play }
|
||||
val pick = remember(visible) { arcadePick(visible) }
|
||||
val recent = recentVisible(data.recent, visible)
|
||||
var chosen by remember { mutableStateOf(recent.firstOrNull() ?: pick ?: visible.firstOrNull()) }
|
||||
|
||||
@@ -24,6 +24,8 @@ internal class ArcadeRepo private constructor(context: Context) {
|
||||
fun legacyFlag(key: String, default: Boolean) = runCatching { legacy.getBoolean(key, default) }.getOrDefault(default)
|
||||
|
||||
companion object {
|
||||
// Holds only the application context, which lives as long as the app.
|
||||
@android.annotation.SuppressLint("StaticFieldLeak")
|
||||
@Volatile private var made: ArcadeRepo? = null
|
||||
fun get(context: Context): ArcadeRepo = made ?: synchronized(this) { made ?: ArcadeRepo(context).also { made = it } }
|
||||
}
|
||||
|
||||
@@ -22,14 +22,25 @@ internal fun rememberArcadeShown(): Boolean {
|
||||
return focused && state.isAtLeast(Lifecycle.State.RESUMED)
|
||||
}
|
||||
|
||||
/** Pauses a running game when the Arcade goes out of sight or loses the remote, so nobody loses a game to a pop-up. */
|
||||
/**
|
||||
* Pauses a running game when the Arcade goes out of sight or loses the remote, so nobody loses a game to a pop-up.
|
||||
* Only a change from shown to hidden pauses: a game that opens while a closing dialog (How to Play) still holds the
|
||||
* window's focus isn't paused at once; its loop simply waits ([ArcadeGameLoop]) until the focus comes back.
|
||||
*/
|
||||
@Composable
|
||||
internal fun PauseWhenHidden(alive: Boolean, pause: () -> Unit) {
|
||||
val shown = rememberArcadeShown()
|
||||
val latest by rememberUpdatedState(pause)
|
||||
LaunchedEffect(shown) { if (!shown && alive) latest() }
|
||||
val wasShown = androidx.compose.runtime.remember { booleanArrayOf(false) }
|
||||
LaunchedEffect(shown) {
|
||||
if (shouldPauseOnHide(wasShown[0], shown, alive)) latest()
|
||||
if (shown) wasShown[0] = true
|
||||
}
|
||||
}
|
||||
|
||||
/** Pause only when a game that was on screen goes out of sight while it's still going. */
|
||||
internal fun shouldPauseOnHide(wasShown: Boolean, shown: Boolean, alive: Boolean) = wasShown && !shown && alive
|
||||
|
||||
/**
|
||||
* The shared frame loop: [onFrame] gets each frame's time and the time since the previous one, from the second frame of
|
||||
* each run (the first only sets the clock, so time spent paused or hidden never arrives as one big step). [onStart] runs
|
||||
|
||||
@@ -45,4 +45,11 @@ class ArcadeInputTest {
|
||||
assertTrue(loopRuns(paused = false, alive = true, shown = true))
|
||||
assertFalse(loopRuns(true, true, true)); assertFalse(loopRuns(false, false, true)); assertFalse(loopRuns(false, true, false))
|
||||
}
|
||||
|
||||
@Test fun onlyGoingOutOfSightPausesNotStartingBehindADialog() {
|
||||
assertFalse(shouldPauseOnHide(wasShown = false, shown = false, alive = true))
|
||||
assertTrue(shouldPauseOnHide(wasShown = true, shown = false, alive = true))
|
||||
assertFalse(shouldPauseOnHide(wasShown = true, shown = false, alive = false))
|
||||
assertFalse(shouldPauseOnHide(wasShown = true, shown = true, alive = true))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user