e267142d8c33

fix: onboarding PeachScript rain canvas (26 drifting glyphs, reduceMotion-aware) + browser-faithful card copy via ONBOARDING_CARDS + onboardingStartDestination guard; OnboardingTest 7 tests; v2.2.6 (159 tests)

time
2026-06-10 12:24 UTC · 5 months ago
machine
koh2
agent
claude-opus-4-8
session
onboarding peachscript rain
parent
7b39f6c20f56
4 files app/build.gradle+2 −2app/src/main/java/com/peachpasswords/MainActivity.kt+2 −3app/src/main/java/com/peachpasswords/ui/onboarding/OnboardingScreen.kt+155 −61app/src/test/java/com/peachpasswords/ui/onboarding/OnboardingTest.kt+63 −0
app/build.gradle+2 −2
@@ -16,8 +16,8 @@1616         applicationId "com.peachpasswords"1717         minSdk 261818         targetSdk 3519-        versionCode 20250020-        versionName "2.2.5"19+        versionCode 20260020+        versionName "2.2.6"2121 2222         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"2323         vectorDrawables {

view file

app/src/main/java/com/peachpasswords/MainActivity.kt+2 −3
@@ -15,9 +15,9 @@1515 import dagger.hilt.android.AndroidEntryPoint1616 import javax.inject.Inject1717 import com.peachpasswords.ui.PeachAppNavHost18-import com.peachpasswords.ui.PeachNav1918 import com.peachpasswords.ui.onboarding.ONBOARD_KEY2019 import com.peachpasswords.ui.onboarding.ONBOARD_PREFS20+import com.peachpasswords.ui.onboarding.onboardingStartDestination2121 import com.peachpasswords.ui.theme.ACCENT_COLORS2222 import com.peachpasswords.ui.theme.DEFAULT_ACCENT2323 import com.peachpasswords.ui.theme.PeachTheme@@ -67,8 +67,7 @@6767         // Onboarding runs once, only on a fresh install with no vault yet.6868         val onboarded = getSharedPreferences(ONBOARD_PREFS, MODE_PRIVATE)6969             .getBoolean(ONBOARD_KEY, false)70-        val start =71-            if (!vault.hasVault() && !onboarded) PeachNav.Onboarding else PeachNav.Lock70+        val start = onboardingStartDestination(hasVault = vault.hasVault(), onboarded = onboarded)7271 7372         setContent {7473             val settings by vault.settings.collectAsState()

view file

