1package com.peachpasswords.ui.settings23import android.content.Intent4import android.net.Uri5import androidx.compose.animation.AnimatedVisibility6import androidx.compose.animation.core.animateDpAsState7import androidx.compose.foundation.background8import androidx.compose.foundation.border9import androidx.compose.foundation.clickable10import androidx.compose.foundation.layout.Arrangement11import androidx.compose.foundation.layout.Box12import androidx.compose.foundation.layout.Column13import androidx.compose.foundation.layout.FlowRow14import androidx.compose.foundation.layout.ExperimentalLayoutApi15import androidx.compose.foundation.layout.Row16import androidx.compose.foundation.layout.RowScope17import androidx.compose.foundation.layout.Spacer18import androidx.compose.foundation.layout.fillMaxWidth19import androidx.compose.foundation.layout.height20import androidx.compose.foundation.layout.padding21import androidx.compose.foundation.layout.size22import androidx.compose.foundation.layout.width23import androidx.compose.foundation.shape.CircleShape24import androidx.compose.foundation.shape.RoundedCornerShape25import androidx.compose.foundation.text.BasicTextField26import androidx.compose.runtime.Composable27import androidx.compose.material3.CircularProgressIndicator28import androidx.compose.runtime.DisposableEffect29import androidx.compose.runtime.collectAsState30import androidx.compose.runtime.getValue31import com.peachpasswords.feedback.FeedbackState32import com.peachpasswords.shared.PeachClipboard33import com.peachpasswords.sync.SyncMode34import com.peachpasswords.sync.describeSyncOutcome35import com.peachpasswords.sync.syncIndicator36import com.peachpasswords.sync.syncIndicatorLabel37import com.peachpasswords.ui.components.SyncIndicatorDot38import com.peachpasswords.ui.theme.LocalPeachAccent39import com.peachpasswords.vault.DuressAction40import com.peachpasswords.ui.theme.peachColors41import androidx.compose.runtime.mutableStateOf42import androidx.compose.runtime.remember43import androidx.compose.runtime.rememberCoroutineScope44import androidx.compose.runtime.setValue45import androidx.compose.ui.Alignment46import androidx.compose.ui.Modifier47import androidx.compose.ui.draw.clip48import androidx.compose.ui.graphics.Color49import androidx.compose.ui.graphics.SolidColor50import androidx.compose.ui.platform.LocalContext51import androidx.compose.ui.text.TextStyle52import androidx.compose.ui.text.font.FontStyle53import androidx.compose.ui.text.input.PasswordVisualTransformation54import androidx.compose.ui.unit.Dp55import androidx.compose.ui.unit.dp56import androidx.compose.ui.unit.em57import androidx.compose.ui.unit.sp58import androidx.compose.material3.Text59import com.peachpasswords.BuildConfig60import com.peachpasswords.autofill.AutofillEnablement61import com.peachpasswords.ui.PeachNav62import com.peachpasswords.ui.components.PeachEmptyOrEndState63import com.peachpasswords.ui.components.PeachField64import com.peachpasswords.ui.sync.SyncViewModel65import com.peachpasswords.ui.theme.ACCENT_COLORS66import com.peachpasswords.ui.theme.PeachSpacing67import com.peachpasswords.ui.theme.PeachType68import com.peachpasswords.ui.updates.UpdatePhase69import com.peachpasswords.ui.updates.UpdateViewModel70import androidx.hilt.navigation.compose.hiltViewModel71import com.peachpasswords.vault.VaultSettings72import com.peachpasswords.vault.VaultSnapshot73import kotlinx.coroutines.launch74import kotlinx.coroutines.delay75import java.text.SimpleDateFormat76import java.util.Date77import java.util.Locale7879private const val PRO_URL = "https://buy.polar.sh/polar_cl_IXSFIPojx67rcOTksn8LkH5mnU3osPHtYqBIl1eyuIz"808182838485868788@Composable89fun CardBody(90 id: CardId,91 fg: Color,92 vm: SettingsViewModel,93 settings: VaultSettings,94 entriesCount: Int,95 onNavigate: (PeachNav) -> Unit,96) {97 when (id) {98 CardId.Appearance -> AppearanceBody(fg, vm, settings)99 CardId.Protection -> ProtectionBody(fg, vm, settings, onNavigate)100 CardId.Vault -> VaultBody(fg, vm, settings, entriesCount, onNavigate)101 CardId.Sync -> SyncBody(fg, onNavigate)102 CardId.Pro -> ProBody(fg, vm)103 CardId.Feedback -> {104 105 106 AboutUpdatesBody(fg, onNavigate)107 FeedbackBody(fg, vm)108 }109 }110}111112113114@Composable115private fun AboutUpdatesBody(fg: Color, onNavigate: (PeachNav) -> Unit) {116 val vm: UpdateViewModel = hiltViewModel()117 val available by vm.available.collectAsState()118 val state by vm.state.collectAsState()119120 SubLabel("THIS BUILD", fg, top = 0.dp)121 RowLine(fg) {122 Name("Version", fg)123 ValueText(BuildConfig.VERSION_NAME, fg)124 }125 RowLine(fg) {126 Column(Modifier.weight(1f)) {127 Text("Updates", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)128 Text(129 when {130 available != null -> "v${available?.version} is available"131 state.phase == UpdatePhase.Checking -> "Checking…"132 state.phase == UpdatePhase.UpToDate -> "You're on the latest version"133 state.phase == UpdatePhase.Failed -> "Couldn't reach the update server"134 else -> "Peach checks once a day and tells you when there's a new version."135 },136 color = fg.copy(alpha = 0.7f),137 fontFamily = PeachType.Body,138 fontSize = 11.sp,139 lineHeight = 16.sp,140 modifier = Modifier.padding(top = 2.dp),141 )142 }143 if (available != null) {144 SubtleButton("update", fg) { onNavigate(PeachNav.Update) }145 } else {146 SubtleButton(if (state.phase == UpdatePhase.Checking) "checking" else "check now", fg) {147 vm.check()148 }149 }150 }151}152153154155@Composable156private fun SubLabel(text: String, fg: Color, top: Dp = 14.dp) {157 Text(158 text,159 modifier = Modifier.padding(top = top, bottom = 4.dp),160 color = fg.copy(alpha = 0.58f),161 fontFamily = PeachType.Mono,162 fontSize = 8.sp,163 letterSpacing = 0.22.em,164 )165}166167@Composable168private fun RowLine(169 fg: Color,170 modifier: Modifier = Modifier,171 verticalPadding: Dp = 9.dp,172 content: @Composable RowScope.() -> Unit,173) {174 Row(175 Modifier.fillMaxWidth().then(modifier).padding(vertical = verticalPadding),176 verticalAlignment = Alignment.CenterVertically,177 horizontalArrangement = Arrangement.SpaceBetween,178 content = content,179 )180 Box(Modifier.fillMaxWidth().height(1.dp).background(fg.copy(alpha = 0.12f)))181}182183@Composable184private fun RowScope.Name(text: String, fg: Color) {185 Text(text, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp, modifier = Modifier.weight(1f))186}187188@Composable189private fun ValueText(text: String, fg: Color) {190 Text(text, color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Mono, fontSize = 11.sp)191}192193@Composable194private fun SubtleButton(label: String, fg: Color, onClick: () -> Unit) {195 Box(196 Modifier.clip(RoundedCornerShape(8.dp))197 .border(1.dp, fg.copy(alpha = 0.28f), RoundedCornerShape(8.dp))198 .background(fg.copy(alpha = 0.08f))199 .clickable(onClick = onClick)200 .padding(horizontal = 12.dp, vertical = 6.dp),201 ) {202 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 11.sp)203 }204}205206@Composable207private fun Toggle(on: Boolean, fg: Color, onToggle: (Boolean) -> Unit) {208 val knob by animateDpAsState(if (on) 16.dp else 2.dp, label = "knob")209 Box(210 Modifier.size(width = 34.dp, height = 20.dp).clip(RoundedCornerShape(999.dp))211 .background(if (on) fg.copy(alpha = 0.28f) else fg.copy(alpha = 0.08f))212 .border(1.dp, fg.copy(alpha = if (on) 0.5f else 0.32f), RoundedCornerShape(999.dp))213 .clickable { onToggle(!on) },214 ) {215 Box(216 Modifier.padding(top = 2.dp).width(16.dp).fillMaxWidth().height(16.dp)217 .padding(start = knob - 2.dp)218 .size(14.dp).clip(CircleShape)219 .background(if (on) fg else fg.copy(alpha = 0.58f)),220 )221 }222}223224@Composable225private fun Pill(label: String, active: Boolean, fg: Color, onClick: () -> Unit) {226 Box(227 Modifier.clip(RoundedCornerShape(999.dp))228 .border(1.dp, fg.copy(alpha = if (active) 0.55f else 0.32f), RoundedCornerShape(999.dp))229 .background(if (active) fg.copy(alpha = 0.18f) else Color.Transparent)230 .clickable(onClick = onClick)231 .padding(horizontal = 12.dp, vertical = 5.dp),232 ) {233 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)234 }235}236237@Composable238private fun ProBadge(fg: Color) {239 Box(240 Modifier.padding(start = 6.dp).clip(RoundedCornerShape(4.dp))241 .background(fg.copy(alpha = 0.16f)).padding(horizontal = 5.dp, vertical = 1.dp),242 ) {243 Text("Pro", color = fg.copy(alpha = 0.85f), fontFamily = PeachType.Mono, fontSize = 8.sp)244 }245}246247@Composable248private fun Hint(text: String, fg: Color) {249 Text(250 text,251 modifier = Modifier.padding(top = 6.dp),252 color = fg.copy(alpha = 0.6f),253 fontFamily = PeachType.Display,254 fontStyle = FontStyle.Italic,255 fontSize = 11.5.sp,256 lineHeight = 16.sp,257 )258}259260261262@OptIn(ExperimentalLayoutApi::class)263@Composable264private fun AppearanceBody(fg: Color, vm: SettingsViewModel, s: VaultSettings) {265 SubLabel("ACCENT", fg, top = 0.dp)266 FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {267 ACCENT_COLORS.forEach { (name, color) ->268 Box(269 Modifier.size(22.dp).clip(CircleShape).background(color)270 .border(271 if (s.accentColor == name) 2.dp else 1.dp,272 if (s.accentColor == name) fg else fg.copy(alpha = 0.2f),273 CircleShape,274 )275 .clickable { vm.setAccent(name) },276 )277 }278 }279 SubLabel("MOTION", fg)280 RowLine(fg) {281 Name("Reduce motion", fg)282 SubtleButton(if (s.reduceMotion) "On" else "Off", fg) { vm.setReduceMotion(!s.reduceMotion) }283 }284}285286287288@Composable289private fun ProtectionBody(fg: Color, vm: SettingsViewModel, s: VaultSettings, onNavigate: (PeachNav) -> Unit) {290 val lockOptions = listOf(1 to "1 minute", 5 to "5 minutes", 15 to "15 minutes", 30 to "30 minutes", 0 to "Never")291 val current = s.autoLockMinutes ?: 0292293 SubLabel("LOCKING", fg, top = 0.dp)294 RowLine(fg) {295 Name("Auto-lock after", fg)296 val idx = lockOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)297 SubtleButton(lockOptions[idx].second, fg) {298 val next = lockOptions[(idx + 1) % lockOptions.size].first299 vm.setAutoLockMinutes(if (next == 0) 0 else next)300 }301 }302 SubLabel("BIOMETRICS", fg)303 val bioActivity = LocalContext.current as? androidx.fragment.app.FragmentActivity304 RowLine(fg) {305 Name("Unlock with biometrics", fg)306 Toggle(s.biometricsEnabled, fg) { on ->307 if (on && bioActivity != null) vm.enableBiometrics(bioActivity) else vm.disableBiometrics()308 }309 }310 val bioError = com.peachpasswords.ui.lock.Biometrics.statusMessage(LocalContext.current)311 if (bioError != null) {312 Text(313 bioError,314 color = com.peachpasswords.ui.theme.peachColors.Breach,315 fontFamily = PeachType.Mono, fontSize = 10.sp,316 modifier = Modifier.padding(start = 2.dp, top = 2.dp, bottom = 4.dp),317 )318 }319 SubLabel("AUTOFILL", fg)320 run {321 322 323 val ctx = LocalContext.current324 val enabled = AutofillEnablement.isEnabled(ctx)325 RowLine(fg) {326 Column(Modifier.weight(1f)) {327 Text("Fill passwords in other apps", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)328 Text(329 if (enabled) {330 "Peach is your autofill service."331 } else {332 "Android decides which app fills passwords. Turn Peach on in system settings."333 },334 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,335 modifier = Modifier.padding(top = 2.dp),336 )337 }338 if (!enabled) {339 SubtleButton("enable", fg) {340 341 342 343 runCatching { ctx.startActivity(AutofillEnablement.requestIntent(ctx)) }344 .onFailure { runCatching { ctx.startActivity(AutofillEnablement.fallbackIntent()) } }345 }346 } else {347 ValueText("on", fg)348 }349 }350 }351352 SubLabel("PASSKEYS", fg)353 RowLine(fg) {354 Column(Modifier.weight(1f)) {355 Text("Credential provider", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)356 Text(357 "Peach can handle passkey sign-in and creation through Android Credential Manager.",358 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,359 modifier = Modifier.padding(top = 2.dp),360 )361 }362 Toggle(s.passkeyProviderEnabled, fg) { vm.setPasskeyProviderEnabled(it) }363 }364 RowLine(fg) {365 Name("Status", fg)366 ValueText(if (s.passkeyProviderEnabled) "enabled" else "off", fg)367 }368 SubLabel("RECOVERY", fg)369 RowLine(fg) {370 Column(Modifier.weight(1f)) {371 Text("View recovery words", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)372 Text(373 "Keep the paper copy current before rotating sync identity or replacing devices.",374 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,375 modifier = Modifier.padding(top = 2.dp),376 )377 }378 SubtleButton("view", fg) { onNavigate(PeachNav.RecoveryView) }379 }380 SubLabel("BREACH PROTECTION", fg)381 val checkingBreaches by vm.checkingBreaches.collectAsState()382 val breachResult by vm.breachResult.collectAsState()383 RowLine(fg) {384 Name("Breach monitoring", fg)385 Toggle(s.breachMonitoring, fg) { vm.setBreachMonitoring(it) }386 }387 RowLine(fg) {388 Name("Check all passwords", fg)389 SubtleButton(if (checkingBreaches) "checking..." else "run", fg) { vm.checkAllBreaches() }390 }391 breachResult?.let { result ->392 RowLine(fg) {393 Name("Last check", fg)394 ValueText(result, fg)395 }396 }397398 SubLabel("MASTER PASSWORD", fg)399 ChangePasswordRow(fg, vm)400401 SubLabel("DURESS PASSWORD", fg)402 val duressIsPro by vm.isPro.collectAsState()403 if (!duressIsPro) {404 RowLine(fg) {405 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {406 Name("Duress password", fg); ProBadge(fg)407 }408 ValueText("off", fg)409 }410 Hint("If entered under coercion, a decoy empty vault opens; your real vault stays hidden. Pro feature.", fg)411 } else {412 DuressSection(fg, vm)413 }414}415416@Composable417private fun ChangePasswordRow(fg: Color, vm: SettingsViewModel) {418 var open by remember { mutableStateOf(false) }419 var current by remember { mutableStateOf("") }420 var next by remember { mutableStateOf("") }421 var confirm by remember { mutableStateOf("") }422 var error by remember { mutableStateOf<String?>(null) }423 var done by remember { mutableStateOf(false) }424 val scope = rememberCoroutineScope()425426 RowLine(fg) {427 Name("Master password", fg)428 SubtleButton(if (open) "cancel" else "change", fg) { open = !open; error = null; done = false }429 }430 AnimatedVisibility(open) {431 Column(Modifier.fillMaxWidth().padding(top = PeachSpacing.sm), verticalArrangement = Arrangement.spacedBy(PeachSpacing.sm)) {432 PwField("current password", current, fg) { current = it }433 PwField("new password (min 12 chars)", next, fg) { next = it }434 PwField("confirm new password", confirm, fg) { confirm = it }435 error?.let { Text(it, color = Color(0xFFE5805C), fontFamily = PeachType.Mono, fontSize = 10.sp) }436 if (done) Text("password changed ✓", color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)437 SubtleButton("save new password", fg) {438 error = when {439 current.isBlank() -> "enter your current password"440 next.length < 12 -> "new password must be at least 12 characters"441 next != confirm -> "new passwords do not match"442 next == current -> "new password must differ from current"443 else -> null444 }445 if (error == null) scope.launch {446 if (vm.changePassword(current, next)) {447 current = ""; next = ""; confirm = ""; open = false; done = true448 } else error = "incorrect current password"449 }450 }451 }452 }453}454455@Composable456private fun PwField(placeholder: String, value: String, @Suppress("UNUSED_PARAMETER") fg: Color, onChange: (String) -> Unit) {457 PeachField(458 label = placeholder,459 value = value,460 onValueChange = onChange,461 keyboardType = androidx.compose.ui.text.input.KeyboardType.Password,462 visualTransformation = PasswordVisualTransformation(),463 )464}465466467468@Composable469private fun VaultBody(470 fg: Color,471 vm: SettingsViewModel,472 s: VaultSettings,473 entriesCount: Int,474 onNavigate: (PeachNav) -> Unit,475) {476 val trashOptions = listOf(7 to "7 days", 30 to "30 days", 90 to "90 days", 0 to "Never")477 val current = s.trashRetentionDays ?: 0478 val isPro by vm.isPro.collectAsState()479 val dedupCount by vm.dedupCount.collectAsState()480 val dedupRunning by vm.dedupRunning.collectAsState()481 val dedupDone by vm.dedupDone.collectAsState()482 val history by vm.vaultHistory.collectAsState()483 val restoringSnapshotId by vm.restoringSnapshotId.collectAsState()484485 SubLabel("ENTRIES", fg, top = 0.dp)486 RowLine(fg) { Name("Entries", fg); ValueText("$entriesCount", fg) }487 RowLine(fg) {488 Name("Duplicates", fg)489 val done = dedupDone490 if (done != null) {491 ValueText(if (done == 0) "already clean" else "removed $done", com.peachpasswords.ui.theme.peachColors.SyncOk)492 } else {493 val count = dedupCount494 val label = when {495 dedupRunning -> "scanning..."496 count == null -> "scan"497 count == 0 -> "none found"498 else -> "$count found"499 }500 SubtleButton(label, fg) {501 if (count == null || count == 0) vm.scanDuplicates()502 }503 }504 }505 if ((dedupCount ?: 0) > 0 && dedupDone == null) {506 Column(507 Modifier.fillMaxWidth()508 .padding(top = 2.dp, bottom = 8.dp)509 .clip(RoundedCornerShape(8.dp))510 .background(fg.copy(alpha = 0.08f))511 .border(1.dp, fg.copy(alpha = 0.18f), RoundedCornerShape(8.dp))512 .padding(10.dp),513 verticalArrangement = Arrangement.spacedBy(8.dp),514 ) {515 val count = dedupCount ?: 0516 Text(517 "$count duplicate ${if (count == 1) "entry" else "entries"} found. The newest copy of each will be kept; older duplicates will be moved to trash.",518 color = fg.copy(alpha = 0.82f),519 fontFamily = PeachType.Body,520 fontSize = 11.sp,521 lineHeight = 16.sp,522 )523 Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {524 SubtleButton("cancel", fg) { vm.cancelDuplicateRemoval() }525 SubtleButton(if (dedupRunning) "removing..." else "remove duplicates", fg) { vm.removeDuplicates() }526 }527 }528 }529530 SubLabel("MAINTENANCE", fg)531 RowLine(fg) {532 Name("Trash auto-delete", fg)533 val idx = trashOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)534 SubtleButton(trashOptions[idx].second, fg) {535 vm.setTrashRetentionDays(trashOptions[(idx + 1) % trashOptions.size].first)536 }537 }538 RowLine(fg) { Name("Advanced Vault Health", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Health) } }539 RowLine(fg) { Name("Trash", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Trash) } }540541 SubLabel("DATA", fg)542 RowLine(fg) { Name("Import passwords", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Import) } }543 RowLine(fg) { Name("Export backup", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Export) } }544 RowLine(fg) {545 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Peach Codex", fg); if (!isPro) ProBadge(fg) }546 SubtleButton(if (isPro) "open" else "Pro", fg) { if (isPro) onNavigate(PeachNav.CodexGenerate) }547 }548 RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } }549550 var historyShowAll by remember { mutableStateOf(false) }551 SubLabel("VAULT HISTORY", fg)552 if (history.isEmpty()) {553 Text(554 "No snapshots yet. Peach saves automatically before every change — saves, syncs, and imports.",555 color = fg.copy(alpha = 0.68f),556 fontFamily = PeachType.Body,557 fontSize = 11.sp,558 lineHeight = 16.sp,559 modifier = Modifier.padding(bottom = 6.dp),560 )561 } else {562 Text(563 "Restoring locks your vault. Unlock with the password that encrypted that snapshot to confirm.",564 color = fg.copy(alpha = 0.68f),565 fontFamily = PeachType.Body,566 fontSize = 11.sp,567 lineHeight = 16.sp,568 modifier = Modifier.padding(bottom = 4.dp),569 )570 history.take(if (historyShowAll) history.size else 3).forEach { snap ->571 RowLine(fg) {572 Column(Modifier.weight(1f)) {573 Text(snapshotTimeLabel(snap.savedAt), color = fg, fontFamily = PeachType.Body, fontSize = 12.sp)574 Text(snapshotSubLabel(snap), color = fg.copy(alpha = 0.62f), fontFamily = PeachType.Mono, fontSize = 10.sp)575 }576 SubtleButton(if (restoringSnapshotId == snap.id) "..." else "restore", fg) {577 vm.restoreVaultSnapshot(snap.id)578 }579 }580 }581 if (history.size > 3) {582 RowLine(fg) {583 Name(if (historyShowAll) "show less" else "${history.size - 3} older", fg)584 SubtleButton(if (historyShowAll) "hide" else "show", fg) { historyShowAll = !historyShowAll }585 }586 }587 Text(588 "${history.size} of 5 snapshots",589 color = fg.copy(alpha = 0.58f),590 fontFamily = PeachType.Mono,591 fontSize = 10.sp,592 modifier = Modifier.padding(top = 2.dp, bottom = 6.dp),593 )594 }595596 var advancedOpen by remember { mutableStateOf(false) }597 SubLabel("ADVANCED", fg)598 RowLine(fg) {599 Name("Advanced", fg)600 SubtleButton(if (advancedOpen) "hide" else "show", fg) { advancedOpen = !advancedOpen }601 }602 if (advancedOpen) {603 RowLine(fg) {604 Name("Replace vault from backup", com.peachpasswords.ui.theme.peachColors.SyncBusy)605 SubtleButton("open", com.peachpasswords.ui.theme.peachColors.SyncBusy) { onNavigate(PeachNav.Import) }606 }607 RowLine(fg) {608 Name("Destroy vault", com.peachpasswords.ui.theme.peachColors.Breach)609 SubtleButton("destroy", com.peachpasswords.ui.theme.peachColors.Breach) { onNavigate(PeachNav.Panic) }610 }611 }612}613614private fun snapshotSubLabel(snapshot: VaultSnapshot): String {615 val count = snapshot.entryCount?.let { "up to $it ${if (it == 1) "entry" else "entries"}" }616 return listOfNotNull(count, snapshotReasonLabel(snapshot.reason)).joinToString(" · ")617}618619private fun snapshotReasonLabel(reason: String): String = when (reason) {620 "local_save" -> "saved"621 "sync_received" -> "synced"622 "import" -> "imported"623 "restore" -> "restored"624 else -> reason625}626627private fun snapshotTimeLabel(savedAt: Long): String {628 val diff = System.currentTimeMillis() - savedAt629 if (diff < 60_000) return "Just now"630 if (diff < 3_600_000) return "${diff / 60_000}m ago"631 val date = Date(savedAt)632 val today = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date())633 val thenDay = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(date)634 val time = SimpleDateFormat("h:mm a", Locale.getDefault()).format(date)635 if (today == thenDay) return "Today $time"636 val yesterday = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date(System.currentTimeMillis() - 86_400_000))637 if (yesterday == thenDay) return "Yesterday $time"638 return SimpleDateFormat("MMM d h:mm a", Locale.getDefault()).format(date)639}640641642643@Composable644private fun SyncBody(fg: Color, onNavigate: (PeachNav) -> Unit) {645 val syncVm: SyncViewModel = hiltViewModel()646 val pairedDevices by syncVm.pairedDevices.collectAsState()647 val pendingVouched by syncVm.pendingVouched.collectAsState()648 val syncStatus by syncVm.status.collectAsState()649 val configuredRelayUrl by syncVm.relayUrl.collectAsState()650 val syncMode by syncVm.syncMode.collectAsState()651 val scope = rememberCoroutineScope()652 var confirmUnpair by remember { mutableStateOf<String?>(null) }653 var rotateConfirmOpen by remember { mutableStateOf(false) }654 var rotating by remember { mutableStateOf(false) }655 var rotateError by remember { mutableStateOf<String?>(null) }656 var relayUrlDraft by remember(configuredRelayUrl) { mutableStateOf(configuredRelayUrl) }657 var relayUrlStatus by remember { mutableStateOf<String?>(null) }658659 660 661 662 SubLabel("PAIR A DEVICE", fg, top = 0.dp)663 RowLine(fg) {664 Column(Modifier.weight(1f)) {665 Row(verticalAlignment = Alignment.CenterVertically) {666 Text("Peach Sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp); ProBadge(fg)667 }668 Text(669 "End-to-end encrypted, through a relay that can read none of it.",670 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,671 modifier = Modifier.padding(top = 2.dp),672 )673 }674 }675 RowLine(fg) {676 Column(Modifier.weight(1f)) {677 Text("Show a code", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)678 Text(679 "For the other device to scan. Always use this one to pair a browser.",680 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,681 modifier = Modifier.padding(top = 2.dp),682 )683 }684 SubtleButton("show", fg) { onNavigate(PeachNav.CodePair) }685 }686 RowLine(fg) {687 Column(Modifier.weight(1f)) {688 Text("Scan a code", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)689 Text(690 "Joins that vault. Your entries are kept and the two merge; this phone's " +691 "recovery words are replaced, and shown to you first.",692 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,693 modifier = Modifier.padding(top = 2.dp),694 )695 }696 SubtleButton("scan", fg) { onNavigate(PeachNav.AdoptVault) }697 }698699 700 701 702 703 SubLabel("SYNC STATUS", fg)704 val indicator = syncIndicator(syncStatus, pairedDevices.size)705 RowLine(fg) {706 SyncIndicatorDot(707 indicator = indicator,708 label = syncIndicatorLabel(indicator, syncStatus),709 modifier = Modifier.padding(end = PeachSpacing.sm),710 size = 8.dp,711 )712 Text(713 describeSyncOutcome(syncStatus),714 color = fg.copy(alpha = 0.7f),715 fontFamily = PeachType.Body,716 fontSize = 11.sp,717 lineHeight = 16.sp,718 modifier = Modifier.weight(1f),719 )720 SubtleButton(if (syncStatus.syncing) "syncing..." else "sync now", fg) {721 if (!syncStatus.syncing) syncVm.syncNow()722 }723 }724725 SubLabel("PAIRED DEVICES", fg)726 if (pairedDevices.isEmpty()) {727 PeachEmptyOrEndState(728 message = "No paired devices yet.",729 detail = "Pair a nearby phone, tablet, or browser when you're ready to sync.",730 modifier = Modifier.padding(top = PeachSpacing.xs),731 )732 } else {733 pairedDevices.forEach { d ->734 RowLine(fg) {735 Column(Modifier.weight(1f)) {736 Text(d.deviceName ?: d.deviceId, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)737 Text(738 "${deviceTypeLabel(d.deviceType)} · ${syncTimeLabel(d.lastSyncedAt)}${if (isSyncStale(d.lastSyncedAt)) " · not seen recently" else ""}",739 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,740 modifier = Modifier.padding(top = 2.dp),741 )742 }743 if (confirmUnpair != d.deviceId) {744 SubtleButton("remove", fg) { confirmUnpair = d.deviceId }745 }746 }747 748 749 750 751 752 if (confirmUnpair == d.deviceId) {753 Column(Modifier.fillMaxWidth().padding(bottom = PeachSpacing.sm)) {754 Text(755 "Stops this device receiving future changes. It doesn't lock it " +756 "out of what it already has - if it's lost or stolen, also " +757 "change your master password and generate new recovery words.",758 color = fg.copy(alpha = 0.7f),759 fontFamily = PeachType.Body,760 fontSize = 11.sp,761 lineHeight = 16.sp,762 )763 Row(764 modifier = Modifier.fillMaxWidth().padding(top = PeachSpacing.sm),765 horizontalArrangement = Arrangement.End,766 ) {767 SubtleButton("cancel", fg) { confirmUnpair = null }768 Spacer(Modifier.width(PeachSpacing.sm))769 SubtleButton("remove", peachColors.Breach) { syncVm.unpairDevice(d.deviceId); confirmUnpair = null }770 }771 }772 }773 }774 }775776 777 778 779 780 781 SubLabel("HOW THIS VAULT SYNCS", fg)782 SyncModeRow(783 title = "Public relay",784 detail = "Peach's own relay. Works anywhere, nothing to set up. It never sees " +785 "your vault — everything is encrypted before it leaves this device.",786 selected = syncMode == SyncMode.PUBLIC,787 fg = fg,788 ) { syncVm.setSyncMode(SyncMode.PUBLIC) }789 SyncModeRow(790 title = "Private relay",791 detail = "Your own peach-relay, on your own domain. Same open-source code.",792 selected = syncMode == SyncMode.PRIVATE,793 fg = fg,794 ) { syncVm.setSyncMode(SyncMode.PRIVATE) }795796 if (syncMode == SyncMode.PRIVATE) {797 Text(798 "RELAY URL",799 color = fg.copy(alpha = 0.6f),800 fontFamily = PeachType.Mono,801 fontSize = 8.sp,802 letterSpacing = 0.22.em,803 modifier = Modifier.padding(top = 8.dp),804 )805 Box(806 Modifier.fillMaxWidth().padding(top = 6.dp)807 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))808 .padding(horizontal = 12.dp, vertical = 10.dp),809 ) {810 BasicTextField(811 value = relayUrlDraft,812 onValueChange = { relayUrlDraft = it; relayUrlStatus = null },813 singleLine = true,814 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 11.sp, color = fg),815 cursorBrush = SolidColor(fg),816 modifier = Modifier.fillMaxWidth(),817 )818 }819 RowLine(fg) {820 ValueText(relayUrlStatus ?: "Only secure wss:// relays are accepted.", fg)821 SubtleButton("save", fg) {822 relayUrlStatus = if (syncVm.setPrivateRelayUrl(relayUrlDraft)) {823 relayUrlDraft = syncVm.relayUrl.value824 "Saved"825 } else {826 "Use a valid wss:// relay URL"827 }828 }829 }830 }831832 SyncModeRow(833 title = "No sync",834 detail = "This device keeps to itself. Move your vault by hand with Codex or " +835 "CSV export and import.",836 selected = syncMode == SyncMode.OFF,837 fg = fg,838 ) { syncVm.setSyncMode(SyncMode.OFF) }839840 if (pendingVouched.isNotEmpty()) {841 SubLabel("PENDING DEVICES", fg)842 pendingVouched.forEach { dev ->843 RowLine(fg) {844 Column(Modifier.weight(1f)) {845 Text(dev.deviceName, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)846 Text(847 "Was added by another of your devices. Allow it to sync with this vault?",848 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,849 modifier = Modifier.padding(top = 2.dp),850 )851 }852 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {853 SubtleButton("Allow", fg) { syncVm.confirmVouchedDevice(dev.deviceId) }854 SubtleButton("Reject", fg) { syncVm.rejectVouchedDevice(dev.deviceId) }855 }856 }857 }858 }859860 SubLabel("RECOVERY", fg)861 if (rotateConfirmOpen) {862 Hint("This will disconnect all paired devices and your 12 recovery words will change. You'll be shown the new words next.", peachColors.Breach)863 rotateError?.let {864 Text(it, color = peachColors.Breach, fontFamily = PeachType.Body, fontSize = 11.sp, modifier = Modifier.padding(top = 6.dp))865 }866 Row(Modifier.padding(top = 10.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {867 SubtleButton("cancel", fg) { if (!rotating) rotateConfirmOpen = false }868 SubtleButton(if (rotating) "rotating..." else "Rotate sync identity", peachColors.Breach) {869 if (rotating) return@SubtleButton870 rotating = true871 rotateError = null872 scope.launch {873 val ok = syncVm.rotateSyncIdentity()874 rotating = false875 if (ok) {876 rotateConfirmOpen = false877 onNavigate(PeachNav.RecoverySetup)878 } else {879 rotateError = "Rotation failed. Unlock your real vault and try again."880 }881 }882 }883 }884 } else {885 RowLine(fg) {886 Column(Modifier.weight(1f)) {887 Text("Rotate sync identity", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)888 Text(889 "Use this if a paired device was lost or stolen. Re-keys the vault so the old device's key is useless.",890 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,891 modifier = Modifier.padding(top = 2.dp),892 )893 }894 SubtleButton("rotate", peachColors.Breach) { rotateError = null; rotateConfirmOpen = true }895 }896 }897898 Hint("Sync uses the same zero-knowledge vault format as backup and restore; pairing authorizes a device, not a cloud account.", fg)899}900901private fun deviceTypeLabel(type: String?): String = when (type) {902 "android" -> "Android"903 "phone" -> "Phone"904 "tablet" -> "Tablet"905 "browser" -> "Browser"906 else -> "Device"907}908909private fun syncTimeLabel(lastSyncedAt: Long?): String {910 if (lastSyncedAt == null) return "never synced"911 val diff = System.currentTimeMillis() - lastSyncedAt912 if (diff < 60_000) return "just now"913 if (diff < 3_600_000) return "${diff / 60_000}m ago"914 if (diff < 86_400_000) return "${diff / 3_600_000}h ago"915 return "${diff / 86_400_000}d ago"916}917918private fun isSyncStale(lastSyncedAt: Long?): Boolean =919 lastSyncedAt != null && System.currentTimeMillis() - lastSyncedAt > 7L * 24L * 60L * 60L * 1000L920921922923@Composable924private fun ProBody(fg: Color, vm: SettingsViewModel) {925 val ctx = LocalContext.current926 val isPro by vm.isPro.collectAsState()927 if (isPro) {928 ProActiveBody(fg, vm)929 return930 }931 val features = listOf(932 "Peach Sync" to "Encrypted · peer-to-peer",933 "Peach Codex" to "Restore from paper",934 "Passkeys" to "Zero-knowledge WebAuthn",935 "Advanced Vault Health" to "Reuse · age · exposure",936 "Canary entries" to "Detects vault compromise",937 "Duress vault" to "Decoy under coercion",938 )939 Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)940 Text(941 "Everything, everywhere.",942 modifier = Modifier.padding(top = 8.dp),943 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp,944 )945 Text(946 "One key unlocks every Pro feature — for the lifetime of the app.",947 modifier = Modifier.padding(top = 6.dp),948 color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,949 )950 Spacer(Modifier.height(10.dp))951 features.forEachIndexed { i, (name, desc) ->952 953 954 955 956 RowLine(fg, verticalPadding = 6.dp) {957 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {958 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))959 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)960 }961 Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)962 }963 }964 Spacer(Modifier.height(12.dp))965 Text(966 "$39",967 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp,968 )969 Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em)970 Spacer(Modifier.height(10.dp))971 Box(972 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))973 .background(fg.copy(alpha = 0.16f))974 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))975 .clickable {976 runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) }977 }978 .padding(vertical = 12.dp),979 contentAlignment = Alignment.Center,980 ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }981982 983 984 985 986 Spacer(Modifier.height(44.dp))987988 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)989 var key by remember { mutableStateOf("") }990 val activating by vm.activating.collectAsState()991 val activationError by vm.activationError.collectAsState()992 Box(993 Modifier.fillMaxWidth().padding(top = 6.dp)994 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))995 .padding(horizontal = 12.dp, vertical = 10.dp),996 ) {997 BasicTextField(998 value = key,999 1000 1001 1002 1003 onValueChange = { key = it; vm.clearActivationError() },1004 singleLine = true,1005 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em, color = fg),1006 cursorBrush = SolidColor(fg),1007 modifier = Modifier.fillMaxWidth(),1008 decorationBox = { inner ->1009 if (key.isEmpty()) Text("PPK-XXXX-XXXX-XXXX", color = fg.copy(alpha = 0.3f), fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em)1010 inner()1011 },1012 )1013 }1014 if (activationError != null) {1015 Text(activationError!!, color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 6.dp))1016 }1017 Spacer(Modifier.height(8.dp))1018 Box(1019 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1020 .background(fg.copy(alpha = if (activating || key.isBlank()) 0.08f else 0.16f))1021 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1022 .clickable(enabled = !activating && key.isNotBlank()) { vm.activateLicense(key) }1023 .padding(vertical = 12.dp),1024 contentAlignment = Alignment.Center,1025 ) { Text(if (activating) "Activating…" else "Activate", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }1026}10271028@Composable1029private fun ProActiveBody(fg: Color, vm: SettingsViewModel) {1030 val ctx = LocalContext.current1031 val features = listOf("Peach Sync", "Peach Codex", "Passkeys", "Advanced Vault Health", "Canary entries", "Duress vault")1032 val licenseKey by vm.licenseKey.collectAsState()1033 val issuedAt by vm.licenseIssuedAt.collectAsState()1034 var showKey by remember { mutableStateOf(false) }1035 var copied by remember { mutableStateOf(false) }1036 val scope = rememberCoroutineScope()1037 Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {1038 com.peachpasswords.ui.components.PeachMark(size = 60.dp)1039 }1040 Text(1041 "Peach Pro",1042 modifier = Modifier.fillMaxWidth(),1043 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp,1044 textAlign = androidx.compose.ui.text.style.TextAlign.Center,1045 )1046 Text(1047 formatLicenseActiveSince(issuedAt),1048 modifier = Modifier.fillMaxWidth().padding(top = 4.dp),1049 color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em,1050 textAlign = androidx.compose.ui.text.style.TextAlign.Center,1051 )1052 licenseKey?.let { key ->1053 Spacer(Modifier.height(12.dp))1054 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1055 RowLine(fg) {1056 Text(1057 if (showKey) key else "************************",1058 color = fg.copy(alpha = if (showKey) 0.82f else 0.58f),1059 fontFamily = PeachType.Mono,1060 fontSize = 10.sp,1061 modifier = Modifier.weight(1f),1062 )1063 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {1064 SubtleButton(if (copied) "copied" else "copy", fg) {1065 PeachClipboard.copy(ctx, "peach license", key)1066 copied = true1067 scope.launch {1068 delay(1_500)1069 copied = false1070 }1071 }1072 SubtleButton(if (showKey) "hide" else "reveal", fg) { showKey = !showKey }1073 }1074 }1075 }1076 Spacer(Modifier.height(12.dp))1077 features.forEachIndexed { i, name ->1078 RowLine(fg) {1079 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {1080 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))1081 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1082 }1083 Text("unlocked", color = com.peachpasswords.ui.theme.peachColors.HealthOk, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)1084 }1085 }1086 Spacer(Modifier.height(12.dp))1087 Box(1088 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1089 .border(1.dp, com.peachpasswords.ui.theme.peachColors.Breach.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1090 .clickable { vm.deactivate() }1091 .padding(vertical = 12.dp),1092 contentAlignment = Alignment.Center,1093 ) { Text("Deactivate", color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 12.sp) }1094}10951096private fun formatLicenseActiveSince(issuedAt: Long?): String {1097 if (issuedAt == null) return "Active"1098 val monthYear = SimpleDateFormat("MMMM yyyy", Locale.getDefault()).format(Date(issuedAt))1099 return "Active since $monthYear"1100}1101110211031104@OptIn(ExperimentalLayoutApi::class)1105@Composable1106private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {1107 val categories = listOf("Bug report", "Feature request", "Question", "Other")1108 var category by remember { mutableStateOf(categories[0]) }1109 var message by remember { mutableStateOf("") }1110 val state by vm.feedbackState.collectAsState()11111112 1113 DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }11141115 if (state is FeedbackState.Sent) {1116 Box(1117 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))1118 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),1119 ) {1120 Column {1121 Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp)1122 Text("Your note is in the queue. Someone will process it soon.", color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 12.sp, modifier = Modifier.padding(top = 4.dp))1123 }1124 }1125 return1126 }11271128 val sending = state is FeedbackState.Sending11291130 Text("Help us improve Peach. Every report goes directly to our inbox.", color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp)1131 SubLabel("TYPE", fg)1132 FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1133 categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }1134 }1135 SubLabel("MESSAGE", fg)1136 Box(1137 Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp))1138 .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))1139 .padding(10.dp),1140 ) {1141 if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)1142 BasicTextField(1143 value = message, onValueChange = { message = it.take(MAX_FEEDBACK_MESSAGE_LENGTH) },1144 enabled = !sending,1145 textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),1146 cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),1147 )1148 }1149 Text(1150 "Version ${BuildConfig.VERSION_NAME} · will be included automatically",1151 modifier = Modifier.padding(top = 6.dp),1152 color = fg.copy(alpha = 0.52f),1153 fontFamily = PeachType.Mono,1154 fontSize = 10.sp,1155 lineHeight = 14.sp,1156 )1157 Spacer(Modifier.height(8.dp))11581159 Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {1160 val canSend = !sending && sanitizeFeedbackMessage(message).isNotBlank()1161 Box(1162 Modifier.clip(RoundedCornerShape(8.dp))1163 .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))1164 .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))1165 .clickable(enabled = canSend) { vm.sendFeedback(category, message) }1166 .padding(horizontal = 12.dp, vertical = 6.dp),1167 ) {1168 Text(1169 feedbackSubmitLabel(state),1170 color = fg.copy(alpha = if (canSend) 1f else 0.4f),1171 fontFamily = PeachType.Mono, fontSize = 11.sp,1172 )1173 }1174 if (sending) {1175 CircularProgressIndicator(1176 color = LocalPeachAccent.current,1177 strokeWidth = 2.dp,1178 modifier = Modifier.size(16.dp),1179 )1180 }1181 }11821183 (state as? FeedbackState.Error)?.let { err ->1184 Text(1185 err.message,1186 modifier = Modifier.padding(top = 8.dp),1187 color = peachColors.Breach,1188 fontFamily = PeachType.Mono,1189 fontSize = 11.sp,1190 lineHeight = 15.sp,1191 )1192 }11931194 Hint("Sent anonymously · no account required", fg)1195}1196119711981199@Composable1200internal fun DuressSection(fg: Color, vm: SettingsViewModel) {1201 val configured by vm.duressConfigured.collectAsState()1202 if (configured) DuressActiveState(fg, vm) else DuressForm(fg, vm)1203}12041205@Composable1206private fun DuressActiveState(fg: Color, vm: SettingsViewModel) {1207 Text(1208 "Duress password is active",1209 color = peachColors.HealthOk,1210 fontFamily = PeachType.Mono,1211 fontSize = 11.sp,1212 modifier = Modifier.padding(top = 6.dp),1213 )1214 Spacer(Modifier.height(8.dp))1215 DuressDangerGhostButton("Disable duress password", fg) { vm.disableDuress() }1216 Hint("Entering your duress password instead of your real one triggers the action you chose.", fg)1217}12181219@Composable1220private fun DuressForm(fg: Color, vm: SettingsViewModel) {1221 var enabled by remember { mutableStateOf(false) }1222 var password by remember { mutableStateOf("") }1223 var confirm by remember { mutableStateOf("") }1224 var action by remember { mutableStateOf(DuressAction.DECOY) }1225 var error by remember { mutableStateOf<String?>(null) }1226 val scope = rememberCoroutineScope()12271228 RowLine(fg) {1229 Name("Duress password", fg)1230 Toggle(enabled, fg) { on ->1231 enabled = on1232 if (!on) { password = ""; confirm = ""; error = null }1233 }1234 }1235 Text(1236 "Entering your duress password instead of your real one opens a decoy vault or wipes the real one.",1237 color = fg.copy(alpha = 0.7f),1238 fontFamily = PeachType.Mono,1239 fontSize = 10.sp,1240 modifier = Modifier.padding(top = 6.dp),1241 )12421243 AnimatedVisibility(enabled) {1244 Column(Modifier.fillMaxWidth().padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1245 PwField("DURESS PASSPHRASE", password, fg) { password = it; error = null }1246 PwField("CONFIRM DURESS PASSPHRASE", confirm, fg) { confirm = it; error = null }12471248 Text(1249 "When your duress password is entered at the lock screen, Peach will:",1250 color = fg.copy(alpha = 0.7f),1251 fontFamily = PeachType.Mono,1252 fontSize = 10.sp,1253 modifier = Modifier.padding(top = 4.dp),1254 )12551256 DuressRadioOption("Show a decoy vault", action == DuressAction.DECOY, fg) { action = DuressAction.DECOY }1257 DuressRadioOption("Destroy the real vault", action == DuressAction.DESTROY, fg) { action = DuressAction.DESTROY }12581259 error?.let { Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }12601261 val canSave = password.isNotBlank() && confirm.isNotBlank()1262 DuressSaveButton("Save duress password", fg, canSave) {1263 error = when {1264 password.isBlank() || confirm.isBlank() -> "Enter and confirm a duress password"1265 password != confirm -> "Passwords do not match"1266 else -> null1267 }1268 if (error == null) scope.launch {1269 if (vm.saveDuress(password, action)) {1270 password = ""; confirm = ""; enabled = false1271 } else {1272 error = "Couldn't save — the duress passphrase must differ from your real password"1273 }1274 }1275 }1276 }1277 }1278}12791280@Composable1281private fun DuressRadioOption(label: String, selected: Boolean, fg: Color, onClick: () -> Unit) {1282 val accent = LocalPeachAccent.current1283 Row(1284 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)).clickable(onClick = onClick).padding(vertical = 7.dp),1285 verticalAlignment = Alignment.CenterVertically,1286 horizontalArrangement = Arrangement.spacedBy(10.dp),1287 ) {1288 Box(1289 Modifier.size(16.dp).clip(CircleShape)1290 .border(1.dp, if (selected) accent else fg.copy(alpha = 0.4f), CircleShape),1291 contentAlignment = Alignment.Center,1292 ) {1293 if (selected) Box(Modifier.size(8.dp).clip(CircleShape).background(accent))1294 }1295 Text(label, color = if (selected) accent else fg, fontFamily = PeachType.Mono, fontSize = 11.sp)1296 }1297}12981299@Composable1300private fun DuressSaveButton(label: String, fg: Color, enabled: Boolean, onClick: () -> Unit) {1301 val accent = LocalPeachAccent.current1302 val tint = if (enabled) accent else fg.copy(alpha = 0.3f)1303 Box(1304 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1305 .border(1.dp, tint.copy(alpha = if (enabled) 0.6f else 0.3f), RoundedCornerShape(8.dp))1306 .background(tint.copy(alpha = if (enabled) 0.16f else 0.06f))1307 .let { if (enabled) it.clickable(onClick = onClick) else it }1308 .padding(vertical = 11.dp),1309 contentAlignment = Alignment.Center,1310 ) {1311 Text(label, color = if (enabled) accent else fg.copy(alpha = 0.4f), fontFamily = PeachType.Mono, fontSize = 11.sp)1312 }1313}13141315@Composable1316private fun DuressDangerGhostButton(label: String, fg: Color, onClick: () -> Unit) {1317 Box(1318 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1319 .border(1.dp, peachColors.Breach.copy(alpha = 0.5f), RoundedCornerShape(8.dp))1320 .clickable(onClick = onClick)1321 .padding(vertical = 11.dp),1322 contentAlignment = Alignment.Center,1323 ) {1324 Text(label, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 11.sp)1325 }1326}132713281329@Composable1330private fun SyncModeRow(1331 title: String,1332 detail: String,1333 selected: Boolean,1334 fg: Color,1335 onSelect: () -> Unit,1336) {1337 RowLine(fg, Modifier.clickable(onClick = onSelect)) {1338 Column(Modifier.weight(1f)) {1339 Text(title, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1340 Text(1341 detail,1342 color = fg.copy(alpha = 0.7f),1343 fontFamily = PeachType.Body,1344 fontSize = 11.sp,1345 lineHeight = 16.sp,1346 modifier = Modifier.padding(top = 2.dp),1347 )1348 }1349 Text(1350 if (selected) "●" else "○",1351 color = if (selected) fg else fg.copy(alpha = 0.45f),1352 fontFamily = PeachType.Mono,1353 fontSize = 14.sp,1354 modifier = Modifier.padding(start = 10.dp),1355 )1356 }1357}