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.heightIn21import androidx.compose.foundation.layout.padding22import androidx.compose.foundation.layout.size23import androidx.compose.foundation.layout.width24import androidx.compose.foundation.shape.CircleShape25import androidx.compose.foundation.shape.RoundedCornerShape26import androidx.compose.foundation.text.BasicTextField27import androidx.compose.runtime.Composable28import androidx.compose.material3.CircularProgressIndicator29import androidx.compose.material3.AlertDialog30import androidx.compose.runtime.DisposableEffect31import androidx.compose.runtime.collectAsState32import androidx.compose.runtime.getValue33import com.peachpasswords.feedback.FeedbackState34import com.peachpasswords.shared.PeachClipboard35import com.peachpasswords.sync.LEGACY_ACTIVE36import com.peachpasswords.sync.REPAIRING37import com.peachpasswords.sync.RESET_CONFIRMED38import com.peachpasswords.sync.RESET_REQUIRED39import com.peachpasswords.sync.SyncMode40import com.peachpasswords.sync.UNKNOWN_STATE41import com.peachpasswords.sync.V2_ACTIVE42import com.peachpasswords.sync.V2_ANCHOR43import com.peachpasswords.sync.canShowBackgroundSyncNotification44import com.peachpasswords.sync.describeSyncOutcome45import com.peachpasswords.sync.privateRelayDraftOf46import com.peachpasswords.sync.syncIndicator47import com.peachpasswords.sync.syncIndicatorLabel48import com.peachpasswords.ui.components.SyncIndicatorDot49import com.peachpasswords.ui.theme.LocalPeachAccent50import com.peachpasswords.vault.DuressAction51import com.peachpasswords.ui.theme.peachColors52import androidx.compose.runtime.mutableStateOf53import androidx.compose.runtime.remember54import androidx.compose.runtime.rememberCoroutineScope55import androidx.compose.runtime.setValue56import androidx.compose.ui.Alignment57import androidx.compose.ui.Modifier58import androidx.compose.ui.draw.clip59import androidx.compose.ui.graphics.Color60import androidx.compose.ui.graphics.SolidColor61import androidx.compose.ui.platform.LocalContext62import androidx.compose.ui.text.TextStyle63import androidx.compose.ui.text.font.FontStyle64import androidx.compose.ui.text.input.PasswordVisualTransformation65import androidx.compose.ui.text.input.KeyboardType66import androidx.compose.ui.unit.Dp67import androidx.compose.ui.unit.dp68import androidx.compose.ui.unit.em69import androidx.compose.ui.unit.sp70import androidx.compose.material3.Text71import com.peachpasswords.BuildConfig72import com.peachpasswords.autofill.AutofillEnablement73import com.peachpasswords.ui.PeachNav74import com.peachpasswords.ui.components.PeachEmptyOrEndState75import com.peachpasswords.ui.components.PeachField76import com.peachpasswords.ui.pairing.BackgroundSyncDialog77import com.peachpasswords.ui.sync.SyncViewModel78import com.peachpasswords.ui.theme.ACCENT_COLORS79import com.peachpasswords.ui.theme.PeachSpacing80import com.peachpasswords.ui.theme.PeachType81import com.peachpasswords.ui.updates.ChangelogPhase82import com.peachpasswords.ui.updates.UpdatePhase83import com.peachpasswords.ui.updates.UpdateViewModel84import com.peachpasswords.updates.compareVersions85import androidx.hilt.navigation.compose.hiltViewModel86import com.peachpasswords.vault.VaultSettings87import com.peachpasswords.vault.VaultSnapshot88import com.peachpasswords.vault.faviconsAllowed89import kotlinx.coroutines.launch90import kotlinx.coroutines.delay91import java.text.SimpleDateFormat92import java.util.Date93import java.util.Locale9495private const val PRO_URL = "https://buy.polar.sh/polar_cl_IXSFIPojx67rcOTksn8LkH5mnU3osPHtYqBIl1eyuIz"9697internal const val FAVICON_DISCLOSURE_TEXT =98 "Peach requests site icons from DuckDuckGo. Turning this on discloses your full vault domain inventory to DuckDuckGo as icons are requested."99100101102103104105106107@Composable108fun CardBody(109 id: CardId,110 fg: Color,111 vm: SettingsViewModel,112 settings: VaultSettings,113 entriesCount: Int,114 onNavigate: (PeachNav) -> Unit,115) {116 when (id) {117 CardId.Appearance -> AppearanceBody(fg, vm, settings)118 CardId.Protection -> ProtectionBody(fg, vm, settings, onNavigate)119 CardId.Vault -> VaultBody(fg, vm, settings, entriesCount, onNavigate)120 CardId.Sync -> SyncBody(fg, onNavigate)121 CardId.Pro -> ProBody(fg, vm)122 CardId.Feedback -> FeedbackBody(fg, vm)123 }124}125126127128@Composable129private fun SubLabel(text: String, fg: Color, top: Dp = 14.dp) {130 Text(131 text,132 modifier = Modifier.padding(top = top, bottom = 4.dp),133 color = fg.copy(alpha = 0.58f),134 fontFamily = PeachType.Mono,135 fontSize = 8.sp,136 letterSpacing = 0.22.em,137 )138}139140141142143144145@Composable146private fun SettingsGroup(147 label: String,148 fg: Color,149 initiallyOpen: Boolean = true,150 top: Dp = 14.dp,151 content: @Composable () -> Unit,152) {153 var open by remember { mutableStateOf(initiallyOpen) }154 Row(155 Modifier.fillMaxWidth()156 .clip(RoundedCornerShape(6.dp))157 .clickable { open = !open }158 .padding(top = top, bottom = 4.dp),159 verticalAlignment = Alignment.CenterVertically,160 ) {161 Text(162 label,163 modifier = Modifier.weight(1f),164 color = fg.copy(alpha = 0.58f),165 fontFamily = PeachType.Mono,166 fontSize = 8.sp,167 letterSpacing = 0.22.em,168 )169 Text(170 if (open) "–" else "+",171 color = fg.copy(alpha = 0.58f),172 fontFamily = PeachType.Mono,173 fontSize = 10.sp,174 )175 }176 177 178 AnimatedVisibility(visible = open) {179 Column(Modifier.fillMaxWidth()) { content() }180 }181}182183@Composable184private fun RowLine(185 fg: Color,186 modifier: Modifier = Modifier,187 verticalPadding: Dp = 9.dp,188 content: @Composable RowScope.() -> Unit,189) {190 Row(191 Modifier.fillMaxWidth().then(modifier).padding(vertical = verticalPadding),192 verticalAlignment = Alignment.CenterVertically,193 horizontalArrangement = Arrangement.SpaceBetween,194 content = content,195 )196 Box(Modifier.fillMaxWidth().height(1.dp).background(fg.copy(alpha = 0.12f)))197}198199@Composable200private fun RowScope.Name(text: String, fg: Color) {201 Text(text, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp, modifier = Modifier.weight(1f))202}203204@Composable205private fun ValueText(text: String, fg: Color, modifier: Modifier = Modifier) {206 Text(text, color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Mono, fontSize = 11.sp, modifier = modifier)207}208209@Composable210private fun SubtleButton(label: String, fg: Color, onClick: () -> Unit) {211 Box(212 Modifier.clip(RoundedCornerShape(8.dp))213 .border(1.dp, fg.copy(alpha = 0.28f), RoundedCornerShape(8.dp))214 .background(fg.copy(alpha = 0.08f))215 .clickable(onClick = onClick)216 .padding(horizontal = 12.dp, vertical = 6.dp),217 ) {218 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 11.sp, maxLines = 1)219 }220}221222@Composable223private fun SyncDisclosure(224 title: String,225 summary: String,226 expanded: Boolean,227 fg: Color,228 onToggle: () -> Unit,229) {230 Row(231 modifier = Modifier232 .fillMaxWidth()233 .heightIn(min = 48.dp)234 .clip(RoundedCornerShape(8.dp))235 .clickable(onClick = onToggle)236 .padding(vertical = 8.dp),237 verticalAlignment = Alignment.CenterVertically,238 ) {239 Column(Modifier.weight(1f)) {240 Text(241 title.uppercase(),242 color = fg.copy(alpha = 0.58f),243 fontFamily = PeachType.Mono,244 fontSize = 8.sp,245 letterSpacing = 0.22.em,246 )247 Text(248 summary,249 color = fg.copy(alpha = 0.7f),250 fontFamily = PeachType.Body,251 fontSize = 11.sp,252 modifier = Modifier.padding(top = 3.dp),253 )254 }255 Text(256 if (expanded) "hide" else "show",257 color = fg,258 fontFamily = PeachType.Mono,259 fontSize = 10.sp,260 )261 }262}263264@Composable265private fun Toggle(on: Boolean, fg: Color, onToggle: (Boolean) -> Unit) {266 val knob by animateDpAsState(if (on) 16.dp else 2.dp, label = "knob")267 Box(268 Modifier.size(width = 34.dp, height = 20.dp).clip(RoundedCornerShape(999.dp))269 .background(if (on) fg.copy(alpha = 0.28f) else fg.copy(alpha = 0.08f))270 .border(1.dp, fg.copy(alpha = if (on) 0.5f else 0.32f), RoundedCornerShape(999.dp))271 .clickable { onToggle(!on) },272 ) {273 Box(274 Modifier.padding(top = 2.dp).width(16.dp).fillMaxWidth().height(16.dp)275 .padding(start = knob - 2.dp)276 .size(14.dp).clip(CircleShape)277 .background(if (on) fg else fg.copy(alpha = 0.58f)),278 )279 }280}281282@Composable283private fun Pill(label: String, active: Boolean, fg: Color, onClick: () -> Unit) {284 Box(285 Modifier.clip(RoundedCornerShape(999.dp))286 .border(1.dp, fg.copy(alpha = if (active) 0.55f else 0.32f), RoundedCornerShape(999.dp))287 .background(if (active) fg.copy(alpha = 0.18f) else Color.Transparent)288 .clickable(onClick = onClick)289 .padding(horizontal = 12.dp, vertical = 5.dp),290 ) {291 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)292 }293}294295@Composable296private fun ProBadge(fg: Color) {297 Box(298 Modifier.padding(start = 6.dp).clip(RoundedCornerShape(4.dp))299 .background(fg.copy(alpha = 0.16f)).padding(horizontal = 5.dp, vertical = 1.dp),300 ) {301 Text("Pro", color = fg.copy(alpha = 0.85f), fontFamily = PeachType.Mono, fontSize = 8.sp)302 }303}304305@Composable306private fun Hint(text: String, fg: Color) {307 Text(308 text,309 modifier = Modifier.padding(top = 6.dp),310 color = fg.copy(alpha = 0.6f),311 fontFamily = PeachType.Display,312 fontStyle = FontStyle.Italic,313 fontSize = 11.5.sp,314 lineHeight = 16.sp,315 )316}317318319320@OptIn(ExperimentalLayoutApi::class)321@Composable322private fun AppearanceBody(fg: Color, vm: SettingsViewModel, s: VaultSettings) {323 var showFaviconDisclosure by remember { mutableStateOf(false) }324 SubLabel("ACCENT", fg, top = 0.dp)325 FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {326 ACCENT_COLORS.forEach { (name, color) ->327 Box(328 Modifier.size(22.dp).clip(CircleShape).background(color)329 .border(330 if (s.accentColor == name) 2.dp else 1.dp,331 if (s.accentColor == name) fg else fg.copy(alpha = 0.2f),332 CircleShape,333 )334 .clickable { vm.setAccent(name) },335 )336 }337 }338 SubLabel("TEXT SIZE", fg)339 RowLine(fg) {340 Name("Text size", fg)341 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {342 Pill("small", s.textSize == "small", fg) { vm.setTextSize("small") }343 Pill("medium", s.textSize == "medium", fg) { vm.setTextSize("medium") }344 Pill("large", s.textSize == "large", fg) { vm.setTextSize("large") }345 }346 }347 SubLabel("UI SCALE", fg)348 RowLine(fg) {349 Name("Large-screen sizing", fg)350 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {351 Pill("compact", s.uiScale == "compact", fg) { vm.setUiScale("compact") }352 Pill("auto", s.uiScale == "auto", fg) { vm.setUiScale("auto") }353 Pill("large", s.uiScale == "large", fg) { vm.setUiScale("large") }354 }355 }356 Hint("Auto keeps foldables roomy while preventing tablet controls from inflating.", fg)357 SubLabel("ICONS", fg)358 RowLine(fg) {359 Name("Site icons", fg)360 val siteIconsAllowed = faviconsAllowed(s)361 SubtleButton(if (siteIconsAllowed) "On" else "Off", fg) {362 if (siteIconsAllowed) vm.setFaviconsEnabled(false) else showFaviconDisclosure = true363 }364 }365 if (showFaviconDisclosure) {366 AlertDialog(367 onDismissRequest = { showFaviconDisclosure = false },368 title = { Text("Enable site icons?", color = fg, fontFamily = PeachType.Body) },369 text = { Text(FAVICON_DISCLOSURE_TEXT, color = fg, fontFamily = PeachType.Body) },370 confirmButton = {371 SubtleButton("Enable", fg) {372 showFaviconDisclosure = false373 vm.setFaviconsEnabled(true)374 }375 },376 dismissButton = {377 SubtleButton("Cancel", fg) { showFaviconDisclosure = false }378 },379 )380 }381 SubLabel("MOTION", fg)382 RowLine(fg) {383 Name("Reduce motion", fg)384 SubtleButton(if (s.reduceMotion) "On" else "Off", fg) { vm.setReduceMotion(!s.reduceMotion) }385 }386}387388389390@Composable391private fun ProtectionBody(fg: Color, vm: SettingsViewModel, s: VaultSettings, onNavigate: (PeachNav) -> Unit) {392 val lockOptions = listOf(1 to "1 minute", 5 to "5 minutes", 15 to "15 minutes", 30 to "30 minutes", 0 to "Never")393 val current = s.autoLockMinutes ?: 0394 val pinEnabled by vm.pinEnabled.collectAsState()395 var pinOpen by remember { mutableStateOf(false) }396 var pinRemovalOpen by remember { mutableStateOf(false) }397 var pinMaster by remember { mutableStateOf("") }398 var pin by remember { mutableStateOf("") }399 var pinConfirm by remember { mutableStateOf("") }400 var pinRemovalMaster by remember { mutableStateOf("") }401 var pinError by remember { mutableStateOf<String?>(null) }402 val pinScope = rememberCoroutineScope()403404 SubLabel("LOCKING", fg, top = 0.dp)405 RowLine(fg) {406 Name("Allow screenshots", fg)407 Toggle(s.allowScreenshots, fg) { vm.setAllowScreenshots(it) }408 }409 RowLine(fg) {410 Name("Auto-lock after", fg)411 val idx = lockOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)412 SubtleButton(lockOptions[idx].second, fg) {413 val next = lockOptions[(idx + 1) % lockOptions.size].first414 vm.setAutoLockMinutes(if (next == 0) 0 else next)415 }416 }417 SubLabel("PIN UNLOCK", fg)418 RowLine(fg) {419 Name("Unlock with PIN", fg)420 Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) {421 ValueText(if (pinEnabled) "enabled" else "off", fg)422 SubtleButton(if (pinEnabled) "change" else "set", fg) {423 pin = ""424 pinConfirm = ""425 pinMaster = ""426 pinError = null427 pinOpen = !pinOpen428 }429 }430 }431 if (pinEnabled) {432 RowLine(fg) {433 Name("Remove PIN unlock", fg)434 SubtleButton("turn off", fg) {435 pinRemovalMaster = ""436 pinError = null437 pinRemovalOpen = !pinRemovalOpen438 }439 }440 }441 AnimatedVisibility(pinRemovalOpen) {442 Column(Modifier.fillMaxWidth().padding(top = PeachSpacing.sm), verticalArrangement = Arrangement.spacedBy(PeachSpacing.sm)) {443 PeachField(444 label = "master password",445 value = pinRemovalMaster,446 onValueChange = { pinRemovalMaster = it; pinError = null },447 keyboardType = KeyboardType.Password,448 visualTransformation = PasswordVisualTransformation(),449 )450 pinError?.let { Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }451 SubtleButton("remove PIN", fg) {452 pinScope.launch {453 val error = vm.disablePin(pinRemovalMaster)454 if (error == null) {455 pinRemovalMaster = ""456 pinRemovalOpen = false457 } else {458 pinError = error459 }460 }461 }462 }463 }464 AnimatedVisibility(pinOpen) {465 Column(Modifier.fillMaxWidth().padding(top = PeachSpacing.sm), verticalArrangement = Arrangement.spacedBy(PeachSpacing.sm)) {466 PeachField(467 label = "master password",468 value = pinMaster,469 onValueChange = { pinMaster = it; pinError = null },470 keyboardType = KeyboardType.Password,471 visualTransformation = PasswordVisualTransformation(),472 )473 PeachField(474 label = "new PIN (4–12 digits)",475 value = pin,476 onValueChange = { pin = it.filter(Char::isDigit).take(12); pinError = null },477 keyboardType = KeyboardType.NumberPassword,478 visualTransformation = PasswordVisualTransformation(),479 )480 PeachField(481 label = "confirm PIN",482 value = pinConfirm,483 onValueChange = { pinConfirm = it.filter(Char::isDigit).take(12); pinError = null },484 keyboardType = KeyboardType.NumberPassword,485 visualTransformation = PasswordVisualTransformation(),486 )487 pinError?.let { Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }488 SubtleButton("save PIN", fg) {489 pinError = if (pin != pinConfirm) "PINs do not match" else null490 if (pinError == null) pinScope.launch {491 val error = vm.savePin(pinMaster, pin)492 if (error == null) {493 pinMaster = ""494 pin = ""495 pinConfirm = ""496 pinOpen = false497 } else {498 pinError = error499 }500 }501 }502 }503 }504 SubLabel("BIOMETRICS", fg)505 val bioActivity = LocalContext.current as? androidx.fragment.app.FragmentActivity506 RowLine(fg) {507 Name("Unlock with biometrics", fg)508 Toggle(s.biometricsEnabled, fg) { on ->509 if (on && bioActivity != null) vm.enableBiometrics(bioActivity) else vm.disableBiometrics()510 }511 }512 val bioError = com.peachpasswords.ui.lock.Biometrics.statusMessage(LocalContext.current)513 if (bioError != null) {514 Text(515 bioError,516 color = com.peachpasswords.ui.theme.peachColors.Breach,517 fontFamily = PeachType.Mono, fontSize = 10.sp,518 modifier = Modifier.padding(start = 2.dp, top = 2.dp, bottom = 4.dp),519 )520 }521 SubLabel("AUTOFILL", fg)522 run {523 524 525 val ctx = LocalContext.current526 val enabled = AutofillEnablement.isEnabled(ctx)527 RowLine(fg) {528 Column(Modifier.weight(1f)) {529 Text("Fill passwords in other apps", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)530 Text(531 if (enabled) {532 "Peach is your autofill service."533 } else {534 "Android decides which app fills passwords. Turn Peach on in system settings."535 },536 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,537 modifier = Modifier.padding(top = 2.dp),538 )539 }540 if (!enabled) {541 SubtleButton("enable", fg) {542 543 544 545 runCatching { ctx.startActivity(AutofillEnablement.requestIntent(ctx)) }546 .onFailure { runCatching { ctx.startActivity(AutofillEnablement.fallbackIntent()) } }547 }548 } else {549 ValueText("on", fg)550 }551 }552 }553554 RowLine(fg) {555 Column(Modifier.weight(1f)) {556 Text("Hide autofill previews", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)557 Text(558 "Keyboard chips and suggestion rows show only Peach until tapped — no entry names or usernames over your shoulder.",559 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,560 modifier = Modifier.padding(top = 2.dp),561 )562 }563 Toggle(s.hideAutofillPreviews, fg) { vm.setHideAutofillPreviews(it) }564 }565566 SubLabel("PASSKEYS", fg)567 RowLine(fg) {568 Column(Modifier.weight(1f)) {569 Text("Credential provider", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)570 Text(571 "Peach can handle passkey sign-in and creation through Android Credential Manager.",572 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,573 modifier = Modifier.padding(top = 2.dp),574 )575 }576 Toggle(s.passkeyProviderEnabled, fg) { vm.setPasskeyProviderEnabled(it) }577 }578 RowLine(fg) {579 Name("Status", fg)580 ValueText(if (s.passkeyProviderEnabled) "enabled" else "off", fg)581 }582 SubLabel("RECOVERY", fg)583 RowLine(fg) {584 Column(Modifier.weight(1f)) {585 Text("View recovery words", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)586 Text(587 "Keep the paper copy current before rotating sync identity or replacing devices.",588 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,589 modifier = Modifier.padding(top = 2.dp),590 )591 }592 SubtleButton("view", fg) {593 if (bioActivity != null) {594 com.peachpasswords.ui.lock.Biometrics.authenticate(595 activity = bioActivity,596 title = "View recovery words",597 subtitle = "Confirm your identity to view your recovery words",598 onSuccess = { onNavigate(PeachNav.RecoveryView) },599 )600 } else onNavigate(PeachNav.RecoveryView)601 }602 }603 SubLabel("BREACH PROTECTION", fg)604 val checkingBreaches by vm.checkingBreaches.collectAsState()605 val breachResult by vm.breachResult.collectAsState()606 RowLine(fg) {607 Name("Breach monitoring", fg)608 Toggle(s.breachMonitoring, fg) { vm.setBreachMonitoring(it) }609 }610 RowLine(fg) {611 Name("Check all passwords", fg)612 SubtleButton(if (checkingBreaches) "checking..." else "run", fg) { vm.checkAllBreaches() }613 }614 breachResult?.let { result ->615 RowLine(fg) {616 Name("Last check", fg)617 ValueText(result, fg)618 }619 }620621 SubLabel("MASTER PASSWORD", fg)622 ChangePasswordRow(fg, vm)623624 SubLabel("DURESS PASSWORD", fg)625 626 627 628 629 DuressSection(fg, vm)630}631632@Composable633private fun ChangePasswordRow(fg: Color, vm: SettingsViewModel) {634 var open by remember { mutableStateOf(false) }635 var current by remember { mutableStateOf("") }636 var next by remember { mutableStateOf("") }637 var confirm by remember { mutableStateOf("") }638 var error by remember { mutableStateOf<String?>(null) }639 var done by remember { mutableStateOf(false) }640 val scope = rememberCoroutineScope()641642 RowLine(fg) {643 Name("Master password", fg)644 SubtleButton(if (open) "cancel" else "change", fg) { open = !open; error = null; done = false }645 }646 AnimatedVisibility(open) {647 Column(Modifier.fillMaxWidth().padding(top = PeachSpacing.sm), verticalArrangement = Arrangement.spacedBy(PeachSpacing.sm)) {648 PwField("current password", current, fg) { current = it }649 PwField("new password (min 12 chars)", next, fg) { next = it }650 PwField("confirm new password", confirm, fg) { confirm = it }651 error?.let { Text(it, color = Color(0xFFE5805C), fontFamily = PeachType.Mono, fontSize = 10.sp) }652 if (done) Text("password changed ✓", color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)653 SubtleButton("save new password", fg) {654 error = when {655 current.isBlank() -> "enter your current password"656 next.length < 12 -> "new password must be at least 12 characters"657 next != confirm -> "new passwords do not match"658 next == current -> "new password must differ from current"659 else -> null660 }661 if (error == null) scope.launch {662 if (vm.changePassword(current, next)) {663 current = ""; next = ""; confirm = ""; open = false; done = true664 } else error = "incorrect current password"665 }666 }667 }668 }669}670671@Composable672private fun PwField(placeholder: String, value: String, @Suppress("UNUSED_PARAMETER") fg: Color, onChange: (String) -> Unit) {673 PeachField(674 label = placeholder,675 value = value,676 onValueChange = onChange,677 keyboardType = androidx.compose.ui.text.input.KeyboardType.Password,678 visualTransformation = PasswordVisualTransformation(),679 )680}681682683684@Composable685private fun UpdatesRows(fg: Color, onNavigate: (PeachNav) -> Unit) {686 val vm: UpdateViewModel = hiltViewModel()687 val available by vm.available.collectAsState()688 val state by vm.state.collectAsState()689 val changelog by vm.changelog.collectAsState()690 var changelogOpen by remember { mutableStateOf(false) }691692 RowLine(fg) {693 Name("Version", fg)694 ValueText(BuildConfig.VERSION_NAME, fg)695 }696 RowLine(fg) {697 Column(Modifier.weight(1f)) {698 Text("Updates", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)699 Text(700 when {701 available != null -> "v${available?.version} is available"702 state.phase == UpdatePhase.Checking -> "Checking…"703 state.phase == UpdatePhase.UpToDate -> "You're on the latest version"704 state.phase == UpdatePhase.Failed -> "Couldn't reach the update server"705 else -> "Peach checks once a day and tells you when there's a new version."706 },707 color = fg.copy(alpha = 0.7f),708 fontFamily = PeachType.Body,709 fontSize = 11.sp,710 lineHeight = 16.sp,711 modifier = Modifier.padding(top = 2.dp),712 )713 }714 Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {715 SubtleButton("changelog", fg) {716 changelogOpen = !changelogOpen717 if (changelogOpen) vm.loadChangelog()718 }719 if (available != null) {720 SubtleButton("tap to install", fg) { onNavigate(PeachNav.Update) }721 } else {722 SubtleButton(if (state.phase == UpdatePhase.Checking) "checking" else "check for updates", fg) {723 vm.check()724 }725 }726 }727 }728 if (changelogOpen) {729 when (changelog.phase) {730 ChangelogPhase.Idle -> {}731 ChangelogPhase.Loading -> Text(732 "Loading changelog…",733 color = fg.copy(alpha = 0.68f),734 fontFamily = PeachType.Body,735 fontSize = 11.sp,736 modifier = Modifier.padding(vertical = 8.dp),737 )738 ChangelogPhase.Failed -> RowLine(fg) {739 Name("Couldn't reach the update server", fg)740 SubtleButton("retry", fg) { vm.loadChangelog() }741 }742 ChangelogPhase.Loaded -> Column(Modifier.fillMaxWidth()) {743 changelog.entries.forEachIndexed { index, entry ->744 Column(Modifier.fillMaxWidth().padding(vertical = 8.dp)) {745 Row(verticalAlignment = Alignment.CenterVertically) {746 Text("v${entry.version}", color = fg, fontFamily = PeachType.Mono, fontSize = 11.sp)747 if (compareVersions(entry.version, vm.currentVersion) == 0) {748 Text(" current", color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 9.sp)749 }750 }751 Text(752 entry.notes ?: "No notes for this release.",753 color = fg.copy(alpha = 0.72f),754 fontFamily = PeachType.Body,755 fontSize = 11.sp,756 lineHeight = 16.sp,757 modifier = Modifier.padding(top = 3.dp),758 )759 }760 if (index < changelog.entries.lastIndex) {761 Box(Modifier.fillMaxWidth().height(1.dp).background(fg.copy(alpha = 0.08f)))762 }763 }764 }765 }766 }767}768769@Composable770private fun VaultBody(771 fg: Color,772 vm: SettingsViewModel,773 s: VaultSettings,774 entriesCount: Int,775 onNavigate: (PeachNav) -> Unit,776) {777 val trashOptions = listOf(7 to "7 days", 30 to "30 days", 90 to "90 days", 0 to "Never")778 val current = s.trashRetentionDays ?: 0779 val isPro by vm.isPro.collectAsState()780 val dedupCount by vm.dedupCount.collectAsState()781 val dedupRunning by vm.dedupRunning.collectAsState()782 val dedupDone by vm.dedupDone.collectAsState()783 val history by vm.vaultHistory.collectAsState()784 val restoringSnapshotId by vm.restoringSnapshotId.collectAsState()785786 SettingsGroup("ENTRIES", fg, top = 0.dp) {787 RowLine(fg) { Name("Entries", fg); ValueText("$entriesCount", fg) }788 RowLine(fg) {789 Name("Duplicates", fg)790 val done = dedupDone791 if (done != null) {792 ValueText(if (done == 0) "already clean" else "removed $done", com.peachpasswords.ui.theme.peachColors.SyncOk)793 } else {794 val count = dedupCount795 val label = when {796 dedupRunning -> "scanning..."797 count == null -> "scan"798 count == 0 -> "none found"799 else -> "$count found"800 }801 SubtleButton(label, fg) {802 if (count == null || count == 0) vm.scanDuplicates()803 }804 }805 }806 if ((dedupCount ?: 0) > 0 && dedupDone == null) {807 Column(808 Modifier.fillMaxWidth()809 .padding(top = 2.dp, bottom = 8.dp)810 .clip(RoundedCornerShape(8.dp))811 .background(fg.copy(alpha = 0.08f))812 .border(1.dp, fg.copy(alpha = 0.18f), RoundedCornerShape(8.dp))813 .padding(10.dp),814 verticalArrangement = Arrangement.spacedBy(8.dp),815 ) {816 val count = dedupCount ?: 0817 Text(818 "$count duplicate ${if (count == 1) "entry" else "entries"} found. The newest copy of each will be kept; older duplicates will be moved to trash.",819 color = fg.copy(alpha = 0.82f),820 fontFamily = PeachType.Body,821 fontSize = 11.sp,822 lineHeight = 16.sp,823 )824 Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {825 SubtleButton("cancel", fg) { vm.cancelDuplicateRemoval() }826 SubtleButton(if (dedupRunning) "removing..." else "remove duplicates", fg) { vm.removeDuplicates() }827 }828 }829 }830 }831832 SettingsGroup("MAINTENANCE", fg) {833 RowLine(fg) {834 Name("Trash auto-delete", fg)835 val idx = trashOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)836 SubtleButton(trashOptions[idx].second, fg) {837 vm.setTrashRetentionDays(trashOptions[(idx + 1) % trashOptions.size].first)838 }839 }840 RowLine(fg) { Name("Advanced Vault Health", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Health) } }841 RowLine(fg) { Name("Trash", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Trash) } }842 }843844 SettingsGroup("DATA", fg) {845 RowLine(fg) { Name("Import passwords", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Import) } }846 RowLine(fg) { Name("Export backup", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Export) } }847 RowLine(fg) {848 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Peach Codex", fg); if (!isPro) ProBadge(fg) }849 SubtleButton(if (isPro) "open" else "Pro", fg) { if (isPro) onNavigate(PeachNav.CodexGenerate) }850 }851 RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } }852 }853854 SettingsGroup("UPDATES", fg) {855 UpdatesRows(fg, onNavigate)856 }857858 SettingsGroup("VAULT HISTORY", fg, initiallyOpen = false) {859 var historyShowAll by remember { mutableStateOf(false) }860 if (history.isEmpty()) {861 Text(862 "No snapshots yet. Peach saves automatically before every change — saves, syncs, and imports.",863 color = fg.copy(alpha = 0.68f),864 fontFamily = PeachType.Body,865 fontSize = 11.sp,866 lineHeight = 16.sp,867 modifier = Modifier.padding(bottom = 6.dp),868 )869 } else {870 Text(871 "Restoring locks your vault. Unlock with the password that encrypted that snapshot to confirm.",872 color = fg.copy(alpha = 0.68f),873 fontFamily = PeachType.Body,874 fontSize = 11.sp,875 lineHeight = 16.sp,876 modifier = Modifier.padding(bottom = 4.dp),877 )878 history.take(if (historyShowAll) history.size else 3).forEach { snap ->879 RowLine(fg) {880 Column(Modifier.weight(1f)) {881 Text(snapshotTimeLabel(snap.savedAt), color = fg, fontFamily = PeachType.Body, fontSize = 12.sp)882 Text(snapshotSubLabel(snap), color = fg.copy(alpha = 0.62f), fontFamily = PeachType.Mono, fontSize = 10.sp)883 }884 SubtleButton(if (restoringSnapshotId == snap.id) "..." else "restore", fg) {885 vm.restoreVaultSnapshot(snap.id)886 }887 }888 }889 if (history.size > 3) {890 RowLine(fg) {891 Name(if (historyShowAll) "show less" else "${history.size - 3} older", fg)892 SubtleButton(if (historyShowAll) "hide" else "show", fg) { historyShowAll = !historyShowAll }893 }894 }895 Text(896 "${history.size} of 5 snapshots",897 color = fg.copy(alpha = 0.58f),898 fontFamily = PeachType.Mono,899 fontSize = 10.sp,900 modifier = Modifier.padding(top = 2.dp, bottom = 6.dp),901 )902 }903 }904905 SettingsGroup("ADVANCED", fg, initiallyOpen = false) {906 RowLine(fg) {907 Name("Replace vault from backup", com.peachpasswords.ui.theme.peachColors.SyncBusy)908 SubtleButton("open", com.peachpasswords.ui.theme.peachColors.SyncBusy) { onNavigate(PeachNav.Import) }909 }910 RowLine(fg) {911 Name("Destroy vault", com.peachpasswords.ui.theme.peachColors.Breach)912 SubtleButton("destroy", com.peachpasswords.ui.theme.peachColors.Breach) { onNavigate(PeachNav.Panic) }913 }914 }915}916917private fun snapshotSubLabel(snapshot: VaultSnapshot): String {918 val count = snapshot.entryCount?.let { "up to $it ${if (it == 1) "entry" else "entries"}" }919 return listOfNotNull(count, snapshotReasonLabel(snapshot.reason)).joinToString(" · ")920}921922private fun snapshotReasonLabel(reason: String): String = when (reason) {923 "local_save" -> "saved"924 "sync_received" -> "synced"925 "import" -> "imported"926 "restore" -> "restored"927 else -> reason928}929930private fun snapshotTimeLabel(savedAt: Long): String {931 val diff = System.currentTimeMillis() - savedAt932 if (diff < 60_000) return "Just now"933 if (diff < 3_600_000) return "${diff / 60_000}m ago"934 val date = Date(savedAt)935 val today = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date())936 val thenDay = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(date)937 val time = SimpleDateFormat("h:mm a", Locale.getDefault()).format(date)938 if (today == thenDay) return "Today $time"939 val yesterday = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date(System.currentTimeMillis() - 86_400_000))940 if (yesterday == thenDay) return "Yesterday $time"941 return SimpleDateFormat("MMM d h:mm a", Locale.getDefault()).format(date)942}943944945946947948949950private const val SECURE_RESET_DISCLOSURE =951 "Peach will archive this device's old Sync trust and start the new Sync generation. " +952 "Every other device must be updated first, then re-paired with this one — they will " +953 "not continue on their own. Your vault and your recovery words are not changed."954955private fun secureResetHeadline(state: String): String = when (state) {956 LEGACY_ACTIVE -> "Legacy Sync generation"957 RESET_REQUIRED -> "Reset required"958 RESET_CONFIRMED -> "Reset not completed"959 V2_ANCHOR, REPAIRING -> "Not re-paired"960 V2_ACTIVE -> "New Sync generation"961 UNKNOWN_STATE -> "Sync generation unreadable"962 else -> "Sync generation"963}964965private fun secureResetDetail(state: String): String = when (state) {966 LEGACY_ACTIVE ->967 "This device still holds the old Sync trust. Resetting retires it for good: update " +968 "Peach on every other device, then re-pair each one."969 RESET_REQUIRED ->970 "Sync is stopped until the reset completes. Update Peach on every other device, then " +971 "reset this one and re-pair each device."972 RESET_CONFIRMED ->973 "The reset did not finish. Nothing was lost — the old trust is archived. Try again."974 V2_ANCHOR, REPAIRING ->975 "This device anchors the new Sync generation and is not re-paired yet. Pair each device " +976 "again; until then it keeps its own vault and cannot sync."977 V2_ACTIVE ->978 "This device is on the new Sync generation. Each device is re-paired individually."979 UNKNOWN_STATE ->980 "This device's Sync generation can't be read, so sync is stopped. Reinstall or contact support."981 else -> "Sync state is unavailable."982}983984@Composable985private fun SyncBody(fg: Color, onNavigate: (PeachNav) -> Unit) {986 val context = LocalContext.current987 val syncVm: SyncViewModel = hiltViewModel()988 val pairedDevices by syncVm.pairedDevices.collectAsState()989 val pendingVouched by syncVm.pendingVouched.collectAsState()990 val syncStatus by syncVm.status.collectAsState()991 val configuredRelayUrl by syncVm.privateRelayUrl.collectAsState()992 val syncMode by syncVm.syncMode.collectAsState()993 val backgroundSyncEnabled by syncVm.backgroundSyncEnabled.collectAsState()994 var notificationsAvailable by remember {995 mutableStateOf(canShowBackgroundSyncNotification(context))996 }997 var showBackgroundSyncPrompt by remember { mutableStateOf(false) }998 val scope = rememberCoroutineScope()999 var confirmUnpair by remember { mutableStateOf<String?>(null) }1000 var renamingDeviceId by remember { mutableStateOf<String?>(null) }1001 var renameDraft by remember { mutableStateOf("") }1002 var rotateConfirmOpen by remember { mutableStateOf(false) }1003 var rotating by remember { mutableStateOf(false) }1004 var rotateError by remember { mutableStateOf<String?>(null) }1005 var relayUrlDraft by remember(configuredRelayUrl) {1006 mutableStateOf(privateRelayDraftOf(configuredRelayUrl))1007 }1008 var relayUrlStatus by remember { mutableStateOf<String?>(null) }1009 var showConnection by remember { mutableStateOf(false) }1010 var showRecovery by remember { mutableStateOf(false) }10111012 SubLabel("SECURE SYNC RESET", fg)1013 val generation by syncVm.generationState.collectAsState()1014 var resetOpen by remember { mutableStateOf(false) }1015 var resetPassword by remember { mutableStateOf("") }1016 var resetError by remember { mutableStateOf<String?>(null) }1017 var resetting by remember { mutableStateOf(false) }1018 val resetOffered = generation.state == LEGACY_ACTIVE ||1019 generation.state == RESET_REQUIRED ||1020 generation.state == RESET_CONFIRMED10211022 RowLine(fg) {1023 Column(Modifier.weight(1f)) {1024 Text(secureResetHeadline(generation.state), color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1025 Text(1026 secureResetDetail(generation.state),1027 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,1028 modifier = Modifier.padding(top = 2.dp),1029 )1030 resetError?.let {1031 Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 2.dp))1032 }1033 }1034 if (resetOffered) {1035 SubtleButton("reset sync", fg) {1036 resetError = null1037 resetPassword = ""1038 resetOpen = true1039 }1040 }1041 }10421043 if (resetOpen) {1044 AlertDialog(1045 onDismissRequest = { if (!resetting) resetOpen = false },1046 title = { Text("Reset Sync on this device?", color = fg, fontFamily = PeachType.Body) },1047 text = {1048 Column(verticalArrangement = Arrangement.spacedBy(PeachSpacing.sm)) {1049 Text(1050 SECURE_RESET_DISCLOSURE,1051 color = fg.copy(alpha = 0.8f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,1052 )1053 PwField("master password", resetPassword, fg) { resetPassword = it }1054 }1055 },1056 confirmButton = {1057 SubtleButton(if (resetting) "resetting..." else "reset", peachColors.Breach) {1058 if (!resetting) scope.launch {1059 resetting = true1060 resetError = syncVm.confirmReset(resetPassword)1061 resetPassword = ""1062 resetting = false1063 if (resetError == null) resetOpen = false1064 }1065 }1066 },1067 dismissButton = {1068 SubtleButton("cancel", fg) { if (!resetting) resetOpen = false }1069 },1070 )1071 }10721073 SubLabel("ADD A DEVICE", fg, top = 0.dp)1074 RowLine(fg) {1075 Column(Modifier.weight(1f)) {1076 Text("Pair a device", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1077 Text(1078 "Either scan a QR shown on the other device, or show this device's QR for the other one to scan.",1079 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,1080 modifier = Modifier.padding(top = 2.dp),1081 )1082 }1083 1084 1085 1086 1087 SubtleButton("scan", fg) { onNavigate(PeachNav.AdoptVault) }1088 Spacer(Modifier.width(PeachSpacing.xs))1089 SubtleButton("show code", fg) { onNavigate(PeachNav.CodePair) }1090 }10911092 SubLabel("SYNC STATUS", fg)1093 val indicator = syncIndicator(syncStatus, pairedDevices.size)1094 RowLine(fg) {1095 SyncIndicatorDot(1096 indicator = indicator,1097 label = syncIndicatorLabel(indicator, syncStatus),1098 modifier = Modifier.padding(end = PeachSpacing.sm),1099 size = 8.dp,1100 )1101 Text(1102 describeSyncOutcome(syncStatus),1103 color = fg.copy(alpha = 0.7f),1104 fontFamily = PeachType.Body,1105 fontSize = 11.sp,1106 lineHeight = 16.sp,1107 modifier = Modifier.weight(1f),1108 )1109 SubtleButton(if (syncStatus.syncing) "syncing..." else "sync now", fg) {1110 if (!syncStatus.syncing) syncVm.syncNow()1111 }1112 }11131114 SubLabel("PAIRED DEVICES", fg)1115 if (pairedDevices.isEmpty()) {1116 PeachEmptyOrEndState(1117 message = "No paired devices yet.",1118 detail = "Pair a nearby phone, tablet, or browser when you're ready to sync.",1119 modifier = Modifier.padding(top = PeachSpacing.xs),1120 )1121 } else {1122 pairedDevices.forEach { d ->1123 RowLine(fg) {1124 Column(Modifier.weight(1f)) {1125 if (renamingDeviceId == d.deviceId) {1126 Box(1127 Modifier.fillMaxWidth()1128 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))1129 .padding(horizontal = 10.dp, vertical = 8.dp),1130 ) {1131 BasicTextField(1132 value = renameDraft,1133 onValueChange = { renameDraft = it.take(64) },1134 singleLine = true,1135 textStyle = TextStyle(fontFamily = PeachType.Body, fontSize = 13.sp, color = fg),1136 cursorBrush = SolidColor(fg),1137 modifier = Modifier.fillMaxWidth(),1138 )1139 }1140 } else {1141 Text(d.localAlias ?: d.deviceName ?: d.deviceId, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1142 }1143 Text(1144 "${deviceTypeLabel(d.deviceType)} · ${syncTimeLabel(d.lastSyncedAt)}${if (isSyncStale(d.lastSyncedAt)) " · not seen recently" else ""}",1145 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,1146 modifier = Modifier.padding(top = 2.dp),1147 )1148 }1149 if (confirmUnpair != d.deviceId) {1150 if (renamingDeviceId == d.deviceId) {1151 SubtleButton("cancel", fg) { renamingDeviceId = null }1152 Spacer(Modifier.width(PeachSpacing.xs))1153 SubtleButton("save", fg) {1154 if (renameDraft.isNotBlank()) {1155 syncVm.renameDevice(d.deviceId, renameDraft)1156 renamingDeviceId = null1157 }1158 }1159 } else {1160 SubtleButton("rename", fg) {1161 renameDraft = d.localAlias ?: d.deviceName ?: ""1162 renamingDeviceId = d.deviceId1163 }1164 }1165 if (renamingDeviceId != d.deviceId) {1166 Spacer(Modifier.width(PeachSpacing.xs))1167 SubtleButton("remove", fg) { confirmUnpair = d.deviceId }1168 }1169 }1170 }1171 1172 1173 1174 1175 1176 if (confirmUnpair == d.deviceId) {1177 Column(Modifier.fillMaxWidth().padding(bottom = PeachSpacing.sm)) {1178 Text(1179 "Stops this device receiving future changes. It doesn't lock it " +1180 "out of what it already has - if it's lost or stolen, also " +1181 "change your master password and generate new recovery words.",1182 color = fg.copy(alpha = 0.7f),1183 fontFamily = PeachType.Body,1184 fontSize = 11.sp,1185 lineHeight = 16.sp,1186 )1187 Row(1188 modifier = Modifier.fillMaxWidth().padding(top = PeachSpacing.sm),1189 horizontalArrangement = Arrangement.End,1190 ) {1191 SubtleButton("cancel", fg) { confirmUnpair = null }1192 Spacer(Modifier.width(PeachSpacing.sm))1193 SubtleButton("remove", peachColors.Breach) { syncVm.unpairDevice(d.deviceId); confirmUnpair = null }1194 }1195 }1196 }1197 }1198 }11991200 SyncDisclosure(1201 title = "Connection",1202 summary = "Background sync, relay, and privacy choices",1203 expanded = showConnection,1204 fg = fg,1205 onToggle = { showConnection = !showConnection },1206 )1207 if (showConnection) {1208 RowLine(fg) {1209 Column(Modifier.weight(1f)) {1210 Text("Background sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1211 Text(1212 when {1213 backgroundSyncEnabled && !notificationsAvailable ->1214 "Action needed — Android notifications are off, so background sync is not visible."1215 backgroundSyncEnabled ->1216 "On — keeps this phone reachable for paired devices."1217 else ->1218 "Off — Peach syncs only while you are using the app."1219 },1220 color = fg.copy(alpha = 0.7f),1221 fontFamily = PeachType.Body,1222 fontSize = 11.sp,1223 lineHeight = 16.sp,1224 modifier = Modifier.padding(top = 2.dp),1225 )1226 }1227 SubtleButton(1228 if (backgroundSyncEnabled && !notificationsAvailable) "allow" else "change",1229 if (backgroundSyncEnabled && !notificationsAvailable) peachColors.Breach else fg,1230 ) { showBackgroundSyncPrompt = true }1231 }1232 SyncModeRow(1233 title = "Public relay",1234 detail = "Works anywhere with nothing to set up. The relay cannot read your vault.",1235 selected = syncMode == SyncMode.PUBLIC,1236 fg = fg,1237 ) { syncVm.setSyncMode(SyncMode.PUBLIC) }1238 SyncModeRow(1239 title = "Private relay",1240 detail = "Use your own peach-relay on your own domain.",1241 selected = syncMode == SyncMode.PRIVATE,1242 fg = fg,1243 ) { syncVm.setSyncMode(SyncMode.PRIVATE) }12441245 if (syncMode == SyncMode.PRIVATE) {1246 Text(1247 "RELAY URL",1248 color = fg.copy(alpha = 0.6f),1249 fontFamily = PeachType.Mono,1250 fontSize = 8.sp,1251 letterSpacing = 0.22.em,1252 modifier = Modifier.padding(top = 8.dp),1253 )1254 Box(1255 Modifier.fillMaxWidth().padding(top = 6.dp)1256 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))1257 .padding(horizontal = 12.dp, vertical = 10.dp),1258 ) {1259 BasicTextField(1260 value = relayUrlDraft,1261 onValueChange = { relayUrlDraft = it; relayUrlStatus = null },1262 singleLine = true,1263 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 11.sp, color = fg),1264 cursorBrush = SolidColor(fg),1265 modifier = Modifier.fillMaxWidth(),1266 )1267 }1268 val needsRelayUrl = configuredRelayUrl.isEmpty()1269 RowLine(fg) {1270 val message = relayUrlStatus1271 ?: if (needsRelayUrl) {1272 "Sync is paused until you enter your relay URL."1273 } else {1274 "Only secure wss:// relays are accepted."1275 }1276 val warn = relayUrlStatus?.startsWith("Use") == true ||1277 (relayUrlStatus == null && needsRelayUrl)1278 ValueText(message, if (warn) peachColors.Breach else fg, Modifier.weight(1f))1279 Spacer(Modifier.width(PeachSpacing.xs))1280 SubtleButton("save", fg) {1281 relayUrlStatus = if (syncVm.setRelayUrl(relayUrlDraft)) {1282 relayUrlDraft = privateRelayDraftOf(syncVm.privateRelayUrl.value)1283 "Saved"1284 } else {1285 "Use a valid wss:// relay URL"1286 }1287 }1288 }1289 }12901291 SyncModeRow(1292 title = "No sync",1293 detail = "Keep this device separate and move backups by hand.",1294 selected = syncMode == SyncMode.OFF,1295 fg = fg,1296 ) { syncVm.setSyncMode(SyncMode.OFF) }1297 Hint("Pairing authorizes a device, not a cloud account.", fg)1298 }12991300 if (pendingVouched.isNotEmpty()) {1301 SubLabel("PENDING DEVICES", fg)1302 pendingVouched.forEach { dev ->1303 RowLine(fg) {1304 Column(Modifier.weight(1f)) {1305 Text(dev.deviceName, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1306 Text(1307 "Was added by another device. Allow it to sync?",1308 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,1309 modifier = Modifier.padding(top = 2.dp),1310 )1311 }1312 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {1313 SubtleButton("Allow", fg) { syncVm.confirmVouchedDevice(dev.deviceId) }1314 SubtleButton("Reject", fg) { syncVm.rejectVouchedDevice(dev.deviceId) }1315 }1316 }1317 }1318 }13191320 SyncDisclosure(1321 title = "Recovery & security",1322 summary = "For a lost or stolen device",1323 expanded = showRecovery,1324 fg = fg,1325 onToggle = { showRecovery = !showRecovery },1326 )1327 if (showRecovery) {1328 RowLine(fg) {1329 Column(Modifier.weight(1f)) {1330 Text("Re-pair this device", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1331 Text(1332 "Scan only when this populated vault previously trusted the source device.",1333 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,1334 modifier = Modifier.padding(top = 2.dp),1335 )1336 }1337 SubtleButton("scan", fg) { onNavigate(PeachNav.AdoptVault) }1338 }1339 if (rotateConfirmOpen) {1340 Hint("This disconnects every paired device and changes your 12 recovery words. You'll be shown the new words next.", peachColors.Breach)1341 rotateError?.let {1342 Text(it, color = peachColors.Breach, fontFamily = PeachType.Body, fontSize = 11.sp, modifier = Modifier.padding(top = 6.dp))1343 }1344 Row(Modifier.padding(top = 10.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {1345 SubtleButton("cancel", fg) { if (!rotating) rotateConfirmOpen = false }1346 SubtleButton(if (rotating) "rotating..." else "Rotate sync identity", peachColors.Breach) {1347 if (rotating) return@SubtleButton1348 rotating = true1349 rotateError = null1350 scope.launch {1351 val ok = syncVm.rotateSyncIdentity()1352 rotating = false1353 if (ok) {1354 rotateConfirmOpen = false1355 onNavigate(PeachNav.RecoverySetup)1356 } else {1357 rotateError = "Rotation failed. Unlock your real vault and try again."1358 }1359 }1360 }1361 }1362 } else {1363 RowLine(fg) {1364 Column(Modifier.weight(1f)) {1365 Text("Rotate sync identity", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1366 Text(1367 "Disconnects every device and replaces the keys used for sync.",1368 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,1369 modifier = Modifier.padding(top = 2.dp),1370 )1371 }1372 SubtleButton("rotate", peachColors.Breach) { rotateError = null; rotateConfirmOpen = true }1373 }1374 }1375 }13761377 if (showBackgroundSyncPrompt) {1378 BackgroundSyncDialog { enabled ->1379 showBackgroundSyncPrompt = false1380 notificationsAvailable = canShowBackgroundSyncNotification(context)1381 syncVm.setBackgroundSyncEnabled(enabled)1382 }1383 }1384}13851386private fun deviceTypeLabel(type: String?): String = when (type) {1387 "android" -> "Android"1388 "phone" -> "Phone"1389 "tablet" -> "Tablet"1390 "browser" -> "Browser"1391 else -> "Device"1392}13931394private fun syncTimeLabel(lastSyncedAt: Long?): String {1395 if (lastSyncedAt == null) return "never synced"1396 val diff = System.currentTimeMillis() - lastSyncedAt1397 if (diff < 60_000) return "just now"1398 if (diff < 3_600_000) return "${diff / 60_000}m ago"1399 if (diff < 86_400_000) return "${diff / 3_600_000}h ago"1400 return "${diff / 86_400_000}d ago"1401}14021403private fun isSyncStale(lastSyncedAt: Long?): Boolean =1404 lastSyncedAt != null && System.currentTimeMillis() - lastSyncedAt > 7L * 24L * 60L * 60L * 1000L1405140614071408@Composable1409private fun ProBody(fg: Color, vm: SettingsViewModel) {1410 val ctx = LocalContext.current1411 val isPro by vm.isPro.collectAsState()1412 if (isPro) {1413 ProActiveBody(fg, vm)1414 return1415 }1416 val features = listOf(1417 "Peach Sync" to "End-to-end encrypted",1418 "Peach Codex" to "Restore from paper",1419 "Passkeys" to "Zero-knowledge WebAuthn",1420 "Advanced Vault Health" to "Reuse · age · exposure",1421 "Canary entries" to "Detects vault compromise",1422 "Duress vault" to "Decoy under coercion",1423 )1424 Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1425 Text(1426 "Everything, everywhere.",1427 modifier = Modifier.padding(top = 8.dp),1428 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp,1429 )1430 Text(1431 "One key unlocks every Pro feature — for the lifetime of the app.",1432 modifier = Modifier.padding(top = 6.dp),1433 color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,1434 )1435 Spacer(Modifier.height(10.dp))1436 features.forEachIndexed { i, (name, desc) ->1437 1438 1439 1440 1441 RowLine(fg, verticalPadding = 6.dp) {1442 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {1443 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))1444 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1445 }1446 Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)1447 }1448 }1449 Spacer(Modifier.height(12.dp))1450 Text(1451 "$39",1452 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp,1453 )1454 Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em)1455 Spacer(Modifier.height(10.dp))1456 Box(1457 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1458 .background(fg.copy(alpha = 0.16f))1459 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1460 .clickable {1461 runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) }1462 }1463 .padding(vertical = 12.dp),1464 contentAlignment = Alignment.Center,1465 ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }14661467 1468 1469 1470 1471 Spacer(Modifier.height(44.dp))14721473 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1474 var key by remember { mutableStateOf("") }1475 val activating by vm.activating.collectAsState()1476 val activationError by vm.activationError.collectAsState()1477 Box(1478 Modifier.fillMaxWidth().padding(top = 6.dp)1479 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))1480 .padding(horizontal = 12.dp, vertical = 10.dp),1481 ) {1482 BasicTextField(1483 value = key,1484 1485 1486 1487 1488 onValueChange = { key = it; vm.clearActivationError() },1489 singleLine = true,1490 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em, color = fg),1491 cursorBrush = SolidColor(fg),1492 modifier = Modifier.fillMaxWidth(),1493 decorationBox = { inner ->1494 if (key.isEmpty()) Text("PPK-XXXX-XXXX-XXXX", color = fg.copy(alpha = 0.3f), fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em)1495 inner()1496 },1497 )1498 }1499 if (activationError != null) {1500 Text(activationError!!, color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 6.dp))1501 }1502 Spacer(Modifier.height(8.dp))1503 Box(1504 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1505 .background(fg.copy(alpha = if (activating || key.isBlank()) 0.08f else 0.16f))1506 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1507 .clickable(enabled = !activating && key.isNotBlank()) { vm.activateLicense(key) }1508 .padding(vertical = 12.dp),1509 contentAlignment = Alignment.Center,1510 ) { Text(if (activating) "Activating…" else "Activate", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }1511}15121513@Composable1514private fun ProActiveBody(fg: Color, vm: SettingsViewModel) {1515 val ctx = LocalContext.current1516 val features = listOf("Peach Sync", "Peach Codex", "Passkeys", "Advanced Vault Health", "Canary entries", "Duress vault")1517 val licenseKey by vm.licenseKey.collectAsState()1518 val issuedAt by vm.licenseIssuedAt.collectAsState()1519 var showKey by remember { mutableStateOf(false) }1520 var copied by remember { mutableStateOf(false) }1521 val scope = rememberCoroutineScope()1522 Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {1523 com.peachpasswords.ui.components.PeachMark(size = 60.dp)1524 }1525 Text(1526 "Peach Pro",1527 modifier = Modifier.fillMaxWidth(),1528 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp,1529 textAlign = androidx.compose.ui.text.style.TextAlign.Center,1530 )1531 Text(1532 formatLicenseActiveSince(issuedAt),1533 modifier = Modifier.fillMaxWidth().padding(top = 4.dp),1534 color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em,1535 textAlign = androidx.compose.ui.text.style.TextAlign.Center,1536 )1537 licenseKey?.let { key ->1538 Spacer(Modifier.height(12.dp))1539 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1540 RowLine(fg) {1541 Text(1542 if (showKey) key else "************************",1543 color = fg.copy(alpha = if (showKey) 0.82f else 0.58f),1544 fontFamily = PeachType.Mono,1545 fontSize = 10.sp,1546 modifier = Modifier.weight(1f),1547 )1548 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {1549 SubtleButton(if (copied) "copied" else "copy", fg) {1550 PeachClipboard.copy(ctx, "peach license", key)1551 copied = true1552 scope.launch {1553 delay(1_500)1554 copied = false1555 }1556 }1557 SubtleButton(if (showKey) "hide" else "reveal", fg) { showKey = !showKey }1558 }1559 }1560 }1561 Spacer(Modifier.height(12.dp))1562 features.forEachIndexed { i, name ->1563 RowLine(fg) {1564 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {1565 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))1566 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1567 }1568 Text("unlocked", color = com.peachpasswords.ui.theme.peachColors.HealthOk, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)1569 }1570 }1571 Spacer(Modifier.height(12.dp))1572 Box(1573 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1574 .border(1.dp, com.peachpasswords.ui.theme.peachColors.Breach.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1575 .clickable { vm.deactivate() }1576 .padding(vertical = 12.dp),1577 contentAlignment = Alignment.Center,1578 ) { Text("Deactivate", color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 12.sp) }1579}15801581private fun formatLicenseActiveSince(issuedAt: Long?): String {1582 if (issuedAt == null) return "Active"1583 val monthYear = SimpleDateFormat("MMMM yyyy", Locale.getDefault()).format(Date(issuedAt))1584 return "Active since $monthYear"1585}1586158715881589@OptIn(ExperimentalLayoutApi::class)1590@Composable1591private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {1592 val categories = listOf("Bug report", "Feature request", "Question", "Other")1593 var category by remember { mutableStateOf(categories[0]) }1594 var message by remember { mutableStateOf("") }1595 val state by vm.feedbackState.collectAsState()15961597 1598 DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }15991600 if (state is FeedbackState.Sent) {1601 Box(1602 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))1603 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),1604 ) {1605 Column {1606 Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp)1607 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))1608 }1609 }1610 return1611 }16121613 val sending = state is FeedbackState.Sending16141615 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)1616 SubLabel("TYPE", fg)1617 FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1618 categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }1619 }1620 SubLabel("MESSAGE", fg)1621 Box(1622 Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp))1623 .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))1624 .padding(10.dp),1625 ) {1626 if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)1627 BasicTextField(1628 value = message, onValueChange = { message = it.take(MAX_FEEDBACK_MESSAGE_LENGTH) },1629 enabled = !sending,1630 textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),1631 cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),1632 )1633 }1634 Text(1635 "Version ${BuildConfig.VERSION_NAME} · will be included automatically",1636 modifier = Modifier.padding(top = 6.dp),1637 color = fg.copy(alpha = 0.52f),1638 fontFamily = PeachType.Mono,1639 fontSize = 10.sp,1640 lineHeight = 14.sp,1641 )1642 Spacer(Modifier.height(8.dp))16431644 Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {1645 val canSend = !sending && sanitizeFeedbackMessage(message).isNotBlank()1646 Box(1647 Modifier.clip(RoundedCornerShape(8.dp))1648 .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))1649 .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))1650 .clickable(enabled = canSend) { vm.sendFeedback(category, message) }1651 .padding(horizontal = 12.dp, vertical = 6.dp),1652 ) {1653 Text(1654 feedbackSubmitLabel(state),1655 color = fg.copy(alpha = if (canSend) 1f else 0.4f),1656 fontFamily = PeachType.Mono, fontSize = 11.sp,1657 )1658 }1659 if (sending) {1660 CircularProgressIndicator(1661 color = LocalPeachAccent.current,1662 strokeWidth = 2.dp,1663 modifier = Modifier.size(16.dp),1664 )1665 }1666 }16671668 (state as? FeedbackState.Error)?.let { err ->1669 Text(1670 err.message,1671 modifier = Modifier.padding(top = 8.dp),1672 color = peachColors.Breach,1673 fontFamily = PeachType.Mono,1674 fontSize = 11.sp,1675 lineHeight = 15.sp,1676 )1677 }16781679 Hint("Sent anonymously · no account required", fg)1680}1681168216831684@Composable1685internal fun DuressSection(fg: Color, vm: SettingsViewModel) {1686 val configured by vm.duressConfigured.collectAsState()1687 val isPro by vm.isPro.collectAsState()1688 if (configured) {1689 if (!isPro) {1690 1691 1692 Text(1693 "Duress password is active · Pro required to change or add one",1694 color = peachColors.Breach,1695 fontFamily = PeachType.Mono,1696 fontSize = 11.sp,1697 modifier = Modifier.padding(top = 6.dp),1698 )1699 Spacer(Modifier.height(8.dp))1700 }1701 DuressActiveState(fg, vm)1702 } else if (isPro) {1703 DuressForm(fg, vm)1704 } else {1705 RowLine(fg) {1706 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {1707 Name("Duress password", fg); ProBadge(fg)1708 }1709 ValueText("off", fg)1710 }1711 Hint("If entered under coercion, a decoy empty vault opens; your real vault stays hidden. Pro feature.", fg)1712 }1713}17141715@Composable1716private fun DuressActiveState(fg: Color, vm: SettingsViewModel) {1717 Text(1718 "Duress password is active",1719 color = peachColors.HealthOk,1720 fontFamily = PeachType.Mono,1721 fontSize = 11.sp,1722 modifier = Modifier.padding(top = 6.dp),1723 )1724 Spacer(Modifier.height(8.dp))1725 DuressDangerGhostButton("Disable duress password", fg) { vm.disableDuress() }1726 Hint("Entering your duress password instead of your real one triggers the action you chose.", fg)1727}17281729@Composable1730private fun DuressForm(fg: Color, vm: SettingsViewModel) {1731 var enabled by remember { mutableStateOf(false) }1732 var password by remember { mutableStateOf("") }1733 var confirm by remember { mutableStateOf("") }1734 var action by remember { mutableStateOf(DuressAction.DECOY) }1735 var error by remember { mutableStateOf<String?>(null) }1736 val scope = rememberCoroutineScope()17371738 RowLine(fg) {1739 Name("Duress password", fg)1740 Toggle(enabled, fg) { on ->1741 enabled = on1742 if (!on) { password = ""; confirm = ""; error = null }1743 }1744 }1745 Text(1746 "Entering your duress password instead of your real one opens a decoy vault or wipes the real one.",1747 color = fg.copy(alpha = 0.7f),1748 fontFamily = PeachType.Mono,1749 fontSize = 10.sp,1750 modifier = Modifier.padding(top = 6.dp),1751 )17521753 AnimatedVisibility(enabled) {1754 Column(Modifier.fillMaxWidth().padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1755 PwField("DURESS PASSPHRASE", password, fg) { password = it; error = null }1756 PwField("CONFIRM DURESS PASSPHRASE", confirm, fg) { confirm = it; error = null }17571758 Text(1759 "When your duress password is entered at the lock screen, Peach will:",1760 color = fg.copy(alpha = 0.7f),1761 fontFamily = PeachType.Mono,1762 fontSize = 10.sp,1763 modifier = Modifier.padding(top = 4.dp),1764 )17651766 DuressRadioOption("Show a decoy vault", action == DuressAction.DECOY, fg) { action = DuressAction.DECOY }1767 DuressRadioOption("Destroy the real vault", action == DuressAction.DESTROY, fg) { action = DuressAction.DESTROY }17681769 error?.let { Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }17701771 val canSave = password.isNotBlank() && confirm.isNotBlank()1772 DuressSaveButton("Save duress password", fg, canSave) {1773 error = when {1774 password.isBlank() || confirm.isBlank() -> "Enter and confirm a duress password"1775 password != confirm -> "Passwords do not match"1776 else -> null1777 }1778 if (error == null) scope.launch {1779 if (vm.saveDuress(password, action)) {1780 password = ""; confirm = ""; enabled = false1781 } else {1782 error = "Couldn't save — the duress passphrase must differ from your real password"1783 }1784 }1785 }1786 }1787 }1788}17891790@Composable1791private fun DuressRadioOption(label: String, selected: Boolean, fg: Color, onClick: () -> Unit) {1792 val accent = LocalPeachAccent.current1793 Row(1794 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)).clickable(onClick = onClick).padding(vertical = 7.dp),1795 verticalAlignment = Alignment.CenterVertically,1796 horizontalArrangement = Arrangement.spacedBy(10.dp),1797 ) {1798 Box(1799 Modifier.size(16.dp).clip(CircleShape)1800 .border(1.dp, if (selected) accent else fg.copy(alpha = 0.4f), CircleShape),1801 contentAlignment = Alignment.Center,1802 ) {1803 if (selected) Box(Modifier.size(8.dp).clip(CircleShape).background(accent))1804 }1805 Text(label, color = if (selected) accent else fg, fontFamily = PeachType.Mono, fontSize = 11.sp)1806 }1807}18081809@Composable1810private fun DuressSaveButton(label: String, fg: Color, enabled: Boolean, onClick: () -> Unit) {1811 val accent = LocalPeachAccent.current1812 val tint = if (enabled) accent else fg.copy(alpha = 0.3f)1813 Box(1814 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1815 .border(1.dp, tint.copy(alpha = if (enabled) 0.6f else 0.3f), RoundedCornerShape(8.dp))1816 .background(tint.copy(alpha = if (enabled) 0.16f else 0.06f))1817 .let { if (enabled) it.clickable(onClick = onClick) else it }1818 .padding(vertical = 11.dp),1819 contentAlignment = Alignment.Center,1820 ) {1821 Text(label, color = if (enabled) accent else fg.copy(alpha = 0.4f), fontFamily = PeachType.Mono, fontSize = 11.sp)1822 }1823}18241825@Composable1826private fun DuressDangerGhostButton(label: String, fg: Color, onClick: () -> Unit) {1827 Box(1828 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1829 .border(1.dp, peachColors.Breach.copy(alpha = 0.5f), RoundedCornerShape(8.dp))1830 .clickable(onClick = onClick)1831 .padding(vertical = 11.dp),1832 contentAlignment = Alignment.Center,1833 ) {1834 Text(label, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 11.sp)1835 }1836}183718381839@Composable1840private fun SyncModeRow(1841 title: String,1842 detail: String,1843 selected: Boolean,1844 fg: Color,1845 onSelect: () -> Unit,1846) {1847 RowLine(fg, Modifier.clickable(onClick = onSelect)) {1848 Column(Modifier.weight(1f)) {1849 Text(title, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1850 Text(1851 detail,1852 color = fg.copy(alpha = 0.7f),1853 fontFamily = PeachType.Body,1854 fontSize = 11.sp,1855 lineHeight = 16.sp,1856 modifier = Modifier.padding(top = 2.dp),1857 )1858 }1859 Text(1860 if (selected) "●" else "○",1861 color = if (selected) fg else fg.copy(alpha = 0.45f),1862 fontFamily = PeachType.Mono,1863 fontSize = 14.sp,1864 modifier = Modifier.padding(start = 10.dp),1865 )1866 }1867}