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.SyncStatus34import com.peachpasswords.ui.theme.LocalPeachAccent35import com.peachpasswords.vault.DuressAction36import com.peachpasswords.ui.theme.peachColors37import androidx.compose.runtime.mutableStateOf38import androidx.compose.runtime.remember39import androidx.compose.runtime.rememberCoroutineScope40import androidx.compose.runtime.setValue41import androidx.compose.ui.Alignment42import androidx.compose.ui.Modifier43import androidx.compose.ui.draw.clip44import androidx.compose.ui.graphics.Color45import androidx.compose.ui.graphics.SolidColor46import androidx.compose.ui.platform.LocalContext47import androidx.compose.ui.text.TextStyle48import androidx.compose.ui.text.font.FontStyle49import androidx.compose.ui.text.input.PasswordVisualTransformation50import androidx.compose.ui.unit.Dp51import androidx.compose.ui.unit.dp52import androidx.compose.ui.unit.em53import androidx.compose.ui.unit.sp54import androidx.compose.material3.Text55import com.peachpasswords.BuildConfig56import com.peachpasswords.autofill.AutofillEnablement57import com.peachpasswords.ui.PeachNav58import com.peachpasswords.ui.components.PeachEmptyOrEndState59import com.peachpasswords.ui.components.PeachField60import com.peachpasswords.ui.sync.SyncViewModel61import com.peachpasswords.ui.theme.ACCENT_COLORS62import com.peachpasswords.ui.theme.PeachSpacing63import com.peachpasswords.ui.theme.PeachType64import androidx.hilt.navigation.compose.hiltViewModel65import com.peachpasswords.vault.VaultSettings66import com.peachpasswords.vault.VaultSnapshot67import kotlinx.coroutines.launch68import kotlinx.coroutines.delay69import java.text.SimpleDateFormat70import java.util.Date71import java.util.Locale7273private const val PRO_URL = "https://buy.polar.sh/polar_cl_IXSFIPojx67rcOTksn8LkH5mnU3osPHtYqBIl1eyuIz"747576777879808182@Composable83fun CardBody(84 id: CardId,85 fg: Color,86 vm: SettingsViewModel,87 settings: VaultSettings,88 entriesCount: Int,89 onNavigate: (PeachNav) -> Unit,90) {91 when (id) {92 CardId.Appearance -> AppearanceBody(fg, vm, settings)93 CardId.Protection -> ProtectionBody(fg, vm, settings, onNavigate)94 CardId.Vault -> VaultBody(fg, vm, settings, entriesCount, onNavigate)95 CardId.Sync -> SyncBody(fg, onNavigate)96 CardId.Shortcuts -> ShortcutsBody(fg)97 CardId.Pro -> ProBody(fg, vm)98 CardId.Feedback -> FeedbackBody(fg, vm)99 }100}101102103104@Composable105private fun SubLabel(text: String, fg: Color, top: Dp = 14.dp) {106 Text(107 text,108 modifier = Modifier.padding(top = top, bottom = 4.dp),109 color = fg.copy(alpha = 0.58f),110 fontFamily = PeachType.Mono,111 fontSize = 8.sp,112 letterSpacing = 0.22.em,113 )114}115116@Composable117private fun RowLine(118 fg: Color,119 modifier: Modifier = Modifier,120 verticalPadding: Dp = 9.dp,121 content: @Composable RowScope.() -> Unit,122) {123 Row(124 Modifier.fillMaxWidth().then(modifier).padding(vertical = verticalPadding),125 verticalAlignment = Alignment.CenterVertically,126 horizontalArrangement = Arrangement.SpaceBetween,127 content = content,128 )129 Box(Modifier.fillMaxWidth().height(1.dp).background(fg.copy(alpha = 0.12f)))130}131132@Composable133private fun RowScope.Name(text: String, fg: Color) {134 Text(text, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp, modifier = Modifier.weight(1f))135}136137@Composable138private fun ValueText(text: String, fg: Color) {139 Text(text, color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Mono, fontSize = 11.sp)140}141142@Composable143private fun SubtleButton(label: String, fg: Color, onClick: () -> Unit) {144 Box(145 Modifier.clip(RoundedCornerShape(8.dp))146 .border(1.dp, fg.copy(alpha = 0.28f), RoundedCornerShape(8.dp))147 .background(fg.copy(alpha = 0.08f))148 .clickable(onClick = onClick)149 .padding(horizontal = 12.dp, vertical = 6.dp),150 ) {151 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 11.sp)152 }153}154155@Composable156private fun Toggle(on: Boolean, fg: Color, onToggle: (Boolean) -> Unit) {157 val knob by animateDpAsState(if (on) 16.dp else 2.dp, label = "knob")158 Box(159 Modifier.size(width = 34.dp, height = 20.dp).clip(RoundedCornerShape(999.dp))160 .background(if (on) fg.copy(alpha = 0.28f) else fg.copy(alpha = 0.08f))161 .border(1.dp, fg.copy(alpha = if (on) 0.5f else 0.32f), RoundedCornerShape(999.dp))162 .clickable { onToggle(!on) },163 ) {164 Box(165 Modifier.padding(top = 2.dp).width(16.dp).fillMaxWidth().height(16.dp)166 .padding(start = knob - 2.dp)167 .size(14.dp).clip(CircleShape)168 .background(if (on) fg else fg.copy(alpha = 0.58f)),169 )170 }171}172173@Composable174private fun Pill(label: String, active: Boolean, fg: Color, onClick: () -> Unit) {175 Box(176 Modifier.clip(RoundedCornerShape(999.dp))177 .border(1.dp, fg.copy(alpha = if (active) 0.55f else 0.32f), RoundedCornerShape(999.dp))178 .background(if (active) fg.copy(alpha = 0.18f) else Color.Transparent)179 .clickable(onClick = onClick)180 .padding(horizontal = 12.dp, vertical = 5.dp),181 ) {182 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)183 }184}185186@Composable187private fun ProBadge(fg: Color) {188 Box(189 Modifier.padding(start = 6.dp).clip(RoundedCornerShape(4.dp))190 .background(fg.copy(alpha = 0.16f)).padding(horizontal = 5.dp, vertical = 1.dp),191 ) {192 Text("Pro", color = fg.copy(alpha = 0.85f), fontFamily = PeachType.Mono, fontSize = 8.sp)193 }194}195196@Composable197private fun Hint(text: String, fg: Color) {198 Text(199 text,200 modifier = Modifier.padding(top = 6.dp),201 color = fg.copy(alpha = 0.6f),202 fontFamily = PeachType.Display,203 fontStyle = FontStyle.Italic,204 fontSize = 11.5.sp,205 lineHeight = 16.sp,206 )207}208209210211@OptIn(ExperimentalLayoutApi::class)212@Composable213private fun AppearanceBody(fg: Color, vm: SettingsViewModel, s: VaultSettings) {214 SubLabel("THEME", fg, top = 0.dp)215 RowLine(fg) {216 Name("Theme", fg)217 val (label, next) = when (s.theme) {218 "dark" -> "Switch to light" to "light"219 else -> "Switch to dark" to "dark"220 }221 SubtleButton(label, fg) { vm.setTheme(next) }222 }223 SubLabel("ACCENT", fg)224 FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {225 ACCENT_COLORS.forEach { (name, color) ->226 Box(227 Modifier.size(22.dp).clip(CircleShape).background(color)228 .border(229 if (s.accentColor == name) 2.dp else 1.dp,230 if (s.accentColor == name) fg else fg.copy(alpha = 0.2f),231 CircleShape,232 )233 .clickable { vm.setAccent(name) },234 )235 }236 }237 SubLabel("TEXT SIZE", fg)238 RowLine(fg) {239 Name("Size", fg)240 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {241 Pill("Default", s.textSize == "medium", fg) { vm.setTextSize("medium") }242 Pill("Large", s.textSize == "large", fg) { vm.setTextSize("large") }243 }244 }245 SubLabel("MOTION", fg)246 RowLine(fg) {247 Name("Reduce motion", fg)248 SubtleButton(if (s.reduceMotion) "On" else "Off", fg) { vm.setReduceMotion(!s.reduceMotion) }249 }250}251252253254@Composable255private fun ProtectionBody(fg: Color, vm: SettingsViewModel, s: VaultSettings, onNavigate: (PeachNav) -> Unit) {256 val lockOptions = listOf(1 to "1 minute", 5 to "5 minutes", 15 to "15 minutes", 30 to "30 minutes", 0 to "Never")257 val current = s.autoLockMinutes ?: 0258259 SubLabel("LOCKING", fg, top = 0.dp)260 RowLine(fg) {261 Name("Auto-lock after", fg)262 val idx = lockOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)263 SubtleButton(lockOptions[idx].second, fg) {264 val next = lockOptions[(idx + 1) % lockOptions.size].first265 vm.setAutoLockMinutes(if (next == 0) 0 else next)266 }267 }268 SubLabel("BIOMETRICS", fg)269 val bioActivity = LocalContext.current as? androidx.fragment.app.FragmentActivity270 RowLine(fg) {271 Name("Unlock with biometrics", fg)272 Toggle(s.biometricsEnabled, fg) { on ->273 if (on && bioActivity != null) vm.enableBiometrics(bioActivity) else vm.disableBiometrics()274 }275 }276 val bioError = com.peachpasswords.ui.lock.Biometrics.statusMessage(LocalContext.current)277 if (bioError != null) {278 Text(279 bioError,280 color = com.peachpasswords.ui.theme.peachColors.Breach,281 fontFamily = PeachType.Mono, fontSize = 10.sp,282 modifier = Modifier.padding(start = 2.dp, top = 2.dp, bottom = 4.dp),283 )284 }285 SubLabel("AUTOFILL", fg)286 run {287 288 289 val ctx = LocalContext.current290 val enabled = AutofillEnablement.isEnabled(ctx)291 RowLine(fg) {292 Column(Modifier.weight(1f)) {293 Text("Fill passwords in other apps", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)294 Text(295 if (enabled) {296 "Peach is your autofill service."297 } else {298 "Android decides which app fills passwords. Turn Peach on in system settings."299 },300 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,301 modifier = Modifier.padding(top = 2.dp),302 )303 }304 if (!enabled) {305 SubtleButton("enable", fg) {306 307 308 309 runCatching { ctx.startActivity(AutofillEnablement.requestIntent(ctx)) }310 .onFailure { runCatching { ctx.startActivity(AutofillEnablement.fallbackIntent()) } }311 }312 } else {313 ValueText("on", fg)314 }315 }316 }317318 SubLabel("PASSKEYS", fg)319 RowLine(fg) {320 Column(Modifier.weight(1f)) {321 Text("Credential provider", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)322 Text(323 "Peach can handle passkey sign-in and creation through Android Credential Manager.",324 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,325 modifier = Modifier.padding(top = 2.dp),326 )327 }328 Toggle(s.passkeyProviderEnabled, fg) { vm.setPasskeyProviderEnabled(it) }329 }330 RowLine(fg) {331 Name("Status", fg)332 ValueText(if (s.passkeyProviderEnabled) "enabled" else "off", fg)333 }334 SubLabel("RECOVERY", fg)335 RowLine(fg) {336 Column(Modifier.weight(1f)) {337 Text("View recovery words", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)338 Text(339 "Keep the paper copy current before rotating sync identity or replacing devices.",340 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,341 modifier = Modifier.padding(top = 2.dp),342 )343 }344 SubtleButton("view", fg) { onNavigate(PeachNav.RecoveryView) }345 }346 SubLabel("BREACH PROTECTION", fg)347 val checkingBreaches by vm.checkingBreaches.collectAsState()348 val breachResult by vm.breachResult.collectAsState()349 RowLine(fg) {350 Name("Breach monitoring", fg)351 Toggle(s.breachMonitoring, fg) { vm.setBreachMonitoring(it) }352 }353 RowLine(fg) {354 Name("Check all passwords", fg)355 SubtleButton(if (checkingBreaches) "checking..." else "run", fg) { vm.checkAllBreaches() }356 }357 breachResult?.let { result ->358 RowLine(fg) {359 Name("Last check", fg)360 ValueText(result, fg)361 }362 }363364 SubLabel("MASTER PASSWORD", fg)365 ChangePasswordRow(fg, vm)366367 SubLabel("DURESS PASSWORD", fg)368 val duressIsPro by vm.isPro.collectAsState()369 if (!duressIsPro) {370 RowLine(fg) {371 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {372 Name("Duress password", fg); ProBadge(fg)373 }374 ValueText("off", fg)375 }376 Hint("If entered under coercion, a decoy empty vault opens; your real vault stays hidden. Pro feature.", fg)377 } else {378 DuressSection(fg, vm)379 }380}381382@Composable383private fun ChangePasswordRow(fg: Color, vm: SettingsViewModel) {384 var open by remember { mutableStateOf(false) }385 var current by remember { mutableStateOf("") }386 var next by remember { mutableStateOf("") }387 var confirm by remember { mutableStateOf("") }388 var error by remember { mutableStateOf<String?>(null) }389 var done by remember { mutableStateOf(false) }390 val scope = rememberCoroutineScope()391392 RowLine(fg) {393 Name("Master password", fg)394 SubtleButton(if (open) "cancel" else "change", fg) { open = !open; error = null; done = false }395 }396 AnimatedVisibility(open) {397 Column(Modifier.fillMaxWidth().padding(top = PeachSpacing.sm), verticalArrangement = Arrangement.spacedBy(PeachSpacing.sm)) {398 PwField("current password", current, fg) { current = it }399 PwField("new password (min 12 chars)", next, fg) { next = it }400 PwField("confirm new password", confirm, fg) { confirm = it }401 error?.let { Text(it, color = Color(0xFFE5805C), fontFamily = PeachType.Mono, fontSize = 10.sp) }402 if (done) Text("password changed ✓", color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)403 SubtleButton("save new password", fg) {404 error = when {405 current.isBlank() -> "enter your current password"406 next.length < 12 -> "new password must be at least 12 characters"407 next != confirm -> "new passwords do not match"408 next == current -> "new password must differ from current"409 else -> null410 }411 if (error == null) scope.launch {412 if (vm.changePassword(current, next)) {413 current = ""; next = ""; confirm = ""; open = false; done = true414 } else error = "incorrect current password"415 }416 }417 }418 }419}420421@Composable422private fun PwField(placeholder: String, value: String, @Suppress("UNUSED_PARAMETER") fg: Color, onChange: (String) -> Unit) {423 PeachField(424 label = placeholder,425 value = value,426 onValueChange = onChange,427 keyboardType = androidx.compose.ui.text.input.KeyboardType.Password,428 visualTransformation = PasswordVisualTransformation(),429 )430}431432433434@Composable435private fun VaultBody(436 fg: Color,437 vm: SettingsViewModel,438 s: VaultSettings,439 entriesCount: Int,440 onNavigate: (PeachNav) -> Unit,441) {442 val trashOptions = listOf(7 to "7 days", 30 to "30 days", 90 to "90 days", 0 to "Never")443 val current = s.trashRetentionDays ?: 0444 val isPro by vm.isPro.collectAsState()445 val dedupCount by vm.dedupCount.collectAsState()446 val dedupRunning by vm.dedupRunning.collectAsState()447 val dedupDone by vm.dedupDone.collectAsState()448 val history by vm.vaultHistory.collectAsState()449 val restoringSnapshotId by vm.restoringSnapshotId.collectAsState()450451 SubLabel("ENTRIES", fg, top = 0.dp)452 RowLine(fg) { Name("Entries", fg); ValueText("$entriesCount", fg) }453 RowLine(fg) {454 Name("Duplicates", fg)455 val done = dedupDone456 if (done != null) {457 ValueText(if (done == 0) "already clean" else "removed $done", com.peachpasswords.ui.theme.peachColors.SyncOk)458 } else {459 val count = dedupCount460 val label = when {461 dedupRunning -> "scanning..."462 count == null -> "scan"463 count == 0 -> "none found"464 else -> "$count found"465 }466 SubtleButton(label, fg) {467 if (count == null || count == 0) vm.scanDuplicates()468 }469 }470 }471 if ((dedupCount ?: 0) > 0 && dedupDone == null) {472 Column(473 Modifier.fillMaxWidth()474 .padding(top = 2.dp, bottom = 8.dp)475 .clip(RoundedCornerShape(8.dp))476 .background(fg.copy(alpha = 0.08f))477 .border(1.dp, fg.copy(alpha = 0.18f), RoundedCornerShape(8.dp))478 .padding(10.dp),479 verticalArrangement = Arrangement.spacedBy(8.dp),480 ) {481 val count = dedupCount ?: 0482 Text(483 "$count duplicate ${if (count == 1) "entry" else "entries"} found. The newest copy of each will be kept; older duplicates will be moved to trash.",484 color = fg.copy(alpha = 0.82f),485 fontFamily = PeachType.Body,486 fontSize = 11.sp,487 lineHeight = 16.sp,488 )489 Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {490 SubtleButton("cancel", fg) { vm.cancelDuplicateRemoval() }491 SubtleButton(if (dedupRunning) "removing..." else "remove duplicates", fg) { vm.removeDuplicates() }492 }493 }494 }495496 SubLabel("MAINTENANCE", fg)497 RowLine(fg) {498 Name("Trash auto-delete", fg)499 val idx = trashOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)500 SubtleButton(trashOptions[idx].second, fg) {501 vm.setTrashRetentionDays(trashOptions[(idx + 1) % trashOptions.size].first)502 }503 }504 RowLine(fg) { Name("Advanced Vault Health", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Health) } }505 RowLine(fg) { Name("Trash", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Trash) } }506507 SubLabel("DATA", fg)508 RowLine(fg) { Name("Import passwords", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Import) } }509 RowLine(fg) { Name("Export backup", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Export) } }510 RowLine(fg) {511 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Peach Codex", fg); if (!isPro) ProBadge(fg) }512 SubtleButton(if (isPro) "open" else "Pro", fg) { if (isPro) onNavigate(PeachNav.CodexGenerate) }513 }514 RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } }515516 var historyShowAll by remember { mutableStateOf(false) }517 SubLabel("VAULT HISTORY", fg)518 if (history.isEmpty()) {519 Text(520 "No snapshots yet. Peach saves automatically before every change — saves, syncs, and imports.",521 color = fg.copy(alpha = 0.68f),522 fontFamily = PeachType.Body,523 fontSize = 11.sp,524 lineHeight = 16.sp,525 modifier = Modifier.padding(bottom = 6.dp),526 )527 } else {528 Text(529 "Restoring locks your vault. Unlock with the password that encrypted that snapshot to confirm.",530 color = fg.copy(alpha = 0.68f),531 fontFamily = PeachType.Body,532 fontSize = 11.sp,533 lineHeight = 16.sp,534 modifier = Modifier.padding(bottom = 4.dp),535 )536 history.take(if (historyShowAll) history.size else 3).forEach { snap ->537 RowLine(fg) {538 Column(Modifier.weight(1f)) {539 Text(snapshotTimeLabel(snap.savedAt), color = fg, fontFamily = PeachType.Body, fontSize = 12.sp)540 Text(snapshotSubLabel(snap), color = fg.copy(alpha = 0.62f), fontFamily = PeachType.Mono, fontSize = 10.sp)541 }542 SubtleButton(if (restoringSnapshotId == snap.id) "..." else "restore", fg) {543 vm.restoreVaultSnapshot(snap.id)544 }545 }546 }547 if (history.size > 3) {548 RowLine(fg) {549 Name(if (historyShowAll) "show less" else "${history.size - 3} older", fg)550 SubtleButton(if (historyShowAll) "hide" else "show", fg) { historyShowAll = !historyShowAll }551 }552 }553 Text(554 "${history.size} of 5 snapshots",555 color = fg.copy(alpha = 0.58f),556 fontFamily = PeachType.Mono,557 fontSize = 10.sp,558 modifier = Modifier.padding(top = 2.dp, bottom = 6.dp),559 )560 }561562 var advancedOpen by remember { mutableStateOf(false) }563 SubLabel("ADVANCED", fg)564 RowLine(fg) {565 Name("Advanced", fg)566 SubtleButton(if (advancedOpen) "hide" else "show", fg) { advancedOpen = !advancedOpen }567 }568 if (advancedOpen) {569 RowLine(fg) {570 Name("Replace vault from backup", com.peachpasswords.ui.theme.peachColors.SyncBusy)571 SubtleButton("open", com.peachpasswords.ui.theme.peachColors.SyncBusy) { onNavigate(PeachNav.Import) }572 }573 RowLine(fg) {574 Name("Destroy vault", com.peachpasswords.ui.theme.peachColors.Breach)575 SubtleButton("destroy", com.peachpasswords.ui.theme.peachColors.Breach) { onNavigate(PeachNav.Panic) }576 }577 }578}579580private fun snapshotSubLabel(snapshot: VaultSnapshot): String {581 val count = snapshot.entryCount?.let { "up to $it ${if (it == 1) "entry" else "entries"}" }582 return listOfNotNull(count, snapshotReasonLabel(snapshot.reason)).joinToString(" · ")583}584585private fun snapshotReasonLabel(reason: String): String = when (reason) {586 "local_save" -> "saved"587 "sync_received" -> "synced"588 "import" -> "imported"589 "restore" -> "restored"590 else -> reason591}592593private fun snapshotTimeLabel(savedAt: Long): String {594 val diff = System.currentTimeMillis() - savedAt595 if (diff < 60_000) return "Just now"596 if (diff < 3_600_000) return "${diff / 60_000}m ago"597 val date = Date(savedAt)598 val today = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date())599 val thenDay = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(date)600 val time = SimpleDateFormat("h:mm a", Locale.getDefault()).format(date)601 if (today == thenDay) return "Today $time"602 val yesterday = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date(System.currentTimeMillis() - 86_400_000))603 if (yesterday == thenDay) return "Yesterday $time"604 return SimpleDateFormat("MMM d h:mm a", Locale.getDefault()).format(date)605}606607608609@Composable610private fun SyncBody(fg: Color, onNavigate: (PeachNav) -> Unit) {611 val syncVm: SyncViewModel = hiltViewModel()612 val pairedDevices by syncVm.pairedDevices.collectAsState()613 val pendingVouched by syncVm.pendingVouched.collectAsState()614 val syncStatus by syncVm.status.collectAsState()615 val relayEnabled by syncVm.relayEnabled.collectAsState()616 val scope = rememberCoroutineScope()617 var confirmUnpair by remember { mutableStateOf<String?>(null) }618 var rotateConfirmOpen by remember { mutableStateOf(false) }619 var rotating by remember { mutableStateOf(false) }620 var rotateError by remember { mutableStateOf<String?>(null) }621622 SubLabel("PAIRING", fg, top = 0.dp)623 RowLine(fg) {624 Column(Modifier.weight(1f)) {625 Row(verticalAlignment = Alignment.CenterVertically) {626 Text("Peach Sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp); ProBadge(fg)627 }628 Text(629 "Pair devices with a code over your local network and keep encrypted vault blobs in step without a central account.",630 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,631 modifier = Modifier.padding(top = 2.dp),632 )633 }634 }635 636 637 RowLine(fg, Modifier.clickable { onNavigate(PeachNav.CodePair) }) {638 Name("Sync hub", fg)639 Text("›", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 15.sp)640 }641 RowLine(fg) {642 Column(Modifier.weight(1f)) {643 Text("Pair new device", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)644 Text(645 "This phone shows a code; type it into Peach in your browser.",646 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,647 modifier = Modifier.padding(top = 2.dp),648 )649 }650 SubtleButton("pair", fg) { onNavigate(PeachNav.CodePair) }651 }652653 SubLabel("PAIRED DEVICES", fg)654 if (pairedDevices.isEmpty()) {655 PeachEmptyOrEndState(656 message = "No paired devices yet.",657 detail = "Pair a nearby phone, browser, or desktop helper when you're ready to sync.",658 modifier = Modifier.padding(top = PeachSpacing.xs),659 )660 } else {661 pairedDevices.forEach { d ->662 RowLine(fg) {663 Column(Modifier.weight(1f)) {664 Text(d.deviceName ?: d.deviceId, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)665 Text(666 "${deviceTypeLabel(d.deviceType)} · ${syncTimeLabel(d.lastSyncedAt)}${if (isSyncStale(d.lastSyncedAt)) " · not seen recently" else ""}",667 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,668 modifier = Modifier.padding(top = 2.dp),669 )670 }671 if (confirmUnpair == d.deviceId) {672 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {673 SubtleButton("cancel", fg) { confirmUnpair = null }674 SubtleButton("remove", peachColors.Breach) { syncVm.unpairDevice(d.deviceId); confirmUnpair = null }675 }676 } else {677 SubtleButton("remove", fg) { confirmUnpair = d.deviceId }678 }679 }680 }681 RowLine(fg) {682 ValueText(syncFlashLabel(syncStatus), fg)683 SubtleButton(if (syncStatus == SyncStatus.Syncing) "syncing..." else "sync now", fg) {684 if (syncStatus != SyncStatus.Syncing) syncVm.syncNow()685 }686 }687 }688689 SubLabel("RELAYING", fg)690 RowLine(fg) {691 Column(Modifier.weight(1f)) {692 Text("Relay for other devices", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)693 Text(694 "Two browsers can't reach each other directly, so this phone passes their encrypted sync between them. It can't read any of it.",695 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,696 modifier = Modifier.padding(top = 2.dp),697 )698 }699 Toggle(relayEnabled, fg) { syncVm.setRelayEnabled(it) }700 }701702 if (pendingVouched.isNotEmpty()) {703 SubLabel("PENDING DEVICES", fg)704 pendingVouched.forEach { dev ->705 RowLine(fg) {706 Column(Modifier.weight(1f)) {707 Text(dev.deviceName, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)708 Text(709 "Was added by another of your devices. Allow it to sync with this vault?",710 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,711 modifier = Modifier.padding(top = 2.dp),712 )713 }714 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {715 SubtleButton("Allow", fg) { syncVm.confirmVouchedDevice(dev.deviceId) }716 SubtleButton("Reject", fg) { syncVm.rejectVouchedDevice(dev.deviceId) }717 }718 }719 }720 }721722 SubLabel("RECOVERY", fg)723 if (rotateConfirmOpen) {724 Hint("This will disconnect all paired devices and your 12 recovery words will change. You'll be shown the new words next.", peachColors.Breach)725 rotateError?.let {726 Text(it, color = peachColors.Breach, fontFamily = PeachType.Body, fontSize = 11.sp, modifier = Modifier.padding(top = 6.dp))727 }728 Row(Modifier.padding(top = 10.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {729 SubtleButton("cancel", fg) { if (!rotating) rotateConfirmOpen = false }730 SubtleButton(if (rotating) "rotating..." else "Rotate sync identity", peachColors.Breach) {731 if (rotating) return@SubtleButton732 rotating = true733 rotateError = null734 scope.launch {735 val ok = syncVm.rotateSyncIdentity()736 rotating = false737 if (ok) {738 rotateConfirmOpen = false739 onNavigate(PeachNav.RecoverySetup)740 } else {741 rotateError = "Rotation failed. Unlock your real vault and try again."742 }743 }744 }745 }746 } else {747 RowLine(fg) {748 Column(Modifier.weight(1f)) {749 Text("Rotate sync identity", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)750 Text(751 "Use this if a paired device was lost or stolen. Re-keys the vault so the old device's key is useless.",752 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,753 modifier = Modifier.padding(top = 2.dp),754 )755 }756 SubtleButton("rotate", peachColors.Breach) { rotateError = null; rotateConfirmOpen = true }757 }758 }759760 Hint("Sync uses the same zero-knowledge vault format as backup and restore; pairing authorizes a device, not a cloud account.", fg)761}762763private fun deviceTypeLabel(type: String?): String = when (type) {764 "android" -> "Android"765 "phone" -> "Phone"766 "tablet" -> "Tablet"767 "desktop" -> "Desktop"768 "browser" -> "Browser"769 else -> "Device"770}771772private fun syncTimeLabel(lastSyncedAt: Long?): String {773 if (lastSyncedAt == null) return "never synced"774 val diff = System.currentTimeMillis() - lastSyncedAt775 if (diff < 60_000) return "just now"776 if (diff < 3_600_000) return "${diff / 60_000}m ago"777 if (diff < 86_400_000) return "${diff / 3_600_000}h ago"778 return "${diff / 86_400_000}d ago"779}780781private fun isSyncStale(lastSyncedAt: Long?): Boolean =782 lastSyncedAt != null && System.currentTimeMillis() - lastSyncedAt > 7L * 24L * 60L * 60L * 1000L783784private fun syncFlashLabel(status: SyncStatus): String = when (status) {785 SyncStatus.Idle -> ""786 SyncStatus.Syncing -> "syncing..."787 SyncStatus.Offline -> "offline"788 is SyncStatus.Error -> status.message789 is SyncStatus.LastSynced -> "synced ${syncTimeLabel(status.timestamp)}"790}791792793794@Composable795private fun ShortcutsBody(fg: Color) {796 val bindings = listOf(797 "Copy password" to "⌘C", "Copy username" to "⌘⇧C", "Open entry" to "↵",798 "Edit entry" to "E", "New entry" to "⌘N", "Search" to "/",799 )800 SubLabel("KEYBINDINGS", fg, top = 0.dp)801 Hint("Shortcuts apply when a hardware keyboard is attached. Defaults shown below.", fg)802 Spacer(Modifier.height(8.dp))803 bindings.forEach { (label, key) ->804 RowLine(fg) {805 Name(label, fg)806 Box(807 Modifier.clip(RoundedCornerShape(4.dp)).background(fg.copy(alpha = 0.06f))808 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(4.dp))809 .padding(horizontal = 7.dp, vertical = 2.dp),810 ) { Text(key, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp) }811 }812 }813}814815816817@Composable818private fun ProBody(fg: Color, vm: SettingsViewModel) {819 val ctx = LocalContext.current820 val isPro by vm.isPro.collectAsState()821 if (isPro) {822 ProActiveBody(fg, vm)823 return824 }825 val features = listOf(826 "Peach Sync" to "Encrypted · peer-to-peer",827 "Peach Codex" to "Restore from paper",828 "Passkeys" to "Zero-knowledge WebAuthn",829 "Advanced Vault Health" to "Reuse · age · exposure",830 "Canary entries" to "Detects vault compromise",831 "Duress vault" to "Decoy under coercion",832 )833 Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)834 Text(835 "Everything, everywhere.",836 modifier = Modifier.padding(top = 8.dp),837 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp,838 )839 Text(840 "One key unlocks every Pro feature — for the lifetime of the app.",841 modifier = Modifier.padding(top = 6.dp),842 color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,843 )844 Spacer(Modifier.height(10.dp))845 features.forEachIndexed { i, (name, desc) ->846 847 848 849 850 RowLine(fg, verticalPadding = 6.dp) {851 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {852 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))853 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)854 }855 Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)856 }857 }858 Spacer(Modifier.height(12.dp))859 Text(860 "$39",861 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp,862 )863 Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em)864 Spacer(Modifier.height(10.dp))865 Box(866 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))867 .background(fg.copy(alpha = 0.16f))868 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))869 .clickable {870 runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) }871 }872 .padding(vertical = 12.dp),873 contentAlignment = Alignment.Center,874 ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }875876 877 878 879 880 Spacer(Modifier.height(44.dp))881882 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)883 var key by remember { mutableStateOf("") }884 val activating by vm.activating.collectAsState()885 val activationError by vm.activationError.collectAsState()886 Box(887 Modifier.fillMaxWidth().padding(top = 6.dp)888 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))889 .padding(horizontal = 12.dp, vertical = 10.dp),890 ) {891 BasicTextField(892 value = key,893 894 895 896 897 onValueChange = { key = it; vm.clearActivationError() },898 singleLine = true,899 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em, color = fg),900 cursorBrush = SolidColor(fg),901 modifier = Modifier.fillMaxWidth(),902 decorationBox = { inner ->903 if (key.isEmpty()) Text("PPK-XXXX-XXXX-XXXX", color = fg.copy(alpha = 0.3f), fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em)904 inner()905 },906 )907 }908 if (activationError != null) {909 Text(activationError!!, color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 6.dp))910 }911 Spacer(Modifier.height(8.dp))912 Box(913 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))914 .background(fg.copy(alpha = if (activating || key.isBlank()) 0.08f else 0.16f))915 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))916 .clickable(enabled = !activating && key.isNotBlank()) { vm.activateLicense(key) }917 .padding(vertical = 12.dp),918 contentAlignment = Alignment.Center,919 ) { Text(if (activating) "Activating…" else "Activate", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }920}921922@Composable923private fun ProActiveBody(fg: Color, vm: SettingsViewModel) {924 val ctx = LocalContext.current925 val features = listOf("Peach Sync", "Peach Codex", "Passkeys", "Advanced Vault Health", "Canary entries", "Duress vault")926 val licenseKey by vm.licenseKey.collectAsState()927 val issuedAt by vm.licenseIssuedAt.collectAsState()928 var showKey by remember { mutableStateOf(false) }929 var copied by remember { mutableStateOf(false) }930 val scope = rememberCoroutineScope()931 Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {932 com.peachpasswords.ui.components.PeachMark(size = 60.dp)933 }934 Text(935 "Peach Pro",936 modifier = Modifier.fillMaxWidth(),937 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp,938 textAlign = androidx.compose.ui.text.style.TextAlign.Center,939 )940 Text(941 formatLicenseActiveSince(issuedAt),942 modifier = Modifier.fillMaxWidth().padding(top = 4.dp),943 color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em,944 textAlign = androidx.compose.ui.text.style.TextAlign.Center,945 )946 licenseKey?.let { key ->947 Spacer(Modifier.height(12.dp))948 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)949 RowLine(fg) {950 Text(951 if (showKey) key else "************************",952 color = fg.copy(alpha = if (showKey) 0.82f else 0.58f),953 fontFamily = PeachType.Mono,954 fontSize = 10.sp,955 modifier = Modifier.weight(1f),956 )957 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {958 SubtleButton(if (copied) "copied" else "copy", fg) {959 PeachClipboard.copy(ctx, "peach license", key)960 copied = true961 scope.launch {962 delay(1_500)963 copied = false964 }965 }966 SubtleButton(if (showKey) "hide" else "reveal", fg) { showKey = !showKey }967 }968 }969 }970 Spacer(Modifier.height(12.dp))971 features.forEachIndexed { i, name ->972 RowLine(fg) {973 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {974 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))975 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)976 }977 Text("unlocked", color = com.peachpasswords.ui.theme.peachColors.HealthOk, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)978 }979 }980 Spacer(Modifier.height(12.dp))981 Box(982 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))983 .border(1.dp, com.peachpasswords.ui.theme.peachColors.Breach.copy(alpha = 0.4f), RoundedCornerShape(10.dp))984 .clickable { vm.deactivate() }985 .padding(vertical = 12.dp),986 contentAlignment = Alignment.Center,987 ) { Text("Deactivate", color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 12.sp) }988}989990private fun formatLicenseActiveSince(issuedAt: Long?): String {991 if (issuedAt == null) return "Active"992 val monthYear = SimpleDateFormat("MMMM yyyy", Locale.getDefault()).format(Date(issuedAt))993 return "Active since $monthYear"994}995996997998@OptIn(ExperimentalLayoutApi::class)999@Composable1000private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {1001 val categories = listOf("Bug report", "Feature request", "Question", "Other")1002 var category by remember { mutableStateOf(categories[0]) }1003 var message by remember { mutableStateOf("") }1004 val state by vm.feedbackState.collectAsState()10051006 1007 DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }10081009 if (state is FeedbackState.Sent) {1010 Box(1011 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))1012 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),1013 ) {1014 Column {1015 Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp)1016 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))1017 }1018 }1019 return1020 }10211022 val sending = state is FeedbackState.Sending10231024 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)1025 SubLabel("TYPE", fg)1026 FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1027 categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }1028 }1029 SubLabel("MESSAGE", fg)1030 Box(1031 Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp))1032 .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))1033 .padding(10.dp),1034 ) {1035 if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)1036 BasicTextField(1037 value = message, onValueChange = { message = it.take(MAX_FEEDBACK_MESSAGE_LENGTH) },1038 enabled = !sending,1039 textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),1040 cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),1041 )1042 }1043 Text(1044 "Version ${BuildConfig.VERSION_NAME} · will be included automatically",1045 modifier = Modifier.padding(top = 6.dp),1046 color = fg.copy(alpha = 0.52f),1047 fontFamily = PeachType.Mono,1048 fontSize = 10.sp,1049 lineHeight = 14.sp,1050 )1051 Spacer(Modifier.height(8.dp))10521053 Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {1054 val canSend = !sending && sanitizeFeedbackMessage(message).isNotBlank()1055 Box(1056 Modifier.clip(RoundedCornerShape(8.dp))1057 .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))1058 .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))1059 .clickable(enabled = canSend) { vm.sendFeedback(category, message) }1060 .padding(horizontal = 12.dp, vertical = 6.dp),1061 ) {1062 Text(1063 feedbackSubmitLabel(state),1064 color = fg.copy(alpha = if (canSend) 1f else 0.4f),1065 fontFamily = PeachType.Mono, fontSize = 11.sp,1066 )1067 }1068 if (sending) {1069 CircularProgressIndicator(1070 color = LocalPeachAccent.current,1071 strokeWidth = 2.dp,1072 modifier = Modifier.size(16.dp),1073 )1074 }1075 }10761077 (state as? FeedbackState.Error)?.let { err ->1078 Text(1079 err.message,1080 modifier = Modifier.padding(top = 8.dp),1081 color = peachColors.Breach,1082 fontFamily = PeachType.Mono,1083 fontSize = 11.sp,1084 lineHeight = 15.sp,1085 )1086 }10871088 Hint("Sent anonymously · no account required", fg)1089}1090109110921093@Composable1094internal fun DuressSection(fg: Color, vm: SettingsViewModel) {1095 val configured by vm.duressConfigured.collectAsState()1096 if (configured) DuressActiveState(fg, vm) else DuressForm(fg, vm)1097}10981099@Composable1100private fun DuressActiveState(fg: Color, vm: SettingsViewModel) {1101 Text(1102 "Duress password is active",1103 color = peachColors.HealthOk,1104 fontFamily = PeachType.Mono,1105 fontSize = 11.sp,1106 modifier = Modifier.padding(top = 6.dp),1107 )1108 Spacer(Modifier.height(8.dp))1109 DuressDangerGhostButton("Disable duress password", fg) { vm.disableDuress() }1110 Hint("Entering your duress password instead of your real one triggers the action you chose.", fg)1111}11121113@Composable1114private fun DuressForm(fg: Color, vm: SettingsViewModel) {1115 var enabled by remember { mutableStateOf(false) }1116 var password by remember { mutableStateOf("") }1117 var confirm by remember { mutableStateOf("") }1118 var action by remember { mutableStateOf(DuressAction.DECOY) }1119 var error by remember { mutableStateOf<String?>(null) }1120 val scope = rememberCoroutineScope()11211122 RowLine(fg) {1123 Name("Duress password", fg)1124 Toggle(enabled, fg) { on ->1125 enabled = on1126 if (!on) { password = ""; confirm = ""; error = null }1127 }1128 }1129 Text(1130 "Entering your duress password instead of your real one opens a decoy vault or wipes the real one.",1131 color = fg.copy(alpha = 0.7f),1132 fontFamily = PeachType.Mono,1133 fontSize = 10.sp,1134 modifier = Modifier.padding(top = 6.dp),1135 )11361137 AnimatedVisibility(enabled) {1138 Column(Modifier.fillMaxWidth().padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1139 PwField("DURESS PASSPHRASE", password, fg) { password = it; error = null }1140 PwField("CONFIRM DURESS PASSPHRASE", confirm, fg) { confirm = it; error = null }11411142 Text(1143 "When your duress password is entered at the lock screen, Peach will:",1144 color = fg.copy(alpha = 0.7f),1145 fontFamily = PeachType.Mono,1146 fontSize = 10.sp,1147 modifier = Modifier.padding(top = 4.dp),1148 )11491150 DuressRadioOption("Show a decoy vault", action == DuressAction.DECOY, fg) { action = DuressAction.DECOY }1151 DuressRadioOption("Destroy the real vault", action == DuressAction.DESTROY, fg) { action = DuressAction.DESTROY }11521153 error?.let { Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }11541155 val canSave = password.isNotBlank() && confirm.isNotBlank()1156 DuressSaveButton("Save duress password", fg, canSave) {1157 error = when {1158 password.isBlank() || confirm.isBlank() -> "Enter and confirm a duress password"1159 password != confirm -> "Passwords do not match"1160 else -> null1161 }1162 if (error == null) scope.launch {1163 if (vm.saveDuress(password, action)) {1164 password = ""; confirm = ""; enabled = false1165 } else {1166 error = "Couldn't save — the duress passphrase must differ from your real password"1167 }1168 }1169 }1170 }1171 }1172}11731174@Composable1175private fun DuressRadioOption(label: String, selected: Boolean, fg: Color, onClick: () -> Unit) {1176 val accent = LocalPeachAccent.current1177 Row(1178 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)).clickable(onClick = onClick).padding(vertical = 7.dp),1179 verticalAlignment = Alignment.CenterVertically,1180 horizontalArrangement = Arrangement.spacedBy(10.dp),1181 ) {1182 Box(1183 Modifier.size(16.dp).clip(CircleShape)1184 .border(1.dp, if (selected) accent else fg.copy(alpha = 0.4f), CircleShape),1185 contentAlignment = Alignment.Center,1186 ) {1187 if (selected) Box(Modifier.size(8.dp).clip(CircleShape).background(accent))1188 }1189 Text(label, color = if (selected) accent else fg, fontFamily = PeachType.Mono, fontSize = 11.sp)1190 }1191}11921193@Composable1194private fun DuressSaveButton(label: String, fg: Color, enabled: Boolean, onClick: () -> Unit) {1195 val accent = LocalPeachAccent.current1196 val tint = if (enabled) accent else fg.copy(alpha = 0.3f)1197 Box(1198 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1199 .border(1.dp, tint.copy(alpha = if (enabled) 0.6f else 0.3f), RoundedCornerShape(8.dp))1200 .background(tint.copy(alpha = if (enabled) 0.16f else 0.06f))1201 .let { if (enabled) it.clickable(onClick = onClick) else it }1202 .padding(vertical = 11.dp),1203 contentAlignment = Alignment.Center,1204 ) {1205 Text(label, color = if (enabled) accent else fg.copy(alpha = 0.4f), fontFamily = PeachType.Mono, fontSize = 11.sp)1206 }1207}12081209@Composable1210private fun DuressDangerGhostButton(label: String, fg: Color, onClick: () -> Unit) {1211 Box(1212 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1213 .border(1.dp, peachColors.Breach.copy(alpha = 0.5f), RoundedCornerShape(8.dp))1214 .clickable(onClick = onClick)1215 .padding(vertical = 11.dp),1216 contentAlignment = Alignment.Center,1217 ) {1218 Text(label, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 11.sp)1219 }1220}