app/src/main/java/com/peachpasswords/ui/onboarding/OnboardingScreen.kt+155 −61
@@ -1,7 +1,12 @@11 package com.peachpasswords.ui.onboarding22 33 import androidx.compose.animation.core.Animatable4+import androidx.compose.animation.core.LinearEasing5+import androidx.compose.animation.core.animateFloat6+import androidx.compose.animation.core.infiniteRepeatable7+import androidx.compose.animation.core.rememberInfiniteTransition48 import androidx.compose.animation.core.tween9+import androidx.compose.foundation.Canvas510 import androidx.compose.foundation.background611 import androidx.compose.foundation.border712 import androidx.compose.foundation.clickable@@ -31,27 +36,73 @@3136 import androidx.compose.ui.draw.clip3237 import androidx.compose.ui.draw.drawBehind3338 import androidx.compose.ui.geometry.Offset39+import androidx.compose.ui.graphics.Color3440 import androidx.compose.ui.graphics.PathEffect3541 import androidx.compose.ui.platform.LocalContext3642 import androidx.compose.ui.platform.LocalDensity3743 import androidx.compose.ui.text.TextStyle44+import androidx.compose.ui.text.drawText3845 import androidx.compose.ui.text.font.FontStyle46+import androidx.compose.ui.text.rememberTextMeasurer3947 import androidx.compose.ui.unit.IntOffset4048 import androidx.compose.ui.unit.dp4149 import androidx.compose.ui.unit.em4250 import androidx.compose.ui.unit.sp4351 import androidx.compose.material3.Text4452 import com.peachpasswords.ui.theme.LocalPeachAccent53+import com.peachpasswords.ui.theme.LocalReduceMotion4554 import com.peachpasswords.ui.theme.peachColors4655 import com.peachpasswords.ui.theme.PeachType4756 import com.peachpasswords.ui.theme.ShellBackground57+import kotlin.random.Random4858 4959 /**60+ * One onboarding card's copy. Drives [OnboardingScreen] so the wording is a61+ * single source of truth (and testable). Ported from the browser onboarding62+ * (`popup/views/Onboarding.tsx`); the warning sits on the final card per the63+ * mobile layout, which trades the browser's prose card 3 for feature-style copy.64+ */65+data class OnboardingCardCopy(66+    val headline: String,67+    val body: List<String>,68+    val warning: String?,69+)70+71+/** The three onboarding cards, in order. */72+val ONBOARDING_CARDS: List<OnboardingCardCopy> = listOf(73+    OnboardingCardCopy(74+        headline = "your passwords\nlive here.\nnowhere else.",75+        body = listOf(76+            "No account. No server. No one but you can ever see your vault.",77+            "Everything is encrypted on your device with a password only you know.",78+        ),79+        warning = null,80+    ),81+    OnboardingCardCopy(82+        headline = "two keys.",83+        body = listOf(84+            "Your master password is yours alone. Peach never sees it.",85+            "If you forget it, your 12 recovery words can reset it from settings — save them somewhere safe.",86+        ),87+        warning = null,88+    ),89+    OnboardingCardCopy(90+        headline = "everything\nyou need.",91+        body = listOf(92+            "Free includes passwords, cards, secure notes, two-factor codes, autofill, strong passwords, and breach checks.",93+            "Pro adds encrypted sync, Peach Codex paper restore, passkeys, advanced vault health, canary entries, and duress tools.",94+        ),95+        warning = "Lose both your password and your recovery words and your vault cannot be opened.",96+    ),97+)98+99+/**50100  * First-run onboarding: a three-card swipeable intro shown once before the51- * lock screen's create-vault flow. The "onboarded" flag lives in52- * SharedPreferences("peach_prefs") under key "peach_onboarded"; the launch53- * guard that decides whether to route here is in PeachAppNavHost (see54- * INTEGRATION.md) — this screen only writes the flag on completion.101+ * lock screen's create-vault flow. A drifting field of PeachScript glyphs sits102+ * behind the glass cards as ambient background. The "onboarded" flag lives in103+ * SharedPreferences("peach_prefs") under key "peach_onboarded"; the launch guard104+ * that decides whether to route here ([onboardingStartDestination]) is applied in105+ * MainActivity — this screen only writes the flag on completion.55106  */56107 @Composable57108 fun OnboardingScreen(@@ -59,7 +110,8 @@59110 ) {60111     val context = LocalContext.current61112     var card by remember { mutableIntStateOf(0) }62-    val cardCount = 3113+    val cardCount = ONBOARDING_CARDS.size114+    val accent = LocalPeachAccent.current63115 64116     val finish: () -> Unit = {65117         context@@ -71,10 +123,13 @@71123     }72124 73125     ShellBackground {126+        // Ambient PeachScript rain behind everything.127+        PeachScriptRainCanvas(modifier = Modifier.fillMaxSize(), accent = accent)128+74129         // Wordmark, top-left — matches LockScreen.75130         Text(76131             text = "peach",77-            color = LocalPeachAccent.current,132+            color = accent,78133             style = PeachType.wordmark,79134             modifier = Modifier80135                 .align(Alignment.TopStart)@@ -92,11 +147,7 @@92147         ) {93148             CardSwitcher(card) { active ->94149                 GlassCardPanel {95-                    when (active) {96-                        0 -> WelcomeCard()97-                        1 -> TwoKeysCard()98-                        else -> EverythingCard()99-                    }150+                    CardContent(ONBOARDING_CARDS[active])100151                 }101152             }102153 @@ -112,6 +163,70 @@112163     }113164 }114165 166+// ── PeachScript rain ─────────────────────────────────────────────────────────167+168+private const val RAIN_COLUMNS = 26169+170+private class RainColumn(171+    val glyph: String,172+    val xFraction: Float,173+    val speed: Float,174+    val startOffset: Float,175+)176+177+/**178+ * A field of ~26 PeachScript glyphs drifting very slowly downward — ambient, not179+ * Matrix: each column has its own x, speed (≈40–80s per cycle), and start phase,180+ * drawn in the accent at ~9% opacity. Honors reduce-motion by holding every glyph181+ * at its start position (still rendered, just not animated).182+ */183+@Composable184+fun PeachScriptRainCanvas(modifier: Modifier = Modifier, accent: Color) {185+    val reduceMotion = LocalReduceMotion.current186+    val measurer = rememberTextMeasurer()187+    val columns = remember {188+        List(RAIN_COLUMNS) {189+            RainColumn(190+                glyph = (0xE000 + Random.nextInt(256)).toChar().toString(),191+                xFraction = Random.nextFloat(),192+                // 0.5–1.0 → with the 80s base cycle, ≈40–80s per full fall.193+                speed = 0.5f + Random.nextFloat() * 0.5f,194+                startOffset = Random.nextFloat(),195+            )196+        }197+    }198+    val glyphStyle = remember(accent) {199+        TextStyle(fontFamily = PeachType.Script, fontSize = 30.sp, color = accent.copy(alpha = 0.09f))200+    }201+    val measured = remember(columns, glyphStyle, measurer) {202+        columns.map { measurer.measure(it.glyph, glyphStyle) }203+    }204+205+    val phase: Float = if (reduceMotion) {206+        0f207+    } else {208+        val transition = rememberInfiniteTransition(label = "peachscript_rain")209+        val animated by transition.animateFloat(210+            initialValue = 0f,211+            targetValue = 1f,212+            animationSpec = infiniteRepeatable(tween(80_000, easing = LinearEasing)),213+            label = "rain_phase",214+        )215+        animated216+    }217+218+    Canvas(modifier) {219+        val glyphPx = 30.sp.toPx()220+        val travel = size.height + glyphPx * 2221+        columns.forEachIndexed { i, col ->222+            val x = col.xFraction * size.width223+            val progress = ((phase * col.speed) + col.startOffset) % 1f224+            val y = progress * travel - glyphPx225+            drawText(measured[i], topLeft = Offset(x, y))226+        }227+    }228+}229+115230 // ── Card switcher (enter/exit transition) ───────────────────────────────────116231 117232 /**@@ -173,52 +288,34 @@173288     )174289 }175290 176-// ── Cards ───────────────────────────────────────────────────────────────────291+// ── Card content ─────────────────────────────────────────────────────────────177292 178293 private fun headline() = TextStyle(179294     fontFamily = PeachType.Display,180295     fontStyle = FontStyle.Italic,181-    fontSize = 44.sp,182-    lineHeight = (44 * 0.95).sp,296+    fontSize = 40.sp,297+    lineHeight = (40 * 0.98).sp,183298 )184299 185300 @Composable186-private fun WelcomeCard() {187-    Text("welcome to\npeach.", color = peachColors.T0, style = headline())301+private fun CardContent(copy: OnboardingCardCopy) {302+    Text(copy.headline, color = peachColors.T0, style = headline())188303     Spacer(Modifier.height(18.dp))189-    Text(190-        "Your passwords live here, on your device. Nothing leaves without your permission.",191-        color = peachColors.T1,192-        style = PeachType.body.copy(fontSize = 13.sp, lineHeight = (13 * 1.5).sp),193-    )304+    copy.body.forEachIndexed { i, para ->305+        if (i > 0) Spacer(Modifier.height(12.dp))306+        Text(307+            para,308+            color = peachColors.T1,309+            style = PeachType.body.copy(fontSize = 13.sp, lineHeight = (13 * 1.5).sp),310+        )311+    }312+    copy.warning?.let { WarningRow(it) }194313 }195314 196315 @Composable197-private fun TwoKeysCard() {198-    Text("two keys,\nnot one.", color = peachColors.T0, style = headline())199-    Spacer(Modifier.height(18.dp))200-    Text(201-        "Your master password encrypts everything. Your recovery words are your backup. Both are yours alone.",202-        color = peachColors.T1,203-        style = PeachType.body.copy(fontSize = 13.sp, lineHeight = (13 * 1.5).sp),204-    )205-}206-207-@Composable208-private fun EverythingCard() {316+private fun WarningRow(text: String) {209317     val accent = LocalPeachAccent.current210-    Text("everything\nyou need.", color = peachColors.T0, style = headline())211318     Spacer(Modifier.height(20.dp))212-213-    FeatureRow("Autofill", "works in every browser and app")214-    Spacer(Modifier.height(10.dp))215-    FeatureRow("Sync", "pairs over audio, no servers")216-    Spacer(Modifier.height(10.dp))217-    FeatureRow("Codex", "your vault on paper, forever")218-219-    Spacer(Modifier.height(20.dp))220-221-    // Warning row with a dashed accent top border.222319     Column(223320         modifier = Modifier224321             .fillMaxWidth()@@ -238,7 +335,7 @@238335             Text("⚠", color = accent, style = PeachType.labelMono.copy(fontSize = 11.sp))239336             Spacer(Modifier.width(8.dp))240337             Text(241-                "Peach is local-first. If you lose your password and recovery words, your vault cannot be recovered.",338+                text,242339                 color = peachColors.T1,243340                 style = PeachType.labelMono.copy(fontSize = 10.sp, lineHeight = (10 * 1.5).sp),244341             )@@ -246,22 +343,6 @@246343     }247344 }248345 249-@Composable250-private fun FeatureRow(name: String, desc: String) {251-    val accent = LocalPeachAccent.current252-    Row(verticalAlignment = Alignment.Top) {253-        Text("↳", color = accent, style = PeachType.labelMono.copy(fontSize = 11.sp))254-        Spacer(Modifier.width(8.dp))255-        Text(256-            buildLabel(name, desc),257-            color = peachColors.T1,258-            style = PeachType.labelMono.copy(fontSize = 11.sp, lineHeight = (11 * 1.45).sp),259-        )260-    }261-}262-263-private fun buildLabel(name: String, desc: String) = "$name — $desc"264-265346 // ── Nav row ─────────────────────────────────────────────────────────────────266347 267348 @Composable@@ -329,3 +410,16 @@329410 330411 const val ONBOARD_PREFS = "peach_prefs"331412 const val ONBOARD_KEY = "peach_onboarded"413+414+/**415+ * Where the app starts: onboarding runs once, only on a fresh install that has no416+ * vault yet and has not completed onboarding. Otherwise go straight to the lock417+ * screen. (A user who quit mid-vault-creation has no vault but is "onboarded",418+ * so they land on Lock, not back through the intro.)419+ */420+fun onboardingStartDestination(421+    hasVault: Boolean,422+    onboarded: Boolean,423+): com.peachpasswords.ui.PeachNav =424+    if (!hasVault && !onboarded) com.peachpasswords.ui.PeachNav.Onboarding425+    else com.peachpasswords.ui.PeachNav.Lock

view file

app/src/test/java/com/peachpasswords/ui/onboarding/OnboardingTest.kt+63 −0
@@ -0,0 +1,63 @@1+package com.peachpasswords.ui.onboarding2+3+import com.peachpasswords.ui.PeachNav4+import org.junit.Assert.assertEquals5+import org.junit.Assert.assertNotNull6+import org.junit.Assert.assertNull7+import org.junit.Assert.assertTrue8+import org.junit.Test9+10+class OnboardingTest {11+12+    // ── Launch guard ──────────────────────────────────────────────────────────13+14+    @Test fun onboarding_shows_first_launch() {15+        assertEquals(PeachNav.Onboarding, onboardingStartDestination(hasVault = false, onboarded = false))16+    }17+18+    @Test fun onboarding_skipped_after_completion() {19+        // Onboarded → Lock even with no vault yet (quit mid-create returns to Lock).20+        assertEquals(PeachNav.Lock, onboardingStartDestination(hasVault = false, onboarded = true))21+        // Existing vault → always Lock, regardless of flag.22+        assertEquals(PeachNav.Lock, onboardingStartDestination(hasVault = true, onboarded = false))23+        assertEquals(PeachNav.Lock, onboardingStartDestination(hasVault = true, onboarded = true))24+    }25+26+    // ── Card copy (the spec is ONBOARDING_CARDS, ported from the browser) ──────27+28+    @Test fun onboarding_has_three_cards() {29+        assertEquals(3, ONBOARDING_CARDS.size)30+    }31+32+    @Test fun onboarding_card_copy_card1_matches_spec() {33+        val c = ONBOARDING_CARDS[0]34+        assertTrue(c.headline.contains("live here"))35+        assertEquals(2, c.body.size)36+        assertTrue(c.body[0].contains("No account. No server."))37+        assertTrue(c.body[1].contains("encrypted on your device"))38+    }39+40+    @Test fun onboarding_card_copy_card2_matches_spec() {41+        val c = ONBOARDING_CARDS[1]42+        assertEquals("two keys.", c.headline)43+        assertEquals(2, c.body.size)44+        assertTrue(c.body[0].contains("master password is yours alone"))45+        assertTrue(c.body[1].contains("12 recovery words"))46+    }47+48+    @Test fun onboarding_card_copy_card3_matches_spec() {49+        val c = ONBOARDING_CARDS[2]50+        assertTrue(c.headline.contains("everything"))51+        assertEquals(2, c.body.size)52+        assertTrue(c.body[0].contains("Free includes"))53+        assertTrue(c.body[1].contains("Pro adds"))54+    }55+56+    @Test fun onboarding_card3_has_warning_row() {57+        assertNotNull("card 3 carries the warning", ONBOARDING_CARDS[2].warning)58+        assertTrue(ONBOARDING_CARDS[2].warning!!.contains("cannot be opened"))59+        // The first two cards do not show a warning row.60+        assertNull(ONBOARDING_CARDS[0].warning)61+        assertNull(ONBOARDING_CARDS[1].warning)62+    }63+}

view file