A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
Reduce motion: one policy, and Mochi stops idling
Claude7fe77f6d0fc1
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/AppModel.kt b/android/app/src/main/kotlin/com/coucou/android/app/AppModel.ktindex af62022b..c265d8ec 100644--- a/android/app/src/main/kotlin/com/coucou/android/app/AppModel.kt+++ b/android/app/src/main/kotlin/com/coucou/android/app/AppModel.kt@@ -142,6 +142,7 @@ class AppModel(private val context: Context) : LinkListener {UserSettings.save(kv, next)applySound()notifier.applyApprovalSettings(settings.vibration, settings.keepScreenOff)+ com.coucou.android.core.MotionState.choice = settings.motion// Switching the relay on or off rebuilds the connection with the right routes.if (relayChanged) currentPairing?.let { restartLink(it) }}@@ -154,6 +155,7 @@ class AppModel(private val context: Context) : LinkListener {init {applySound()notifier.applyApprovalSettings(settings.vibration, settings.keepScreenOff)+ com.coucou.android.core.MotionState.choice = settings.motion}/** What the computer says Mochi wears ("auto" or an outfit); the last one it told, kept for when it is away. */diff --git a/android/app/src/main/kotlin/com/coucou/android/core/MotionPolicy.kt b/android/app/src/main/kotlin/com/coucou/android/core/MotionPolicy.ktnew file mode 100644index 00000000..fe95e15b--- /dev/null+++ b/android/app/src/main/kotlin/com/coucou/android/core/MotionPolicy.kt@@ -0,0 +1,28 @@+package com.coucou.android.core++/** What the user chose for motion: follow Android's "Remove animations" (the default), always reduce it, or always keep it. */+enum class MotionChoice(val key: String) {+ SYSTEM("system"), REDUCE("reduce"), FULL("full");++ companion object {+ /** An unknown or missing key follows the system. */+ fun parse(key: String?): MotionChoice = values().firstOrNull { it.key == key } ?: SYSTEM+ }+}++/**+ * Whether motion is reduced. Reduced motion stops Mochi's idle animations (breathing, bouncing, scanning, blinking, floating+ * particles) and turns the island's and the sheets' springs into a short fade or a jump. Pure, so every case is a unit test.+ */+object MotionPolicy {+ fun reduced(choice: MotionChoice, animatorDurationScale: Float): Boolean = when (choice) {+ MotionChoice.REDUCE -> true+ MotionChoice.FULL -> false+ MotionChoice.SYSTEM -> MotionSpec.isReduced(animatorDurationScale)+ }+}++/** The choice in force, set by the app model when Settings change; read by the Mochi view, the island and the sheets. */+object MotionState {+ @Volatile var choice: MotionChoice = MotionChoice.SYSTEM+}diff --git a/android/app/src/main/kotlin/com/coucou/android/core/UserSettings.kt b/android/app/src/main/kotlin/com/coucou/android/core/UserSettings.ktindex 6efe4fb9..c289491c 100644--- a/android/app/src/main/kotlin/com/coucou/android/core/UserSettings.kt+++ b/android/app/src/main/kotlin/com/coucou/android/core/UserSettings.kt@@ -42,6 +42,8 @@ data class UserSettings(val keepScreenOff: Boolean = false,/** How a request buzzes the phone; the standard pattern is today's. */val vibration: VibrationChoice = VibrationChoice.STANDARD,+ /** Reduce motion: follow the system (default), always, or never. */+ val motion: MotionChoice = MotionChoice.SYSTEM,) {companion object {private const val SOUND = "sound_on"@@ -54,6 +56,7 @@ data class UserSettings(private const val RELAY = "use_relay"private const val NO_WAKE = "no_wake_screen"private const val VIBRATION = "vibration_choice"+ private const val MOTION = "motion_choice"fun load(store: KeyValueStore): UserSettings {val d = UserSettings()@@ -70,6 +73,7 @@ data class UserSettings(useRelay = store.getBoolean(RELAY, d.useRelay),keepScreenOff = store.getBoolean(NO_WAKE, d.keepScreenOff),vibration = VibrationChoice.parse(store.getString(VIBRATION, d.vibration.key)),+ motion = MotionChoice.parse(store.getString(MOTION, d.motion.key)),)}@@ -84,6 +88,7 @@ data class UserSettings(store.put(RELAY, s.useRelay)store.put(NO_WAKE, s.keepScreenOff)store.put(VIBRATION, s.vibration.key)+ store.put(MOTION, s.motion.key)}}}diff --git a/android/app/src/main/kotlin/com/coucou/android/mochi/MochiEngine.kt b/android/app/src/main/kotlin/com/coucou/android/mochi/MochiEngine.ktindex 79e4fd4e..d4e5df48 100644--- a/android/app/src/main/kotlin/com/coucou/android/mochi/MochiEngine.kt+++ b/android/app/src/main/kotlin/com/coucou/android/mochi/MochiEngine.kt@@ -392,10 +392,16 @@ class MochiEngine(/** Wearing something visible: the body then turns as one piece when it rolls. */val rigidRoll: Boolean get() = !isMini && outfit != Outfit.NONE && outfitPresence > 0.05+ /**+ * Reduce motion (Settings): no idle animation at all, so nothing moves until the state changes: no breathing, bouncing or scanning,+ * no random blinks, no floating particles and no wandering of the small bots. A change of state still plays, once.+ */+ @Volatile var reduceMotion: Boolean = false+/** True while anything is still moving, so the host can stop its frame loop. */val busy: Booleanget() = tweens.isNotEmpty() || scheduled.isNotEmpty() || _particles.isNotEmpty() ||- cfg.bounces || cfg.scans || cfg.breathes || cfg.zz || cfg.sweat || isMini ||+ (!reduceMotion && (cfg.bounces || cfg.scans || cfg.breathes || cfg.zz || cfg.sweat || isMini)) ||abs(tgYaw - yaw) > 0.002 || abs(tgPitch - pitch) > 0.002 || abs(tgTilt - tilt) > 0.002 ||abs(tgSy - sy) > 0.002 || abs(tgSx - sx) > 0.002 || abs(tgEs - es) > 0.002 ||slotH > 0.001 || abs(slotHVel) > 0.001 ||@@ -446,7 +452,7 @@ class MochiEngine(ty = ty * 0.35 + lx * 0.55tp = tp * 0.3 + ly * 0.5}- if (cfg.scans) {+ if (cfg.scans && !reduceMotion) {ty = sin(t * 2.6) * 0.6tp = -0.06}@@ -454,7 +460,7 @@ class MochiEngine(if (state == BotState.DIZZY) ty = sin(t * 9) * 0.25// Mini bots never follow the pointer; they wander.- if (isMini && cfg.look == null && !cfg.scans && state != BotState.SLEEPING && state != BotState.DIZZY) {+ if (isMini && !reduceMotion && cfg.look == null && !cfg.scans && state != BotState.SLEEPING && state != BotState.DIZZY) {if (n > miniLookNextTime) {miniLookX = -0.88 + random.nextDouble() * 1.76miniLookY = -0.55 + random.nextDouble() * 1.0@@ -473,15 +479,15 @@ class MochiEngine(tgTilt = -0.06 + sin(2 * PI * 1.2 * wt) * 0.07}- val bounce = if (cfg.bounces) -abs(sin(t * 5.2)) * 0.07 else 0.0+ val bounce = if (cfg.bounces && !reduceMotion) -abs(sin(t * 5.2)) * 0.07 else 0.0val kGen = 1 - 0.0008.pow(dt)if (Prop.OY !in locks) oy += (bounce - oy) * kGen- if (cfg.breathes) {+ if (cfg.breathes && !reduceMotion) {val amp = if (isMini) 0.07 else 0.035tgSy = 1 + sin(t * 1.8) * amptgSx = 1 - sin(t * 1.8) * amp * 0.57- } else if (isMini) {+ } else if (isMini && !reduceMotion) {tgSy = 1 + sin(t * 2.2) * 0.04tgSx = 1 - sin(t * 2.2) * 0.02} else {@@ -489,7 +495,7 @@ class MochiEngine(tgSx = 1.0}- if (isMini && n > miniNextBehavior) doMiniBehaviorLoop()+ if (isMini && !reduceMotion && n > miniNextBehavior) doMiniBehaviorLoop()val kLook = 1 - 0.0025.pow(dt)if (Prop.YAW !in locks) yaw += (tgYaw - yaw) * kLook@@ -502,7 +508,7 @@ class MochiEngine(col = col.mix(colT, 1 - 0.002.pow(dt))if (n > nextBlink) {- if (state != BotState.SLEEPING && state != BotState.DIZZY) {+ if (!reduceMotion && state != BotState.SLEEPING && state != BotState.DIZZY) {blink()if (random.nextDouble() < 0.22) after(230.0) { blink() }}@@ -516,8 +522,8 @@ class MochiEngine(if (n - lastAmbient > 1.3) {lastAmbient = n- if (cfg.zz) emit(ParticleType.Z, 1)- if (!isMini && cfg.sweat && random.nextDouble() < 0.5) emit(ParticleType.SWEAT, 1)+ if (!reduceMotion && cfg.zz) emit(ParticleType.Z, 1)+ if (!reduceMotion && !isMini && cfg.sweat && random.nextDouble() < 0.5) emit(ParticleType.SWEAT, 1)}_particles.forEach { it.age += dt }diff --git a/android/app/src/main/kotlin/com/coucou/android/mochi/MochiView.kt b/android/app/src/main/kotlin/com/coucou/android/mochi/MochiView.ktindex afe030ee..30d7cbb7 100644--- a/android/app/src/main/kotlin/com/coucou/android/mochi/MochiView.kt+++ b/android/app/src/main/kotlin/com/coucou/android/mochi/MochiView.kt@@ -12,6 +12,8 @@ import androidx.lifecycle.Lifecycleimport androidx.lifecycle.repeatOnLifecycleimport com.coucou.android.mochi.MochiPainter.drawMochi+private const val IDLE_STEP_S = 0.25+/*** Hosts a [MochiEngine] and redraws it every frame while the screen is visible.* The frame loop only runs while the lifecycle is STARTED, so a backgrounded app costs no CPU.@@ -20,10 +22,21 @@ import com.coucou.android.mochi.MochiPainter.drawMochifun MochiView(engine: MochiEngine, modifier: Modifier = Modifier) {val frame = remember { mutableLongStateOf(0L) }val lifecycle = LocalLifecycleOwner.current.lifecycle+ val reduced = com.coucou.android.ui.reducedMotion()+ androidx.compose.runtime.SideEffect { engine.reduceMotion = reduced }LaunchedEffect(engine, lifecycle) {lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {var last = 0Lwhile (true) {+ // Reduce motion: nothing idles, so while nothing is moving the loop only wakes a few times a second (a state change+ // still plays, then he is still again).+ if (engine.reduceMotion && !engine.busy) {+ engine.update(IDLE_STEP_S)+ frame.longValue += 1+ kotlinx.coroutines.delay((IDLE_STEP_S * 1000).toLong())+ last = 0L+ continue+ }androidx.compose.runtime.withFrameNanos { ns ->val dt = if (last == 0L) 1.0 / 60 else ((ns - last) / 1e9).coerceIn(0.0, 0.1)last = nsdiff --git a/android/app/src/test/kotlin/com/coucou/android/ReduceMotionTest.kt b/android/app/src/test/kotlin/com/coucou/android/ReduceMotionTest.ktnew file mode 100644index 00000000..d768eae3--- /dev/null+++ b/android/app/src/test/kotlin/com/coucou/android/ReduceMotionTest.kt@@ -0,0 +1,88 @@+package com.coucou.android++import com.coucou.android.core.KeyValueStore+import com.coucou.android.core.MotionChoice+import com.coucou.android.core.MotionPolicy+import com.coucou.android.core.UserSettings+import com.coucou.android.mochi.BotState+import com.coucou.android.mochi.MochiEngine+import com.coucou.android.mochi.SoundSink+import java.io.File+import kotlin.random.Random+import org.junit.Assert.assertEquals+import org.junit.Assert.assertFalse+import org.junit.Assert.assertTrue+import org.junit.Test++class ReduceMotionTest {+ private class Clock { var ms = 10_000.0 }+ private fun engine(clock: Clock, state: BotState) =+ MochiEngine({ clock.ms }, Random(1), SoundSink { }).apply { setState(state, force = true) }+ private fun MochiEngine.run(clock: Clock, ms: Int) { repeat(ms / 16) { clock.ms += 16; update(0.016) } }++ @Test fun followsTheSystemUnlessTheUserChoseOtherwise() {+ assertTrue(MotionPolicy.reduced(MotionChoice.SYSTEM, 0f))+ assertFalse(MotionPolicy.reduced(MotionChoice.SYSTEM, 1f))+ assertFalse(MotionPolicy.reduced(MotionChoice.SYSTEM, 0.5f))+ assertTrue(MotionPolicy.reduced(MotionChoice.REDUCE, 1f))+ assertFalse(MotionPolicy.reduced(MotionChoice.FULL, 0f))+ }++ @Test fun theDefaultFollowsTheSystemAndIsSaved() {+ assertEquals(MotionChoice.SYSTEM, UserSettings().motion)+ assertEquals(MotionChoice.SYSTEM, MotionChoice.parse(null))+ assertEquals(MotionChoice.SYSTEM, MotionChoice.parse("fast"))+ for (c in MotionChoice.values()) assertEquals(c, MotionChoice.parse(c.key))+ val m = HashMap<String, Any>()+ val store = object : KeyValueStore {+ override fun getBoolean(key: String, default: Boolean) = m[key] as? Boolean ?: default+ override fun getInt(key: String, default: Int) = m[key] as? Int ?: default+ override fun getFloat(key: String, default: Float) = m[key] as? Float ?: default+ override fun getString(key: String, default: String) = m[key] as? String ?: default+ override fun put(key: String, value: Any) { m[key] = value }+ }+ UserSettings.save(store, UserSettings(motion = MotionChoice.REDUCE))+ assertEquals(MotionChoice.REDUCE, UserSettings.load(store).motion)+ }++ @Test fun anIdleBouncingMochiStopsWhenMotionIsReduced() {+ val clock = Clock()+ val moving = engine(clock, BotState.APPROVAL) // bounces for as long as he waits+ moving.run(clock, 3_000)+ assertTrue("without reduce motion he keeps moving", moving.busy)++ val still = engine(clock, BotState.APPROVAL).apply { reduceMotion = true }+ still.run(clock, 3_000)+ assertFalse("with it, nothing idles once the state has played", still.busy)+ assertEquals(0.0, still.oy, 1e-3)+ }++ @Test fun aSleepingMochiEmitsNoFloatingZsWhenMotionIsReduced() {+ val clock = Clock()+ val still = engine(clock, BotState.SLEEPING).apply { reduceMotion = true }+ still.run(clock, 6_000)+ assertTrue(still.particles.isEmpty())+ assertFalse(still.busy)+ val moving = engine(clock, BotState.SLEEPING)+ moving.run(clock, 6_000)+ assertTrue("normally the Zs float up", moving.particles.isNotEmpty() || moving.busy)+ }++ @Test fun aChangeOfStateStillPlaysThenMochiIsStill() {+ val clock = Clock()+ val e = engine(clock, BotState.IDLE).apply { reduceMotion = true }+ e.run(clock, 1_000)+ e.setState(BotState.FINISHED)+ e.run(clock, 4_000)+ assertFalse(e.busy)+ }++ @Test fun settingsOffersTheChoice() {+ val ui = File("src/main/kotlin/com/coucou/android/ui/SettingsScreens.kt").readText()+ assertTrue(ui.contains("MotionChoice.REDUCE") && ui.contains("R.string.settings_motion"))+ // The island and the Mochi view both ask the one policy.+ assertTrue(File("src/main/kotlin/com/coucou/android/ui/IslandOverlay.kt").readText().contains("MotionPolicy.reduced"))+ assertTrue(File("src/main/kotlin/com/coucou/android/ui/DesignSystem.kt").readText().contains("MotionPolicy.reduced"))+ assertTrue(File("src/main/kotlin/com/coucou/android/mochi/MochiView.kt").readText().contains("engine.reduceMotion"))+ }+}