PeachIntentRouter.kt

2.2 KB · raw

1package com.peachpasswords23import kotlinx.coroutines.flow.MutableStateFlow4import kotlinx.coroutines.flow.StateFlow5import kotlinx.coroutines.flow.asStateFlow67/**8 * Launch actions the app declares to the system: the three launcher shortcuts in9 * `res/xml/shortcuts.xml` and the credential-provider unlock entry point in10 * [com.peachpasswords.passkeys.PasskeyUnlockIntent]. These strings are a public11 * contract with the launcher and with system UI — they must stay byte-identical12 * to the manifest/XML, so they live in one place rather than being retyped.13 */14object PeachActions {15    const val SEARCH = "com.peachpasswords.action.SEARCH"16    const val ADD = "com.peachpasswords.action.ADD"17    const val PAIR = "com.peachpasswords.action.PAIR"18    const val PASSKEY_UNLOCK = "com.peachpasswords.passkeys.ACTION_PASSKEY_UNLOCK"19}2021/** What a launch action asks the app to do once the vault is actually open. */22enum class PendingAction { Search, AddEntry, Pair, PasskeyUnlock }2324/** Unknown/absent actions (the plain launcher icon) route nowhere — start destination wins. */25fun routeAction(action: String?): PendingAction? = when (action) {26    PeachActions.SEARCH -> PendingAction.Search27    PeachActions.ADD -> PendingAction.AddEntry28    PeachActions.PAIR -> PendingAction.Pair29    PeachActions.PASSKEY_UNLOCK -> PendingAction.PasskeyUnlock30    else -> null31}3233/**34 * Holds the action from the launch intent until the vault is unlocked. Every one35 * of these destinations needs an open vault, and a shortcut can be tapped while36 * the app is locked or not running at all, so the request has to outlive the37 * lock screen instead of being spent on it.38 *39 * ponytail: a process-scoped object rather than a Hilt singleton + ViewModel like40 * [com.peachpasswords.autofill.AutofillNavRepository]. Single activity, single41 * process, one consumer — the DI ceremony buys nothing here. Promote it if a42 * second consumer or a test that needs isolation ever appears.43 */44object PendingActionQueue {45    private val _pending = MutableStateFlow<PendingAction?>(null)46    val pending: StateFlow<PendingAction?> = _pending.asStateFlow()4748    fun request(action: PendingAction) { _pending.value = action }49    fun consume() { _pending.value = null }50}