VaultSettings.kt

3.1 KB · raw

1package com.peachpasswords.vault23import kotlinx.serialization.Serializable45@Serializable6data class VaultSettings(7    val accentColor: String = "peach",8    val breachMonitoring: Boolean = true,9    val autoLockMinutes: Int? = null,10    val reduceMotion: Boolean = false,11    /** Browser-parity text size: "small" | "medium" | "large". */12    val textSize: String = "medium",13    /** Large-screen layout sizing: "compact" | "auto" | "large". */14    val uiScale: String = "auto",15    /** U1 site icons in lists; off (default) keeps the cleaner initials-only look. */16    val faviconsEnabled: Boolean = false,17    /** Version of the DuckDuckGo domain-inventory disclosure the user accepted. */18    val faviconConsentVersion: Int = 0,19    val biometricsEnabled: Boolean = false,20    val trashRetentionDays: Int? = null,21    val sortOrder: String = "url-first",22    /** Keyboard chips and suggestion rows show only "Peach" until tapped. */23    val hideAutofillPreviews: Boolean = false,24    // Default-on for new installs (Peach handles passkey sign-in / creation through25    // the Android Credential Manager). Existing users are not migrated: the stored26    // setting is preserved on load, so anyone who explicitly disabled it stays27    // off until they re-enable it in Settings → Passkeys.28    val passkeyProviderEnabled: Boolean = true,29    val shortcuts: Map<String, ShortcutBinding> = emptyMap(),30    val allowScreenshots: Boolean = false,31)3233internal const val CURRENT_FAVICON_CONSENT_VERSION = 13435/** Network-backed site icons are enabled only after consent to the current disclosure. */36fun faviconsAllowed(settings: VaultSettings): Boolean =37    settings.faviconsEnabled && settings.faviconConsentVersion >= CURRENT_FAVICON_CONSENT_VERSION3839/** Record an explicit acceptance of the current third-party favicon disclosure. */40fun grantCurrentFaviconConsent(settings: VaultSettings): VaultSettings = settings.copy(41    faviconsEnabled = true,42    faviconConsentVersion = CURRENT_FAVICON_CONSENT_VERSION,43)44/** Settings that imports may apply without changing local security policy. */45internal val IMPORT_PRESENTATION_FIELDS = listOf(46    "accentColor", "textSize", "uiScale", "sortOrder", "reduceMotion",47    "shortcuts", "hideAutofillPreviews",48)4950/** Settings imports must never override; these remain controlled by this device. */51internal val IMPORT_SECURITY_POLICY_FIELDS = listOf(52    "allowScreenshots", "faviconsEnabled", "faviconConsentVersion", "breachMonitoring",53    "autoLockMinutes", "biometricsEnabled", "passkeyProviderEnabled", "trashRetentionDays",54)5556internal fun applyImportedPresentationSettings(57    current: VaultSettings,58    imported: VaultSettings,59): VaultSettings = current.copy(60    accentColor = imported.accentColor,61    textSize = imported.textSize,62    uiScale = imported.uiScale,63    sortOrder = imported.sortOrder,64    reduceMotion = imported.reduceMotion,65    shortcuts = imported.shortcuts,66    hideAutofillPreviews = imported.hideAutofillPreviews,67)6869@Serializable70data class ShortcutBinding(71    val key: String,72    val ctrl: Boolean = false,73    val meta: Boolean = false,74    val shift: Boolean = false,75    val alt: Boolean = false,76)